ymlentity.h

Go to the documentation of this file.
00001 /*******************************************************************\
00002 
00003                    SESAME project software license
00004 
00005               Copyright (C) 2002 University of Amsterdam
00006 
00007     This program is free software; you can redistribute it and/or
00008      modify it under the terms of the GNU General Public License
00009     as published by the Free Software Foundation; either version 2
00010         of the License, or (at your option) any later version.
00011 
00012    This program is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015              GNU General Public License for more details.
00016 
00017   You should have received a copy of the GNU General Public License
00018      along with this program; if not, write to the Free Software
00019       Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00020                            02111-1307, USA.
00021 
00022       For information regarding the SESAME software project see
00023               http://sesamesim.sourceforge.net or email
00024                     jcofflan@users.sourceforge.net
00025 
00026 \*******************************************************************/
00037 #ifndef YMLENTITY_H
00038 #define YMLENTITY_H
00039 
00040 #include <BasicUtils/BasicArray.h>
00041 #include <BasicUtils/BasicException.h>
00042 #include <XMLCereal/XMLSerializer.h>
00043 
00044 #include <string.h>
00045 #include <map>
00046 #include <iostream>
00047 
00048 #ifndef LTSTR
00049 #define LTSTR
00050 #include <string.h>
00051 struct ltstr {
00052   bool operator()(const char* s1, const char* s2) const {
00053     return strcmp(s1, s2) < 0;
00054   }
00055 };
00056 #endif
00057 
00058 typedef enum {ymlUnknown = -1, ymlNetwork, ymlNode,
00059               ymlLink, ymlPort, ymlConnection} ymlentity_t;
00060 
00061 class YMLEntity {
00062   // Attributes
00063 private:
00065   int argc;
00067   char **args;
00069   BasicArray<char **> properties;
00071   std::map<const char *, const char *, ltstr> property_map;
00073   char *doc;
00074 
00075   // Operations
00076 public:
00077   YMLEntity();
00078   virtual ~YMLEntity();
00079 
00080   void addProperty(const char *name, const char *value);
00084   int getNumProperties() {return properties.getSize();}
00090   const char *getPropName(int i) {return properties.get(i)[0];}
00096   const char *getPropValue(int i) {return properties.get(i)[1];}
00104   const char *findProperty(const char *name) {return property_map[name];}
00105 
00106   virtual void setArgs(int argc, const char * const *args);
00110   int getArgc() {return argc;}
00118   const char *getArg(int i) 
00119   {ASSERT_OR_THROW("Out of range!", 0 <= i && i < argc); return args[i];}
00126   void setDoc(const char *doc) {this->doc = strdup(doc);}
00130   const char *getDoc() {return doc;}
00131 
00135   virtual ymlentity_t getType() = 0;
00141   virtual void dumpXML(XMLSerializer &stream) = 0;
00150   virtual void dumpDOT(std::ostream &stream, int tabLevel) {};
00155   virtual void finalize() {}
00160   virtual void doFinalize() = 0;
00161 
00162   void dumpXMLProperties(XMLSerializer &stream);
00163   static void tabs(std::ostream &stream, int num);
00164 };
00165 #endif

Generated on Wed Apr 5 20:57:46 2006 for Sesame by  doxygen 1.4.6