|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 #ifndef XMLDATAMAP |
|
18 #define XMLDATAMAP |
|
19 |
|
20 // STL related includes |
|
21 #include <stack> |
|
22 #include <list> |
|
23 //#include <unistd.h> |
|
24 using namespace std; |
|
25 |
|
26 template<typename T> |
|
27 class XMLDomainMap |
|
28 { |
|
29 // typedef T DomainObject; //satarupa |
|
30 typedef std::stack<T> DomainObjectStack; |
|
31 typedef std::list<T> DomainObjectList; |
|
32 |
|
33 public: |
|
34 XMLDomainMap() { |
|
35 } |
|
36 |
|
37 XMLDomainMap(const XMLDomainMap<T>& rhs) { |
|
38 if(&rhs == this) |
|
39 return; |
|
40 |
|
41 this->operator=(rhs); |
|
42 return; |
|
43 } |
|
44 |
|
45 virtual ~XMLDomainMap() { |
|
46 } |
|
47 |
|
48 XMLDomainMap<T>& operator=(const XMLDomainMap<T>& rhs) { |
|
49 if(&rhs == this) |
|
50 return *this; |
|
51 |
|
52 objectStack = rhs.objectStack; |
|
53 objectList = rhs.objectList; |
|
54 return *this; |
|
55 } |
|
56 |
|
57 // public interface |
|
58 void create(const std::string& name) { |
|
59 T obj(name); |
|
60 objectStack.push(obj); |
|
61 } |
|
62 |
|
63 void create(const std::string& name,const std::string& value) { |
|
64 T obj(name,value); |
|
65 objectStack.push(obj); |
|
66 } |
|
67 |
|
68 |
|
69 // called from the endElement method of SAX Handler |
|
70 void add(const std::string& name) { |
|
71 T child = objectStack.top(); |
|
72 child.name(name); |
|
73 objectStack.pop(); |
|
74 |
|
75 if(objectStack.size()) |
|
76 { |
|
77 T parent = objectStack.top(); |
|
78 objectStack.pop(); |
|
79 parent.addChild(child); |
|
80 objectStack.push(parent); |
|
81 } |
|
82 else |
|
83 { |
|
84 objectList.push_back(child); |
|
85 } |
|
86 } |
|
87 |
|
88 // called from the characters method of SAX Handler |
|
89 void updateAttribute(const std::string& v) |
|
90 { |
|
91 T obj = objectStack.top(); |
|
92 |
|
93 if((obj!= "headerfile") &&(obj != "library") && (obj != "version")) |
|
94 { |
|
95 objectStack.pop(); |
|
96 if((v.c_str()[0] == '&')||(v.c_str()[0] == '>')||(v.c_str()[0] == '<')) |
|
97 { |
|
98 string ws = obj.value(); |
|
99 ws.append(v.data()); |
|
100 obj.value(ws); |
|
101 |
|
102 } |
|
103 else |
|
104 obj.value(v); |
|
105 |
|
106 objectStack.push(obj); |
|
107 } |
|
108 } |
|
109 |
|
110 size_t size() |
|
111 { |
|
112 return objectList.size(); |
|
113 } |
|
114 |
|
115 T& root() |
|
116 { |
|
117 //DomainObjectList::iterator start = objectList.begin(); |
|
118 // return *start; |
|
119 return *(objectList.begin()); |
|
120 |
|
121 } |
|
122 |
|
123 private: |
|
124 DomainObjectStack objectStack; |
|
125 DomainObjectList objectList; |
|
126 }; |
|
127 |
|
128 #endif // XMLDATAMAP |