| 1 |
#pragma once |
| 2 |
|
| 3 |
#include <cstddef> |
| 4 |
#include <string_view> |
| 5 |
|
| 6 |
#ifdef GVDLL |
| 7 |
#if gvc___EXPORTS // CMake's substitution of gvc++_EXPORTS |
| 8 |
#define GVRENDER_API __declspec(dllexport) |
| 9 |
#else |
| 10 |
#define GVRENDER_API __declspec(dllimport) |
| 11 |
#endif |
| 12 |
#endif |
| 13 |
|
| 14 |
#ifndef GVRENDER_API |
| 15 |
#define GVRENDER_API /* nothing */ |
| 16 |
#endif |
| 17 |
|
| 18 |
namespace GVC { |
| 19 |
|
| 20 |
class GVLayout; |
| 21 |
|
| 22 |
/** |
| 23 |
* @brief The GVRenderData class represents a rendered layout in a specific text |
| 24 |
* format |
| 25 |
*/ |
| 26 |
|
| 27 |
class GVRENDER_API GVRenderData { |
| 28 |
public: |
| 29 |
~GVRenderData(); |
| 30 |
|
| 31 |
// delete copy for now since we cannot use default because we manage a C |
| 32 |
// string using a raw pointer |
| 33 |
GVRenderData(GVRenderData &) = delete; |
| 34 |
GVRenderData &operator=(GVRenderData &) = delete; |
| 35 |
|
| 36 |
// delete move for now since we cannot use default because we manage a C |
| 37 |
// string using a raw pointer |
| 38 |
GVRenderData(GVRenderData &&) = delete; |
| 39 |
GVRenderData &operator=(GVRenderData &&) = delete; |
| 40 |
|
| 41 |
// get the rendered string as a C string. The string is null terminated, but |
| 42 |
// that is not useful for binary formats. Combine with the length method for |
| 43 |
// that case. |
| 44 |
char *c_str() const { return m_data; } |
| 45 |
|
| 46 |
// get the length of the rendered string |
| 47 |
std::size_t length() const { return m_length; } |
| 48 |
|
| 49 |
// get the rendered string as a string view |
| 50 |
std::string_view string_view() const { |
| 51 |
return std::string_view{m_data, m_length}; |
| 52 |
} |
| 53 |
|
| 54 |
friend GVLayout; |
| 55 |
|
| 56 |
private: |
| 57 |
// use GVLayout::render to constuct a GVRenderData object |
| 58 |
GVRenderData(char *rendered_data, std::size_t length); |
| 59 |
|
| 60 |
// the underlying C data structure |
| 61 |
char *m_data = nullptr; |
| 62 |
std::size_t m_length = 0; |
| 63 |
}; |
| 64 |
|
| 65 |
} // namespace GVC |
| 66 |
|
| 67 |
#undef GVRENDER_API |