| 1 |
#pragma once |
| 2 |
|
| 3 |
#include <string> |
| 4 |
#include <utility> |
| 5 |
|
| 6 |
#include "cgraph.h" |
| 7 |
|
| 8 |
#ifdef GVDLL |
| 9 |
#if cgraph___EXPORTS // CMake's substitution of cgraph++_EXPORTS |
| 10 |
#define AGRAPH_API __declspec(dllexport) |
| 11 |
#else |
| 12 |
#define AGRAPH_API __declspec(dllimport) |
| 13 |
#endif |
| 14 |
#endif |
| 15 |
|
| 16 |
#ifndef AGRAPH_API |
| 17 |
#define AGRAPH_API /* nothing */ |
| 18 |
#endif |
| 19 |
|
| 20 |
namespace CGraph { |
| 21 |
|
| 22 |
/** |
| 23 |
* @brief The AGraph class represents an abstract graph |
| 24 |
*/ |
| 25 |
|
| 26 |
class AGRAPH_API AGraph { |
| 27 |
public: |
| 28 |
explicit AGraph(const std::string &dot); |
| 29 |
~AGraph(); |
| 30 |
|
| 31 |
// delete copy since we manage a C struct using a raw pointer and the struct |
| 32 |
// cannot be easily copied since it contains even more raw pointers |
| 33 |
AGraph(const AGraph &) = delete; |
| 34 |
AGraph &operator=(const AGraph &) = delete; |
| 35 |
|
| 36 |
// implement move since we manage a C struct using a raw pointer |
| 37 |
AGraph(AGraph &&other) noexcept : m_g(std::exchange(other.m_g, nullptr)) {} |
| 38 |
AGraph &operator=(AGraph &&other) noexcept { |
| 39 |
using std::swap; |
| 40 |
swap(m_g, other.m_g); |
| 41 |
return *this; |
| 42 |
} |
| 43 |
|
| 44 |
// get a non-owning pointer to the underlying C data structure |
| 45 |
Agraph_t *c_struct() const { return m_g; } |
| 46 |
|
| 47 |
private: |
| 48 |
// the underlying C data structure |
| 49 |
Agraph_t *m_g = nullptr; |
| 50 |
}; |
| 51 |
|
| 52 |
} // namespace CGraph |
| 53 |
|
| 54 |
#undef AGRAPH_API |