00001
00002
00003
00004
00005
00006
00007
00008
00043 #ifdef _MSC_VER
00044 #pragma once
00045 #endif
00046
00047 #ifndef OGDF_GML_PARSER_H
00048 #define OGDF_GML_PARSER_H
00049
00050
00051 #include <ogdf/basic/Hashing.h>
00052 #include <ogdf/basic/String.h>
00053 #include <ogdf/basic/GraphAttributes.h>
00054 #include <ogdf/cluster/ClusterGraph.h>
00055 #include <ogdf/cluster/ClusterGraphAttributes.h>
00056
00057
00058 namespace ogdf {
00059
00060
00061 typedef HashElement<String,int> *GmlKey;
00062 enum GmlObjectType { gmlIntValue, gmlDoubleValue, gmlStringValue, gmlListBegin,
00063 gmlListEnd, gmlKey, gmlEOF, gmlError };
00064
00065
00066
00067
00068
00069
00070 struct OGDF_EXPORT GmlObject {
00071 GmlObject *m_pBrother;
00072 GmlKey m_key;
00073 GmlObjectType m_valueType;
00074
00075
00076
00077
00078
00079
00080
00081 union {
00082 int m_intValue;
00083 double m_doubleValue;
00084 const char *m_stringValue;
00085 GmlObject *m_pFirstSon;
00086 };
00087
00088
00089 GmlObject(GmlKey key, int intValue) : m_pBrother(0), m_key(key),
00090 m_valueType(gmlIntValue), m_intValue(intValue) { }
00091
00092 GmlObject(GmlKey key, double doubleValue) : m_pBrother(0), m_key(key),
00093 m_valueType(gmlDoubleValue), m_doubleValue(doubleValue) { }
00094
00095 GmlObject(GmlKey key, const char *stringValue) : m_pBrother(0), m_key(key),
00096 m_valueType(gmlStringValue), m_stringValue(stringValue) { }
00097
00098 GmlObject(GmlKey key) : m_pBrother(0), m_key(key),
00099 m_valueType(gmlListBegin), m_pFirstSon(0) { }
00100
00101 OGDF_NEW_DELETE
00102 };
00103
00104
00105
00106
00107
00108
00109 class OGDF_EXPORT GmlParser {
00110 Hashing<String,int> m_hashTable;
00111 int m_num;
00112
00113 istream *m_is;
00114 bool m_error;
00115 String m_errorString;
00116
00117 char *m_rLineBuffer, *m_lineBuffer, *m_pCurrent, *m_pStore, m_cStore;
00118
00119 int m_intSymbol;
00120 double m_doubleSymbol;
00121 const char *m_stringSymbol;
00122 GmlKey m_keySymbol;
00123 String m_longString;
00124
00125 GmlObject *m_objectTree;
00126
00127 bool m_doCheck;
00128 Array<node> m_mapToNode;
00129 GmlObject *m_graphObject;
00130
00131 public:
00132
00133 enum PredefinedKey { idPredefKey = 0, labelPredefKey, CreatorPredefKey,
00134 namePredefKey, graphPredefKey, versionPredefKey, directedPredefKey,
00135 nodePredefKey, edgePredefKey, graphicsPredefKey, xPredefKey,
00136 yPredefKey, wPredefKey, hPredefKey, typePredefKey, widthPredefKey,
00137 sourcePredefKey, targetPredefKey, arrowPredefKey, LinePredefKey,
00138 pointPredefKey, generalizationPredefKey, subGraphPredefKey, fillPredefKey, clusterPredefKey,
00139 rootClusterPredefKey, vertexPredefKey, colorPredefKey,
00140 heightPredefKey, stipplePredefKey, patternPredefKey,
00141 linePredefKey, lineWidthPredefKey, templatePredefKey,
00142 edgeWeightPredefKey, NEXTPREDEFKEY };
00143
00144
00145
00146 GmlParser(const char *fileName, bool doCheck = false);
00147 GmlParser(istream &is, bool doCheck = false);
00148
00149
00150 ~GmlParser();
00151
00152
00153 int id(GmlObject *object) const { return object->m_key->info(); }
00154
00155
00156 bool error() const { return m_error; }
00157
00158 const String &errorString() const { return m_errorString; }
00159
00160
00161 bool read(Graph &G);
00162
00163 bool read(Graph &G, GraphAttributes &AG);
00164
00165
00166
00167 bool readCluster(Graph &G, ClusterGraph& CG);
00168
00169 bool readAttributedCluster(Graph &G, ClusterGraph& CG,
00170 ClusterGraphAttributes& ACG);
00171
00172 protected:
00173
00174
00175 bool clusterRead(GmlObject* rootCluster,
00176 ClusterGraph& CG);
00177
00178 bool attributedClusterRead(GmlObject* rootCluster,
00179 ClusterGraph& CG,
00180 ClusterGraphAttributes& ACG);
00181
00182 bool recursiveClusterRead(GmlObject* clusterObject,
00183 ClusterGraph& CG,
00184 cluster c);
00185 bool recursiveAttributedClusterRead(GmlObject* clusterObject,
00186 ClusterGraph& CG,
00187 ClusterGraphAttributes& ACG,
00188 cluster c);
00189 bool readClusterAttributes(GmlObject* cGraphics,
00190 cluster c,
00191 ClusterGraphAttributes& ACG);
00192
00193 private:
00194 void doInit(istream &is, bool doCheck);
00195 void createObjectTree(istream &is, bool doCheck);
00196 void initPredefinedKeys();
00197 void setError(const char *errorString);
00198
00199 GmlObject *parseList(GmlObjectType closingKey, GmlObjectType errorKey);
00200 GmlObjectType getNextSymbol();
00201 bool getLine();
00202
00203 GmlKey hashString(const String &str);
00204
00205 GmlObject *getNodeIdRange(int &minId,int &maxId);
00206 void readLineAttribute(GmlObject *object, DPolyline &dpl);
00207
00208 void destroyObjectList(GmlObject *object);
00209
00210 void indent(ostream &os, int d);
00211 void output(ostream &os, GmlObject *object, int d);
00212
00213 };
00214
00215
00216 }
00217
00218 #endif