2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file config_generator.h
18 * @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
22 #ifndef CONFIG_GENERATOR_H_
23 #define CONFIG_GENERATOR_H_
25 #include <dpl/abstract_output.h>
26 #include <dpl/assert.h>
27 #include <dpl/exception.h>
53 * -Global attributes support xml:lang, dir
54 * -Children cardinality
58 DECLARE_EXCEPTION_TYPE(DPL::Exception, Base);
59 DECLARE_EXCEPTION_TYPE(Base, NodeCreationError);
60 DECLARE_EXCEPTION_TYPE(Base, DocCreationError);
61 DECLARE_EXCEPTION_TYPE(Base, ChildCreationError);
62 DECLARE_EXCEPTION_TYPE(Base, PropertyCreationError);
64 // ELEMENT ///////////////////////////////////////////////////////////
67 typedef std::shared_ptr<Element> ElementPtr;
70 typedef std::shared_ptr<XmlNodeWrapper> XmlNodeWrapperPtr;
74 template <Tag TagId, typename... Params>
75 ElementPtr Add(Params... parameters);
78 friend class Document;
80 // helper class for handling nodes
81 template <Tag TagId,typename... Params>
84 explicit Handler(XmlNodeWrapperPtr parent) : m_parent(parent) {}
86 XmlNodeWrapperPtr CreateNode(Params... parameters);
89 XmlNodeWrapperPtr m_parent;
92 explicit Element(XmlNodeWrapperPtr node) : m_node(node)
98 XmlNodeWrapperPtr m_node;
101 template <Tag TagId, typename... Params>
102 ElementPtr Element::Add(Params... parameters)
104 Handler<TagId,Params...> eh(m_node);
105 ElementPtr e(new Element(eh.CreateNode(parameters...)));
110 // DOCUMENT //////////////////////////////////////////////////////////
113 typedef std::shared_ptr<Document> DocumentPtr;
116 typedef std::shared_ptr<XmlDocWrapper> XmlDocWrapperPtr;
120 static DocumentPtr Create();
122 void Write(DPL::AbstractOutput& output);
124 template <Tag TagId, typename... Params>
125 ElementPtr Add(Params... parameters);
130 explicit Document(XmlDocWrapperPtr document) :
136 // helper class for handling root node
137 template <Tag TagId,typename... Params>
140 explicit Handler(XmlDocWrapperPtr document) : m_document(document) {}
142 XmlNodeWrapperPtr CreateRoot(const Params... parameters);
145 XmlDocWrapperPtr m_document;
148 XmlDocWrapperPtr m_document;
151 template <Tag TagId, typename... Params>
152 ElementPtr Document::Add(Params... parameters)
154 Handler<TagId,Params...> dh(m_document);
155 ElementPtr e(new Element(dh.CreateRoot(parameters...)));
161 #endif /* CONFIG_GENERATOR_H_ */