Skip to content

Commit 3e777f5

Browse files
author
Pavel Siska
committed
fieldHandler
1 parent 9782281 commit 3e777f5

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

new-process-api/fieldHandler.hpp

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/**
2+
* @file
3+
* @author Pavel Siska <[email protected]>
4+
* @brief Handle representing a single field within a FlowRecord.
5+
*
6+
* This file defines the FieldHandler class which provides an interface
7+
* for marking a field as available or unavailable in a FlowRecord and
8+
* querying its presence status.
9+
*
10+
* @copyright Copyright (c) 2025 CESNET, z.s.p.o.
11+
*/
12+
13+
#pragma once
14+
15+
#include "flowRecord.hpp"
16+
17+
#include <cstdint>
18+
19+
namespace ipxp {
20+
21+
/**
22+
* @brief Represents a handle to a single field within a FlowRecord.
23+
*
24+
* FieldHandler allows checking whether a field is present in a record
25+
* and provides methods to set or clear its presence flag in `FlowRecord::fieldsAvailable`.
26+
*/
27+
class FieldHandler {
28+
public:
29+
/**
30+
* @brief Sets the associated bit in the FlowRecord to indicate field availability.
31+
*
32+
* This method modifies the mutable member `fieldsAvailable` of FlowRecord even if
33+
* the FlowRecord instance is const. This is safe and intentional, as the presence
34+
* information is considered logically mutable.
35+
*
36+
* @param record Reference to FlowRecord (can be const, modifies only mutable member).
37+
*/
38+
void setAsAvailable(const FlowRecord& record) const { record.fieldsAvailable.set(m_bitIndex); }
39+
40+
/**
41+
* @brief Clears the associated bit in the FlowRecord to indicate field unavailability.
42+
*
43+
* This method modifies the mutable member `fieldsAvailable` of FlowRecord even if
44+
* the FlowRecord instance is const. This is safe and intentional, as the presence
45+
* information is considered logically mutable.
46+
*
47+
* @param record Reference to FlowRecord (can be const, modifies only mutable member).
48+
*/
49+
void setAsUnavailable(const FlowRecord& record) const
50+
{
51+
record.fieldsAvailable.reset(m_bitIndex);
52+
}
53+
54+
/**
55+
* @brief Returns the availability status of the field in the given FlowRecord.
56+
*/
57+
[[nodiscard]]
58+
bool getStatus(const FlowRecord& record) const
59+
{
60+
return record.fieldsAvailable.test(m_bitIndex);
61+
}
62+
63+
private:
64+
friend class FieldManager;
65+
66+
/// Constructor used only by FieldManager to create a valid handler.
67+
explicit constexpr FieldHandler(std::size_t bitIndex) noexcept
68+
: m_bitIndex(bitIndex)
69+
{
70+
}
71+
72+
const std::size_t m_bitIndex;
73+
};
74+
75+
} // namespace ipxp

0 commit comments

Comments
 (0)