Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
Utils.h
Go to the documentation of this file.
1
32#pragma once
33
34#include <ogdf/basic/basic.h>
35
36#include <map>
37
38namespace ogdf {
39
40// Provides a nicer syntax for reading formatted input through streams, e.g.
41// `stream >> a >> ';' >> y`.
43private:
44 char m_c;
45
46public:
47 explicit TokenIgnorer(const char c) : m_c(c) {};
48
49 friend std::istream& operator>>(std::istream& is, TokenIgnorer c);
50};
51
52std::istream& operator>>(std::istream& is, TokenIgnorer token);
53
54template<typename E>
55static inline E toEnum(const std::string& str, // A string we want to convert.
56 std::string toString(const E&), const E first, const E last, const E def) // Enum informations.
57{
58 static std::map<std::string, E> map; // A map to be lazily evaluated.
59 if (map.empty()) {
60 // Iterating over enums is potentially unsafe... (fixable in C++11).
61 for (int it = static_cast<int>(last); it >= static_cast<int>(first); it--) {
62 const E e = static_cast<E>(it);
63 map[toString(e)] = e;
64 }
65 }
66
67 return map.find(str) == map.end() ? def : map[str];
68}
69
70}
Basic declarations, included by all source files.
TokenIgnorer(const char c)
Definition Utils.h:47
friend std::istream & operator>>(std::istream &is, TokenIgnorer c)
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
The namespace for all OGDF objects.
std::istream & operator>>(std::istream &is, TokenIgnorer token)
string toString(FromClass key)
Definition graphics.h:557
static E toEnum(const std::string &str, std::string toString(const E &), const E first, const E last, const E def)
Definition Utils.h:55