MRPT  1.9.9
TMetricMapTypesRegistry.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 
10 #include "obs-precomp.h" // Precomp header
11 
12 #include <mrpt/maps/CMetricMap.h>
16 
17 using namespace std;
18 using namespace mrpt;
19 using namespace mrpt::maps;
20 using namespace mrpt::maps::internal;
21 
22 TMetricMapTypesRegistry& TMetricMapTypesRegistry::Instance()
23 {
24  static TMetricMapTypesRegistry reg;
25  return reg;
26 }
27 
28 size_t TMetricMapTypesRegistry::doRegister(
29  const std::string& names, MapDefCtorFunctor func1,
31 {
32  std::vector<std::string> lstNames;
33  mrpt::system::tokenize(names, " \t\r\n,", lstNames);
34  for (const auto& lstName : lstNames)
35  m_registry[lstName] = std::make_pair(func1, func2);
36  return m_registry.size();
37 }
38 
40  TMetricMapTypesRegistry::factoryMapDefinition(
41  const std::string& className) const
42 {
43  auto it = m_registry.find(className);
44  if (it == m_registry.end()) return nullptr;
45  ASSERT_(it->second.first);
46  return (it->second.first)();
47 }
48 
49 mrpt::maps::CMetricMap* TMetricMapTypesRegistry::factoryMapObjectFromDefinition(
50  const mrpt::maps::TMetricMapInitializer& mi) const
51 {
52  auto it = m_registry.find(mi.getMetricMapClassType()->className);
53  if (it == m_registry.end())
54  {
56  "[TMetricMapTypesRegistry] Error: Cannot create map of "
57  "unregistered map type '%s'",
58  mi.getMetricMapClassType()->className);
59  }
60 
61  ASSERT_(it->second.second);
62  mrpt::maps::CMetricMap* theMap = (it->second.second)(mi);
63 
64  // Common params for all maps:
66 
67  return theMap;
68 }
Virtual base for specifying the kind and parameters of one map (normally, to be inserted into mrpt::m...
STL namespace.
TMapGenericParams genericMapParams
Common params to all maps.
Definition: CMetricMap.h:275
const mrpt::rtti::TRuntimeClassId::Ptr & getMetricMapClassType() const
Query the map type (C++ class), as set by the factory method MapDefinition()
void tokenize(const std::string &inString, const std::string &inDelimiters, OUT_CONTAINER &outTokens, bool skipBlankTokens=true) noexcept
Tokenizes a string according to a set of delimiting characters.
mrpt::maps::TMapGenericParams genericMapParams
Common params for all maps: These are automatically set in TMetricMapTypesRegistry::factoryMapObjectF...
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:120
GLsizei const GLchar ** string
Definition: glext.h:4116
std::vector< string > names
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Declares a virtual base class for all metric maps storage classes.
Definition: CMetricMap.h:52
std::function< mrpt::maps::CMetricMap *(const mrpt::maps::TMetricMapInitializer &)> MapCtorFromDefFunctor
Class factory & registry for map classes.
#define THROW_EXCEPTION_FMT(_FORMAT_STRING,...)
Definition: exceptions.h:69
std::function< mrpt::maps::TMetricMapInitializer *(void)> MapDefCtorFunctor



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: d046c631e Tue Jul 23 10:47:41 2019 -0700 at mar jul 23 19:50:16 CEST 2019