#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;
}