MRPT  1.9.9
CParameterizedTrajectoryGenerator_factory.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 
10 #include "nav-precomp.h" // Precomp header
11 
15 
16 using namespace mrpt::nav;
17 
18 /*---------------------------------------------------------------
19  Class factory
20  ---------------------------------------------------------------*/
22  const std::string& ptgClassName_, const mrpt::config::CConfigFileBase& cfg,
23  const std::string& sSection, const std::string& sKeyPrefix)
24 {
26 
28 
29  // Special names for backwards compatibility with MRPT < 1.5.0
30  std::string ptgClassName = mrpt::system::trim(ptgClassName_);
31  if (ptgClassName.size() == 1)
32  {
33  switch (ptgClassName[0])
34  {
35  case '1':
36  ptgClassName = "CPTG_DiffDrive_C";
37  break;
38  case '2':
39  ptgClassName = "CPTG_DiffDrive_alpha";
40  break;
41  case '3':
42  ptgClassName = "CPTG_DiffDrive_CCS";
43  break;
44  case '4':
45  ptgClassName = "CPTG_DiffDrive_CC";
46  break;
47  case '5':
48  ptgClassName = "CPTG_DiffDrive_CS";
49  break;
50  };
51  }
52 
53  // Factory:
54  const mrpt::rtti::TRuntimeClassId* classId =
55  mrpt::rtti::findRegisteredClass(ptgClassName);
56  if (!classId)
57  {
59  "[CreatePTG] No PTG named `%s` is registered!",
60  ptgClassName.c_str());
61  }
62 
64  dynamic_cast<CParameterizedTrajectoryGenerator*>(
65  classId->createObject());
66  if (!ptg)
67  {
69  "[CreatePTG] Object of type `%s` seems not to be a PTG!",
70  ptgClassName.c_str());
71  }
72 
73  // Wrapper to transparently add prefixes to all config keys:
75  cfp.bind(cfg);
76  cfp.setPrefixes("", sKeyPrefix);
77 
78  ptg->loadFromConfigFile(cfp, sSection);
79  return ptg;
80  MRPT_END
81 }
void registerAllPendingClasses()
Register all pending classes - to be called just before de-serializing an object, for example...
#define MRPT_START
Definition: exceptions.h:262
static CParameterizedTrajectoryGenerator * CreatePTG(const std::string &ptgClassName, const mrpt::config::CConfigFileBase &cfg, const std::string &sSection, const std::string &sKeyPrefix)
The class factory for creating a PTG from a list of parameters in a section of a given config file (p...
A structure that holds runtime class type information.
Definition: CObject.h:30
This is the base class for any user-defined PTG.
This class allows loading and storing values and vectors of different types from a configuration text...
A wrapper for other CConfigFileBase-based objects that prefixes a given token to every key and/or sec...
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.
void bind(const CConfigFileBase &o)
Make this object to wrap the given existing CConfigFileBase object.
virtual void loadFromConfigFile(const mrpt::config::CConfigFileBase &cfg, const std::string &sSection) override
Parameters accepted by this base class:
#define MRPT_END
Definition: exceptions.h:266
std::string trim(const std::string &str)
Removes leading and trailing spaces.
void setPrefixes(const std::string &prefix_sections, const std::string &prefix_keys)
Change the prefix for sections and keys.
mrpt::rtti::CObject * createObject() const
Definition: CObject.cpp:79
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
Definition: exceptions.h:43



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