Caffa  1.1.0
C++ Application Framework for Embedded Systems with introspection
cafJsonSerializer.h
1 // ##################################################################################################
2 //
3 // Caffa
4 // Copyright (C) 2021- 3D-Radar AS
5 //
6 // GNU Lesser General Public License Usage
7 // This library is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU Lesser General Public License as published by
9 // the Free Software Foundation; either version 2.1 of the License, or
10 // (at your option) any later version.
11 //
12 // This library is distributed in the hope that it will be useful, but WITHOUT ANY
13 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 // FITNESS FOR A PARTICULAR PURPOSE.
15 //
16 // See the GNU Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
17 // for more details.
18 //
19 #pragma once
20 
21 #include "cafSerializer.h"
22 
23 #include <nlohmann/json.hpp>
24 
25 #include <set>
26 #include <string>
27 
28 namespace caffa
29 {
30 class ObjectHandle;
31 
35 class JsonSerializer : public Serializer
36 {
37 public:
43 
50  std::string readUUIDFromObjectString( const std::string& string ) const override;
51 
57  void readObjectFromString( ObjectHandle* object, const std::string& string ) const override;
58 
64  std::string writeObjectToString( const ObjectHandle* object ) const override;
65 
71  std::shared_ptr<ObjectHandle> copyBySerialization( const ObjectHandle* object ) const override;
72 
81  std::shared_ptr<ObjectHandle> copyAndCastBySerialization( const ObjectHandle* object,
82  const std::string& destinationClassKeyword ) const override;
83 
89  std::shared_ptr<ObjectHandle> createObjectFromString( const std::string& string ) const override;
90 
96  void readStream( ObjectHandle* object, std::istream& stream ) const override;
97 
103  void writeStream( const ObjectHandle* object, std::ostream& stream ) const override;
104 
105  void readObjectFromJson( ObjectHandle* object, const nlohmann::json& jsonObject ) const;
106  void writeObjectToJson( const ObjectHandle* object, nlohmann::json& jsonObject ) const;
107 };
108 } // End of namespace caffa
Definition: cafJsonSerializer.h:36
void readStream(ObjectHandle *object, std::istream &stream) const override
Definition: cafJsonSerializer.cpp:310
std::shared_ptr< ObjectHandle > copyBySerialization(const ObjectHandle *object) const override
Definition: cafJsonSerializer.cpp:233
JsonSerializer(ObjectFactory *objectFactory=nullptr)
Definition: cafJsonSerializer.cpp:191
void writeStream(const ObjectHandle *object, std::ostream &stream) const override
Definition: cafJsonSerializer.cpp:323
std::string writeObjectToString(const ObjectHandle *object) const override
Definition: cafJsonSerializer.cpp:223
void readObjectFromString(ObjectHandle *object, const std::string &string) const override
Definition: cafJsonSerializer.cpp:214
std::string readUUIDFromObjectString(const std::string &string) const override
Definition: cafJsonSerializer.cpp:199
std::shared_ptr< ObjectHandle > copyAndCastBySerialization(const ObjectHandle *object, const std::string &destinationClassKeyword) const override
Definition: cafJsonSerializer.cpp:249
std::shared_ptr< ObjectHandle > createObjectFromString(const std::string &string) const override
Definition: cafJsonSerializer.cpp:275
Definition: cafObjectFactory.h:39
Definition: cafObjectHandle.h:55
Definition: cafSerializer.h:36
ObjectFactory * objectFactory() const
Definition: cafSerializer.cpp:63
Main Caffa namespace.
Definition: __init__.py:1