src/Env/Param/ParamXMLTree.h

説明を見る。
00001 // 
00002 // Copyright (c) 2005-2008 Kenichi Watanabe.
00003 // Copyright (c) 2005-2008 Yasuhiro Watari.
00004 // Copyright (c) 2005-2008 Hironori Ichibayashi.
00005 // Copyright (c) 2008-2009 Kazuo Horio.
00006 // Copyright (c) 2009-2013 Naruki Kurata.
00007 // Copyright (c) 2005-2013 Ryota Shioya.
00008 // Copyright (c) 2005-2013 Masahiro Goshima.
00009 // 
00010 // This software is provided 'as-is', without any express or implied
00011 // warranty. In no event will the authors be held liable for any damages
00012 // arising from the use of this software.
00013 // 
00014 // Permission is granted to anyone to use this software for any purpose,
00015 // including commercial applications, and to alter it and redistribute it
00016 // freely, subject to the following restrictions:
00017 // 
00018 // 1. The origin of this software must not be misrepresented; you must not
00019 // claim that you wrote the original software. If you use this software
00020 // in a product, an acknowledgment in the product documentation would be
00021 // appreciated but is not required.
00022 // 
00023 // 2. Altered source versions must be plainly marked as such, and must not be
00024 // misrepresented as being the original software.
00025 // 
00026 // 3. This notice may not be removed or altered from any source
00027 // distribution.
00028 // 
00029 // 
00030 
00031 
00032 //
00033 // Parameter XML Tree
00034 //
00035 
00036 #ifndef ENV_PARAM_PARAM_XML_TREE_H
00037 #define ENV_PARAM_PARAM_XML_TREE_H
00038 
00039 #include "Env/Param/ParamXMLPath.h"
00040 
00041 namespace Onikiri
00042 {
00043 
00044     class ParamXMLTree
00045     {
00046     public:
00047         struct NodeStatus
00048         {
00049             bool stReadOnly;
00050             bool stArray;
00051             bool stRequireDefault;
00052             bool stDefault;
00053             bool stAttribute;
00054         };
00055 
00056         class StringHash
00057         {
00058         public:
00059             size_t operator()(const String& value) const;
00060         };
00061 
00062         struct Node;
00063         typedef boost::shared_ptr<Node>    NodePtr;
00064         typedef std::vector<NodePtr>       NodeArray;
00065         typedef unordered_map<String, NodeArray, StringHash> ChildMap;
00066         typedef unordered_map<String, NodePtr,  StringHash>  AttributeMap;
00067         typedef unordered_map<String, NodePtr,  StringHash>  ArrayPlaceMap;
00068 
00069         struct Node
00070         {
00071             Node();
00072             String        name;
00073             String        value;
00074             ChildMap      children;
00075             AttributeMap  attributes;
00076             ArrayPlaceMap arrayPlace;   // for PDB_Array palce holder
00077             NodeStatus    status;
00078             int           inputIndex;
00079             bool          accessed;
00080         };
00081 
00082         struct InputInfo
00083         {
00084             enum Type
00085             {
00086                 IT_FILE,
00087                 IT_STRING,
00088                 IT_CMD
00089             };
00090             Type   type;
00091             String fileName;
00092         };
00093 
00094         ParamXMLTree();
00095         virtual ~ParamXMLTree();
00096 
00097         void LoadXMLFile( const String& fileName, bool isDefault );
00098         void LoadString( const String& str, bool isDefault, const String& signature );
00099         void LoadValue( const ParamXMLPath& path, const String& value );
00100 
00101         void ToXMLDoc(TiXmlDocument& doc);
00102         String ToXMLString();
00103 
00104         void Set( const ParamXMLPath& path, const String& value, bool forceOverWrite = false);
00105         bool Get( const ParamXMLPath& path,       String* value, NodeStatus* status = NULL );
00106         NodePtr GetNode( const ParamXMLPath& path, bool addNewNode = false );
00107 
00108         NodeArray* GetNodeArray( const ParamXMLPath& path, bool addNewNode = false );
00109         NodeArray* GetNodeArray( NodePtr parentNode, const String& childName, bool addNewNode = false );
00110         NodePtr    GetAttribute( NodePtr parentNode, const String& attributeName, bool addNewNode = false );
00111 
00112         NodePtr CreateNewNode( const String& name = "" );
00113 
00114         const std::vector<InputInfo>& GetInputList();
00115         bool GetSourceXMLFile( const ParamXMLPath& path, String& fileName );
00116 
00117     protected:
00118         NodePtr m_root;
00119         std::vector<InputInfo> m_inputList;
00120 
00121         void CheckXMLParseError( TiXmlDocument& doc, const String& from );
00122         void LoadXMLToTiXMLDoc( const String& fileName, TiXmlDocument& doc );
00123 
00124         void ConvertXMLToMap( NodePtr mapParent, TiXmlNode* xmlParent, int inputIndex, bool stDefault );
00125         void ConvertMapToXML( TiXmlNode* xmlParent, NodePtr mapParent );
00126         void CopyTree( NodePtr dst, NodePtr src );
00127     };
00128     
00129 
00130 }   // namespace Onikiri
00131 
00132 #endif  // #ifdef ENV_PARAM_PARAM_XML_TREE_H
00133 
00134 

Onikiri2に対してTue Jun 18 14:34:21 2013に生成されました。  doxygen 1.4.7