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 #include <iostream>
00010 
00011 using namespace std;
00019 // count the leading tabs, split the rest into vector vec
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         // make a node from a ?type?value? string
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         //helper function, should be private
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         // get everything to the right of this 
00045         // pointer as a vector of strings
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                 //Aceobj(const Aceobj &obj);
00081                 //
00082                 //Destructor, needs to clean all nodes of the tree
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                 //node_pointer at(const string &tag_path);
00099                 //node<pair<string, string> >* at(const string &tag_path, int pos=0);
00100                 Acenode* at(const string &tag_path, int pos=0);
00101 
00104                 //node<pair<string, string> >* get(const string &tag, int pos=0);
00105                 Acenode* get(const string &tag, int pos=0);
00106 
00107         private:
00108                 //node<pair<string, string> > *root;
00109                 Acenode *root;
00110                 //string objtype;  // object type: Sequence, Protein, Paper ....
00111                 //string objname;  // string identifier for the object
00112 };
00113 
00114 #endif

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