llxmltree.h

Go to the documentation of this file.
00001 
00033 #ifndef LL_LLXMLTREE_H
00034 #define LL_LLXMLTREE_H
00035 
00036 #include <map>
00037 #include <list>
00038 #include "llstring.h"
00039 #include "llxmlparser.h"
00040 #include "string_table.h"
00041 
00042 class LLColor4;
00043 class LLColor4U;
00044 class LLQuaternion;
00045 class LLUUID;
00046 class LLVector3;
00047 class LLVector3d;
00048 class LLXmlTreeNode;
00049 class LLXmlTreeParser;
00050 
00052 // LLXmlTree
00053 
00054 class LLXmlTree
00055 {
00056         friend class LLXmlTreeNode;
00057         
00058 public:
00059         LLXmlTree();
00060         virtual ~LLXmlTree();
00061         void cleanup();
00062 
00063         virtual BOOL    parseFile(const std::string &path, BOOL keep_contents = TRUE);
00064 
00065         LLXmlTreeNode*  getRoot() { return mRoot; }
00066 
00067         void                    dump();
00068         void                    dumpNode( LLXmlTreeNode* node, const LLString &prefix );
00069 
00070         static LLStdStringHandle addAttributeString( const std::string& name)
00071         {
00072                 return sAttributeKeys.addString( name );
00073         }
00074         
00075 public:
00076         // global
00077         static LLStdStringTable sAttributeKeys;
00078         
00079 protected:
00080         LLXmlTreeNode* mRoot;
00081 
00082         // local
00083         LLStdStringTable mNodeNames;    
00084 };
00085 
00087 // LLXmlTreeNode
00088 
00089 class LLXmlTreeNode
00090 {
00091         friend class LLXmlTree;
00092         friend class LLXmlTreeParser;
00093 
00094 protected:
00095         // Protected since nodes are only created and destroyed by friend classes and other LLXmlTreeNodes
00096         LLXmlTreeNode( const std::string& name, LLXmlTreeNode* parent, LLXmlTree* tree );
00097         
00098 public:
00099         virtual ~LLXmlTreeNode();
00100 
00101         const std::string&      getName()
00102         {
00103                 return mName;
00104         }
00105         BOOL hasName( const std::string& name )
00106         {
00107                 return mName == name;
00108         }
00109 
00110         BOOL hasAttribute( const std::string& name );
00111 
00112         // Fast versions use cannonical_name handlee to entru in LLXmlTree::sAttributeKeys string table
00113         BOOL                    getFastAttributeBOOL(           LLStdStringHandle cannonical_name, BOOL& value );
00114         BOOL                    getFastAttributeU8(                     LLStdStringHandle cannonical_name, U8& value );
00115         BOOL                    getFastAttributeS8(                     LLStdStringHandle cannonical_name, S8& value );
00116         BOOL                    getFastAttributeU16(            LLStdStringHandle cannonical_name, U16& value );
00117         BOOL                    getFastAttributeS16(            LLStdStringHandle cannonical_name, S16& value );
00118         BOOL                    getFastAttributeU32(            LLStdStringHandle cannonical_name, U32& value );
00119         BOOL                    getFastAttributeS32(            LLStdStringHandle cannonical_name, S32& value );
00120         BOOL                    getFastAttributeF32(            LLStdStringHandle cannonical_name, F32& value );
00121         BOOL                    getFastAttributeF64(            LLStdStringHandle cannonical_name, F64& value );
00122         BOOL                    getFastAttributeColor(          LLStdStringHandle cannonical_name, LLColor4& value );
00123         BOOL                    getFastAttributeColor4(         LLStdStringHandle cannonical_name, LLColor4& value );
00124         BOOL                    getFastAttributeColor4U(        LLStdStringHandle cannonical_name, LLColor4U& value );
00125         BOOL                    getFastAttributeVector3(        LLStdStringHandle cannonical_name, LLVector3& value );
00126         BOOL                    getFastAttributeVector3d(       LLStdStringHandle cannonical_name, LLVector3d& value );
00127         BOOL                    getFastAttributeQuat(           LLStdStringHandle cannonical_name, LLQuaternion& value );
00128         BOOL                    getFastAttributeUUID(           LLStdStringHandle cannonical_name, LLUUID& value );
00129         BOOL                    getFastAttributeString(         LLStdStringHandle cannonical_name, LLString& value );
00130 
00131         // Normal versions find 'name' in LLXmlTree::sAttributeKeys then call fast versions
00132         virtual BOOL            getAttributeBOOL(               const std::string& name, BOOL& value );
00133         virtual BOOL            getAttributeU8(                 const std::string& name, U8& value );
00134         virtual BOOL            getAttributeS8(                 const std::string& name, S8& value );
00135         virtual BOOL            getAttributeU16(                const std::string& name, U16& value );
00136         virtual BOOL            getAttributeS16(                const std::string& name, S16& value );
00137         virtual BOOL            getAttributeU32(                const std::string& name, U32& value );
00138         virtual BOOL            getAttributeS32(                const std::string& name, S32& value );
00139         virtual BOOL            getAttributeF32(                const std::string& name, F32& value );
00140         virtual BOOL            getAttributeF64(                const std::string& name, F64& value );
00141         virtual BOOL            getAttributeColor(              const std::string& name, LLColor4& value );
00142         virtual BOOL            getAttributeColor4(             const std::string& name, LLColor4& value );
00143         virtual BOOL            getAttributeColor4U(    const std::string& name, LLColor4U& value );
00144         virtual BOOL            getAttributeVector3(    const std::string& name, LLVector3& value );
00145         virtual BOOL            getAttributeVector3d(   const std::string& name, LLVector3d& value );
00146         virtual BOOL            getAttributeQuat(               const std::string& name, LLQuaternion& value );
00147         virtual BOOL            getAttributeUUID(               const std::string& name, LLUUID& value );
00148         virtual BOOL            getAttributeString(             const std::string& name, LLString& value );
00149 
00150         const LLString& getContents()
00151         {
00152                 return mContents;
00153         }
00154         LLString getTextContents();
00155 
00156         LLXmlTreeNode*  getParent()                                                     { return mParent; }
00157         LLXmlTreeNode*  getFirstChild();
00158         LLXmlTreeNode*  getNextChild();
00159         S32                             getChildCount()                                         { return (S32)mChildList.size(); }
00160         LLXmlTreeNode*  getChildByName( const std::string& name );      // returns first child with name, NULL if none
00161         LLXmlTreeNode*  getNextNamedChild();                            // returns next child with name, NULL if none
00162 
00163 protected:
00164         const LLString* getAttribute( LLStdStringHandle name)
00165         {
00166                 attribute_map_t::iterator iter = mAttributes.find(name);
00167                 return (iter == mAttributes.end()) ? 0 : iter->second;
00168         }
00169 
00170 private:
00171         void                    addAttribute( const std::string& name, const std::string& value );
00172         void                    appendContents( const std::string& str );
00173         void                    addChild( LLXmlTreeNode* child );
00174 
00175         void                    dump( const LLString& prefix );
00176 
00177 protected:
00178         typedef std::map<LLStdStringHandle, const LLString*> attribute_map_t;
00179         attribute_map_t                                         mAttributes;
00180 
00181 private:
00182         LLString                                                        mName;
00183         LLString                                                        mContents;
00184         
00185         typedef std::list<class LLXmlTreeNode *> child_list_t;
00186         child_list_t                                            mChildList;
00187         child_list_t::iterator                          mChildListIter;
00188         
00189         typedef std::multimap<LLStdStringHandle, LLXmlTreeNode *> child_map_t;
00190         child_map_t                                                     mChildMap;              // for fast name lookups
00191         child_map_t::iterator                           mChildMapIter;
00192         child_map_t::iterator                           mChildMapEndIter;
00193 
00194         LLXmlTreeNode*                                          mParent;
00195         LLXmlTree*                                                      mTree;
00196 };
00197 
00199 // LLXmlTreeParser
00200 
00201 class LLXmlTreeParser : public LLXmlParser
00202 {
00203 public:
00204         LLXmlTreeParser(LLXmlTree* tree);
00205         virtual ~LLXmlTreeParser();
00206 
00207         BOOL parseFile(const std::string &path, LLXmlTreeNode** root, BOOL keep_contents );
00208 
00209 protected:
00210         const std::string& tabs();
00211 
00212         // Overrides from LLXmlParser
00213         virtual void    startElement(const char *name, const char **attributes); 
00214         virtual void    endElement(const char *name);
00215         virtual void    characterData(const char *s, int len);
00216         virtual void    processingInstruction(const char *target, const char *data);
00217         virtual void    comment(const char *data);
00218         virtual void    startCdataSection();
00219         virtual void    endCdataSection();
00220         virtual void    defaultData(const char *s, int len);
00221         virtual void    unparsedEntityDecl(
00222                 const char* entity_name,
00223                 const char* base,
00224                 const char* system_id,
00225                 const char* public_id,
00226                 const char* notation_name);
00227 
00228         //template method pattern
00229         virtual LLXmlTreeNode* CreateXmlTreeNode(const std::string& name, LLXmlTreeNode* parent);
00230 
00231 protected:
00232         LLXmlTree*              mTree;
00233         LLXmlTreeNode*  mRoot;
00234         LLXmlTreeNode*  mCurrent;
00235         BOOL                    mDump;  // Dump parse tree to llinfos as it is read.
00236         BOOL                    mKeepContents;
00237 };
00238 
00239 #endif  // LL_LLXMLTREE_H

Generated on Thu Jul 1 06:09:49 2010 for Second Life Viewer by  doxygen 1.4.7