Initialize Tizen 2.3
[framework/web/wrt-installer.git] / src_mobile / configuration_parser / element_parser.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 /**
17  * @file        element_parser.h
18  * @author      Lukasz Wrzosek (l.wrzosek@samsung.com)
19  * @version     0.1
20  * @brief
21  */
22 #ifndef ELEMENT_PARSER_H_
23 #define ELEMENT_PARSER_H_
24
25 #include <map>
26 #include <string>
27 #include <cstring>
28 #include <memory>
29
30 #include <dpl/fast_delegate.h>
31 #include <dpl/exception.h>
32 #include <dpl/optional.h>
33 #include <dpl/string.h>
34 #include <dpl/shared_ptr.h>
35 #include <dpl/enable_shared_from_this.h>
36
37 struct XmlAttribute
38 {
39     DPL::String prefix;
40     DPL::String name;
41     DPL::String value;
42     DPL::String ns;
43     DPL::String lang;
44 };
45
46 struct Element
47 {
48     DPL::String name;
49     DPL::String value;
50     DPL::String ns;
51     DPL::String lang;
52 };
53
54 struct Text
55 {
56     DPL::String value;
57     DPL::String ns;
58     DPL::String lang;
59 };
60
61 class ElementParser;
62
63 typedef std::shared_ptr<ElementParser> ElementParserPtr;
64
65 class ElementParser : public std::enable_shared_from_this<ElementParser>
66 {
67   public:
68     class Exception
69     {
70       public:
71         DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
72         DECLARE_EXCEPTION_TYPE(Base, ParseError)
73     };
74     typedef DPL::FastDelegate0<ElementParserPtr> ActionFunc;
75     typedef std::map<DPL::String, ActionFunc> FuncMap;
76
77     virtual void Accept(const Element&) = 0;
78     virtual void Accept(const XmlAttribute&) = 0;
79     virtual void Accept(const Text&) = 0;
80     virtual void Verify() = 0;
81     virtual ActionFunc GetElementParser(const DPL::String &ns,
82                                         const DPL::String &name) = 0;
83     virtual ~ElementParser()
84     {}
85
86   protected:
87     ElementParser()
88     {}
89 };
90
91 #endif // ELEMENT_PARSER_H_