MRPT  1.9.9
CListOfClasses.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 #include "rtti-precomp.h" // Precompiled headers
10 
12 #include <sstream>
13 #include <algorithm>
14 #include <functional>
15 #include <cctype>
16 #include <locale>
17 
18 using namespace mrpt::rtti;
19 
21  const mrpt::rtti::TRuntimeClassId* id) const
22 {
23  for (const auto& i : data)
24  if (i->derivedFrom(id)) return true;
25  return false;
26 }
27 
29 {
30  std::string s;
31  unsigned int cnt = 0;
32  for (const auto& i : data)
33  {
34  if (cnt++ != 0) s += ", ";
35  s += std::string(i->className);
36  }
37  return s;
38 }
39 
40 // trim from start
41 static inline std::string& ltrim(std::string& s)
42 {
43  s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](const char c) {
44  return !std::isspace(c);
45  }));
46  return s;
47 }
48 
49 // trim from end
50 static inline std::string& rtrim(std::string& s)
51 {
52  s.erase(
53  std::find_if(
54  s.rbegin(), s.rend(), [](const char c) { return !std::isspace(c); })
55  .base(),
56  s.end());
57  return s;
58 }
59 
60 // trim from both ends
61 static inline std::string& trim(std::string& s) { return ltrim(rtrim(s)); }
63 {
65 
66  data.clear();
67  std::stringstream ss(s);
68  std::string lin;
69  while (std::getline(ss, lin, ','))
70  {
71  lin = trim(lin);
72  const TRuntimeClassId* id = findRegisteredClass(lin);
73  ASSERTMSG_(
74  id != nullptr, format("Unknown class name: %s", lin.c_str()));
75  this->insert(id);
76  }
77 
79 }
#define MRPT_TRY_END
The end of a standard MRPT "try...catch()" block that allows tracing throw the call stack after an ex...
Definition: exceptions.h:231
A structure that holds runtime class type information.
Definition: CObject.h:30
GLdouble s
Definition: glext.h:3676
void insert(const mrpt::rtti::TRuntimeClassId *id)
Insert a class in the list.
#define MRPT_TRY_START
The start of a standard MRPT "try...catch()" block that allows tracing throw the call stack after an ...
Definition: exceptions.h:224
const GLubyte * c
Definition: glext.h:6313
static std::string & ltrim(std::string &s)
static std::string & trim(std::string &s)
#define ASSERTMSG_(f, __ERROR_MSG)
Defines an assertion mechanism.
Definition: exceptions.h:101
static std::string & rtrim(std::string &s)
GLsizei const GLchar ** string
Definition: glext.h:4101
const TRuntimeClassId * findRegisteredClass(const std::string &className)
Return info about a given class by its name, or nullptr if the class is not registered.
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition: format.cpp:16
bool containsDerivedFrom(const mrpt::rtti::TRuntimeClassId *id) const
Does the list contains a class derived from...?
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:3546
void fromString(const std::string &s)
Builds from a string representation of the list, for example: "CPose2D, CObservation, CPose3D".
std::string toString() const
Return a string representation of the list, for example: "CPose2D, CObservation, CPose3D".



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020