1+ /* *
2+ * @file field.h
3+ * @brief Defines the Field class, which represents runtime instances of field definitions.
4+ *
5+ * The Field class is the runtime representation of a field definition in the field graph.
6+ * It manages the current and updated values of a field, handles update propagation,
7+ * and integrates with the event queue system for asynchronous processing.
8+ */
9+
110#ifndef FIELD_H
211#define FIELD_H
312
@@ -12,47 +21,190 @@ class Queue;
1221class ProcessingPhase ;
1322
1423
24+ /* *
25+ * @class Field
26+ * @brief Runtime instance of a field definition in the field graph.
27+ *
28+ * Fields are the computational units that perform actual calculations in the field graph.
29+ * Each field:
30+ * - Maintains current and updated values
31+ * - Propagates updates to connected fields
32+ * - Integrates with the event queue for asynchronous processing
33+ * - Associates with an object in the object graph
34+ *
35+ * The field graph's event-driven nature is implemented through the QueueInterceptor,
36+ * which manages when and how updates are processed.
37+ */
1538class Field {
1639private:
17- FieldDefinition* fieldDefinition;
18- int id;
19- Obj* object;
20- double value;
21- double updatedValue;
22- bool withinUpdate;
23- QueueInterceptor* interceptor;
40+ FieldDefinition* fieldDefinition; // /< The field definition this field is an instance of
41+ int id; // /< Unique identifier for this field
42+ Obj* object; // /< The object this field is associated with
43+ double value; // /< Current value of the field
44+ double updatedValue; // /< Updated value during processing
45+ bool withinUpdate; // /< Flag indicating if field is being updated
46+ QueueInterceptor* interceptor; // /< Manages event queue integration
2447
2548public:
49+ /* *
50+ * @brief Constructs a new Field
51+ *
52+ * @param obj The object this field is associated with
53+ * @param fd The field definition this field is an instance of
54+ * @param id The unique identifier for this field
55+ */
2656 Field (Obj* obj, FieldDefinition* fd, int id);
2757
58+ /* *
59+ * @brief Gets the field's unique identifier
60+ *
61+ * @return The field ID
62+ */
2863 int getId () const ;
64+
65+ /* *
66+ * @brief Checks if the field is currently being updated
67+ *
68+ * @return true if the field is within an update operation
69+ */
2970 bool isWithinUpdate ();
71+
72+ /* *
73+ * @brief Gets the current value of the field
74+ *
75+ * @return The current value
76+ */
3077 double getValue ();
78+
79+ /* *
80+ * @brief Gets the updated value of the field
81+ *
82+ * @return The updated value
83+ */
3184 double getUpdatedValue ();
85+
86+ /* *
87+ * @brief Gets the object this field is associated with
88+ *
89+ * @return The associated object
90+ */
3291 Obj* getObject ();
3392
93+ /* *
94+ * @brief Sets the field to be queued for processing
95+ *
96+ * @param q The queue to use
97+ * @param phase The processing phase
98+ * @param isNextRound Whether to process in the next round
99+ * @return This field for method chaining
100+ */
34101 Field& setQueued (Queue* q, ProcessingPhase& phase, bool isNextRound);
35102
103+ /* *
104+ * @brief Gets the field definition this field is an instance of
105+ *
106+ * @return The field definition
107+ */
36108 FieldDefinition* getFieldDefinition ();
37109
110+ /* *
111+ * @brief Gets the tolerance threshold for this field
112+ *
113+ * @return The tolerance threshold
114+ */
38115 double getTolerance () const ;
116+
117+ /* *
118+ * @brief Gets the name of this field
119+ *
120+ * @return The field name
121+ */
39122 std::string getName () const ;
40123
124+ /* *
125+ * @brief Gets the queue interceptor for this field
126+ *
127+ * @return The queue interceptor
128+ */
41129 QueueInterceptor* getInterceptor ();
130+
131+ /* *
132+ * @brief Sets the queue interceptor for this field
133+ *
134+ * @param interceptor The queue interceptor to set
135+ */
42136 void setInterceptor (QueueInterceptor* interceptor);
43137
138+ /* *
139+ * @brief Sets the current value of the field
140+ *
141+ * @param v The value to set
142+ */
44143 void setValue (double v);
144+
145+ /* *
146+ * @brief Triggers an update to the field's value
147+ *
148+ * @param u The update value
149+ */
45150 void triggerUpdate (double u);
151+
152+ /* *
153+ * @brief Gets the current update value
154+ *
155+ * @return The update value
156+ */
46157 double getUpdate () const ;
158+
159+ /* *
160+ * @brief Propagates the current update to connected fields
161+ */
47162 void propagateUpdate ();
48163
164+ /* *
165+ * @brief Receives an update from another field
166+ *
167+ * @param u The update value
168+ */
49169 void receiveUpdate (double u);
50170
171+ /* *
172+ * @brief Converts the field to a string representation
173+ *
174+ * @return String representation
175+ */
51176 std::string toString () const ;
177+
178+ /* *
179+ * @brief Gets a string representation of the field's value
180+ *
181+ * @return Value string representation
182+ */
52183 std::string getValueString () const ;
53184
185+ /* *
186+ * @brief Checks if a field's value is considered true
187+ *
188+ * @param f The field to check
189+ * @return true if the field's value is considered true
190+ */
54191 static bool isTrue (Field* f);
192+
193+ /* *
194+ * @brief Checks if a field's value is considered true
195+ *
196+ * @param f The field to check
197+ * @param updatedValue Whether to use the updated value
198+ * @return true if the field's value is considered true
199+ */
55200 static bool isTrue (Field* f, bool updatedValue);
201+
202+ /* *
203+ * @brief Checks if a value is considered true
204+ *
205+ * @param v The value to check
206+ * @return true if the value is considered true
207+ */
56208 static bool isTrue (double v);
57209};
58210
0 commit comments