Main MRPT website > C++ reference for MRPT 1.9.9
CMHPropertiesValuesList.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include "hmtslam-precomp.h" // Precompiled headers
11 
13 #include <mrpt/system/os.h>
14 #include <stdio.h>
15 
16 using namespace mrpt::hmtslam;
17 using namespace mrpt::system;
18 using namespace mrpt::serialization;
19 
20 // This must be added to any CSerializable class implementation file.
22 
23 uint8_t CMHPropertiesValuesList::serializeGetVersion() const { return 0; }
26 {
27  uint32_t i, n = (uint32_t)m_properties.size();
28  uint8_t isNull;
29  out << n;
30 
31  for (i = 0; i < n; i++)
32  {
33  // Name:
34  out << m_properties[i].name.c_str();
35 
36  // Object:
37  isNull = !m_properties[i].value;
38  out << isNull;
39 
40  if (!isNull) out << *m_properties[i].value;
41 
42  // Hypot. ID:
43  out << m_properties[i].ID;
44  }
45 }
46 
49 {
50  switch (version)
51  {
52  case 0:
53  {
54  uint32_t i, n;
55  uint8_t isNull;
56 
57  // Erase previous contents:
58  clear();
59 
60  in >> n;
61 
62  m_properties.resize(n);
63  for (i = 0; i < n; i++)
64  {
65  char nameBuf[1024];
66  // Name:
67  in >> nameBuf;
68  m_properties[i].name = nameBuf;
69 
70  // Object:
71  in >> isNull;
72 
73  if (isNull)
74  m_properties[i].value.reset();
75  else
76  in >> m_properties[i].value;
77 
78  // Hypot. ID:
79  in >> m_properties[i].ID;
80  }
81  }
82  break;
83  default:
85  };
86 }
87 
88 /*---------------------------------------------------------------
89  Constructor
90  ---------------------------------------------------------------*/
92 /*---------------------------------------------------------------
93  Destructor
94  ---------------------------------------------------------------*/
96 /*---------------------------------------------------------------
97  clear
98  ---------------------------------------------------------------*/
100 {
101  MRPT_START
102  m_properties.clear();
103  MRPT_END
104 }
105 
106 /*---------------------------------------------------------------
107  get
108  ---------------------------------------------------------------*/
110  const char* propertyName, const int64_t& hypothesis_ID) const
111 {
113  for (it = m_properties.begin(); it != m_properties.end(); ++it)
114  if (!os::_strcmpi(propertyName, it->name.c_str()) &&
115  it->ID == hypothesis_ID)
116  return it->value;
117 
118  for (it = m_properties.begin(); it != m_properties.end(); ++it)
119  if (!os::_strcmpi(propertyName, it->name.c_str()) && it->ID == 0)
120  return it->value;
121 
122  // Not found:
123  return CSerializable::Ptr();
124 }
125 
126 /*---------------------------------------------------------------
127  getAnyHypothesis
128  ---------------------------------------------------------------*/
130  const char* propertyName) const
131 {
133  m_properties.begin();
134  it != m_properties.end(); ++it)
135  {
136  if (!os::_strcmpi(propertyName, it->name.c_str())) return it->value;
137  }
138  // Not found:
139  return CSerializable::Ptr();
140 }
141 
142 /*---------------------------------------------------------------
143  set
144  ---------------------------------------------------------------*/
146  const char* propertyName, const CSerializable::Ptr& obj,
147  const int64_t& hypothesis_ID)
148 {
149  MRPT_START
150 
152  m_properties.begin();
153  it != m_properties.end(); ++it)
154  {
155  if (it->ID == hypothesis_ID &&
156  !os::_strcmpi(propertyName, it->name.c_str()))
157  {
158  // Delete current contents:
159  // Copy new value:
160  it->value.reset(dynamic_cast<CSerializable*>(obj->clone()));
161 
162  // if (!obj) it->value.clear();
163  // else it->value = obj; //->clone();
164  return;
165  }
166  }
167 
168  // Insert:
169  TPropertyValueIDTriplet newPair;
170  newPair.name = std::string(propertyName);
171  newPair.value = obj;
172  newPair.ID = hypothesis_ID;
173  m_properties.push_back(newPair);
174 
176  printf("Exception while setting annotation '%s'", propertyName););
177 }
178 
179 /*---------------------------------------------------------------
180  setMemoryReference
181  ---------------------------------------------------------------*/
183  const char* propertyName, const CSerializable::Ptr& obj,
184  const int64_t& hypothesis_ID)
185 {
186  MRPT_START
187 
189  m_properties.begin();
190  it != m_properties.end(); ++it)
191  {
192  if (it->ID == hypothesis_ID &&
193  !os::_strcmpi(propertyName, it->name.c_str()))
194  {
195  // Delete current contents & set a copy of the same smart pointer:
196  it->value = obj;
197  return;
198  }
199  }
200 
201  // Insert:
202  TPropertyValueIDTriplet newPair;
203  newPair.name = std::string(propertyName);
204  newPair.value = obj;
205  newPair.ID = hypothesis_ID;
206  m_properties.push_back(newPair);
207 
209  printf("Exception while setting annotation '%s'", propertyName););
210 }
211 
212 /*---------------------------------------------------------------
213  getPropertyNames
214  ---------------------------------------------------------------*/
215 std::vector<std::string> CMHPropertiesValuesList::getPropertyNames() const
216 {
217  std::vector<std::string> ret;
218 
220  m_properties.begin();
221  it != m_properties.end(); ++it)
222  {
223  bool isNew = true;
224  for (std::vector<std::string>::iterator itS = ret.begin();
225  itS != ret.end(); ++itS)
226  {
227  if ((*itS) == it->name)
228  {
229  isNew = false;
230  break;
231  }
232  }
233  if (isNew) ret.push_back(it->name); // Yes, it is new:
234  }
235 
236  return ret;
237 }
238 
239 /*---------------------------------------------------------------
240  remove
241  ---------------------------------------------------------------*/
243  const char* propertyName, const int64_t& hypothesis_ID)
244 {
246  m_properties.begin();
247  it != m_properties.end();)
248  if (!os::_strcmpi(propertyName, it->name.c_str()) &&
249  it->ID == hypothesis_ID)
250  it = m_properties.erase(it);
251  else
252  ++it;
253 }
254 
255 /*---------------------------------------------------------------
256  removeAll
257  ---------------------------------------------------------------*/
258 void CMHPropertiesValuesList::removeAll(const int64_t& hypothesis_ID)
259 {
261  m_properties.begin();
262  it != m_properties.end();)
263  if (it->ID == hypothesis_ID)
264  it = m_properties.erase(it);
265  else
266  ++it;
267 }
268 
269 /*---------------------------------------------------------------
270  Copy
271  ---------------------------------------------------------------*/
273  const CMHPropertiesValuesList& o)
274  : m_properties(o.m_properties)
275 {
277  m_properties.begin();
278  it != m_properties.end(); ++it)
279  it->value.reset(dynamic_cast<CSerializable*>(it->value->clone()));
280 }
281 
282 /*---------------------------------------------------------------
283  Copy
284  ---------------------------------------------------------------*/
286  const CMHPropertiesValuesList& o)
287 {
288  if (this == &o) return *this;
289 
291 
293  m_properties.begin();
294  it != m_properties.end(); ++it)
295  it->value.reset(dynamic_cast<CSerializable*>(it->value->clone()));
296  return *this;
297 }
Scalar * iterator
Definition: eigen_plugins.h:26
void set(const char *propertyName, const CSerializable::Ptr &obj, const int64_t &hypothesis_ID)
Sets/change the value of the property (case insensitive) for the given hypothesis ID...
#define MRPT_START
Definition: exceptions.h:262
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
This namespace provides a OS-independent interface to many useful functions: filenames manipulation...
Definition: math_frwds.h:25
Classes related to the implementation of Hybrid Metric Topological (HMT) SLAM.
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
GLenum GLsizei n
Definition: glext.h:5074
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
#define MRPT_END_WITH_CLEAN_UP(stuff)
Definition: exceptions.h:268
GLsizei GLsizei GLuint * obj
Definition: glext.h:4070
unsigned char uint8_t
Definition: rptypes.h:41
void removeAll(const int64_t &hypothesis_ID)
Remove all the properties for the given hypothesis.
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: exceptions.h:90
CSerializable::Ptr getAnyHypothesis(const char *propertyName) const
Returns the value of the property (case insensitive) for the first hypothesis ID found, or nullptr if it does not exist.
void clear()
Clears the list and frees all object&#39;s memory.
__int64 int64_t
Definition: rptypes.h:49
void remove(const char *propertyName, const int64_t &hypothesis_ID)
Remove a given property, if it exists.
GLsizei const GLchar ** string
Definition: glext.h:4101
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:48
CMHPropertiesValuesList & operator=(const CMHPropertiesValuesList &o)
Copy operator.
#define MRPT_END
Definition: exceptions.h:266
Internal triplet for each property in utils::CMHPropertiesValuesList.
mrpt::serialization::CSerializable::Ptr value
GLuint in
Definition: glext.h:7274
The virtual base class which provides a unified interface for all persistent objects in MRPT...
Definition: CSerializable.h:32
An arbitrary list of "annotations", or named attributes, each being an instance of any CSerializable ...
void setMemoryReference(const char *propertyName, const CSerializable::Ptr &obj, const int64_t &hypothesis_ID)
Sets/change the value of the property (case insensitive) for the given hypothesis ID...
std::vector< std::string > getPropertyNames() const
Returns the name of all properties in the list.
CSerializable::Ptr get(const char *propertyName, const int64_t &hypothesis_ID) const
Returns the value of the property (case insensitive) for some given hypothesis ID, or a nullptr smart pointer if it does not exist.
unsigned __int32 uint32_t
Definition: rptypes.h:47
void clear()
Clear the contents of this container.
Definition: ts_hash_map.h:188
const Scalar * const_iterator
Definition: eigen_plugins.h:27
std::vector< TPropertyValueIDTriplet > m_properties
int _strcmpi(const char *str1, const char *str2) noexcept
An OS-independent version of strcmpi.
Definition: os.cpp:320



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at lun oct 28 00:14:14 CET 2019