TreeParser.h

00001 // -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
00002 /* 
00003  * Copyright (C) 2008 Micha Hersch, EPFL
00004  * RobotCub Consortium, European Commission FP6 Project IST-004370
00005  * email:   micha.hersch@robotcub.org
00006  * website: www.robotcub.org
00007  * Permission is granted to copy, distribute, and/or modify this program
00008  * under the terms of the GNU General Public License, version 2 or any
00009  * later version published by the Free Software Foundation.
00010  *
00011  * A copy of the license can be found at
00012  * http://www.robotcub.org/icub/license/gpl.txt
00013  *
00014  * This program is distributed in the hope that it will be useful, but
00015  * WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
00017  * Public License for more details
00018  */
00019 // sXMLParser.h: interface for the sXMLParser class.
00020 //
00022 
00023 #ifndef __TREE_PARSER_H__
00024 #define __TREE_PARSER_H__
00025 
00026 #include <string>
00027 #include <vector>
00028 #include <iostream>
00029 #include <sstream>
00030 #include <fstream>
00031 
00032 using namespace std;
00033 
00034 
00035 #define TREE_START_TAG   0
00036 #define TREE_DATA        1
00037 #define TREE_STOP_TAG    2
00038 #define TREE_EOF         3
00039 
00040 #define TREE_OK          1
00041 #define TREE_ERROR       0
00042 
00043 
00044 class   Tree;
00045 typedef Tree *pTree;
00046 typedef vector<pTree> Tree_List;
00047 
00048 
00049 class Tree
00050 {
00051 public:
00052         //static string CurrentPath;
00053 
00054 protected:
00055         string        m_Name;
00056         string        m_Data;
00057         Tree_List                 m_SubTree;
00058 
00059 //private:
00060         //int                           lookupPos;
00061 
00062 public:
00063         Tree();
00064         Tree(string newName);
00065         Tree(string newName, string newData);
00066   virtual ~Tree();
00067 
00068   void      Clear();
00069   pTree     Clone();
00070 
00071   int       AddSubTree(pTree newSubTree);
00072   int       DelSubTree(pTree oldSubTree);
00073 
00074   string    GetName();
00075   void      SetName(string newName);
00076   string    GetData();
00077   void      SetData(string newData);
00078 
00079 
00080   pTree     Find(string name);
00081   pTree     Find(string name, string data);
00082   string    FindData(string name);
00083 
00084 
00085   double   ToDouble();
00086   float    ToFloat();
00087   int      ToInt();
00088   bool                  ToBool();
00089   string    ToString();
00090   
00091 
00092   
00093   int                           LoadFromFile(string filename);
00094   int                           SaveToFile(string filename);
00095   void                  Print(unsigned int indent = 0);
00096   
00097   Tree_List *GetSubTrees();
00098 
00099 private:
00100   int                           LoadFromStream (ifstream & file);
00101   int                           SaveToStream   (ofstream & file, unsigned int indent = 0);
00102   int                           GetNextTag     (ifstream & file, string & str);
00103 };
00104 
00105 
00106 
00107 #endif
 All Data Structures Functions Variables

Generated on Wed Sep 22 16:51:25 2010 for Body_Schema_Learning by  doxygen 1.6.1