diff options
author | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
commit | 38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch) | |
tree | adca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/llxml/llxmltree.h | |
parent | README.txt (diff) | |
download | meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2 meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz |
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/llxml/llxmltree.h')
-rw-r--r-- | linden/indra/llxml/llxmltree.h | 235 |
1 files changed, 235 insertions, 0 deletions
diff --git a/linden/indra/llxml/llxmltree.h b/linden/indra/llxml/llxmltree.h new file mode 100644 index 0000000..6ce43af --- /dev/null +++ b/linden/indra/llxml/llxmltree.h | |||
@@ -0,0 +1,235 @@ | |||
1 | /** | ||
2 | * @file llxmltree.h | ||
3 | * @author Aaron Yonas, Richard Nelson | ||
4 | * @brief LLXmlTree class definition | ||
5 | * | ||
6 | * Copyright (c) 2001-2007, Linden Research, Inc. | ||
7 | * | ||
8 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
9 | * to you under the terms of the GNU General Public License, version 2.0 | ||
10 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
11 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
12 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
13 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
14 | * | ||
15 | * There are special exceptions to the terms and conditions of the GPL as | ||
16 | * it is applied to this Source Code. View the full text of the exception | ||
17 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
18 | * online at http://secondlife.com/developers/opensource/flossexception | ||
19 | * | ||
20 | * By copying, modifying or distributing this software, you acknowledge | ||
21 | * that you have read and understood your obligations described above, | ||
22 | * and agree to abide by those obligations. | ||
23 | * | ||
24 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
25 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
26 | * COMPLETENESS OR PERFORMANCE. | ||
27 | */ | ||
28 | |||
29 | #ifndef LL_LLXMLTREE_H | ||
30 | #define LL_LLXMLTREE_H | ||
31 | |||
32 | #include <map> | ||
33 | #include <list> | ||
34 | #include "llstring.h" | ||
35 | #include "llxmlparser.h" | ||
36 | #include "string_table.h" | ||
37 | |||
38 | class LLColor4; | ||
39 | class LLColor4U; | ||
40 | class LLQuaternion; | ||
41 | class LLUUID; | ||
42 | class LLVector3; | ||
43 | class LLVector3d; | ||
44 | class LLXmlTreeNode; | ||
45 | class LLXmlTreeParser; | ||
46 | |||
47 | ////////////////////////////////////////////////////////////// | ||
48 | // LLXmlTree | ||
49 | |||
50 | class LLXmlTree | ||
51 | { | ||
52 | friend class LLXmlTreeNode; | ||
53 | |||
54 | public: | ||
55 | LLXmlTree(); | ||
56 | virtual ~LLXmlTree(); | ||
57 | void cleanup(); | ||
58 | |||
59 | virtual BOOL parseFile(const std::string &path, BOOL keep_contents = TRUE); | ||
60 | |||
61 | LLXmlTreeNode* getRoot() { return mRoot; } | ||
62 | |||
63 | void dump(); | ||
64 | void dumpNode( LLXmlTreeNode* node, const LLString &prefix ); | ||
65 | |||
66 | static LLStdStringHandle addAttributeString( const std::string& name) | ||
67 | { | ||
68 | return sAttributeKeys.addString( name ); | ||
69 | } | ||
70 | |||
71 | public: | ||
72 | // global | ||
73 | static LLStdStringTable sAttributeKeys; | ||
74 | |||
75 | protected: | ||
76 | LLXmlTreeNode* mRoot; | ||
77 | |||
78 | // local | ||
79 | LLStdStringTable mNodeNames; | ||
80 | }; | ||
81 | |||
82 | ////////////////////////////////////////////////////////////// | ||
83 | // LLXmlTreeNode | ||
84 | |||
85 | class LLXmlTreeNode | ||
86 | { | ||
87 | friend class LLXmlTree; | ||
88 | friend class LLXmlTreeParser; | ||
89 | |||
90 | protected: | ||
91 | // Protected since nodes are only created and destroyed by friend classes and other LLXmlTreeNodes | ||
92 | LLXmlTreeNode( const std::string& name, LLXmlTreeNode* parent, LLXmlTree* tree ); | ||
93 | |||
94 | public: | ||
95 | virtual ~LLXmlTreeNode(); | ||
96 | |||
97 | const std::string& getName() | ||
98 | { | ||
99 | return mName; | ||
100 | } | ||
101 | BOOL hasName( const std::string& name ) | ||
102 | { | ||
103 | return mName == name; | ||
104 | } | ||
105 | |||
106 | BOOL hasAttribute( const std::string& name ); | ||
107 | |||
108 | // Fast versions use cannonical_name handlee to entru in LLXmlTree::sAttributeKeys string table | ||
109 | BOOL getFastAttributeBOOL( LLStdStringHandle cannonical_name, BOOL& value ); | ||
110 | BOOL getFastAttributeU8( LLStdStringHandle cannonical_name, U8& value ); | ||
111 | BOOL getFastAttributeS8( LLStdStringHandle cannonical_name, S8& value ); | ||
112 | BOOL getFastAttributeU16( LLStdStringHandle cannonical_name, U16& value ); | ||
113 | BOOL getFastAttributeS16( LLStdStringHandle cannonical_name, S16& value ); | ||
114 | BOOL getFastAttributeU32( LLStdStringHandle cannonical_name, U32& value ); | ||
115 | BOOL getFastAttributeS32( LLStdStringHandle cannonical_name, S32& value ); | ||
116 | BOOL getFastAttributeF32( LLStdStringHandle cannonical_name, F32& value ); | ||
117 | BOOL getFastAttributeF64( LLStdStringHandle cannonical_name, F64& value ); | ||
118 | BOOL getFastAttributeColor( LLStdStringHandle cannonical_name, LLColor4& value ); | ||
119 | BOOL getFastAttributeColor4( LLStdStringHandle cannonical_name, LLColor4& value ); | ||
120 | BOOL getFastAttributeColor4U( LLStdStringHandle cannonical_name, LLColor4U& value ); | ||
121 | BOOL getFastAttributeVector3( LLStdStringHandle cannonical_name, LLVector3& value ); | ||
122 | BOOL getFastAttributeVector3d( LLStdStringHandle cannonical_name, LLVector3d& value ); | ||
123 | BOOL getFastAttributeQuat( LLStdStringHandle cannonical_name, LLQuaternion& value ); | ||
124 | BOOL getFastAttributeUUID( LLStdStringHandle cannonical_name, LLUUID& value ); | ||
125 | BOOL getFastAttributeString( LLStdStringHandle cannonical_name, LLString& value ); | ||
126 | |||
127 | // Normal versions find 'name' in LLXmlTree::sAttributeKeys then call fast versions | ||
128 | virtual BOOL getAttributeBOOL( const std::string& name, BOOL& value ); | ||
129 | virtual BOOL getAttributeU8( const std::string& name, U8& value ); | ||
130 | virtual BOOL getAttributeS8( const std::string& name, S8& value ); | ||
131 | virtual BOOL getAttributeU16( const std::string& name, U16& value ); | ||
132 | virtual BOOL getAttributeS16( const std::string& name, S16& value ); | ||
133 | virtual BOOL getAttributeU32( const std::string& name, U32& value ); | ||
134 | virtual BOOL getAttributeS32( const std::string& name, S32& value ); | ||
135 | virtual BOOL getAttributeF32( const std::string& name, F32& value ); | ||
136 | virtual BOOL getAttributeF64( const std::string& name, F64& value ); | ||
137 | virtual BOOL getAttributeColor( const std::string& name, LLColor4& value ); | ||
138 | virtual BOOL getAttributeColor4( const std::string& name, LLColor4& value ); | ||
139 | virtual BOOL getAttributeColor4U( const std::string& name, LLColor4U& value ); | ||
140 | virtual BOOL getAttributeVector3( const std::string& name, LLVector3& value ); | ||
141 | virtual BOOL getAttributeVector3d( const std::string& name, LLVector3d& value ); | ||
142 | virtual BOOL getAttributeQuat( const std::string& name, LLQuaternion& value ); | ||
143 | virtual BOOL getAttributeUUID( const std::string& name, LLUUID& value ); | ||
144 | virtual BOOL getAttributeString( const std::string& name, LLString& value ); | ||
145 | |||
146 | const LLString& getContents() | ||
147 | { | ||
148 | return mContents; | ||
149 | } | ||
150 | LLString getTextContents(); | ||
151 | |||
152 | LLXmlTreeNode* getParent() { return mParent; } | ||
153 | LLXmlTreeNode* getFirstChild(); | ||
154 | LLXmlTreeNode* getNextChild(); | ||
155 | S32 getChildCount() { return (S32)mChildList.size(); } | ||
156 | LLXmlTreeNode* getChildByName( const std::string& name ); // returns first child with name, NULL if none | ||
157 | LLXmlTreeNode* getNextNamedChild(); // returns next child with name, NULL if none | ||
158 | |||
159 | protected: | ||
160 | const LLString* getAttribute( LLStdStringHandle name) | ||
161 | { | ||
162 | attribute_map_t::iterator iter = mAttributes.find(name); | ||
163 | return (iter == mAttributes.end()) ? 0 : iter->second; | ||
164 | } | ||
165 | |||
166 | private: | ||
167 | void addAttribute( const std::string& name, const std::string& value ); | ||
168 | void appendContents( const std::string& str ); | ||
169 | void addChild( LLXmlTreeNode* child ); | ||
170 | |||
171 | void dump( const LLString& prefix ); | ||
172 | |||
173 | protected: | ||
174 | typedef std::map<LLStdStringHandle, const LLString*> attribute_map_t; | ||
175 | attribute_map_t mAttributes; | ||
176 | |||
177 | private: | ||
178 | LLString mName; | ||
179 | LLString mContents; | ||
180 | |||
181 | typedef std::list<class LLXmlTreeNode *> child_list_t; | ||
182 | child_list_t mChildList; | ||
183 | child_list_t::iterator mChildListIter; | ||
184 | |||
185 | typedef std::multimap<LLStdStringHandle, LLXmlTreeNode *> child_map_t; | ||
186 | child_map_t mChildMap; // for fast name lookups | ||
187 | child_map_t::iterator mChildMapIter; | ||
188 | child_map_t::iterator mChildMapEndIter; | ||
189 | |||
190 | LLXmlTreeNode* mParent; | ||
191 | LLXmlTree* mTree; | ||
192 | }; | ||
193 | |||
194 | ////////////////////////////////////////////////////////////// | ||
195 | // LLXmlTreeParser | ||
196 | |||
197 | class LLXmlTreeParser : public LLXmlParser | ||
198 | { | ||
199 | public: | ||
200 | LLXmlTreeParser(LLXmlTree* tree); | ||
201 | virtual ~LLXmlTreeParser(); | ||
202 | |||
203 | BOOL parseFile(const std::string &path, LLXmlTreeNode** root, BOOL keep_contents ); | ||
204 | |||
205 | protected: | ||
206 | const std::string& tabs(); | ||
207 | |||
208 | // Overrides from LLXmlParser | ||
209 | virtual void startElement(const char *name, const char **attributes); | ||
210 | virtual void endElement(const char *name); | ||
211 | virtual void characterData(const char *s, int len); | ||
212 | virtual void processingInstruction(const char *target, const char *data); | ||
213 | virtual void comment(const char *data); | ||
214 | virtual void startCdataSection(); | ||
215 | virtual void endCdataSection(); | ||
216 | virtual void defaultData(const char *s, int len); | ||
217 | virtual void unparsedEntityDecl( | ||
218 | const char* entity_name, | ||
219 | const char* base, | ||
220 | const char* system_id, | ||
221 | const char* public_id, | ||
222 | const char* notation_name); | ||
223 | |||
224 | //template method pattern | ||
225 | virtual LLXmlTreeNode* CreateXmlTreeNode(const std::string& name, LLXmlTreeNode* parent); | ||
226 | |||
227 | protected: | ||
228 | LLXmlTree* mTree; | ||
229 | LLXmlTreeNode* mRoot; | ||
230 | LLXmlTreeNode* mCurrent; | ||
231 | BOOL mDump; // Dump parse tree to llinfos as it is read. | ||
232 | BOOL mKeepContents; | ||
233 | }; | ||
234 | |||
235 | #endif // LL_LLXMLTREE_H | ||