Main MRPT website > C++ reference for MRPT 1.5.6
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.
GLvoid *typedef void(GLAPIENTRY *PFNGLGETVERTEXATTRIBDVPROC)(GLuint
Definition: glew.h:1745
std::vector< TPropertyValuePair > m_properties
The properties list: a map between strings and objects.
#define MRPT_END_WITH_CLEAN_UP(stuff)
The virtual base class which provides a unified interface for all persistent objects in MRPT...
Definition: CSerializable.h:39
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
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
void clear()
Clear the contents of this container.
Definition: ts_hash_map.h:113
GLuint in
Definition: glew.h:7146
unsigned char uint8_t
Definition: rptypes.h:43
GLsizei const GLfloat * value
Definition: glew.h:1756
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 ...
GLsizei n
Definition: glew.h:5051
#define MRPT_END
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
GLhandleARB obj
Definition: glew.h:3276
int version
Definition: mrpt_jpeglib.h:898
GLsizeiptr size
Definition: glew.h:1586
#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 ...
GLsizei const GLcharARB ** string
Definition: glew.h:3293
size_t size() const
Returns the number of properties in the list.
int BASE_IMPEXP _strcmpi(const char *str1, const char *str2) MRPT_NO_THROWS
An OS-independent version of strcmpi.
Definition: os.cpp:320
std::vector< std::string > getPropertyNames() const
Returns the name of all properties in the list.
CSerializablePtr get(const std::string &propertyName) const
Returns the value of the property (case insensitive), or NULL if it does not exist.
unsigned __int32 uint32_t
Definition: rptypes.h:49



Page generated by Doxygen 1.8.6 for MRPT 1.5.6 Git: 4c65e84 Tue Apr 24 08:18:17 2018 +0200 at mar abr 24 08:26:17 CEST 2018