include string include cstring include cstdint include deque include m

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include <string>
#include <cstring>
#include <cstdint>
#include <deque>
#include <memory>
#include "variant/include/mpark/variant.hpp"
#ifndef PROPERTY_VALUES_HPP
#define PROPERTY_VALUES_HPP
namespace Contract
{
/*!
* \brief Хранит оригинальное содержимое / чистый текст объекта
*/
class DataChunk
{
uint8_t *m_data;
uint64_t m_size;
//НЕ копировать!
DataChunk(const DataChunk& other) = delete;
void operator=(const DataChunk& other) = delete;
public:
DataChunk(uint8_t *data, uint64_t size) :
m_data(nullptr),
m_size(size)
{
m_data = new uint8_t[(size_t)size];
std::memcpy(m_data, data, (size_t)m_size);
}
const uint8_t *GetData() const
{
return m_data;
}
uint64_t GetSize() const
{
return m_size;
}
~DataChunk()
{
delete[] m_data;
}
};
typedef std::shared_ptr<DataChunk> DataChunkPtr;
/*!
* \brief Значение свойства объекта
*/
class PropVal
{
typedef mpark::variant<bool,
uint32_t,
uint64_t,
std::string,
DataChunkPtr> PropValT;
PropValT m_val;
public:
PropVal()
{
}
template<class Tval>
PropVal(const Tval &val) :
m_val(val)
{
;
}
template<class Tval>
PropVal &operator=(const Tval &val)
{
m_val = val;
return *this;
}
template<class Tval>
inline Tval &get()
{
try
{
return mpark::get<Tval>(m_val);
}
catch (const mpark::bad_variant_access &e)
{
throw std::logic_error(e.what());
}
}
template<class Tval>
inline const Tval &get() const
{
try
{
return mpark::get<Tval>(m_val);
}
catch (const mpark::bad_variant_access &e)
{
throw std::logic_error(e.what());
}
}
};
typedef std::deque<PropVal> PropValArr;
}