ADTF
Loading...
Searching...
No Matches
datamodel_xml_configurationtoxml.h
Go to the documentation of this file.
1
20
21#ifndef MAPPING_CONFIGURATION_TO_XML_FACTORY_H_INCLUDED
22#define MAPPING_CONFIGURATION_TO_XML_FACTORY_H_INCLUDED
23
27
28#include <stdexcept>
29#include <string>
30
31namespace ddl {
32namespace mapping {
33
43template <typename DomNodeType>
53
59 static void createNode(DomNodeType& parent_node, const datamodel::Header& header)
60 {
61 DomNodeType sub_node = parent_node.createChild("header");
63 sub_node, "language_version", VersionConversion::toString(header.getMappingVersion()));
64 xml_base_type::setSubNodeData(sub_node, "author", header.getAuthor());
65 xml_base_type::setSubNodeData(sub_node, "date_creation", header.getDateCreation());
66 xml_base_type::setSubNodeData(sub_node, "date_change", header.getDateChange());
67 xml_base_type::setSubNodeData(sub_node, "description", header.getDescription());
68 }
69
75 static void createNode(DomNodeType& parent_node, const datamodel::Property& property_value)
76 {
77 DomNodeType property_node = parent_node.createChild("property");
78 property_node.setAttribute("name", property_value.getName());
79 property_node.setData(property_value.getValue());
80 }
81
88 template <typename PropertiesType>
89 static void createProperties(DomNodeType& parent_node, const PropertiesType& properties)
90 {
91 DomNodeType properties_node = parent_node.createChild("properties");
92 for (const auto& current_property: properties) {
93 DomNodeType property_node = properties_node.createChild("property");
94 property_node.setAttribute("name", current_property.second->getName());
95 property_node.setData(current_property.second->getValue());
96 }
97 }
98
104 static void createNode(DomNodeType& parent_node, const datamodel::Source& source)
105 {
106 DomNodeType source_node = parent_node.createChild("source");
107 source_node.setAttribute("name", source.getName());
108 xml_base_type::template setOptionalAttribute(source_node, "source_type", source.getType());
109 createProperties(source_node, source.getProperties());
110 }
111
117 static void createNode(DomNodeType& parent_node,
118 const datamodel::ParameterValue& parameter_value)
119 {
120 DomNodeType param_value_node = parent_node.createChild("parameter_value");
121 param_value_node.setAttribute("name", parameter_value.getName());
122 if (parameter_value.getType() == datamodel::ParameterValue::Type::const_value) {
123 param_value_node.setAttribute("type", "const");
125 param_value_node, "value", parameter_value.getConstValue().value);
126 }
127 else if (parameter_value.getType() == datamodel::ParameterValue::Type::source_value) {
128 param_value_node.setAttribute("type", "source");
129 const auto source_value = parameter_value.getSourceValue();
130 xml_base_type::setSubNodeData(param_value_node, "source_name", source_value.name);
132 param_value_node, "value_name", source_value.value_name);
133 }
134 else if (parameter_value.getType() == datamodel::ParameterValue::Type::internal_value) {
135 param_value_node.setAttribute("type", "internal");
136 const auto internal_value = parameter_value.getInternalValue();
138 param_value_node, "internal_name", internal_value.name);
140 param_value_node, "value_name", internal_value.value_name);
141 }
142 }
143
149 static void createNode(DomNodeType& parent_node, const datamodel::Assignment& assignment)
150 {
151 DomNodeType assignment_node = parent_node.createChild("assignment");
152 xml_base_type::setSubNodeData(assignment_node, "to", assignment.getTo());
154 assignment_node.setAttribute("type", "const");
156 assignment_node, "value", assignment.getConstValue().value);
157 }
158 else if (assignment.getType() == datamodel::Assignment::Type::source_value) {
159 assignment_node.setAttribute("type", "source");
160 const auto source_value = assignment.getSourceValue();
161 xml_base_type::setSubNodeData(assignment_node, "source_name", source_value.name);
163 assignment_node, "value_name", source_value.value_name);
164 }
165 else if (assignment.getType() == datamodel::Assignment::Type::function_call) {
166 assignment_node.setAttribute("type", "call");
167 const auto module_call = assignment.getFunctionCall();
168 xml_base_type::setSubNodeData(assignment_node, "function", module_call.function_name);
169 for (const auto& current_param_value: assignment.getParameterValues()) {
170 createNode(assignment_node, *current_param_value);
171 }
172 }
173 else {
174 throw Error(
175 "createNode", {"assignment", assignment.getName()}, "invalid assignment type");
176 }
177 }
178
184 static void createNode(DomNodeType& parent_node, const datamodel::Trigger& trigger)
185 {
186 DomNodeType trigger_node = parent_node.createChild("trigger");
187
188 if (trigger.getType() == datamodel::Trigger::Type::source) {
189 trigger_node.setAttribute("type", "source");
191 trigger_node, "source_name", trigger.getSource().source_name);
192 }
193 else if (trigger.getType() == datamodel::Trigger::Type::period) {
194 trigger_node.setAttribute("type", "periodic");
195 const auto period = trigger.getPeriod();
196 xml_base_type::setSubNodeData(trigger_node, "time", period.time);
197 xml_base_type::setSubNodeData(trigger_node, "unit", period.unit);
198 }
199 else if (trigger.getType() == datamodel::Trigger::Type::data) {
200 trigger_node.setAttribute("type", "data");
201 const auto data = trigger.getData();
202 xml_base_type::setSubNodeData(trigger_node, "source_name", data.source_name);
203 xml_base_type::setSubNodeData(trigger_node, "value_name", data.source_value_name);
204 xml_base_type::setSubNodeData(trigger_node, "operator", data.operation);
205 xml_base_type::setSubNodeData(trigger_node, "value", data.value);
206 }
207 else {
208 throw Error("createNode", {"trigger"}, "invalid trigger type");
209 }
210 const auto time_strategy = trigger.getTimeStrategy();
211 if (!time_strategy.empty()) {
212 xml_base_type::setSubNodeData(trigger_node, "time_strategy", time_strategy);
213 }
214 }
215
221 static void createNode(DomNodeType& parent_node, const datamodel::Target& target)
222 {
223 DomNodeType target_node = parent_node.createChild("target");
224 target_node.setAttribute("name", target.getName());
225 xml_base_type::template setOptionalAttribute(target_node, "target_type", target.getType());
226
227 // Properties
228 createProperties(target_node, target.getProperties());
229
230 // Assignments
231 DomNodeType assignments_node = target_node.createChild("assignments");
232 for (const auto& current_assignment: target.getAssignments()) {
233 createNode(assignments_node, *(current_assignment));
234 }
235
236 // Triggers
237 DomNodeType triggers_node = target_node.createChild("triggers");
238 for (const auto& current_trigger: target.getTriggers()) {
239 createNode(triggers_node, *(current_trigger));
240 }
241 }
242
248 static void createNode(DomNodeType& parent_node, const datamodel::Function& function_inst)
249 {
250 DomNodeType function_node = parent_node.createChild("function");
251 function_node.setAttribute("name", function_inst.getName());
252 xml_base_type::template setOptionalAttribute(
253 function_node, "function_type", function_inst.getType());
254 createProperties(function_node, function_inst.getProperties());
255 }
256
262 static void createNode(DomNodeType& parent_node, const datamodel::MappingConfiguration& config)
263 {
264 createNode(parent_node, *(config.getHeader()));
265
266 if (config.getVersion() < Version(2, 0)) {
267 xml_mapping10_type::createNode(parent_node, config);
268 }
269 else {
270 DomNodeType sources_node = parent_node.createChild("sources");
271 // write sources
272 const auto& sources = config.getSources();
273 for (const auto& source: sources) {
274 createNode(sources_node, *(source.second));
275 }
276
277 DomNodeType targets_node = parent_node.createChild("targets");
278 // write targets
279 const auto& targets = config.getTargets();
280 for (const auto& target: targets) {
281 createNode(targets_node, *(target.second));
282 }
283
284 DomNodeType functions_node = parent_node.createChild("functions");
285 // write modules
286 const auto& functions = config.getFunctions();
287 for (const auto& func_inst: functions) {
288 createNode(functions_node, *(func_inst.second));
289 }
290 }
291 }
292};
293} // namespace mapping
294} // namespace ddl
295
296#endif // MAPPING_CONFIGURATION_TO_XML_FACTORY_H_INCLUDED
static std::string toString(const Version &version)
Version to string conversion.
Mapping Version.
Definition mapping_version.h:32
Datamodel assignment class used in Target.
Definition datamodel_configuration_items.h:912
const std::string & getName() const
Get the name of the assignment value to assign to (the same as getTo)
@ const_value
The assignment is a const value assignment.
Definition datamodel_configuration_items.h:927
@ source_value
The assignment is a source value assignment.
Definition datamodel_configuration_items.h:922
@ function_call
The assignment is a function call assignment.
Definition datamodel_configuration_items.h:932
ConstValue getConstValue() const
Get the const value if type is set to Type::const_value.
SourceValue getSourceValue() const
Get the source value if type is set to Type::source_value.
FunctionCall getFunctionCall() const
Get the function call value if type is set to Type::function_call.
const ParameterValues & getParameterValues() const
Get the ParameterValues.
const std::string & getTo() const
Get the assignment value to assign to.
Type getType() const
Get the type.
Datamodel function class used in MappingConfiguration.
Definition datamodel_configuration_items.h:1314
const std::string & getType() const
Get the type.
const Properties & getProperties() const
Get the Properties.
const std::string & getName() const
Get the name.
Datamodel header class This class is observable.
Definition datamodel_configuration_items.h:41
const std::string & getDateChange() const
Get the date of last change.
const std::string & getDateCreation() const
Get the date of creation.
const std::string & getDescription() const
Get the description.
Version getMappingVersion() const
Get the mapping version.
const std::string & getAuthor() const
Get the author.
The mapping configuration datamodel.
Definition datamodel_configuration.h:38
std::shared_ptr< const Header > getHeader() const
Get the Header object.
const Functions & getFunctions() const
Get the Functions.
Version getVersion() const
Get the Version.
const Targets & getTargets() const
Get the Targets.
const Sources & getSources() const
Get the Sources.
Datamodel parameter value class used within Assignment.
Definition datamodel_configuration_items.h:654
Type getType() const
Get the type.
const std::string & getName() const
Get the name.
InternalValue getInternalValue() const
Get the internal value if type is set to Type::internal_value.
ConstValue getConstValue() const
Get the const value if type is set to Type::const_value.
@ const_value
The parameter value is a const value.
Definition datamodel_configuration_items.h:669
@ source_value
The parameter value is a source value.
Definition datamodel_configuration_items.h:664
@ internal_value
The parameter value is a const value.
Definition datamodel_configuration_items.h:674
SourceValue getSourceValue() const
Get the source value if type is set to Type::source_value.
Datamodel property class used in Source, Target, Function.
Definition datamodel_configuration_items.h:173
const std::string & getName() const
Get the name.
const std::string & getValue() const
Get the value.
Datamodel source class used in MappingConfiguration.
Definition datamodel_configuration_items.h:262
const std::string & getType() const
Get the type.
const Properties & getProperties() const
Get the Properties.
const std::string & getName() const
Get the name.
Datamodel target class within MappingConfiguration.
Definition datamodel_configuration_items.h:1155
const std::string & getName() const
Get the name.
const Assignments & getAssignments() const
Get the Assignments.
const Triggers & getTriggers() const
Get the Triggers.
const Properties & getProperties() const
Get the Properties.
const std::string & getType() const
Get the type of the target instance to create.
Datamodel trigger class use within Target.
Definition datamodel_configuration_items.h:376
@ source
The trigger is a source trigger.
Definition datamodel_configuration_items.h:386
@ data
The trigger is a data trigger.
Definition datamodel_configuration_items.h:391
@ period
The trigger is a periodic trigger.
Definition datamodel_configuration_items.h:396
definition of the mapping namespace
Definition ddl.h:50
ddl::utility::Error Error
mapping error definition
Definition mapping_configuration_types.h:35
definition of the ddl namespace
Definition codec.h:21
Template class to create MappingConfiguration DOM nodes with the help of the type DomNodeType.
Definition datamodel_xml_configurationtoxml_10.h:158
static void createNode(DomNodeType &parent_node, const datamodel::Source &source)
Create a Node for a source.
Definition datamodel_xml_configurationtoxml_10.h:169
Template class to create MappingConfiguration DOM nodes with the help of the type DomNodeType.
Definition datamodel_xml_configurationtoxml_base.h:43
static void setOptionalSubNodeData(DomNodeType &dom_node, const std::string &sub_node_name, const std::string &value)
Set the data of the new created tag with the name sub_node_name.
Definition datamodel_xml_configurationtoxml_base.h:107
static void setSubNodeData(DomNodeType &dom_node, const std::string &sub_node_name, const std::string &value)
Set the data of the new created tag with the name sub_node_name.
Definition datamodel_xml_configurationtoxml_base.h:93
Template class to create MappingConfiguration DOM nodes with the help of the type DomNodeType.
Definition datamodel_xml_configurationtoxml.h:44
static void createNode(DomNodeType &parent_node, const datamodel::Source &source)
Create a Node for a source.
Definition datamodel_xml_configurationtoxml.h:104
MappingConfigurationToXMLFactoryBase< DomNodeType > xml_base_type
base factory type for xml writing
Definition datamodel_xml_configurationtoxml.h:48
static void createNode(DomNodeType &parent_node, const datamodel::Target &target)
Create a Node for a Target.
Definition datamodel_xml_configurationtoxml.h:221
static void createNode(DomNodeType &parent_node, const datamodel::MappingConfiguration &config)
Create a Node for the MappingConfiguration.
Definition datamodel_xml_configurationtoxml.h:262
static void createNode(DomNodeType &parent_node, const datamodel::Header &header)
Create a Node for the header.
Definition datamodel_xml_configurationtoxml.h:59
MappingConfigurationToXMLFactory10< DomNodeType > xml_mapping10_type
mapping10 xml writing factory type for compatibility of mapping 1.0 definition
Definition datamodel_xml_configurationtoxml.h:52
static void createNode(DomNodeType &parent_node, const datamodel::Function &function_inst)
Create a Node for a Funtion.
Definition datamodel_xml_configurationtoxml.h:248
static void createNode(DomNodeType &parent_node, const datamodel::ParameterValue &parameter_value)
Create a Node for a ParameterValue.
Definition datamodel_xml_configurationtoxml.h:117
static void createNode(DomNodeType &parent_node, const datamodel::Property &property_value)
Create a Node for a property.
Definition datamodel_xml_configurationtoxml.h:75
static void createNode(DomNodeType &parent_node, const datamodel::Assignment &assignment)
Create a Node for an Assignment.
Definition datamodel_xml_configurationtoxml.h:149
static void createNode(DomNodeType &parent_node, const datamodel::Trigger &trigger)
Create a Node for a Trigger.
Definition datamodel_xml_configurationtoxml.h:184
static void createProperties(DomNodeType &parent_node, const PropertiesType &properties)
Create a the properties nodes.
Definition datamodel_xml_configurationtoxml.h:89
std::string value
the const value
Definition datamodel_configuration_items.h:700