00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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
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
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