AbstractObjectSerializer.h
Go to the documentation of this file.
1 /*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package ArmarX::Core
19 * @author ALexey Kozlov ( kozlov at kit dot edu)
20 * @date 11.09.2012
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24 
25 #pragma once
26 
27 #include <ArmarXCore/interface/observers/Serialization.h>
29 
31 {
33  {
37  };
38 }
39 
40 namespace armarx
41 {
43 
46 
47  /**
48  * @class AbstractObjectSerializer
49  * @brief
50  * @ingroup ObserversSub
51  */
53  public ObjectSerializerBase
54  {
55  public:
58  ~AbstractObjectSerializer() override;
59 
60  public:
61  virtual ElementType getElementType(const ::Ice::Current& = Ice::emptyCurrent) const = 0;
62  virtual void setElementType(ElementType elemType, const ::Ice::Current& = Ice::emptyCurrent) = 0;
63 
64  virtual unsigned int size() const = 0;
65  virtual bool hasElement(const ::std::string& key) const = 0;
66 
67  virtual float getFloat(const ::std::string& key) const = 0;
68  virtual double getDouble(const ::std::string& key) const = 0;
69  virtual int getInt(const ::std::string& key) const = 0;
70  virtual bool getBool(const ::std::string& key) const = 0;
71  virtual std::string getString(const ::std::string& key) const = 0;
72  virtual VariantPtr getVariant(const ::std::string& key) const;
73  virtual VariantPtr getVariant(int index) const;
74  virtual SerializablePtr getIceObject(const ::std::string& key) const;
75  virtual SerializablePtr getIceObject(int index) const;
76 
77  virtual AbstractObjectSerializerPtr getElement(unsigned int index) const = 0;
78  virtual AbstractObjectSerializerPtr getElement(const ::std::string& key) const = 0;
79  virtual std::vector<std::string> getElementNames() const = 0;
80 
81  virtual void getIntArray(const ::std::string& key, std::vector<int>& result) = 0;
82  virtual void getFloatArray(const ::std::string& key, std::vector<float>& result) = 0;
83  virtual void getDoubleArray(const ::std::string& key, std::vector<double>& result) = 0;
84  virtual void getStringArray(const ::std::string& key, std::vector<std::string>& result) = 0;
85  virtual void getVariantArray(const ::std::string& key, std::vector<VariantPtr>& result) = 0;
86 
87  virtual void getVariantMap(const ::std::string& key, StringVariantBaseMap& result) = 0;
88 
89  virtual void setBool(const ::std::string& key, bool val) = 0;
90  virtual void setInt(const ::std::string& key, int val) = 0;
91  virtual void setFloat(const ::std::string& key, float val) = 0;
92  virtual void setDouble(const ::std::string& key, double val) = 0;
93  virtual void setString(const ::std::string& key, const std::string& val) = 0;
94  virtual void setElement(const ::std::string& key, const AbstractObjectSerializerPtr& val) = 0;
95  virtual void setVariant(const ::std::string& key, const VariantPtr& val);
96  virtual void setIceObject(const ::std::string& key, const SerializablePtr& val);
97 
98  virtual void setIntArray(const ::std::string& key, const std::vector<int>& val) = 0;
99  virtual void setFloatArray(const ::std::string& key, const std::vector<float>& val) = 0;
100  virtual void setDoubleArray(const ::std::string& key, const std::vector<double>& val) = 0;
101  virtual void setStringArray(const ::std::string& key, const std::vector<std::string>& val) = 0;
102  virtual void setVariantArray(const ::std::string& key, const std::vector<VariantPtr>& val) = 0;
103  virtual void setVariantArray(const ::std::string& key, const std::vector<VariantBasePtr>& val) = 0;
104 
105  virtual void setVariantMap(const ::std::string& key, const StringVariantBaseMap& val) = 0;
106 
107  virtual void setBool(unsigned int index, bool val) = 0;
108  virtual void setInt(unsigned int index, int val) = 0;
109  virtual void setFloat(unsigned int index, float val) = 0;
110  virtual void setDouble(unsigned int index, double val) = 0;
111  virtual void setString(unsigned int index, const std::string& val) = 0;
112  virtual void setElement(unsigned int index, const AbstractObjectSerializerPtr& val) = 0;
113  virtual void setVariant(unsigned int index, const VariantPtr& val);
114  virtual void setIceObject(unsigned int index, const SerializablePtr& val);
115 
116  // add all elements of val as siblings
117  virtual void merge(const AbstractObjectSerializerPtr& val) = 0;
118 
119  virtual void append(const AbstractObjectSerializerPtr& val) = 0;
120 
121  // clear state and init with empty underlying object
122  virtual void reset() = 0;
123 
124  public: // convenience functions to define and use ID field (useful for CommonStorage)
125 
126  std::string getIdField() const
127  {
128  return idField;
129  }
130  void setIdField(const std::string& fieldName)
131  {
132  idField = fieldName;
133  }
134 
135  int getIntId() const
136  {
137  return getInt(idField);
138  }
139  std::string getStringId() const
140  {
141  return getString(idField);
142  }
143 
144  void setId(int val)
145  {
146  setInt(idField, val);
147  }
148  void setId(const std::string& val)
149  {
150  setString(idField, val);
151  }
152 
153  public: // functions to serialize/deserialize Ice object along with its ice_id
154  void serializeIceObject(const SerializablePtr& obj);
155  SerializablePtr deserializeIceObject();
156 
157  public:
158  virtual AbstractObjectSerializerPtr createElement() const = 0;
159 
161 
162  protected:
165 
167  std::string idField;
168 
169  private:
170 
171  };
172 
173 }
174 
armarx::AbstractObjectSerializer::setIntArray
virtual void setIntArray(const ::std::string &key, const std::vector< int > &val)=0
armarx::AbstractObjectSerializer::createElement
virtual AbstractObjectSerializerPtr createElement() const =0
armarx::AbstractObjectSerializer::getIceObject
virtual SerializablePtr getIceObject(const ::std::string &key) const
Definition: AbstractObjectSerializer.cpp:262
armarx::StringVariantBaseMap
std::map< std::string, VariantBasePtr > StringVariantBaseMap
Definition: ManagedIceObject.h:111
index
uint8_t index
Definition: EtherCATFrame.h:59
armarx::AbstractObjectSerializer::setIceCommunicator
void setIceCommunicator(Ice::CommunicatorPtr ic)
Definition: AbstractObjectSerializer.cpp:54
armarx::ElementTypes::eArray
@ eArray
Definition: AbstractObjectSerializer.h:36
armarx::AbstractObjectSerializer::getIntId
int getIntId() const
Definition: AbstractObjectSerializer.h:135
armarx::AbstractObjectSerializer::setVariant
virtual void setVariant(const ::std::string &key, const VariantPtr &val)
Definition: AbstractObjectSerializer.cpp:230
armarx::AbstractObjectSerializer::setVariantMap
virtual void setVariantMap(const ::std::string &key, const StringVariantBaseMap &val)=0
armarx::AbstractObjectSerializer::getIdField
std::string getIdField() const
Definition: AbstractObjectSerializer.h:126
armarx::ElementTypes::eObject
@ eObject
Definition: AbstractObjectSerializer.h:35
armarx::AbstractObjectSerializer::getVariant
virtual VariantPtr getVariant(const ::std::string &key) const
Definition: AbstractObjectSerializer.cpp:244
armarx::AbstractObjectSerializer::serializeVariant
AbstractObjectSerializerPtr serializeVariant(const VariantPtr &val) const
Definition: AbstractObjectSerializer.cpp:59
armarx::AbstractObjectSerializer::getElementNames
virtual std::vector< std::string > getElementNames() const =0
armarx::ElementTypes
Definition: AbstractObjectSerializer.h:30
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::AbstractObjectSerializer::getFloatArray
virtual void getFloatArray(const ::std::string &key, std::vector< float > &result)=0
armarx::AbstractObjectSerializer::idField
std::string idField
Definition: AbstractObjectSerializer.h:167
armarx::AbstractObjectSerializer::getVariantArray
virtual void getVariantArray(const ::std::string &key, std::vector< VariantPtr > &result)=0
armarx::AbstractObjectSerializer::getIntArray
virtual void getIntArray(const ::std::string &key, std::vector< int > &result)=0
armarx::AbstractObjectSerializer::getVariantMap
virtual void getVariantMap(const ::std::string &key, StringVariantBaseMap &result)=0
armarx::AbstractObjectSerializer::merge
virtual void merge(const AbstractObjectSerializerPtr &val)=0
armarx::AbstractObjectSerializer::getElement
virtual AbstractObjectSerializerPtr getElement(unsigned int index) const =0
armarx::AbstractObjectSerializer::setFloat
virtual void setFloat(const ::std::string &key, float val)=0
armarx::AbstractObjectSerializer::getDoubleArray
virtual void getDoubleArray(const ::std::string &key, std::vector< double > &result)=0
armarx::AbstractObjectSerializer::deserializeVariant
VariantPtr deserializeVariant()
Definition: AbstractObjectSerializer.cpp:133
armarx::AbstractObjectSerializer::setElementType
virtual void setElementType(ElementType elemType, const ::Ice::Current &=Ice::emptyCurrent)=0
armarx::AbstractObjectSerializer::deserializeIceObject
SerializablePtr deserializeIceObject()
Definition: AbstractObjectSerializer.cpp:297
armarx::AbstractObjectSerializer::~AbstractObjectSerializer
~AbstractObjectSerializer() override
Definition: AbstractObjectSerializer.cpp:50
armarx::AbstractObjectSerializer::getFloat
virtual float getFloat(const ::std::string &key) const =0
armarx::ElementTypes::eScalar
@ eScalar
Definition: AbstractObjectSerializer.h:34
armarx::AbstractObjectSerializer::serializeIceObject
void serializeIceObject(const SerializablePtr &obj)
Definition: AbstractObjectSerializer.cpp:290
armarx::AbstractObjectSerializer::setId
void setId(const std::string &val)
Definition: AbstractObjectSerializer.h:148
armarx::ElementTypes::ElementType
ElementType
Definition: AbstractObjectSerializer.h:32
armarx::AbstractObjectSerializer::AbstractObjectSerializer
AbstractObjectSerializer()
Definition: AbstractObjectSerializer.cpp:39
armarx::AbstractObjectSerializer::ic
Ice::CommunicatorPtr ic
Definition: AbstractObjectSerializer.h:166
armarx::AbstractObjectSerializer::setFloatArray
virtual void setFloatArray(const ::std::string &key, const std::vector< float > &val)=0
armarx::AbstractObjectSerializer::setIceObject
virtual void setIceObject(const ::std::string &key, const SerializablePtr &val)
Definition: AbstractObjectSerializer.cpp:274
armarx::AbstractObjectSerializer::append
virtual void append(const AbstractObjectSerializerPtr &val)=0
armarx::AbstractObjectSerializer::setDouble
virtual void setDouble(const ::std::string &key, double val)=0
armarx::AbstractObjectSerializer::setIdField
void setIdField(const std::string &fieldName)
Definition: AbstractObjectSerializer.h:130
armarx::AbstractObjectSerializer::getBool
virtual bool getBool(const ::std::string &key) const =0
armarx::AbstractObjectSerializer::getInt
virtual int getInt(const ::std::string &key) const =0
armarx::AbstractObjectSerializer::hasElement
virtual bool hasElement(const ::std::string &key) const =0
armarx::AbstractObjectSerializer::getStringArray
virtual void getStringArray(const ::std::string &key, std::vector< std::string > &result)=0
armarx::AbstractObjectSerializer::setDoubleArray
virtual void setDoubleArray(const ::std::string &key, const std::vector< double > &val)=0
armarx::AbstractObjectSerializer::getStringId
std::string getStringId() const
Definition: AbstractObjectSerializer.h:139
armarx::AbstractObjectSerializer::getString
virtual std::string getString(const ::std::string &key) const =0
armarx::AbstractObjectSerializer::setBool
virtual void setBool(const ::std::string &key, bool val)=0
armarx::AbstractObjectSerializer::size
virtual unsigned int size() const =0
armarx::AbstractObjectSerializer::setElement
virtual void setElement(const ::std::string &key, const AbstractObjectSerializerPtr &val)=0
armarx::AbstractObjectSerializer::setId
void setId(int val)
Definition: AbstractObjectSerializer.h:144
armarx::AbstractObjectSerializer::setInt
virtual void setInt(const ::std::string &key, int val)=0
armarx::AbstractObjectSerializer::setVariantArray
virtual void setVariantArray(const ::std::string &key, const std::vector< VariantPtr > &val)=0
armarx::AbstractObjectSerializer::setStringArray
virtual void setStringArray(const ::std::string &key, const std::vector< std::string > &val)=0
armarx::AbstractObjectSerializer::getDouble
virtual double getDouble(const ::std::string &key) const =0
armarx::AbstractObjectSerializer::getElementType
virtual ElementType getElementType(const ::Ice::Current &=Ice::emptyCurrent) const =0
Variant.h
armarx::AbstractObjectSerializer::reset
virtual void reset()=0
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::AbstractObjectSerializer::setString
virtual void setString(const ::std::string &key, const std::string &val)=0
armarx::AbstractObjectSerializer
Definition: AbstractObjectSerializer.h:52