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 #include <iostream>
00010
00011 using namespace std;
00019
00020 int digestLine(vector<string> &vec, const string &str);
00021
00022 struct Acenode {
00023 Acenode(const string &t, const string &v) : type(t), value(v), parent(0), child(0), sibling(0) {}
00024 Acenode(const string &t, const string&v, Acenode* p) : type(t), value(v), parent(p), child(0), sibling(0) {}
00025
00026
00027 Acenode(const string &dump) : parent(0), child(0), sibling(0) { parse(dump); }
00028 Acenode(const string &dump, Acenode* p) : parent(p), child(0), sibling(0) { parse(dump); }
00029
00030
00031 void parse(const string &dump);
00032
00033 void addChild(const string &t, const string &v) {
00034 child = new Acenode(t,v, this); }
00035 void addChild(const string &dump) {
00036 child = new Acenode(dump, this); }
00037 void addSibling(const string &t, const string&v) {
00038 sibling = new Acenode(t,v,this->parent); }
00039 void addSibling(const string &dump) {
00040 sibling = new Acenode(dump, this->parent); }
00041
00042 Acenode* right() { return sibling; }
00043 Acenode* down() { return child; }
00044
00045
00046 vector<string> row() const;
00047 vector<string> col() const;
00048
00049 void del();
00050
00051 int asInt() { return atoi(value.c_str()); }
00052 double asFloat() { return atof(value.c_str()); }
00053 string asString() { return value; }
00054
00055 string type;
00056 string value;
00057 Acenode *parent;
00058 Acenode *child;
00059 Acenode *sibling;
00060 };
00061 Acenode* find(Acenode *n, const string &tag);
00062 void del(Acenode* p);
00063
00064 class Aceobj {
00065 public:
00068 Aceobj() : root(0) { }
00069
00075 Aceobj(const string &str) { parse(str); }
00080
00081
00082
00083 ~Aceobj() { del(root); }
00084 void clear() { del(root); root=0; }
00085
00089 void parse(const string &str);
00090 bool empty() { return root == 0; }
00091 string getName() const { return root->asString(); }
00092
00093
00099
00100 Acenode* at(const string &tag_path, int pos=0);
00101
00104
00105 Acenode* get(const string &tag, int pos=0);
00106
00107 private:
00108
00109 Acenode *root;
00110
00111
00112 };
00113
00114 #endif