| 1 |
#pragma once |
| 2 |
|
| 3 |
#include <string_view> |
| 4 |
#include <utility> |
| 5 |
|
| 6 |
#include "gvc.h" |
| 7 |
|
| 8 |
#ifdef GVDLL |
| 9 |
#if gvc___EXPORTS // CMake's substitution of gvc++_EXPORTS |
| 10 |
#define GVCONTEXT_API __declspec(dllexport) |
| 11 |
#else |
| 12 |
#define GVCONTEXT_API __declspec(dllimport) |
| 13 |
#endif |
| 14 |
#endif |
| 15 |
|
| 16 |
#ifndef GVCONTEXT_API |
| 17 |
#define GVCONTEXT_API /* nothing */ |
| 18 |
#endif |
| 19 |
|
| 20 |
namespace GVC { |
| 21 |
|
| 22 |
/** |
| 23 |
* @brief The GVContext class represents a Graphviz context |
| 24 |
*/ |
| 25 |
|
| 26 |
class GVCONTEXT_API GVContext { |
| 27 |
public: |
| 28 |
GVContext(); |
| 29 |
/** |
| 30 |
* @brief GVContext Create a graph context with built-in plugins and |
| 31 |
* optionally load dynamic plugins on demand. |
| 32 |
* @param builtins Array of structs, each containing a pointer to |
| 33 |
* the name and the address of a plugin to load. The end of the array is |
| 34 |
* designated by a struct whose name pointer is NULL. |
| 35 |
* @param demand_loading Enables loading plugins dynamically on |
| 36 |
* demand when true. |
| 37 |
*/ |
| 38 |
GVContext(const lt_symlist_t *builtins, bool demand_loading); |
| 39 |
~GVContext(); |
| 40 |
|
| 41 |
// delete copy since we manage a C struct using a raw pointer and the struct |
| 42 |
// cannot be easily copied since it contains even more raw pointers |
| 43 |
GVContext(GVContext &) = delete; |
| 44 |
GVContext &operator=(GVContext &) = delete; |
| 45 |
|
| 46 |
// implement move since we manage a C struct using a raw pointer |
| 47 |
GVContext(GVContext &&other) noexcept |
| 48 |
: m_gvc(std::exchange(other.m_gvc, nullptr)) {} |
| 49 |
GVContext &operator=(GVContext &&other) noexcept { |
| 50 |
using std::swap; |
| 51 |
swap(m_gvc, other.m_gvc); |
| 52 |
return *this; |
| 53 |
} |
| 54 |
|
| 55 |
// get a non-owning pointer to the underlying C data structure |
| 56 |
GVC_t *c_struct() const { return m_gvc; } |
| 57 |
|
| 58 |
std::string_view buildDate() const; |
| 59 |
std::string_view version() const; |
| 60 |
|
| 61 |
private: |
| 62 |
// the underlying C data structure |
| 63 |
GVC_t *m_gvc = nullptr; |
| 64 |
}; |
| 65 |
|
| 66 |
} // namespace GVC |
| 67 |
|
| 68 |
#undef GVCONTEXT_API |