Devel Lib
JsonSerializableBool.h
1 #pragma once
2 
3 #include "Serializing/Core/Types/SerializableBool.h"
4 #include "Serializing/Json/JsonSerializableType.h"
7 namespace Devel::Serializing {
8 #pragma pack(push, 1)
9 
16  class IJsonBool : public IJsonType<bool, Serializing::IBool<>> {
17  public:
20  IJsonBool(const CJsonFieldName i_oFieldName) : IJsonType<bool, Serializing::IBool<>>(i_oFieldName) {}
21 
22  private:
27  bool onDeserialize(IO::CJsonObject &i_oObject, const bool i_bIsStrict) final {
28  IO::CJsonObject *pObject = this->getObject(i_oObject, i_bIsStrict);
29 
30  if (!pObject) {
31  return true;
32  } else if (pObject->type() != IO::EJsonType::JTBoolean) {
33  throw DifferentTypesException;
34  }
35 
36  this->operator=(!(pObject->empty() ||
37  pObject->at(0) < '1' ||
38  pObject->at(0) == 'f' ||
39  pObject->at(0) == 'F')
40  );
41 
42  return true;
43  }
44 
49  bool onSerialize(IO::CJsonObject &i_oObject, const bool i_bIsStrict) const final {
50  return this->serialize(i_oObject, i_bIsStrict);
51  }
52 
56  bool onDeserialize(IO::CJsonObject &i_oObject) final {
57  return this->onDeserialize(i_oObject, false);
58  }
59 
63  bool onSerialize(IO::CJsonObject &i_oObject) const final {
64  return this->onSerialize(i_oObject, false);
65  }
66 
67  public:
68  using IJsonType<bool, Serializing::IBool<>>::IJsonType;
69 
73  IJsonBool &operator=(const bool &i_tValue) {
74  this->setNull(false);
75  this->m_tValue = i_tValue;
76  return *this;
77  }
78 
82  IJsonBool &operator=(bool &&i_tValue) {
83  this->setNull(false);
84  this->m_tValue = std::move(i_tValue);
85  return *this;
86  }
87  };
88 
89 #pragma pack(pop)
90 }
A class that encapsulates a JSON object.
Definition: JsonObject.h:50
EJsonType type() const
Returns the type of the JSON object.
Definition: JsonObject.h:123
A class representing a JSON field name.
Definition: JsonFieldName.h:49
A class representing a boolean value for serialization.
Definition: SerializableBool.h:17
Represents a JSON boolean data type for serialization and deserialization.
Definition: JsonSerializableBool.h:16
IJsonBool & operator=(const bool &i_tValue)
Assignment operator for assigning a boolean value to the IJsonBool object.
Definition: JsonSerializableBool.h:73
IJsonBool & operator=(bool &&i_tValue)
Move assignment operator for assigning a boolean value to the IJsonBool object.
Definition: JsonSerializableBool.h:82
IJsonBool(const CJsonFieldName i_oFieldName)
Constructs an IJsonBool object with the specified JSON field name.
Definition: JsonSerializableBool.h:20
Represents a JSON data type with serialization and deserialization functionality.
Definition: JsonSerializableType.h:84
IO::CJsonObject * getObject(IO::CJsonObject &i_oObject, const bool i_bIsStrict)
Retrieves the JSON object for the specified JSON field.
Definition: JsonSerializableType.h:177
bool serialize(IO::CJsonObject &i_oObject, const bool i_bIsStrict=false) const
Serializes the data to a JSON object.
Definition: JsonSerializableType.h:142
void setNull(bool i_bState)
Sets the null state of the JSON field.
Definition: JsonSerializableType.h:169
IJsonType(const CJsonFieldName i_oFieldName)
Constructs an IJsonType object with the specified JSON field name.
Definition: JsonSerializableType.h:88
T m_tValue
The value.
Definition: SerializableData.h:78
@ JTBoolean
A boolean type.
The namespace encapsulating serializing related functionality in the Devel framework.