ionflux.org | Impressum

Tree.hpp

Go to the documentation of this file.
00001 #ifndef IONFLUX_TOOLS_TREE
00002 #define IONFLUX_TOOLS_TREE
00003 /* ==========================================================================
00004  * Ionflux Tools
00005  * Copyright (c) 2004 Joern P. Meier
00006  * mail@ionflux.org
00007  * --------------------------------------------------------------------------
00008  * Tree.hpp                    Data tree.
00009  * ==========================================================================
00010  * 
00011  * This file is part of Ionflux Tools.
00012  * 
00013  * Ionflux Tools is free software; you can redistribute it and/or modify it 
00014  * under the terms of the GNU General Public License as published by the Free
00015  * Software Foundation; either version 2 of the License, or (at  your option)
00016  * any later version.
00017  * 
00018  * Ionflux Tools is distributed in the hope that it will be useful, but 
00019  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00020  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00021  * for more details.
00022  * 
00023  * You should have received a copy of the GNU General Public License
00024  * along with Ionflux Tools; if not, write to the Free Software Foundation, 
00025  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00026  * 
00027  * ========================================================================== */
00028 
00029 #include <string>
00030 #include <iostream>
00031 #include "ionflux/tools.hpp"
00032 #include "ionflux/Reporter.hpp"
00033 #include "ionflux/Node.hpp"
00034 #include "ionflux/TreeResolver.hpp"
00035 #include "ionflux/TreeEval.hpp"
00036 
00037 namespace Ionflux
00038 {
00039 
00040 namespace Tools
00041 {
00042 
00043 class Node;
00044 struct NodeInfo;
00045 class TreeResolver;
00046 struct TreePath;
00047 class TreeEval;
00048 struct TreeExprElement;
00049 class Tree;
00050 
00056 struct DataEntry
00057 {
00059     Node *node;
00061     unsigned int index;
00063     bool subscript;
00064 };
00065 
00071 struct TreePath
00072 {
00074     Tree *tree;
00076     std::vector<Node *> nodes;
00078     int subscript;
00080     bool explicitSubscript;
00081 };
00082 
00088 struct TreeExprElement
00089 {
00091     int type;
00093     std::string value;
00095     DataEntry data;
00097     bool unary;
00099     static const int TE_INVALID;
00101     static const int TE_CONST;
00103     static const int TE_VAR;
00105     static const int TE_OP;
00106 };
00107 
00115 class Tree
00116 {
00117     protected:
00119         Ionflux::Tools::Reporter log;
00121         NodeInfo root;
00122         
00123     public:
00128         Tree();
00129         
00138         Tree(Node *initRoot, bool initManage);
00139         
00144         virtual ~Tree();
00145         
00154         virtual Node *findNode(int nodeID);
00155         
00164         virtual Node *findNode(const std::string &nodeName);
00165         
00181         virtual DataEntry resolve(const std::string &treePathExpr, 
00182             bool createPath, bool nodesOnly = false);
00183         
00192         virtual void setRoot(Node *newRoot, bool newManage);
00193         
00200         virtual void writeToFile(const std::string &fileName);
00201         
00208         virtual void readFromFile(const std::string &fileName);
00209         
00223         virtual bool eval(const std::string &treeExpr, Node &result, 
00224             bool createPath);
00225         
00246         virtual Node &operator[](int searchID);
00247         
00268         virtual Node &operator[](const std::string &searchName);
00269         
00271         virtual void printDebugInfo();
00272         
00277         virtual Node *getRoot();
00278         
00283         virtual int getNumNodes();
00284         
00286         virtual void clear();
00287         
00292         virtual Reporter &getLog();
00293 };
00294 
00295 }
00296 
00297 }
00298 
00302 #endif

Generated on Tue Mar 14 20:58:30 2006 for Ionflux Tools Class Library (iftools) by  doxygen 1.4.6