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



Page generated by Doxygen 1.8.14 for MRPT 2.0.2 Git: 9b4fd2465 Mon May 4 16:59:08 2020 +0200 at lun may 4 17:26:07 CEST 2020