Main Page | Namespaces | Classes | Compounds | Files | Compound Members | Related Utils.h00001 // 00002 // SYNTOPIA. See http://Syntopia.sourceforge.net for details and documentation. 00003 // 00004 // Author of this file: Mikael Hvidtfeldt Christensen (mikaelc@users.sourceforge.net) 00005 // 00006 00007 #ifndef __Utils__ 00008 #define __Utils__ 00009 00010 00011 #include <iostream> 00012 #include <fstream> 00013 #include <strstream> 00014 #include <stack> 00015 #include <string> 00016 #include <vector> 00017 00018 00019 00028 00029 using namespace std; 00030 00031 00032 00033 namespace Utils { 00034 00036 double Log2(double x); 00037 00039 string floatToString(float f) ; 00040 00042 float stringToFloat(string s) ; 00043 00045 int stringToInt(string s) ; 00046 00047 00049 string intToString(int i); 00050 00051 00055 string newline(); 00056 00057 00059 string space(int indent); 00060 00061 00063 void trim(string & S); 00064 00065 00066 00067 // XML Classes --------------------------------------------------------------------------- 00068 00070 class parseError { 00071 public: 00073 parseError(string message) : myMessage(message) {;}; 00074 00076 void print() { cout << "Parse Error: " << myMessage << endl; } 00077 private: 00078 string myMessage; 00079 }; 00080 00081 class TagNode; // Forward declaration 00082 00084 class XMLNode { 00085 private: 00086 public: 00088 XMLNode * firstChild; 00089 00091 XMLNode * rightSibling; 00092 00094 XMLNode * parent; 00095 00097 bool hasChildren() { return (firstChild != 0); } 00098 00100 bool hasRightSibling() { return (rightSibling != 0); } 00101 00103 bool hasParent() { return (parent != 0); } 00104 00106 void addChild(XMLNode * ch); 00107 00109 virtual string printString() ; 00110 00112 virtual void print() ; 00113 00115 XMLNode() {firstChild = 0; rightSibling = 0; parent = 0; }; 00116 00118 ~XMLNode() { }; 00119 00121 virtual std::string getXML(int indent) {return "";}; 00122 00124 virtual string pathName(); 00125 00127 virtual string path() ; 00128 00132 string getTagText(string tag); 00133 00134 00135 00138 TagNode * getTag(string tag); 00139 }; 00140 00141 00142 00143 00145 class TagNode : public XMLNode { 00146 public: 00148 std::string tagName; 00149 00151 TagNode() {}; 00152 00154 TagNode(std::string s) : tagName(s) {}; 00155 00157 ~TagNode(); 00158 00159 string printString() ; 00160 00161 std::string getXML(int indent); 00162 00163 string pathName(); 00164 00166 string getAttribute(string Attr); 00167 }; 00168 00169 00171 class TextNode : public XMLNode { 00172 public: 00174 std::string text; 00175 00177 TextNode() {}; 00178 00180 TextNode(std::string s) : text(s) {}; 00181 00183 ~TextNode(); 00184 00185 string printString(); 00186 00187 std::string getXML(int indent); 00188 00189 string pathName(); 00190 }; 00191 00193 class AttributeNode : public XMLNode { 00194 public: 00196 string attributeName; 00198 string attributeData; 00199 00200 00202 AttributeNode() {}; 00203 00205 AttributeNode(string name, string data) : attributeName(name),attributeData(data) {}; 00206 00208 ~AttributeNode(); 00209 00210 string printString(); 00211 00212 string getXML(int indent); 00213 00214 string pathName(); 00215 }; 00216 00218 00252 class XMLDoc { 00253 00254 public: // ----------------------------------------------------------------- 00255 00257 XMLNode * rootNode; 00258 00260 XMLDoc() {}; 00261 00263 ~XMLDoc() {}; 00264 00266 void parseFile(std::string filename); 00267 00268 vector<string> tagPartition(string s); 00269 00270 private: // ------------------------------------------------------------------ 00271 00272 00273 int countReturns(string S, int pos); 00274 00275 }; 00276 00279 class XMLSearch { 00280 00281 public: // -------------------------------------------------------------------- 00282 00284 XMLSearch(XMLDoc * d) : doc(d) {;}; 00285 00287 XMLSearch() {;}; 00288 00290 vector<XMLNode *> answer; 00291 00299 00300 void find(string MPath, XMLNode * startNode = 0) ; 00301 00302 00304 void clearQuery() {answer.clear();queryString = "";} ; 00305 00306 private: // ----------------------------------------------------------------- 00307 00308 void findRecurse(XMLNode * cur) ; 00309 00310 string queryString; 00311 00312 XMLDoc * doc; 00313 00314 }; 00315 00316 } // end of namespace Utils 00317 00318 #endif Docs made by Doxygen. Email: Mikael Christensen |