Loading [MathJax]/extensions/tex2jax.js

Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
basic.h
Go to the documentation of this file.
1
32#pragma once
33
35
38
41#define OGDF_ASSERT(expr)
44#define OGDF_HEAVY_ASSERT(expr)
45
46#ifdef OGDF_DEBUG
47# ifdef OGDF_HEAVY_DEBUG
48# undef OGDF_HEAVY_ASSERT
49# define OGDF_HEAVY_ASSERT(expr) OGDF_ASSERT(expr)
50# endif
51# undef OGDF_ASSERT
52# ifndef OGDF_USE_ASSERT_EXCEPTIONS
53# include <cassert>
54# define OGDF_ASSERT(expr) assert(expr)
55# else
56# include <sstream>
57# include <stdexcept>
58
59namespace ogdf {
64class AssertionFailed : public std::runtime_error {
65 using std::runtime_error::runtime_error;
66};
67}
68
69# define OGDF_ASSERT(expr) \
70 do { \
71 if (!(expr)) { \
72 std::stringstream ogdf_assert_ss; \
73 ogdf_assert_ss << "OGDF assertion `" #expr "' failed at " __FILE__ ":" \
74 << __LINE__ << "(" << OGDF_FUNCTION_NAME << ")"; \
75 ogdf::get_stacktrace(ogdf_assert_ss); \
76 throw ogdf::AssertionFailed(ogdf_assert_ss.str()); \
77 } \
78 } while (false)
79# endif
80#endif
81
83
84// g++ 4.8/4.9 does not have is_trivially_copyable,
85// but clang 3.5 (which is also __GNUC__ < 5) has it.
86#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 5
87# define OGDF_TRIVIALLY_COPYABLE std::has_trivial_copy_assign
88#else
89# define OGDF_TRIVIALLY_COPYABLE std::is_trivially_copyable
90#endif
91
92#include <algorithm>
93#include <cmath>
94#include <cstdint>
95#include <ctime>
96#include <fstream>
97#include <limits>
98
100namespace ogdf {
101
103OGDF_EXPORT extern bool debugMode;
104
105// generally used <algorithm> members
106using std::max;
107using std::min;
108
118
119// OGDF_INSTALL is defined only when compiling a dynamic library.
120// Whenever this library is used we can safely assume that this header
121// file is included beforehand.
122// Thus, there will be a static initialization object in the program that uses the library.
123#ifndef OGDF_INSTALL
124// This has to be in the header file. Being in the cpp file does not
125// guarantee that it is constructed (with all linkers).
127#endif
128
129#ifdef OGDF_USE_ASSERT_EXCEPTIONS
131OGDF_EXPORT extern void get_stacktrace(std::ostream& stream);
132#endif
133
134enum class Direction { before, after };
135
138
140
144OGDF_EXPORT long unsigned int randomSeed();
145
148
150
154OGDF_EXPORT int randomNumber(int low, int high);
155
157
161OGDF_EXPORT double randomDouble(double low, double high);
162
165inline double randomDoubleNormal(double m, double sd) {
166 double x1, y1, w;
167
168 do {
169 double rndVal = randomDouble(0, 1);
170 x1 = 2.0 * rndVal - 1.0;
171 rndVal = randomDouble(0, 1);
172 double x2 = 2.0 * rndVal - 1.0;
173 w = x1 * x1 + x2 * x2;
174 } while (w >= 1.0);
175
176 w = sqrt((-2.0 * log(w)) / w);
177 y1 = x1 * w;
178
179 return m + y1 * sd;
180}
181
183
188
190
192
195OGDF_EXPORT double usedTime(double& T);
196
199
201OGDF_EXPORT bool equalIgnoreCase(const string& str1, const string& str2);
202
204OGDF_EXPORT bool prefixIgnoreCase(const string& prefix, const string& str);
205
208
210
219template<typename CONTAINER, typename T>
220int searchPos(const CONTAINER& C, const T& x) {
221 int pos = 0;
222 for (const T& y : C) {
223 if (x == y) {
224 return pos;
225 }
226 ++pos;
227 }
228
229 return -1;
230}
231
233
235
240template<class E>
242public:
243 virtual ~BucketFunc() { }
244
246 virtual int getBucket(const E& x) = 0;
247};
248
249}
Abstract base class for bucket functions.
Definition basic.h:241
virtual ~BucketFunc()
Definition basic.h:243
virtual int getBucket(const E &x)=0
Returns the bucket of x.
The class Initialization is used for initializing global variables.
Definition basic.h:113
Basic configuration file.
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition config.h:101
int searchPos(const CONTAINER &C, const T &x)
Searches for the position of x in container C; returns -1 if not found.
Definition basic.h:220
double usedTime(double &T)
Returns used CPU time from T to current time and assigns current time to T.
int randomNumber(int low, int high)
Returns random integer between low and high (including).
double randomDoubleExponential(double beta)
Returns a random double value from the exponential distribution.
double randomDouble(double low, double high)
Returns a random double value from the interval [low, high).
double randomDoubleNormal(double m, double sd)
Returns a random double value from the normal distribution with mean m and standard deviation sd.
Definition basic.h:165
void setSeed(int val)
Sets the seed for functions like randomSeed(), randomNumber(), randomDouble().
long unsigned int randomSeed()
Returns a random value suitable as initial seed for a random number engine.
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
The namespace for all OGDF objects.
bool equalIgnoreCase(const string &str1, const string &str2)
Compares the two strings str1 and str2, ignoring the case of characters.
bool prefixIgnoreCase(const string &prefix, const string &str)
Tests if prefix is a prefix of str, ignoring the case of characters.
void removeTrailingWhitespace(string &str)
Removes trailing space, horizontal and vertical tab, feed, newline, and carriage return from str.
Direction
Definition basic.h:134
static Initialization s_ogdfInitializer
Definition basic.h:126
bool debugMode
Set to true iff debug mode is used during compilation of the OGDF.