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 
29 namespace armarx
30 {
31  class JSONObject;
33 }
34 
35 namespace memoryx
36 {
37  class MongoSerializer;
39 
41  public DBSerializerBase
42  {
43  public:
44  MongoSerializer(const Ice::CommunicatorPtr ic = Ice::CommunicatorPtr(), 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, const ::Ice::Current& = Ice::emptyCurrent) override;
52  /**
53  * Uses the JSON content of DBStorableDate \p objData and deserializes it into the \p obj pointer.
54  */
55  void deserialize(const DBStorableData& objData, const armarx::SerializablePtr& obj, const ::Ice::Current& = Ice::emptyCurrent) override;
56 
57  /**
58  * Serialize an Ice object passed in the \p obj parameter.
59  * The result is stored in the JSON field of a new DBStorableData
60  * instance and returned.
61  */
62  DBStorableData serializeIceObject(const armarx::SerializablePtr& obj, const ::Ice::Current& = Ice::emptyCurrent);
63  /**
64  * Deserializes the \p objData DBStorableData object into an instance of
65  * Serializable and returns it.
66  */
67  armarx::SerializablePtr deserializeIceObject(const DBStorableData& objData, const ::Ice::Current& = Ice::emptyCurrent);
68 
69  private:
70  bool useMongoIds;
71  /**
72  * jsonSerializer contains a JSONObject instance which is used to create copies for (de)serialization.
73  * Creating copies is better scalable since it would otherwise be necessary to lock the access with mutexes.
74  */
75  armarx::JSONObjectPtr jsonSerializer;
76 
77  void serializeMongoId(const armarx::JSONObjectPtr& serializer);
78  void deserializeMongoId(const armarx::JSONObjectPtr& deserializer);
79  };
80 
81 }
82 
memoryx::MongoSerializer::serialize
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...
Definition: MongoSerializer.cpp:49
cyberglove_with_calib_22dof.ic
ic
Definition: cyberglove_with_calib_22dof.py:22
memoryx::MongoSerializer::MongoSerializer
MongoSerializer(const Ice::CommunicatorPtr ic=Ice::CommunicatorPtr(), bool useMongoObjectIds=false)
Definition: MongoSerializer.cpp:39
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
IceInternal::Handle< JSONObject >
memoryx::MongoSerializer::deserializeIceObject
armarx::SerializablePtr deserializeIceObject(const DBStorableData &objData, const ::Ice::Current &=Ice::emptyCurrent)
Deserializes the objData DBStorableData object into an instance of Serializable and returns it.
Definition: MongoSerializer.cpp:93
armarx::JSONObjectPtr
IceInternal::Handle< JSONObject > JSONObjectPtr
Definition: JSONObject.h:34
memoryx::MongoSerializer::~MongoSerializer
~MongoSerializer() override
memoryx::MongoSerializer
Definition: MongoSerializer.h:40
IceUtil::Handle< MongoSerializer >
memoryx::MongoSerializerPtr
IceUtil::Handle< MongoSerializer > MongoSerializerPtr
Definition: EntityRef.h:40
memoryx::MongoSerializer::deserialize
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.
Definition: MongoSerializer.cpp:63
memoryx::MongoSerializer::serializeIceObject
DBStorableData serializeIceObject(const armarx::SerializablePtr &obj, const ::Ice::Current &=Ice::emptyCurrent)
Serialize an Ice object passed in the obj parameter.
Definition: MongoSerializer.cpp:79
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28