Devel Lib
SerializableArithmetic.h
1 #pragma once
2 
3 #include "Core/Typedef.h"
4 #include "Core/Global.h"
5 #include "Core/Utils/StringUtils.h"
6 #include "Serializing/Core/SerializableData.h"
7 
10 namespace Devel::Serializing {
11 #pragma pack(push, 1)
12 
18  template<typename T, bool IsHidden = false, typename std::enable_if<std::is_arithmetic<T>::value> * = nullptr>
19  class IArithmetic : public IData<T, IsHidden> {
20  private:
24  bool serialize(IO::CWriteStream &i_oStream) const override {
25  i_oStream.push(this->m_tValue);
26  return true;
27  }
28 
29  private:
33  bool deserialize(IO::CReadStream &i_oStream) override {
34  this->m_tValue = i_oStream.get<T>();
35  return true;
36  }
37 
41  bool deserialize(const char *i_szValue) override {
42  if (sizeof(T) <= 4) {
43  this->m_tValue = static_cast<T>(StringUtils::ToUInt(i_szValue));
44  } else {
45  this->m_tValue = static_cast<T>(StringUtils::ToUInt64(i_szValue));
46  }
47 
48  return true;
49  }
50 
55  bool deserialize(std::vector<std::string>::const_iterator &i_oIt,
56  const std::vector<std::string>::const_iterator &i_oItEnd) override {
57  if (sizeof(T) <= 4) {
58  this->m_tValue = static_cast<T>(StringUtils::ToUInt(*i_oIt));
59  } else {
60  this->m_tValue = static_cast<T>(StringUtils::ToUInt64(*i_oIt));
61  }
62 
63  ++i_oIt;
64  return true;
65  }
66 
67  public:
68  CreateSerializeOperators(T, IsHidden);
69  };
70 
72  template<bool IsHidden = false>
74 
76  template<bool IsHidden = false>
78 
80  template<bool IsHidden = false>
82 
84  template<bool IsHidden = false>
86 
88  template<bool IsHidden = false>
90 
92  template<bool IsHidden = false>
94 
96  template<bool IsHidden = false>
98 
100  template<bool IsHidden = false>
102 
104  template<typename T, bool IsHidden = false>
106 #pragma pack(pop)
107 }
This file contains a series of type definitions for the codebase.
A class for reading data from a buffer. This class provides functionality to read data from a buffer....
Definition: ReadStream.h:37
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
Class representing an arithmetic value for serialization.
Definition: SerializableArithmetic.h:19
Template class representing a data field.
Definition: SerializableData.h:86
T m_tValue
The value.
Definition: SerializableData.h:78
The namespace encapsulating serializing related functionality in the Devel framework.
unsigned long long ToUInt64(const std::string &i_sBuffer)
Converts a string to an unsigned 64-bit integer.
Definition: StringUtils.h:231
unsigned int ToUInt(const std::string &i_sBuffer)
Converts a string to an unsigned integer.
Definition: StringUtils.h:248