PageRenderTime 38ms CodeModel.GetById 1ms app.highlight 31ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/llxml/llxmltree.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 234 lines | 156 code | 39 blank | 39 comment | 2 complexity | f552c44bc0b3ff34af762e6add2b7210 MD5 | raw file
  1/** 
  2 * @file llxmltree.h
  3 * @author Aaron Yonas, Richard Nelson
  4 * @brief LLXmlTree class definition
  5 *
  6 * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  7 * Second Life Viewer Source Code
  8 * Copyright (C) 2010, Linden Research, Inc.
  9 * 
 10 * This library is free software; you can redistribute it and/or
 11 * modify it under the terms of the GNU Lesser General Public
 12 * License as published by the Free Software Foundation;
 13 * version 2.1 of the License only.
 14 * 
 15 * This library is distributed in the hope that it will be useful,
 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 18 * Lesser General Public License for more details.
 19 * 
 20 * You should have received a copy of the GNU Lesser General Public
 21 * License along with this library; if not, write to the Free Software
 22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 23 * 
 24 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 25 * $/LicenseInfo$
 26 */
 27
 28#ifndef LL_LLXMLTREE_H
 29#define LL_LLXMLTREE_H
 30
 31#include <map>
 32#include <list>
 33#include "llstring.h"
 34#include "llxmlparser.h"
 35#include "string_table.h"
 36
 37class LLColor4;
 38class LLColor4U;
 39class LLQuaternion;
 40class LLUUID;
 41class LLVector3;
 42class LLVector3d;
 43class LLXmlTreeNode;
 44class LLXmlTreeParser;
 45
 46//////////////////////////////////////////////////////////////
 47// LLXmlTree
 48
 49class LLXmlTree
 50{
 51	friend class LLXmlTreeNode;
 52	
 53public:
 54	LLXmlTree();
 55	virtual ~LLXmlTree();
 56	void cleanup();
 57
 58	virtual BOOL	parseFile(const std::string &path, BOOL keep_contents = TRUE);
 59
 60	LLXmlTreeNode*	getRoot() { return mRoot; }
 61
 62	void			dump();
 63	void			dumpNode( LLXmlTreeNode* node, const std::string& prefix );
 64
 65	static LLStdStringHandle addAttributeString( const std::string& name)
 66	{
 67		return sAttributeKeys.addString( name );
 68	}
 69	
 70public:
 71	// global
 72	static LLStdStringTable sAttributeKeys;
 73	
 74protected:
 75	LLXmlTreeNode* mRoot;
 76
 77	// local
 78	LLStdStringTable mNodeNames;	
 79};
 80
 81//////////////////////////////////////////////////////////////
 82// LLXmlTreeNode
 83
 84class LLXmlTreeNode
 85{
 86	friend class LLXmlTree;
 87	friend class LLXmlTreeParser;
 88
 89protected:
 90	// Protected since nodes are only created and destroyed by friend classes and other LLXmlTreeNodes
 91	LLXmlTreeNode( const std::string& name, LLXmlTreeNode* parent, LLXmlTree* tree );
 92	
 93public:
 94	virtual ~LLXmlTreeNode();
 95
 96	const std::string&	getName()
 97	{
 98		return mName;
 99	}
100	BOOL hasName( const std::string& name )
101	{
102		return mName == name;
103	}
104
105	BOOL hasAttribute( const std::string& name );
106
107	// Fast versions use cannonical_name handlee to entru in LLXmlTree::sAttributeKeys string table
108	BOOL			getFastAttributeBOOL(		LLStdStringHandle cannonical_name, BOOL& value );
109	BOOL			getFastAttributeU8(			LLStdStringHandle cannonical_name, U8& value );
110	BOOL			getFastAttributeS8(			LLStdStringHandle cannonical_name, S8& value );
111	BOOL			getFastAttributeU16(		LLStdStringHandle cannonical_name, U16& value );
112	BOOL			getFastAttributeS16(		LLStdStringHandle cannonical_name, S16& value );
113	BOOL			getFastAttributeU32(		LLStdStringHandle cannonical_name, U32& value );
114	BOOL			getFastAttributeS32(		LLStdStringHandle cannonical_name, S32& value );
115	BOOL			getFastAttributeF32(		LLStdStringHandle cannonical_name, F32& value );
116	BOOL			getFastAttributeF64(		LLStdStringHandle cannonical_name, F64& value );
117	BOOL			getFastAttributeColor(		LLStdStringHandle cannonical_name, LLColor4& value );
118	BOOL			getFastAttributeColor4(		LLStdStringHandle cannonical_name, LLColor4& value );
119	BOOL			getFastAttributeColor4U(	LLStdStringHandle cannonical_name, LLColor4U& value );
120	BOOL			getFastAttributeVector3(	LLStdStringHandle cannonical_name, LLVector3& value );
121	BOOL			getFastAttributeVector3d(	LLStdStringHandle cannonical_name, LLVector3d& value );
122	BOOL			getFastAttributeQuat(		LLStdStringHandle cannonical_name, LLQuaternion& value );
123	BOOL			getFastAttributeUUID(		LLStdStringHandle cannonical_name, LLUUID& value );
124	BOOL			getFastAttributeString(		LLStdStringHandle cannonical_name, std::string& value );
125
126	// Normal versions find 'name' in LLXmlTree::sAttributeKeys then call fast versions
127	virtual BOOL		getAttributeBOOL(		const std::string& name, BOOL& value );
128	virtual BOOL		getAttributeU8(			const std::string& name, U8& value );
129	virtual BOOL		getAttributeS8(			const std::string& name, S8& value );
130	virtual BOOL		getAttributeU16(		const std::string& name, U16& value );
131	virtual BOOL		getAttributeS16(		const std::string& name, S16& value );
132	virtual BOOL		getAttributeU32(		const std::string& name, U32& value );
133	virtual BOOL		getAttributeS32(		const std::string& name, S32& value );
134	virtual BOOL		getAttributeF32(		const std::string& name, F32& value );
135	virtual BOOL		getAttributeF64(		const std::string& name, F64& value );
136	virtual BOOL		getAttributeColor(		const std::string& name, LLColor4& value );
137	virtual BOOL		getAttributeColor4(		const std::string& name, LLColor4& value );
138	virtual BOOL		getAttributeColor4U(	const std::string& name, LLColor4U& value );
139	virtual BOOL		getAttributeVector3(	const std::string& name, LLVector3& value );
140	virtual BOOL		getAttributeVector3d(	const std::string& name, LLVector3d& value );
141	virtual BOOL		getAttributeQuat(		const std::string& name, LLQuaternion& value );
142	virtual BOOL		getAttributeUUID(		const std::string& name, LLUUID& value );
143	virtual BOOL		getAttributeString(		const std::string& name, std::string& value );
144
145	const std::string& getContents()
146	{
147		return mContents;
148	}
149	std::string getTextContents();
150
151	LLXmlTreeNode*	getParent()							{ return mParent; }
152	LLXmlTreeNode*	getFirstChild();
153	LLXmlTreeNode*	getNextChild();
154	S32				getChildCount()						{ return (S32)mChildList.size(); }
155	LLXmlTreeNode*  getChildByName( const std::string& name );	// returns first child with name, NULL if none
156	LLXmlTreeNode*  getNextNamedChild();				// returns next child with name, NULL if none
157
158protected:
159	const std::string* getAttribute( LLStdStringHandle name)
160	{
161		attribute_map_t::iterator iter = mAttributes.find(name);
162		return (iter == mAttributes.end()) ? 0 : iter->second;
163	}
164
165private:
166	void			addAttribute( const std::string& name, const std::string& value );
167	void			appendContents( const std::string& str );
168	void			addChild( LLXmlTreeNode* child );
169
170	void			dump( const std::string& prefix );
171
172protected:
173	typedef std::map<LLStdStringHandle, const std::string*> attribute_map_t;
174	attribute_map_t						mAttributes;
175
176private:
177	std::string							mName;
178	std::string							mContents;
179	
180	typedef std::list<class LLXmlTreeNode *> child_list_t;
181	child_list_t						mChildList;
182	child_list_t::iterator				mChildListIter;
183	
184	typedef std::multimap<LLStdStringHandle, LLXmlTreeNode *> child_map_t;
185	child_map_t							mChildMap;		// for fast name lookups
186	child_map_t::iterator				mChildMapIter;
187	child_map_t::iterator				mChildMapEndIter;
188
189	LLXmlTreeNode*						mParent;
190	LLXmlTree*							mTree;
191};
192
193//////////////////////////////////////////////////////////////
194// LLXmlTreeParser
195
196class LLXmlTreeParser : public LLXmlParser
197{
198public:
199	LLXmlTreeParser(LLXmlTree* tree);
200	virtual ~LLXmlTreeParser();
201
202	BOOL parseFile(const std::string &path, LLXmlTreeNode** root, BOOL keep_contents );
203
204protected:
205	const std::string& tabs();
206
207	// Overrides from LLXmlParser
208	virtual void	startElement(const char *name, const char **attributes); 
209	virtual void	endElement(const char *name);
210	virtual void	characterData(const char *s, int len);
211	virtual void	processingInstruction(const char *target, const char *data);
212	virtual void	comment(const char *data);
213	virtual void	startCdataSection();
214	virtual void	endCdataSection();
215	virtual void	defaultData(const char *s, int len);
216	virtual void	unparsedEntityDecl(
217		const char* entity_name,
218		const char* base,
219		const char* system_id,
220		const char* public_id,
221		const char* notation_name);
222
223	//template method pattern
224	virtual LLXmlTreeNode* CreateXmlTreeNode(const std::string& name, LLXmlTreeNode* parent);
225
226protected:
227	LLXmlTree*		mTree;
228	LLXmlTreeNode*	mRoot;
229	LLXmlTreeNode*  mCurrent;
230	BOOL			mDump;	// Dump parse tree to llinfos as it is read.
231	BOOL			mKeepContents;
232};
233
234#endif  // LL_LLXMLTREE_H