00001
00002
00003
00004
00005
00006
00007
00008
00043 #ifdef _MSC_VER
00044 #pragma once
00045 #endif
00046
00047 #ifndef OGDF_XML_PARSER_H
00048 #define OGDF_XML_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/fileformats/XmlObject.h>
00055 #include <ogdf/basic/SList.h>
00056
00057
00058 namespace ogdf {
00059
00060
00061
00062
00063
00064
00065
00066 class OGDF_EXPORT XmlParser {
00067 Hashing<String,int> m_hashTable;
00068 int m_num;
00069
00070 istream *m_is;
00071 bool m_error;
00072 String m_errorString;
00073
00074 char *m_rLineBuffer, *m_lineBuffer, *m_pCurrent, *m_pStore, m_cStore;
00075
00076 int m_intSymbol;
00077 double m_doubleSymbol;
00078 const char *m_stringSymbol;
00079 char *m_keyName;
00080 XmlKey m_keySymbol;
00081 String m_longString;
00082 bool m_eoTag;
00083
00084 XmlObject *m_objectTree;
00085
00086 bool m_doCheck;
00087
00088 SList<char*> m_objectBody;
00089
00090 public:
00091
00092 enum PredefinedKey { idPredefKey = 0, labelPredefKey, CreatorPredefKey,
00093 namePredefKey, graphPredefKey, versionPredefKey, directedPredefKey,
00094 nodePredefKey, edgePredefKey, graphicsPredefKey, xPredefKey,
00095 yPredefKey, wPredefKey, hPredefKey, nodetypePredefKey, edgetypePredefKey,
00096 typePredefKey, widthPredefKey, heightPredefKey, sizePredefKey,
00097 positionPredefKey, pathPredefKey,
00098 sourcePredefKey, targetPredefKey, sensePredefKey, arrowPredefKey, LinePredefKey,
00099 pointPredefKey, NEXTPREDEFKEY };
00100
00101
00102
00103 XmlParser(const char *fileName, bool doCheck = false);
00104 XmlParser(istream &is, bool doCheck = false);
00105
00106
00107 ~XmlParser();
00108
00109
00110 XmlObject *root() { return m_objectTree; }
00111
00112
00113 int getId(const String &tag) const {
00114 HashElement<String,int> *it = m_hashTable.lookup(tag);
00115 return (it != 0) ? it->info() : -1;
00116 }
00117
00118
00119 int id(XmlObject *object) const { return object->m_key->info(); }
00120
00121
00122 bool error() const { return m_error; }
00123
00124 const String &errorString() const { return m_errorString; }
00125
00126
00127 bool read(Graph &G);
00128
00129 bool read(Graph &G, GraphAttributes &AG);
00130
00131 private:
00132 void createObjectTree(istream &is, bool doCheck);
00133 void initPredefinedKeys();
00134 void setError(const char *errorString);
00135
00136 XmlObject *parseList(XmlObjectType closingKey, XmlObjectType errorKey, const char *objectBodyName);
00137 XmlObjectType getNextSymbol();
00138 bool getLine();
00139
00140 XmlKey hashString(const String &str);
00141
00142 XmlObject *getNodeIdRange(int &minId,int &maxId,
00143 int &nodetypeCount,
00144 XmlObject *graphObject);
00145
00146 bool makeIdMap(int maxId,
00147 Array<char*> &idMap,
00148 int nodetypeCount,
00149 Array<char*> & typeName,
00150 Array<double> &typeWidth,
00151 Array<double> &typeHeight,
00152 XmlObject *graphObject);
00153
00154 void closeLabels(Array<char*> idMap, Array<char*> typeName);
00155
00156 void readLineAttribute(XmlObject *object, DPolyline &dpl);
00157
00158 void destroyObjectList(XmlObject *object);
00159
00160 void indent(ostream &os, int d);
00161 void output(ostream &os, XmlObject *object, int d);
00162
00163 };
00164
00165
00166 }
00167
00168 #endif