Sen API
Sen Libraries
Loading...
Searching...
No Matches
fom_document_set.h
Go to the documentation of this file.
1// === fom_document_set.h ==============================================================================================
2// Sen Infrastructure
3// Released under the Apache License v2.0 (SPDX-License-Identifier Apache-2.0).
4// See the LICENSE.txt file for more information.
5// © Airbus SAS, Airbus Helicopters, and Airbus Defence and Space SAU/GmbH/SAS.
6// =====================================================================================================================
7
8#ifndef SEN_LIBS_CORE_SRC_LANG_FOM_DOCUMENT_SET_H
9#define SEN_LIBS_CORE_SRC_LANG_FOM_DOCUMENT_SET_H
10
11// sen
14#include "sen/core/meta/type.h"
16
17// xml parser
18#include "pugixml.hpp"
19
20// std
21#include <filesystem>
22#include <memory>
23#include <optional>
24#include <utility>
25
26namespace sen::lang
27{
28
30{
31 std::filesystem::path filePath;
32 pugi::xml_document xmlDoc;
33 std::string name;
34 std::string packageName;
35 std::vector<FomDocument*> deps;
36 std::vector<FomDocument*> mappingDeps;
37 std::vector<pugi::xml_node> definedClassesNodes;
38 std::vector<pugi::xml_node> definedInteractionNodes;
39};
40
42{
45 std::vector<ConstTypeHandle<>> storage;
46};
47
49{
50 SEN_MOVE_ONLY(FomDocumentSet)
51public:
52 using DocStorageList = std::vector<std::unique_ptr<FomDocument>>;
53
54public:
55 explicit FomDocumentSet(const std::vector<std::filesystem::path>& paths,
56 const std::vector<std::filesystem::path>& mappings,
57 TypeSettings settings);
58 ~FomDocumentSet() = default;
59
60public:
61 [[nodiscard]] std::map<const FomDocument*, std::unique_ptr<lang::TypeSet>> computeTypeSets() const;
62
63 [[nodiscard]] const lang::TypeSet& getRootTypeSet() const& noexcept { return *rootTypeSet_; }
64 [[nodiscard]] std::unique_ptr<lang::TypeSet> getRootTypeSet() && noexcept { return std::move(rootTypeSet_); }
65
66private:
67 [[nodiscard]] std::optional<std::pair<ConstTypeHandle<>, ParsedDoc*>> searchTypeSenName(
68 const std::string& qualName) const;
69
70 std::optional<std::pair<ConstTypeHandle<>, ParsedDoc*>> searchTypeFromFomNameHelper(const std::string& fomTypeName,
71 ParsedDoc* doc);
72
73 [[nodiscard]] std::optional<std::pair<ConstTypeHandle<>, ParsedDoc*>> searchTypeFromFomName(
74 const std::string& fomTypeName,
75 ParsedDoc* doc);
76
77 [[nodiscard]] FomDocument* searchDocByIdentification(const std::string& identification);
78
79private:
80 enum class CallableEnum : uint8_t
81 {
82 method,
83 event
84 };
85
86 struct FindInteractionResult
87 {
88 pugi::xpath_node node;
89 ParsedDoc* doc;
90 };
91
92private:
93 void readDocs(const std::filesystem::path& path);
94
95 void resolveDeps();
96
97 [[nodiscard]] ParsedDoc* toMutableParsedDoc(const ParsedDoc* doc) { return parsedDocs_.at(doc->doc).get(); }
98
99 [[nodiscard]] ParsedDoc* getParsedDoc(FomDocument* doc);
100
101 void populateTypes(ParsedDoc* result, FomDocument* doc);
102
103 [[nodiscard]] ConstTypeHandle<> storeType(ConstTypeHandle<> type, ParsedDoc* doc);
104
105 void createRootTypeSet();
106
107 template <typename F>
108 [[nodiscard]] ConstTypeHandle<> processTypeSource(ParsedDoc* result, const pugi::xpath_node& node, F func);
109
110 template <typename F>
111 void processTypeSource(ParsedDoc* result, const pugi::xpath_node_set& nodes, F func);
112
113 template <typename F>
114 std::optional<ConstTypeHandle<>> processTypeQuery(ParsedDoc* result,
115 const std::string& query,
116 const std::string& queryPostFix,
117 F func);
118
119 std::pair<ConstTypeHandle<>, ParsedDoc*> getOrCreateTypeFromFomName(const std::string& fomName, ParsedDoc* result);
120
121private:
122 [[nodiscard]] ConstTypeHandle<> simpleData(const pugi::xpath_node& node, ParsedDoc* doc);
123
124 [[nodiscard]] ConstTypeHandle<> arrayType(const pugi::xpath_node& node, const ParsedDoc* doc);
125
126 [[nodiscard]] ConstTypeHandle<> recordType(const pugi::xpath_node& node, ParsedDoc* doc);
127
128 [[nodiscard]] ConstTypeHandle<> variantRecord(const pugi::xpath_node& node, const ParsedDoc* doc);
129
130 [[nodiscard]] ConstTypeHandle<> enumeration(const pugi::xpath_node& node, const ParsedDoc* doc);
131
132 [[nodiscard]] ConstTypeHandle<> classNode(const pugi::xpath_node& node, ParsedDoc* doc);
133
134 void basicDataRepresentation(const pugi::xpath_node& node);
135
136private:
137 [[nodiscard]] std::string fomTypeNameToSenTypeNameUnequal(const std::string& fomTypeName) const;
138
139 [[nodiscard]] std::string fomTypeNameToSenTypeNameQual(const FomDocument* doc, const std::string& fomTypeName) const;
140
141 [[nodiscard]] ConstTypeHandle<> fomDataRepresentationToSenType(const std::string& representation) const;
142
143 [[nodiscard]] std::string prependSenPackageName(const FomDocument* doc, const std::string& str) const;
144
145 [[nodiscard]] std::vector<Arg> collectArgsFromInteractionNode(const pugi::xpath_node& interactionNode,
146 const std::vector<std::string>& ignoredParams,
147 ParsedDoc* doc);
148
149 [[nodiscard]] ConstTypeHandle<> getOrMakeStructFromInteraction(const pugi::xpath_node& node,
150 ParsedDoc* doc,
151 const std::vector<std::string>& ignoredParams);
152
153 [[nodiscard]] CallableSpec makeCallableSpec(const pugi::xpath_node& interactionNode,
154 const std::vector<std::string>& ignoredParams,
155 ParsedDoc* doc,
156 CallableEnum callableEnum,
157 bool packArguments);
158
159 [[nodiscard]] EventSpec makeEventSpec(const pugi::xpath_node& interactionNode,
160 const std::vector<std::string>& ignoredParams,
161 ParsedDoc* doc,
162 bool packArguments);
163
164 [[nodiscard]] MethodSpec makeMethodSpec(const pugi::xpath_node& interactionNode,
165 const pugi::xpath_node& returnNode,
166 const std::vector<std::string>& ignoredParams,
167 ParsedDoc* doc,
168 bool packArguments,
169 bool localOnly,
170 const std::string& qualifiedClassName);
171
172 [[nodiscard]] FindInteractionResult findInteractionNode(const std::string& path, const ParsedDoc* doc);
173
174 [[nodiscard]] FindInteractionResult findInteractionNodeInAllDocs(const std::string& path);
175
176 [[nodiscard]] ConstTypeHandle<> getOptionalPropertyType(const std::string fomElementTypeName, ParsedDoc* doc);
177
178private:
179 DocStorageList docs_;
180 std::unordered_map<FomDocument*, std::shared_ptr<ParsedDoc>> parsedDocs_;
181 std::unordered_map<std::string, ConstTypeHandle<>> representationToTypeMap_;
182 std::unordered_map<std::string, std::string> stringToSenUnitAbbrMap_;
183 std::vector<pugi::xml_document> mappingsDocs_;
184 std::unique_ptr<lang::TypeSet> rootTypeSet_;
185 std::optional<TypeHandle<ClassType>> rootClass_;
186 TypeSettings settings_;
187};
188
189} // namespace sen::lang
190
191#endif // SEN_LIBS_CORE_SRC_LANG_FOM_DOCUMENT_SET_H
A registry of custom types.
Definition type_registry.h:36
std::unique_ptr< lang::TypeSet > getRootTypeSet() &&noexcept
Definition fom_document_set.h:64
std::vector< std::unique_ptr< FomDocument > > DocStorageList
Definition fom_document_set.h:52
std::map< const FomDocument *, std::unique_ptr< lang::TypeSet > > computeTypeSets() const
FomDocumentSet(const std::vector< std::filesystem::path > &paths, const std::vector< std::filesystem::path > &mappings, TypeSettings settings)
const lang::TypeSet & getRootTypeSet() const &noexcept
Definition fom_document_set.h:63
A set of types coming from a STL file.
Definition stl_resolver.h:33
TypeHandle< const T > ConstTypeHandle
Definition type.h:319
Definition code_location.h:14
pugi::xml_document xmlDoc
Definition fom_document_set.h:32
std::string packageName
Definition fom_document_set.h:34
FomDocument * doc
Definition fom_document_set.h:43
std::string name
Definition fom_document_set.h:33
std::vector< FomDocument * > mappingDeps
Definition fom_document_set.h:36
std::filesystem::path filePath
Definition fom_document_set.h:31
std::vector< ConstTypeHandle<> > storage
Definition fom_document_set.h:45
std::vector< FomDocument * > deps
Definition fom_document_set.h:35
std::vector< pugi::xml_node > definedClassesNodes
Definition fom_document_set.h:37
std::vector< pugi::xml_node > definedInteractionNodes
Definition fom_document_set.h:38
CustomTypeRegistry registry
Definition fom_document_set.h:44
Definition fom_document_set.h:30
Definition fom_document_set.h:42
Definition stl_resolver.h:95