@@ -43,6 +43,17 @@ FlattenedType::FlattenedType(Direction* dir, Type* type, const std::map<FieldDef
43
43
}
44
44
}
45
45
46
+ /* *
47
+ * @brief Creates a flattened type for input direction
48
+ *
49
+ * This function creates a flattened type representation for the input direction.
50
+ * It takes a type and a set of field definitions, and maps the field definitions
51
+ * to their corresponding indices in the flattened type.
52
+ *
53
+ * @param type The type to flatten
54
+ * @param fieldDefs The set of field definitions to include in the flattened type
55
+ * @return A new FlattenedType object representing the input flattened type
56
+ */
46
57
FlattenedType* FlattenedType::createInputFlattenedType (Type* type, const std::set<FieldDefinition*>& fieldDefs) {
47
58
std::map<FieldDefinition*, int > fieldMappings;
48
59
@@ -60,6 +71,18 @@ FlattenedType* FlattenedType::createInputFlattenedType(Type* type, const std::se
60
71
return new FlattenedType (Direction::INPUT, type, fieldMappings, requiredFields.size ());
61
72
}
62
73
74
+ /* *
75
+ * @brief Creates a flattened type for output direction
76
+ *
77
+ * This function creates a flattened type representation for the output direction.
78
+ * It takes a type and a set of field definitions, and maps the field definitions
79
+ * to their corresponding indices in the flattened type.
80
+ *
81
+ * @param type The type to flatten
82
+ * @param fieldDefs The set of field definitions to include in the flattened type
83
+ * @param inputSide The flattened type of the input side
84
+ * @return A new FlattenedType object representing the output flattened type
85
+ */
63
86
FlattenedType* FlattenedType::createOutputFlattenedType (Type* type, const std::set<FieldDefinition*>& fieldDefs, FlattenedType* inputSide) {
64
87
std::map<FieldDefinition*, int > fieldMappings;
65
88
for (const auto & fd : fieldDefs) {
@@ -71,6 +94,16 @@ FlattenedType* FlattenedType::createOutputFlattenedType(Type* type, const std::s
71
94
return new FlattenedType (Direction::OUTPUT, type, fieldMappings, inputSide->numberOfFields );
72
95
}
73
96
97
+ /* *
98
+ * @brief Checks if all elements in a vector are null
99
+ *
100
+ * This function checks if all elements in a vector are null.
101
+ * It iterates through the vector and returns true if all elements are null,
102
+ * otherwise it returns false.
103
+ *
104
+ * @param vec The vector to check
105
+ * @return true if all elements are null, otherwise false
106
+ */
74
107
template <typename T>
75
108
bool isAllNull (const std::vector<T>& vec) {
76
109
for (const auto & element : vec) {
@@ -81,6 +114,13 @@ bool isAllNull(const std::vector<T>& vec) {
81
114
return true ; // If no non-null element is found, return true
82
115
}
83
116
117
+ /* *
118
+ * @brief Flattens the type hierarchy
119
+ *
120
+ * This function flattens the type hierarchy by creating a mapping of relations
121
+ * to their corresponding flattened type relations. It iterates through all
122
+ * relations and types to build the mapping.
123
+ */
84
124
void FlattenedType::flatten () {
85
125
mapping = new FlattenedTypeRelation**[type->getRelations ().size ()];
86
126
@@ -101,6 +141,17 @@ void FlattenedType::flatten() {
101
141
}
102
142
}
103
143
144
+ /* *
145
+ * @brief Flattens the type hierarchy per type
146
+ *
147
+ * This function flattens the type hierarchy per type by creating a mapping of
148
+ * field links for a given relation and related type. It iterates through all
149
+ * field definitions and their corresponding field link definitions to build the mapping.
150
+ *
151
+ * @param relation The relation to flatten
152
+ * @param relatedType The related type to flatten
153
+ * @return A new FlattenedTypeRelation object representing the flattened type relation
154
+ */
104
155
FlattenedTypeRelation* FlattenedType::flattenPerType (Relation* relation, Type* relatedType) {
105
156
std::vector<FieldLinkDefinition*> fieldLinks;
106
157
@@ -128,6 +179,15 @@ FlattenedTypeRelation* FlattenedType::flattenPerType(Relation* relation, Type* r
128
179
new FlattenedTypeRelation (this , fieldLinks);
129
180
}
130
181
182
+ /* *
183
+ * @brief Follows links in the flattened type
184
+ *
185
+ * This function follows links in the flattened type by iterating through all
186
+ * relations and their corresponding flattened type relations. It iterates through
187
+ * all relations and their corresponding flattened type relations to follow links.
188
+ *
189
+ * @param field The field to follow links from
190
+ */
131
191
void FlattenedType::followLinks (Field* field) {
132
192
for (int relationId = 0 ; relationId < type->getRelations ().size (); relationId++) {
133
193
auto & ftr = mapping[relationId];
@@ -146,28 +206,76 @@ void FlattenedType::followLinks(Field* field) {
146
206
}
147
207
}
148
208
209
+ /* *
210
+ * @brief Follows links in the flattened type relation
211
+ *
212
+ * This function follows links in the flattened type relation by iterating through
213
+ * all field links and their corresponding field link definitions.
214
+ *
215
+ * @param ftr The flattened type relation to follow links from
216
+ * @param relatedObj The related object to follow links from
217
+ * @param field The field to follow links from
218
+ */
149
219
void FlattenedType::followLinks (FlattenedTypeRelation* ftr, Obj* relatedObj, Field* field) {
150
220
if (ftr != nullptr ) {
151
221
ftr->followLinks (direction, relatedObj, field);
152
222
}
153
223
}
154
224
225
+ /* *
226
+ * @brief Gets the field index
227
+ *
228
+ * This function gets the field index by looking up the field definition in the
229
+ * flattened type.
230
+ *
231
+ * @param fd The field definition to get the index of
232
+ * @return The index of the field definition
233
+ */
155
234
int FlattenedType::getFieldIndex (FieldDefinition* fd) {
156
235
return fields[fd->getId ()];
157
236
}
158
237
238
+ /* *
239
+ * @brief Gets the number of fields
240
+ *
241
+ * This function gets the number of fields in the flattened type.
242
+ *
243
+ * @return The number of fields in the flattened type
244
+ */
159
245
int FlattenedType::getNumberOfFields () const {
160
246
return numberOfFields;
161
247
}
162
248
249
+ /* *
250
+ * @brief Gets the type
251
+ *
252
+ * This function gets the type in the flattened type.
253
+ *
254
+ * @return The type in the flattened type
255
+ */
163
256
Type* FlattenedType::getType () const {
164
257
return type;
165
258
}
166
259
260
+ /* *
261
+ * @brief Gets the fields reverse
262
+ *
263
+ * This function gets the fields reverse in the flattened type.
264
+ *
265
+ * @return The fields reverse in the flattened type
266
+ */
167
267
FieldDefinition*** FlattenedType::getFieldsReverse () {
168
268
return fieldsReverse;
169
269
}
170
270
271
+ /* *
272
+ * @brief Gets the field definition by index
273
+ *
274
+ * This function gets the field definition by index in the flattened type.
275
+ *
276
+ * @param idx The index of the field definition to get
277
+ * @return The field definition by index in the flattened type
278
+ */
171
279
FieldDefinition* FlattenedType::getFieldDefinitionIdByIndex (short idx) {
172
280
return fieldsReverse[idx][0 ];
173
281
}
0 commit comments