ionflux.org | Impressum

Node.hpp

Go to the documentation of this file.
00001 #ifndef IONFLUX_TOOLS_NODE
00002 #define IONFLUX_TOOLS_NODE
00003 /* ==========================================================================
00004  * Ionflux Tools
00005  * Copyright (c) 2004 Joern P. Meier
00006  * mail@ionflux.org
00007  * --------------------------------------------------------------------------
00008  * Node.hpp                    Tree data node.
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 <sstream>
00032 #include <vector>
00033 #include <map>
00034 #include "ionflux/tools.hpp"
00035 #include "ionflux/Reporter.hpp"
00036 #include "ionflux/NodeDump.hpp"
00037 
00038 namespace Ionflux
00039 {
00040 
00041 namespace Tools
00042 {
00043 
00044 class Node;
00045 class NodeDump;
00046 class Reporter;
00047 
00063 struct NodeInfo
00064 {
00066     Node *node;
00068     bool manage;
00069     
00070     // Constructor.
00071     NodeInfo() : node(0), manage(false) { }
00072 };
00073 
00088 class Node
00089 {
00090     protected:
00092         Ionflux::Tools::Reporter *log;
00094         int nodeID;
00096         std::string nodeName;
00098         std::vector<NodeInfo> children;
00100         std::vector<std::string> nodeData;
00102         int dataType;
00104         Node *parent;
00106         int maxUID;
00108         int uidMode;
00114         bool autoCreate;
00116         int indexMode;
00118         std::map<std::string, Node*> nameIndex;
00120         std::vector<Node*> idIndex;
00126         bool managed;
00128         std::map<Node*, unsigned int> childNodeRef;
00129         
00143         virtual bool validateChildIndex(unsigned int childIndex);
00144         
00157         virtual bool validateDataIndex(unsigned int dataIndex);
00158         
00167         virtual unsigned int refChild(Node *childNode);
00168         
00181         virtual unsigned int unrefChild(Node *childNode);
00182         
00191         virtual unsigned int getRefCount(Node *childNode);
00192         
00206         virtual void addIndexEntry(Node *indexNode);
00207         
00221         virtual Node *getIndexEntry(const std::string &indexName);
00222         
00229         virtual void removeIndexEntry(const std::string &indexName);
00230         
00244         virtual Node *getIndexEntry(int indexID);
00245         
00252         virtual void removeIndexEntry(int indexID);
00253         
00258         virtual void removeIndexEntries(Node *indexNode);
00259         
00260     public:
00262         static const int NODE_ID_NOT_SET;
00264         static const int NODE_DATA_BLOB;
00266         static const int NODE_DATA_INT;
00268         static const int NODE_DATA_DOUBLE;
00270         static const int UID_MODE_NONE;
00272         static const int UID_MODE_NODE;
00274         static const int UID_MODE_TREE;
00276         static const int TRAVERSAL_INORDER;
00278         static const int TRAVERSAL_PREORDER;
00280         static const int TRAVERSAL_POSTORDER;
00282         static const unsigned int NODE_HEADER_SIZE;
00284         static const int INDEX_MODE_NONE;
00286         static const int INDEX_MODE_NODE;
00288         static const int INDEX_MODE_TREE;
00290         static const unsigned int MAX_ID_INDEX_SIZE;
00291         
00296         Node();
00297         
00304         Node(Node &sourceNode);
00305         
00312         Node(Node *initParent);
00313         
00321         Node(Node *initParent, int initID);
00322         
00331         Node(Node *initParent, int initID, const std::string &initName);
00332         
00342         Node(Node *initParent, int initID, const std::string &initName, 
00343             int initDataType);
00344         
00356         Node(Node *initParent, int initID, const std::string &initName, 
00357             int initDataType, bool initManaged);
00358         
00363         virtual ~Node();
00364         
00371         virtual void setID(int newID);
00372         
00379         virtual void setName(const std::string &newName);
00380         
00387         virtual void setParent(Node *newParent);
00388         
00396         virtual void setDataType(int newDataType);
00397         
00409         virtual int addData(const std::string &newData);
00410         
00422         virtual int addData(int newData);
00423         
00435         virtual int addData(double newData);
00436         
00449         virtual bool setBlob(unsigned int dataIndex, 
00450             const std::string &newData);
00451         
00464         virtual bool setData(unsigned int dataIndex, 
00465             const std::string &newData);
00466         
00479         virtual bool setData(unsigned int dataIndex, int newData);
00480         
00493         virtual bool setData(unsigned int dataIndex, unsigned int newData);
00494         
00507         virtual bool setData(unsigned int dataIndex, double newData);
00508         
00520         virtual bool setData(const std::string &newData);
00521         
00533         virtual bool setData(int newData);
00534         
00546         virtual bool setData(unsigned int newData);
00547         
00559         virtual bool setData(double newData);
00560         
00574         virtual std::string getData(unsigned int dataIndex);
00575         
00588         virtual std::string getBlob(unsigned int dataIndex);
00589         
00602         virtual int getInt(unsigned int dataIndex);
00603         
00616         virtual double getDouble(unsigned int dataIndex);
00617         
00626         virtual bool removeData(unsigned int dataIndex);
00627         
00636         virtual void clearData(bool recursive);
00637         
00652         virtual Node *addChild(int childID = NODE_ID_NOT_SET, 
00653             const std::string& childName = "");
00654         
00663         virtual void addChild(Node *newChild, bool newManage);
00664         
00676         virtual Node *findChild(int searchID, bool recursive = false);
00677         
00689         virtual Node *findChild(const std::string &searchName, 
00690             bool recursive = false);
00691         
00701         virtual Node *getChild(unsigned int childIndex);
00702         
00715         virtual unsigned int getNumChildren(bool recursive);
00716         
00730         virtual bool removeChild(unsigned int childIndex);
00731         
00747         virtual bool removeChild(Node *targetNode, bool recursive);
00748         
00762         virtual void removeAllChildren(bool recursive);
00763         
00775         virtual bool setChild(unsigned int childIndex, Node *newChild, 
00776             bool newManage);
00777         
00783         virtual void removeManagedChildren();
00784         
00794         virtual int getChildIndex(Node *targetNode);
00795         
00809         virtual unsigned int printDebugInfo(int targetLevel, int callingLevel, 
00810             int parentID, int childID);
00811         
00817         virtual unsigned int printDebugInfo(int targetLevel);
00818         
00829         virtual int getUID(bool treeUID);
00830         
00839         virtual void setUIDMode(int newUIDMode);
00840         
00850         virtual void setAutoCreate(bool newAutoCreate);
00851         
00861         virtual void setIndexMode(int newIndexMode);
00862         
00870         virtual void traverse(NodeDump *target, int order);
00871         
00884         virtual void serialize(std::string &target);
00885         
00907         virtual bool unpack(const std::string &serialized, 
00908             unsigned int blockStart, unsigned int blockSize);
00909         
00920         virtual void convertToNativeType();
00921         
00923         virtual void clearNameIndex();
00924         
00926         virtual void clearIDIndex();
00927         
00929         virtual void clearIndexes();
00930         
00941         virtual void copy(Ionflux::Tools::Node& target, 
00942             unsigned int maxDepth = 0, unsigned int currentDepth = 0);
00943         
00963         virtual Node &operator[](int searchID);
00964         
00984         virtual Node &operator[](const std::string &searchName);
00985         
00992         virtual std::string operator=(const std::string& newData);
00993         
01000         virtual int operator=(int newData);
01001         
01008         virtual double operator=(double newData);
01009         
01019         virtual Node &operator=(Node &sourceNode);
01020         
01025         virtual bool getAutoCreate();
01026          
01031         virtual int getUIDMode();
01032         
01037         virtual int getIndexMode();
01038         
01043         virtual int getID();
01044         
01049         virtual std::string getName();
01050         
01055         virtual int getDataType();
01056         
01061         virtual std::string getData();
01062         
01067         virtual std::string getBlob();
01068         
01073         virtual int getInt();
01074         
01079         virtual double getDouble();
01080         
01085         virtual unsigned int getNumData();
01086         
01091         virtual unsigned int getNumChildren();
01092         
01097         virtual Node *getParent();
01098         
01110         virtual std::string getPath();
01111         
01113         virtual void clear();
01114         
01132         virtual Node& merge(Node &sourceNode, bool replace = false, 
01133             unsigned int maxDepth = 0, unsigned int currentDepth = 0);
01134         
01146         bool combine(unsigned int from, unsigned int to, Node &target);
01147         
01162         std::string toConfig(const std::string& indent = "", 
01163             unsigned int level = 0);
01164         
01181         void setManaged(bool newManaged);
01182         
01190         bool isManaged();
01191         
01196         virtual Reporter &getLog();
01197 };
01198 
01200 
01201 }
01202 
01203 }
01204 
01208 #endif

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