MongoSerializer.h
Go to the documentation of this file.
1/*
2* This file is part of ArmarX.
3*
4* ArmarX is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License version 2 as
6* published by the Free Software Foundation.
7*
8* ArmarX is distributed in the hope that it will be useful, but
9* WITHOUT ANY WARRANTY; without even the implied warranty of
10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11* GNU General Public License for more details.
12*
13* You should have received a copy of the GNU General Public License
14* along with this program. If not, see <http://www.gnu.org/licenses/>.
15*
16* @package MemoryX::CommonStorage
17* @author Alexey Kozlov ( kozlov at kit dot edu)
18* @date Sep 19, 2012
19* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20* GNU General Public License
21*/
22
23#pragma once
24
25#include <ArmarXCore/interface/observers/Serialization.h>
26
27#include <MemoryX/interface/components/CommonStorageInterface.h>
28
29namespace armarx
30{
31 class JSONObject;
32 using JSONObjectPtr = IceInternal::Handle<JSONObject>;
33} // namespace armarx
34
35namespace memoryx
36{
37 class MongoSerializer;
38 using MongoSerializerPtr = IceUtil::Handle<MongoSerializer>;
39
40 class MongoSerializer : public DBSerializerBase
41 {
42 public:
44 bool useMongoObjectIds = false);
45 ~MongoSerializer() override;
46
47 /**
48 * Takes a SerializablePtr and transforms it into a JSON object using the JSONObject serialization mechanism.
49 * The result is returned in a new DBStorableData which contains the result in its JSON field.
50 */
51 DBStorableData serialize(const armarx::SerializablePtr& obj,
52 const ::Ice::Current& = Ice::emptyCurrent) override;
53 /**
54 * Uses the JSON content of DBStorableDate \p objData and deserializes it into the \p obj pointer.
55 */
56 void deserialize(const DBStorableData& objData,
57 const armarx::SerializablePtr& obj,
58 const ::Ice::Current& = Ice::emptyCurrent) override;
59
60 /**
61 * Serialize an Ice object passed in the \p obj parameter.
62 * The result is stored in the JSON field of a new DBStorableData
63 * instance and returned.
64 */
65 DBStorableData serializeIceObject(const armarx::SerializablePtr& obj,
66 const ::Ice::Current& = Ice::emptyCurrent);
67 /**
68 * Deserializes the \p objData DBStorableData object into an instance of
69 * Serializable and returns it.
70 */
71 armarx::SerializablePtr deserializeIceObject(const DBStorableData& objData,
72 const ::Ice::Current& = Ice::emptyCurrent);
73
74 private:
75 bool useMongoIds;
76 /**
77 * jsonSerializer contains a JSONObject instance which is used to create copies for (de)serialization.
78 * Creating copies is better scalable since it would otherwise be necessary to lock the access with mutexes.
79 */
80 armarx::JSONObjectPtr jsonSerializer;
81
82 void serializeMongoId(const armarx::JSONObjectPtr& serializer);
83 void deserializeMongoId(const armarx::JSONObjectPtr& deserializer);
84 };
85
86} // namespace memoryx
The JSONObject class is used to represent and (de)serialize JSON objects.
Definition JSONObject.h:44
void deserialize(const DBStorableData &objData, const armarx::SerializablePtr &obj, const ::Ice::Current &=Ice::emptyCurrent) override
Uses the JSON content of DBStorableDate objData and deserializes it into the obj pointer.
MongoSerializer(const Ice::CommunicatorPtr ic=Ice::CommunicatorPtr(), bool useMongoObjectIds=false)
DBStorableData serialize(const armarx::SerializablePtr &obj, const ::Ice::Current &=Ice::emptyCurrent) override
Takes a SerializablePtr and transforms it into a JSON object using the JSONObject serialization mecha...
DBStorableData serializeIceObject(const armarx::SerializablePtr &obj, const ::Ice::Current &=Ice::emptyCurrent)
Serialize an Ice object passed in the obj parameter.
armarx::SerializablePtr deserializeIceObject(const DBStorableData &objData, const ::Ice::Current &=Ice::emptyCurrent)
Deserializes the objData DBStorableData object into an instance of Serializable and returns it.
::IceInternal::Handle<::Ice::Communicator > CommunicatorPtr
Definition IceManager.h:49
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< JSONObject > JSONObjectPtr
Definition JSONObject.h:34
VirtualRobot headers.
IceUtil::Handle< MongoSerializer > MongoSerializerPtr
Definition EntityRef.h:41