MRPT  1.9.9
CListOfClasses.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #include "rtti-precomp.h" // Precompiled headers
10 
12 #include <algorithm>
13 #include <cctype>
14 #include <functional>
15 #include <locale>
16 #include <sstream>
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:213
std::string std::string format(std::string_view fmt, ARGS &&... args)
Definition: format.h:26
A structure that holds runtime class type information.
Definition: CObject.h:31
GLdouble s
Definition: glext.h:3682
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:206
const GLubyte * c
Definition: glext.h:6406
static std::string & ltrim(std::string &s)
static std::string & trim(std::string &s)
const TRuntimeClassId * findRegisteredClass(const std::string &className, const bool allow_ignore_namespace=true)
Return info about a given class by its name, or nullptr if the class is not registered.
#define ASSERTMSG_(f, __ERROR_MSG)
Defines an assertion mechanism.
Definition: exceptions.h:108
static std::string & rtrim(std::string &s)
GLsizei const GLchar ** string
Definition: glext.h:4116
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:3550
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: cb560b230 Wed Nov 13 08:06:48 2019 +0100 at miƩ nov 13 08:15:10 CET 2019