Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

GmlParser.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/Array.h>
35 #include <ogdf/basic/Graph.h>
36 #include <ogdf/basic/Logger.h>
37 #include <ogdf/basic/basic.h>
38 #include <ogdf/basic/geometry.h>
39 #include <ogdf/basic/memory.h>
41 #include <ogdf/fileformats/GML.h>
42 
43 #include <iosfwd>
44 #include <string>
45 
46 namespace ogdf {
47 class ClusterGraphAttributes;
48 class GraphAttributes;
49 
50 namespace gml {
51 
54  Object* pBrother; // brother of node in tree
55  Key key; // tag of node
56  ObjectType valueType; // type of node
57 
58  // the entry in the union is selected according to m_valueType:
59  // IntValue -> m_intValue
60  // DoubleValue -> m_doubleValue
61  // StringValue -> m_stringValue
62  // ListBegin -> m_pFirstSon (in case of a list, m_pFirstSon is pointer
63  // to first son and the sons are chained by m_pBrother)
64  union {
65  int intValue;
66  double doubleValue;
67  const char* stringValue;
69  };
70 
71  // construction
72  Object(Key k, int value)
73  : pBrother(nullptr), key(k), valueType(ObjectType::IntValue), intValue(value) { }
74 
75  Object(Key k, double value)
76  : pBrother(nullptr), key(k), valueType(ObjectType::DoubleValue), doubleValue(value) { }
77 
78  Object(Key k, const char* value)
79  : pBrother(nullptr), key(k), valueType(ObjectType::StringValue), stringValue(value) { }
80 
82  : pBrother(nullptr), key(k), valueType(ObjectType::ListBegin), pFirstSon(nullptr) { }
83 
85 };
86 
89  std::istream* m_is;
90  bool m_error;
91 
92  char *m_rLineBuffer, *m_lineBuffer, *m_pCurrent, *m_pStore, m_cStore;
93 
96  const char* m_stringSymbol;
98  string m_longString;
99 
100  Object* m_objectTree; // root node of GML parse tree
101 
102  bool m_doCheck;
105 
106 public:
107  // construction: creates object tree
108  // sets m_error flag if an error occured
109  explicit Parser(std::istream& is, bool doCheck = false);
110 
112  ~Parser();
113 
114  // true <=> an error in GML files has been detected
115  bool error() const { return m_error; }
116 
117  // creates graph from GML parse tree
118  bool read(Graph& G);
119  // creates attributed graph from GML parse tree
120  bool read(Graph& G, GraphAttributes& GA);
121 
122  //read only cluster part of object tree and create cluster graph structure
123  bool readCluster(Graph& G, ClusterGraph& CG, ClusterGraphAttributes* ACG = nullptr);
124 
125 protected:
127  bool recursiveClusterRead(Object* clusterObject, ClusterGraph& CG, cluster c,
128  ClusterGraphAttributes* ACG = nullptr);
129 
130 private:
131  void createObjectTree(std::istream& is, bool doCheck);
132  void setError(const string& errorString, Logger::Level level = Logger::Level::Default);
133 
134  Object* parseList(ObjectType closingKey);
135  ObjectType getNextSymbol();
136  bool getLine();
137 
138  Object* getNodeIdRange(int& minId, int& maxId);
139  void readLineAttribute(Object* object, DPolyline& dpl);
140 
141  void destroyObjectList(Object* object);
142 };
143 
144 }
145 
146 }
ogdf::gml::Object::pBrother
Object * pBrother
Definition: GmlParser.h:54
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
ogdf::GraphAttributes
Stores additional attributes of a graph (like layout information).
Definition: GraphAttributes.h:72
Graph.h
Includes declaration of graph class.
geometry.h
Declaration of classes GenericPoint, GenericPolyline, GenericLine, GenericSegment,...
ogdf::gml::Object::key
Key key
Definition: GmlParser.h:55
ogdf::gml::Parser::m_is
std::istream * m_is
Definition: GmlParser.h:89
ogdf::gml::Parser::error
bool error() const
Definition: GmlParser.h:115
ogdf::GenericPolyline
Polylines with PointType points.
Definition: geometry.h:261
ogdf::gml::Key
Key
Definition: GML.h:56
GML.h
GML related enums and string conversion functions.
ogdf::gml::Object::Object
Object(Key k, const char *value)
Definition: GmlParser.h:78
ogdf::Logger::Level
Level
supported log-levels from lowest to highest importance
Definition: Logger.h:105
ogdf::gml::Object::Object
Object(Key k)
Definition: GmlParser.h:81
ogdf::gml::ObjectType::ListBegin
@ ListBegin
ogdf::gml::Object::valueType
ObjectType valueType
Definition: GmlParser.h:56
ogdf::gml::ObjectType::IntValue
@ IntValue
ogdf::Logger::Level::Default
@ Default
ogdf::gml::Parser::m_intSymbol
int m_intSymbol
Definition: GmlParser.h:94
OGDF_NEW_DELETE
#define OGDF_NEW_DELETE
Makes the class use OGDF's memory allocator.
Definition: memory.h:85
ogdf::gml::Parser::m_doCheck
bool m_doCheck
Definition: GmlParser.h:102
ogdf::gml::Parser::m_objectTree
Object * m_objectTree
Definition: GmlParser.h:100
Logger.h
Contains logging functionality.
ogdf::ClusterElement
Representation of clusters in a clustered graph.
Definition: ClusterGraph.h:62
ogdf::gml::Parser
Reads GML file and constructs GML parse tree.
Definition: GmlParser.h:88
ogdf::gml::Object
Represents node in GML parse tree.
Definition: GmlParser.h:53
ogdf::ClusterGraphAttributes
Stores additional attributes of a clustered graph (like layout information).
Definition: ClusterGraphAttributes.h:52
ogdf::gml::ObjectType
ObjectType
Definition: GML.h:45
ogdf::gml::Object::Object
Object(Key k, double value)
Definition: GmlParser.h:75
ogdf::gml::ObjectType::StringValue
@ StringValue
ogdf::gml::Object::stringValue
const char * stringValue
Definition: GmlParser.h:67
ogdf::gml::Object::pFirstSon
Object * pFirstSon
Definition: GmlParser.h:68
ogdf::Array< node >
ogdf::gml::Parser::m_graphObject
Object * m_graphObject
Definition: GmlParser.h:104
ogdf::gml::Parser::m_longString
string m_longString
Definition: GmlParser.h:98
ogdf::Graph
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:869
ogdf::gml::Parser::m_doubleSymbol
double m_doubleSymbol
Definition: GmlParser.h:95
ogdf::gml::Object::doubleValue
double doubleValue
Definition: GmlParser.h:66
ogdf::gml::Parser::m_mapToNode
Array< node > m_mapToNode
Definition: GmlParser.h:103
ogdf::gml::Object::intValue
int intValue
Definition: GmlParser.h:65
ogdf::gml::Parser::m_error
bool m_error
Definition: GmlParser.h:90
ogdf::gml::Parser::m_stringSymbol
const char * m_stringSymbol
Definition: GmlParser.h:96
ogdf::gml::Parser::m_keySymbol
Key m_keySymbol
Definition: GmlParser.h:97
basic.h
Basic declarations, included by all source files.
OGDF_EXPORT
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:101
Array.h
Declaration and implementation of Array class and Array algorithms.
ClusterGraph.h
Derived class of GraphObserver providing additional functionality to handle clustered graphs.
ogdf::gml::Parser::m_rLineBuffer
char * m_rLineBuffer
Definition: GmlParser.h:92
ogdf::ClusterGraph
Representation of clustered graphs.
Definition: ClusterGraph.h:346
ogdf::gml::ObjectType::DoubleValue
@ DoubleValue
memory.h
Declaration of memory manager for allocating small pieces of memory.
ogdf::gml::Object::Object
Object(Key k, int value)
Definition: GmlParser.h:72