Skip to content

Commit 6d58225

Browse files
Added documentation
1 parent a4cc2ab commit 6d58225

18 files changed

+1346
-61
lines changed

include/fields/abstract_function_definition.h

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
/**
2+
* @file abstract_function_definition.h
3+
* @brief Defines the AbstractFunctionDefinition class, which represents mathematical functions in the field graph.
4+
*
5+
* The AbstractFunctionDefinition class provides a base for mathematical functions
6+
* that operate on a fixed number of inputs in the field graph. It handles the
7+
* computation and propagation of updates based on input changes.
8+
*/
9+
110
#ifndef ABSTRACT_FUNCTION_DEFINITION_H
211
#define ABSTRACT_FUNCTION_DEFINITION_H
312

@@ -6,18 +15,50 @@
615
#include "fields/obj.h"
716
#include "fields/field.h"
817

18+
/**
19+
* @class AbstractFunctionDefinition
20+
* @brief Base class for mathematical functions with fixed arguments.
21+
*
22+
* The AbstractFunctionDefinition class extends FieldDefinition to provide:
23+
* - Fixed number of input arguments
24+
* - Abstract computation interface
25+
* - Update propagation logic
26+
*
27+
* This class serves as the foundation for specific mathematical operations
28+
* like addition, multiplication, or exponential functions in the field graph.
29+
*/
930
class AbstractFunctionDefinition : public FieldDefinition {
31+
1032
public:
1133
// Constructors
1234
AbstractFunctionDefinition(Type* objectType, const std::string& name, int numArgs, double tolerance);
1335

1436
// Destructor
1537
virtual ~AbstractFunctionDefinition() = default;
1638

17-
// Abstract method
39+
40+
/**
41+
* @brief Computes the update value based on input changes
42+
*
43+
* This pure virtual method must be implemented by concrete function classes
44+
* to define their specific mathematical operation.
45+
*
46+
* @param inputs Array of input values
47+
* @param updates Array of input updates
48+
* @param numInputs Number of inputs (must match constructor value)
49+
* @return The computed update value
50+
*/
1851
virtual double computeUpdate(Obj* obj, FieldLinkDefinition* fl, double u) = 0;
1952

20-
// Overridden method
53+
/**
54+
* @brief Transmits an update to connected fields
55+
*
56+
* Propagates the computed update through the field graph,
57+
* respecting tolerance thresholds and update rules.
58+
*
59+
* @param field The field being updated
60+
* @param update The update value to transmit
61+
*/
2162
void transmit(Field* targetField, FieldLinkDefinition* fl, double u) override;
2263
};
2364

include/fields/direction.h

Lines changed: 80 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/**
2+
* @file direction.h
3+
* @brief Defines the Direction interface and its implementations for field connections.
4+
*
5+
* The Direction interface and its implementations (Input and Output) provide
6+
* directionality for field connections in the field graph, enabling proper
7+
* update propagation and graph traversal.
8+
*/
19

210
#ifndef DIRECTION_H
311
#define DIRECTION_H
@@ -11,24 +19,83 @@ class FieldLinkDefinition;
1119
class FlattenedType;
1220
class Type;
1321

22+
class Field;
23+
class FieldLinkDefinition;
1424

25+
/**
26+
* @class Direction
27+
* @brief Interface for field connection directionality.
28+
*
29+
* The Direction interface defines the contract for handling directionality
30+
* in field connections. It provides:
31+
* - Direction identification
32+
* - Link traversal
33+
* - Update transmission
34+
* - Direction inversion
35+
*
36+
* This abstraction enables flexible and extensible field graph structures
37+
* with proper update propagation.
38+
*/
1539
class Direction {
1640
public:
17-
static Direction* INPUT;
18-
static Direction* OUTPUT;
41+
static Direction* INPUT; ///< Singleton instance for input direction
42+
static Direction* OUTPUT; ///< Singleton instance for output direction
43+
44+
virtual ~Direction() = default;
1945

46+
/**
47+
* @brief Gets the direction identifier
48+
*
49+
* @return The direction ID
50+
*/
2051
virtual int getDirectionId() const = 0;
52+
53+
/**
54+
* @brief Gets the inverse direction
55+
*
56+
* @return The opposite direction
57+
*/
2158
virtual Direction* invert() const = 0;
59+
60+
/**
61+
* @brief Gets the link definition for a field
62+
*
63+
* @param field The field to get the link for
64+
* @return The link definition
65+
*/
2266
virtual std::vector<FieldLinkDefinition*> getFieldLinkDefinitions(FieldDefinition* fd) const = 0;
67+
68+
/**
69+
* @brief Gets the flattened type for a given type in this direction
70+
*
71+
* Retrieves the flattened type representation associated with the given type
72+
* in the current direction (input or output). Flattened types are used to
73+
* optimize type hierarchy traversal during runtime.
74+
*
75+
* @param type The type to get the flattened representation for
76+
* @return The flattened type representation
77+
*/
2378
virtual FlattenedType* getFlattenedType(Type* type) const = 0;
79+
80+
/**
81+
* @brief Transmits an update through the connection
82+
*
83+
* @param field The field being updated
84+
* @param link The link definition
85+
* @param update The update value
86+
*/
2487
virtual void transmit(Field* originField,
2588
FieldLinkDefinition* fl,
2689
Obj* relatedObject) const = 0;
27-
28-
virtual ~Direction() = default; // Ensure proper cleanup for derived classes
2990
};
3091

31-
92+
/**
93+
* @class Input
94+
* @brief Represents an input direction in field connections.
95+
*
96+
* The Input class implements the Direction interface for input connections,
97+
* handling update reception and propagation from source to target fields.
98+
*/
3299
class Input : public Direction {
33100
public:
34101
int getDirectionId() const override;
@@ -40,7 +107,13 @@ class Input : public Direction {
40107
Obj* relatedObject) const override;
41108
};
42109

43-
110+
/**
111+
* @class Output
112+
* @brief Represents an output direction in field connections.
113+
*
114+
* The Output class implements the Direction interface for output connections,
115+
* handling update propagation from target to source fields.
116+
*/
44117
class Output : public Direction {
45118
public:
46119
int getDirectionId() const override;
@@ -52,5 +125,4 @@ class Output : public Direction {
52125
Obj* relatedObject) const override;
53126
};
54127

55-
56-
#endif //DIRECTION_H
128+
#endif // DIRECTION_H

include/fields/field.h

Lines changed: 159 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
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;
1221
class 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+
*/
1538
class Field {
1639
private:
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

2548
public:
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

Comments
 (0)