Main MRPT website > C++ reference for MRPT 1.5.9
CPropertiesValuesList.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-2017, 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 "base-precomp.h" // Precompiled headers
11 
12 
14 #include <mrpt/utils/CStream.h>
15 #include <mrpt/system/os.h>
16 #include <stdio.h>
17 #include <iostream>
18 
19 using namespace mrpt::utils;
20 using namespace mrpt::system;
21 
22 // This must be added to any CSerializable class implementation file.
24 
25 /*---------------------------------------------------------------
26  writeToStream
27  ---------------------------------------------------------------*/
28 void CPropertiesValuesList::writeToStream(mrpt::utils::CStream &out, int *out_Version) const
29 {
30  if (out_Version)
31  *out_Version = 0;
32  else
33  {
34  uint32_t i,n = (uint32_t)size();
35  uint8_t isNull;
36  out << n;
37 
38  for (i=0;i<n;i++)
39  {
40  // Name:
41  out << m_properties[i].name.c_str();
42 
43  // Object:
44  isNull = m_properties[i].value.present() ? 1:0;
45  out << isNull;
46 
47  if (m_properties[i].value.present())
48  out << *m_properties[i].value;
49  }
50  }
51 }
52 
53 /*---------------------------------------------------------------
54  readFromStream
55  ---------------------------------------------------------------*/
57 {
58  switch(version)
59  {
60  case 0:
61  {
62  uint32_t i,n;
63  uint8_t isNull;
64 
65  // Erase previous contents:
66  clear();
67 
68  in >> n;
69 
70  m_properties.resize(n);
71  for (i=0;i<n;i++)
72  {
73  char nameBuf[1024];
74  // Name:
75  in >> nameBuf;
76  m_properties[i].name = nameBuf;
77 
78  // Object:
79  in >> isNull;
80 
81  if (isNull)
82  m_properties[i].value.set( static_cast<CSerializable*>(NULL) );
83  else
84  in >> m_properties[i].value;
85  }
86  } break;
87  default:
89 
90  };
91 }
92 
93 
94 /*---------------------------------------------------------------
95  Constructor
96  ---------------------------------------------------------------*/
98 {
99 }
100 
101 /*---------------------------------------------------------------
102  Destructor
103  ---------------------------------------------------------------*/
105 {
106  clear();
107 }
108 
109 /*---------------------------------------------------------------
110  Copy Constructor
111  ---------------------------------------------------------------*/
113  m_properties ( o.m_properties )
114 {
116  it->value.make_unique();
117 }
118 
119 /*---------------------------------------------------------------
120  Copy
121  ---------------------------------------------------------------*/
123 {
124  if (this!=&o) return *this;
125 
128  it->value.make_unique();
129  return *this;
130 }
131 
132 
133 /*---------------------------------------------------------------
134  clear
135  ---------------------------------------------------------------*/
137 {
138  MRPT_START
139  m_properties.clear();
140  MRPT_END
141 }
142 
143 /*---------------------------------------------------------------
144  get
145  ---------------------------------------------------------------*/
146 CSerializablePtr CPropertiesValuesList::get(const std::string &propertyName)const
147 {
149  {
150  if (!os::_strcmpi(propertyName.c_str(),it->name.c_str()))
151  return it->value;
152  }
153  // Not found:
154  return CSerializablePtr();
155 }
156 
157 
158 /*---------------------------------------------------------------
159  set
160  ---------------------------------------------------------------*/
161 void CPropertiesValuesList::set(const std::string &propertyName, const CSerializablePtr &obj)
162 {
163  MRPT_START
164 
166  {
167  if (!os::_strcmpi(propertyName.c_str(),it->name.c_str()))
168  {
169  // Delete current contents:
170  // Copy new value:
171  if (!obj) it->value.clear_unique();
172  else it->value = obj; //->duplicate();
173  return;
174  }
175  }
176 
177  // Insert:
178  TPropertyValuePair newPair;
179  newPair.name = std::string(propertyName);
180  newPair.value = obj;
181  m_properties.push_back(newPair);
182 
184  printf("Exception while setting annotation '%s'",propertyName.c_str()); \
185  );
186 }
187 
188 /*---------------------------------------------------------------
189  size
190  ---------------------------------------------------------------*/
192 {
193  return m_properties.size();
194 }
195 
196 /*---------------------------------------------------------------
197  getPropertyNames
198  ---------------------------------------------------------------*/
199 std::vector<std::string> CPropertiesValuesList::getPropertyNames()const
200 {
201  std::vector<std::string> ret;
202 
204  ret.push_back(it->name);
205 
206  return ret;
207 }
CPropertiesValuesList & operator=(const CPropertiesValuesList &o)
Copy operator.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
Definition: zip.h:16
std::vector< TPropertyValuePair > m_properties
The properties list: a map between strings and objects.
#define MRPT_END_WITH_CLEAN_UP(stuff)
This namespace provides a OS-independent interface to many useful functions: filenames manipulation...
Definition: math_frwds.h:29
The virtual base class which provides a unified interface for all persistent objects in MRPT...
Definition: CSerializable.h:39
std::vector< std::string > getPropertyNames() const
Returns the name of all properties in the list.
GLenum GLsizei n
Definition: glext.h:4618
Scalar * iterator
Definition: eigen_plugins.h:23
void readFromStream(mrpt::utils::CStream &in, int version)
Introduces a pure virtual method responsible for loading from a CStream This can not be used directly...
const Scalar * const_iterator
Definition: eigen_plugins.h:24
IMPLEMENTS_SERIALIZABLE(CLogFileRecord_FullEval, CHolonomicLogFileRecord, mrpt::nav) IMPLEMENTS_SERIALIZABLE(CHolonomicFullEval
GLsizei GLsizei GLuint * obj
Definition: glext.h:3902
void clear()
Clear the contents of this container.
Definition: ts_hash_map.h:113
CSerializablePtr get(const std::string &propertyName) const
Returns the value of the property (case insensitive), or NULL if it does not exist.
size_t size() const
Returns the number of properties in the list.
unsigned char uint8_t
Definition: rptypes.h:43
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:38
An arbitrary list of "annotations", or named attributes, each being an instance of any CSerializable ...
#define MRPT_END
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
int version
Definition: mrpt_jpeglib.h:898
GLsizei const GLchar ** string
Definition: glext.h:3919
#define MRPT_START
void set(const std::string &propertyName, const CSerializablePtr &obj)
Sets/change the value of the property (case insensitive), making a copy of the object (or setting it ...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
int BASE_IMPEXP _strcmpi(const char *str1, const char *str2) MRPT_NO_THROWS
An OS-independent version of strcmpi.
Definition: os.cpp:320
GLuint in
Definition: glext.h:6301
typedef void(APIENTRYP PFNGLBLENDCOLORPROC)(GLclampf red
GLsizei const GLfloat * value
Definition: glext.h:3929
GLsizeiptr size
Definition: glext.h:3779
unsigned __int32 uint32_t
Definition: rptypes.h:49



Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020