Devel Lib
SerializableWString.h
1 #pragma once
2 
3 #include "Serializing/Core/SerializableData.h"
4 
7 namespace Devel::Serializing {
8 #pragma pack(push, 1)
9 
17  template<bool IsHidden = false, typename T = std::wstring>
18  class IWString : public IData<T, IsHidden> {
19  public:
22  SCompareData compareData() const override {
23  return {static_cast<const void *>(this->m_tValue.c_str()), this->m_tValue.size() * 2};
24  }
25 
26  private:
31  bool serialize(IO::CWriteStream &i_oStream) override {
32  i_oStream.push<uint>(static_cast<uint>(this->m_tValue.size()));
33  i_oStream.push(this->m_tValue, false);
34  return true;
35  }
36 
37  private:
42  bool deserialize(IO::CReadStream &i_oStream) override {
43  const size_t nSize = static_cast<size_t>(i_oStream.get<uint>());
44  this->m_tValue = i_oStream.getWString(nSize);
45  return true;
46  }
47 
52  bool deserialize(const char *i_szString) override {
53  this->m_tValue = std::wstring(i_szString, i_szString + strlen(i_szString));
54  return true;
55  }
56 
62  bool deserialize(std::vector<std::string>::const_iterator &i_oIt,
63  const std::vector<std::string>::const_iterator &i_oItEnd) override {
64  this->m_tValue = std::wstring(i_oIt->begin(), i_oIt->end());
65  return true;
66  }
67 
68  public:
69  CreateSerializeOperators(T, IsHidden);
70  };
71 
72 #pragma pack(pop)
73 }
unsigned int uint
An unsigned integer type.
Definition: Typedef.h:19
A class for reading data from a buffer. This class provides functionality to read data from a buffer....
Definition: ReadStream.h:37
std::wstring getWString(const size_t i_nPosition, const size_t i_nLength, const bool i_fIsZeroTerminated, const bool i_fSetPosition)
Reads a wide string from the buffer.
Definition: ReadStream.h:285
T get(const size_t i_nPosition, const bool i_fSetPosition)
Reads a value of type T from the buffer.
Definition: ReadStream.h:344
A class for writing data to a buffer. This class provides functionality to write data to a buffer....
Definition: WriteStream.h:42
void push(const void *i_pBuffer, size_t i_nSize)
Pushes the specified data to the buffer.
Definition: WriteStream.cpp:30
Template class representing a data field.
Definition: SerializableData.h:86
T m_tValue
The value.
Definition: SerializableData.h:78
A class representing a wide string value for serialization.
Definition: SerializableWString.h:18
SCompareData compareData() const override
Retrieves the compare data for the wide string value.
Definition: SerializableWString.h:22
The namespace encapsulating serializing related functionality in the Devel framework.
Structure for comparing serialized data.
Definition: SerializableData.h:19