Aceobj.h

Go to the documentation of this file.
00001 #ifndef ACEOBJ_H
00002 #define ACEOBJ_H
00003 
00004 // an Ace object to represent Aceobject in a generic Tree
00005 //#include "gentree.h"
00006 #include <string>
00007 #include <sstream>
00008 #include <vector>
00009 
00010 using namespace std;
00018 // count the leading tabs, split the rest into vector vec
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         // make a node from a ?type?value? string
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         //helper function, should be private
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         // get everything to the right of this 
00044         // pointer as a vector of strings
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                 //Aceobj(const Aceobj &obj);
00080                 //
00081                 //Destructor, needs to clean all nodes of the tree
00082                 ~Aceobj() { del(root); }
00083                 void clear() { del(root); }
00084 
00088                 void parse(const string &str);
00089 
00090                 //node_pointer at(const string &tag_path);
00096                 //node<pair<string, string> >* at(const string &tag_path, int pos=0);
00097                 Acenode* at(const string &tag_path, int pos=0);
00098 
00101                 //node<pair<string, string> >* get(const string &tag, int pos=0);
00102                 Acenode* get(const string &tag, int pos=0);
00103 
00104         private:
00105                 //node<pair<string, string> > *root;
00106                 Acenode *root;
00107                 //string objtype;  // object type: Sequence, Protein, Paper ....
00108                 //string objname;  // string identifier for the object
00109 };
00110 
00111 #endif

Generated on Wed Aug 10 11:56:49 2011 for Softwares from Orpara by  doxygen 1.5.6