Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

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