Aceobj.h
Go to the documentation of this file.00001 #ifndef ACEOBJ_H
00002 #define ACEOBJ_H
00003
00004
00005
00006 #include <string>
00007 #include <sstream>
00008 #include <vector>
00009
00010 using namespace std;
00018
00019 int digestLine(vector<string> &vec, const string &str);
00020
00021 struct Acenode {
00022 Acenode(const string &t, const string &v) : type(t), value(v), parent(0), child(0), sibling(0) {}
00023 Acenode(const string &t, const string&v, Acenode* p) : type(t), value(v), parent(p), child(0), sibling(0) {}
00024
00025
00026 Acenode(const string &dump) : parent(0), child(0), sibling(0) { parse(dump); }
00027 Acenode(const string &dump, Acenode* p) : parent(p), child(0), sibling(0) { parse(dump); }
00028
00029
00030 void parse(const string &dump);
00031
00032 void addChild(const string &t, const string &v) {
00033 child = new Acenode(t,v, this); }
00034 void addChild(const string &dump) {
00035 child = new Acenode(dump, this); }
00036 void addSibling(const string &t, const string&v) {
00037 sibling = new Acenode(t,v,this->parent); }
00038 void addSibling(const string &dump) {
00039 sibling = new Acenode(dump, this->parent); }
00040
00041 Acenode* right() { return sibling; }
00042 Acenode* down() { return child; }
00043
00044
00045 vector<string> row() const;
00046 vector<string> col() const;
00047
00048 void del();
00049
00050 int asInt() { return atoi(value.c_str()); }
00051 double asFloat() { return atof(value.c_str()); }
00052 string asString() { return value; }
00053
00054 string type;
00055 string value;
00056 Acenode *parent;
00057 Acenode *child;
00058 Acenode *sibling;
00059 };
00060 Acenode* find(Acenode *n, const string &tag);
00061 void del(Acenode* p);
00062
00063 class Aceobj {
00064 public:
00067 Aceobj() : root(0) { }
00068
00074 Aceobj(const string &str) { parse(str); }
00079
00080
00081
00082 ~Aceobj() { del(root); }
00083 void clear() { del(root); }
00084
00088 void parse(const string &str);
00089
00090
00096
00097 Acenode* at(const string &tag_path, int pos=0);
00098
00101
00102 Acenode* get(const string &tag, int pos=0);
00103
00104 private:
00105
00106 Acenode *root;
00107
00108
00109 };
00110
00111 #endif