@@ -43,6 +43,17 @@ FlattenedType::FlattenedType(Direction* dir, Type* type, const std::map<FieldDef
4343 }
4444}
4545
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+ */
4657FlattenedType* FlattenedType::createInputFlattenedType (Type* type, const std::set<FieldDefinition*>& fieldDefs) {
4758 std::map<FieldDefinition*, int > fieldMappings;
4859
@@ -60,6 +71,18 @@ FlattenedType* FlattenedType::createInputFlattenedType(Type* type, const std::se
6071 return new FlattenedType (Direction::INPUT, type, fieldMappings, requiredFields.size ());
6172}
6273
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+ */
6386FlattenedType* FlattenedType::createOutputFlattenedType (Type* type, const std::set<FieldDefinition*>& fieldDefs, FlattenedType* inputSide) {
6487 std::map<FieldDefinition*, int > fieldMappings;
6588 for (const auto & fd : fieldDefs) {
@@ -71,6 +94,16 @@ FlattenedType* FlattenedType::createOutputFlattenedType(Type* type, const std::s
7194 return new FlattenedType (Direction::OUTPUT, type, fieldMappings, inputSide->numberOfFields );
7295}
7396
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+ */
74107template <typename T>
75108bool isAllNull (const std::vector<T>& vec) {
76109 for (const auto & element : vec) {
@@ -81,6 +114,13 @@ bool isAllNull(const std::vector<T>& vec) {
81114 return true ; // If no non-null element is found, return true
82115}
83116
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+ */
84124void FlattenedType::flatten () {
85125 mapping = new FlattenedTypeRelation**[type->getRelations ().size ()];
86126
@@ -101,6 +141,17 @@ void FlattenedType::flatten() {
101141 }
102142}
103143
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+ */
104155FlattenedTypeRelation* FlattenedType::flattenPerType (Relation* relation, Type* relatedType) {
105156 std::vector<FieldLinkDefinition*> fieldLinks;
106157
@@ -128,6 +179,15 @@ FlattenedTypeRelation* FlattenedType::flattenPerType(Relation* relation, Type* r
128179 new FlattenedTypeRelation (this , fieldLinks);
129180}
130181
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+ */
131191void FlattenedType::followLinks (Field* field) {
132192 for (int relationId = 0 ; relationId < type->getRelations ().size (); relationId++) {
133193 auto & ftr = mapping[relationId];
@@ -146,28 +206,76 @@ void FlattenedType::followLinks(Field* field) {
146206 }
147207}
148208
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+ */
149219void FlattenedType::followLinks (FlattenedTypeRelation* ftr, Obj* relatedObj, Field* field) {
150220 if (ftr != nullptr ) {
151221 ftr->followLinks (direction, relatedObj, field);
152222 }
153223}
154224
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+ */
155234int FlattenedType::getFieldIndex (FieldDefinition* fd) {
156235 return fields[fd->getId ()];
157236}
158237
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+ */
159245int FlattenedType::getNumberOfFields () const {
160246 return numberOfFields;
161247}
162248
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+ */
163256Type* FlattenedType::getType () const {
164257 return type;
165258}
166259
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+ */
167267FieldDefinition*** FlattenedType::getFieldsReverse () {
168268 return fieldsReverse;
169269}
170270
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+ */
171279FieldDefinition* FlattenedType::getFieldDefinitionIdByIndex (short idx) {
172280 return fieldsReverse[idx][0 ];
173281}
0 commit comments