Main MRPT website > C++ reference for 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 }
ltrim
static std::string & ltrim(std::string &s)
Definition: CListOfClasses.cpp:41
trim
static std::string & trim(std::string &s)
Definition: CListOfClasses.cpp:61
mrpt::rtti::TRuntimeClassId
A structure that holds runtime class type information.
Definition: CObject.h:30
s
GLdouble s
Definition: glext.h:3676
c
const GLubyte * c
Definition: glext.h:6313
mrpt::rtti::CListOfClasses::insert
void insert(const mrpt::rtti::TRuntimeClassId *id)
Insert a class in the list.
Definition: CListOfClasses.h:35
mrpt::rtti::CListOfClasses::toString
std::string toString() const
Return a string representation of the list, for example: "CPose2D, CObservation, CPose3D".
Definition: CListOfClasses.cpp:28
rtrim
static std::string & rtrim(std::string &s)
Definition: CListOfClasses.cpp:50
MRPT_TRY_END
#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
data
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:3547
rtti-precomp.h
mrpt::format
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition: format.cpp:16
mrpt::rtti::CListOfClasses::fromString
void fromString(const std::string &s)
Builds from a string representation of the list, for example: "CPose2D, CObservation,...
Definition: CListOfClasses.cpp:62
MRPT_TRY_START
#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
ASSERTMSG_
#define ASSERTMSG_(f, __ERROR_MSG)
Defines an assertion mechanism.
Definition: exceptions.h:101
mrpt::rtti
Definition: CListOfClasses.h:17
CListOfClasses.h
string
GLsizei const GLchar ** string
Definition: glext.h:4101
mrpt::rtti::CListOfClasses::containsDerivedFrom
bool containsDerivedFrom(const mrpt::rtti::TRuntimeClassId *id) const
Does the list contains a class derived from...?
Definition: CListOfClasses.cpp:20
mrpt::rtti::findRegisteredClass
const TRuntimeClassId * findRegisteredClass(const std::string &className)
Return info about a given class by its name, or nullptr if the class is not registered.
Definition: internal_class_registry.cpp:202



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST