00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #if !defined(__INCLUDE_XMLNodeh_INCLUDE__)
00022 #define __INCLUDE_XMLNodeh_INCLUDE__
00023
00024 #include <list>
00025 #include <lang/LangString.h>
00026 #include <common/Vector.h>
00027 #include <common/FixedVector.h>
00028 #include <common/FileLines.h>
00029 #include <common/NumberParser.h>
00030
00031 class XMLNode
00032 {
00033 public:
00034 enum NodeType
00035 {
00036 XMLNodeType,
00037 XMLParameterType,
00038 XMLCommentType,
00039 XMLContentType
00040 };
00041
00042 XMLNode(const char *name, const char *content = "",
00043 NodeType = XMLNode::XMLNodeType);
00044 XMLNode(const char *name, const std::string &content,
00045 NodeType = XMLNode::XMLNodeType);
00046 XMLNode(const char *name, const LangString &content,
00047 NodeType = XMLNode::XMLNodeType);
00048 XMLNode(const char *name, NumberParser &content,
00049 NodeType = XMLNode::XMLNodeType);
00050 XMLNode(const char *name, float content,
00051 NodeType = XMLNode::XMLNodeType);
00052 XMLNode(const char *name, bool content,
00053 NodeType = XMLNode::XMLNodeType);
00054 XMLNode(const char *name, int content,
00055 NodeType = XMLNode::XMLNodeType);
00056 XMLNode(const char *name, Vector &content,
00057 NodeType = XMLNode::XMLNodeType);
00058 XMLNode(const char *name, unsigned int content,
00059 NodeType = XMLNode::XMLNodeType);
00060 XMLNode(const char *name, fixed content,
00061 NodeType = XMLNode::XMLNodeType);
00062 XMLNode(const char *name, FixedVector &content,
00063 NodeType = XMLNode::XMLNodeType);
00064
00065 virtual ~XMLNode();
00066
00067 bool writeToFile(const std::string &fileName);
00068
00069 NodeType getType() { return type_; }
00070 const char *getName() { return name_.c_str(); }
00071 const char *getContent();
00072 const char *getSource() { return source_.c_str(); }
00073 const XMLNode *getParent() { return parent_; }
00074
00075 std::list<XMLNode *> &getChildren() { return children_; }
00076 std::list<XMLNode *> &getParameters() { return parameters_; }
00077
00078 bool getNamedParameter(const char *name, XMLNode *&node,
00079 bool failOnError = true, bool remove = true);
00080 bool getNamedParameter(const char *name, std::string &value,
00081 bool failOnError = true, bool remove = true);
00082 bool getNamedParameter(const char *name, LangString &value,
00083 bool failOnError = true, bool remove = true);
00084 bool getNamedChild(const char *name, XMLNode *&node,
00085 bool failOnError = true, bool remove = true);
00086 bool getNamedChild(const char *name, LangString &node,
00087 bool failOnError = true, bool remove = true);
00088 bool getNamedChild(const char *name, std::string &value,
00089 bool failOnError = true, bool remove = true);
00090 bool getNamedChild(const char *name, bool &value,
00091 bool failOnError = true, bool remove = true);
00092 bool getNamedChild(const char *name, NumberParser &value,
00093 bool failOnError = true, bool remove = true);
00094 bool getNamedChild(const char *name, float &value,
00095 bool failOnError = true, bool remove = true);
00096 bool getNamedChild(const char *name, int &value,
00097 bool failOnError = true, bool remove = true);
00098 bool getNamedChild(const char *name, unsigned int &value,
00099 bool failOnError = true, bool remove = true);
00100 bool getNamedChild(const char *name, fixed &value,
00101 bool failOnError = true, bool remove = true);
00102 bool getNamedChild(const char *name, Vector &value,
00103 bool failOnError = true, bool remove = true);
00104 bool getNamedChild(const char *name, FixedVector &value,
00105 bool failOnError = true, bool remove = true);
00106
00107 bool failChildren();
00108 bool failContent();
00109 void resurrectRemovedChildren();
00110
00111 void setSource(const char *source);
00112 void setLine(int line, int col);
00113 void setUseContentNodes(bool useContentNodes)
00114 { useContentNodes_ = useContentNodes; }
00115
00116 bool returnError(const std::string &error);
00117 void addChild(XMLNode *node);
00118 void addParameter(XMLNode *node);
00119 void addContent(const char *data, int len);
00120
00121 static void removeSpecialChars(const std::string &content,
00122 std::string &result);
00123 static void addSpecialChars(const std::string &content,
00124 std::string &result);
00125 static const char *getSpacer(int space);
00126
00127 protected:
00128 bool useContentNodes_;
00129 NodeType type_;
00130 XMLNode *parent_;
00131 std::list<XMLNode *> children_;
00132 std::list<XMLNode *> removedChildren_;
00133 std::list<XMLNode *> parameters_;
00134 std::list<XMLNode *> removedParameters_;
00135 std::string name_;
00136 std::string content_;
00137 std::string source_;
00138 int line_, col_;
00139
00140 void addNodeToFile(FileLines &lines, int spacing);
00141
00142 };
00143
00144 #endif