Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

DLParser.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/Graph.h>
36 
37 #include <iostream>
38 #include <sstream>
39 #include <string>
40 #include <vector>
41 #include <map>
42 #include <algorithm>
43 
44 
45 namespace ogdf {
46 
47 
48 class DLParser {
49 private:
50  std::istream &m_istream;
52 
53  int m_nodes;
55  bool m_embedded;
56 
57  std::vector<node> m_nodeId; // For constant-time index to node mapping.
58  std::map<std::string, node> m_nodeLabel; // For embedded label mode.
59 
60  static inline void toUpper(std::string &str) {
61  std::transform(str.begin(), str.end(), str.begin(), toupper);
62  }
63 
64  static inline void toLower(std::string &str) {
65  std::transform(str.begin(), str.end(), str.begin(), tolower);
66  }
67 
68  inline bool fineId(int vid) {
69  return 0 < vid && vid < static_cast<int>(m_nodeId.size());
70  }
71 
72  inline node requestLabel(
73  GraphAttributes *GA, node &nextFree,
74  const std::string &label);
75 
76  void init();
77  bool initGraph(Graph &G);
78 
79  bool readMatrix(Graph &G, GraphAttributes *GA);
80  bool readEdgeList(Graph &G, GraphAttributes *GA);
81  bool readNodeList(Graph &G);
85 
86  bool readAssignment(
87  Graph &G,
88  const std::string &lhs, const std::string &rhs);
89 
90  bool readData(Graph &G, GraphAttributes *GA);
91  bool readWithLabels(Graph &G, GraphAttributes *GA);
92  bool readStatements(Graph &G, GraphAttributes *GA);
93  bool readGraph(Graph &G, GraphAttributes *GA);
94 
95 public:
96  explicit DLParser(std::istream &is);
97 
98  bool read(Graph &G) {
99  return readGraph(G, nullptr);
100  }
101 
102  bool read(Graph &G, GraphAttributes &GA) {
103  return readGraph(G, &GA);
104  }
105 };
106 
107 
108 } // end namespace ogdf
enum ogdf::DLParser::Format m_format
bool readWithLabels(Graph &G, GraphAttributes *GA)
std::map< std::string, node > m_nodeLabel
Definition: DLParser.h:58
Declaration of class GraphAttributes which extends a Graph by additional attributes.
static void toUpper(std::string &str)
Definition: DLParser.h:60
bool readEmbeddedMatrix(Graph &G, GraphAttributes *GA)
std::vector< node > m_nodeId
Definition: DLParser.h:57
Data type for general directed graphs (adjacency list representation).
Definition: Graph_d.h:472
node requestLabel(GraphAttributes *GA, node &nextFree, const std::string &label)
DLParser(std::istream &is)
bool readGraph(Graph &G, GraphAttributes *GA)
bool initGraph(Graph &G)
bool readAssignment(Graph &G, const std::string &lhs, const std::string &rhs)
bool read(Graph &G)
Definition: DLParser.h:98
static void toLower(std::string &str)
Definition: DLParser.h:64
bool readEmbeddedNodeList(Graph &G, GraphAttributes *GA)
Stores additional attributes of a graph (like layout information).
Class for the representation of nodes.
Definition: Graph_d.h:167
std::istream & m_istream
Definition: DLParser.h:50
bool readEmbeddedEdgeList(Graph &G, GraphAttributes *GA)
bool read(Graph &G, GraphAttributes &GA)
Definition: DLParser.h:102
bool fineId(int vid)
Definition: DLParser.h:68
bool m_embedded
Definition: DLParser.h:55
bool m_initialized
Definition: DLParser.h:51
Includes declaration of graph class.
bool readData(Graph &G, GraphAttributes *GA)
The namespace for all OGDF objects.
bool readNodeList(Graph &G)
bool readStatements(Graph &G, GraphAttributes *GA)
bool readEdgeList(Graph &G, GraphAttributes *GA)
bool readMatrix(Graph &G, GraphAttributes *GA)