00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
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;
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 }
00131
00132 #endif // #ifdef ENV_PARAM_PARAM_XML_TREE_H
00133
00134