MRPT  1.9.9
TMetricMapTypesRegistry.h
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 #pragma once
11 
12 #include <mrpt/obs/obs_frwds.h>
13 #include <functional>
14 #include <map>
15 #include <string>
16 
17 namespace mrpt
18 {
19 namespace maps
20 {
21 struct TMetricMapInitializer;
22 namespace internal
23 {
24 using MapDefCtorFunctor =
25  std::function<mrpt::maps::TMetricMapInitializer*(void)>;
26 using MapCtorFromDefFunctor = std::function<mrpt::maps::CMetricMap*(
28 
29 /** Class factory & registry for map classes. Used from
30  * mrpt::maps::TMetricMapInitializer */
32 {
33  public:
35  /** Return the index of the class in the list (not important, just used as a
36  * trick to initialize static members) */
37  size_t doRegister(
38  const std::string& name, MapDefCtorFunctor func1,
39  MapCtorFromDefFunctor func2);
40  /** Return nullptr if not found */
42  const std::string& className) const;
43  /** Return nullptr if not found */
45  const mrpt::maps::TMetricMapInitializer& mi) const;
46  using TListRegisteredMaps = std::map<
47  std::string, std::pair<MapDefCtorFunctor, MapCtorFromDefFunctor>>;
48  const TListRegisteredMaps& getAllRegistered() const { return m_registry; }
49 
50  private:
51  TMetricMapTypesRegistry() = default; // Access thru singleton in Instance()
53 };
54 
55 /** Add a MAP_DEFINITION_START() ... MAP_DEFINITION_END() block inside the
56  * declaration of each metric map */
57 #define MAP_DEFINITION_START(_CLASS_NAME_) \
58  public: \
59  /** @name Map Definition Interface stuff (see \
60  * mrpt::maps::TMetricMapInitializer) @{ */ \
61  struct TMapDefinitionBase : public mrpt::maps::TMetricMapInitializer \
62  { \
63  TMapDefinitionBase() \
64  : TMetricMapInitializer(CLASS_ID(_CLASS_NAME_)) {} \
65  }; \
66  struct TMapDefinition : public TMapDefinitionBase \
67  {
68 #define MAP_DEFINITION_END(_CLASS_NAME_) \
69  TMapDefinition(); \
70  \
71  protected: \
72  void loadFromConfigFile_map_specific( \
73  const mrpt::config::CConfigFileBase& source, \
74  const std::string& sectionNamePrefix) override; \
75  void dumpToTextStream_map_specific(std::ostream& out) const override; \
76  } \
77  ; \
78  /** Returns default map definition initializer. See \
79  * mrpt::maps::TMetricMapInitializer */ \
80  static mrpt::maps::TMetricMapInitializer* MapDefinition(); \
81  /** Constructor from a map definition structure: initializes the map and \
82  * its parameters accordingly */ \
83  static _CLASS_NAME_* CreateFromMapDefinition( \
84  const mrpt::maps::TMetricMapInitializer& def); \
85  static mrpt::maps::CMetricMap* internal_CreateFromMapDefinition( \
86  const mrpt::maps::TMetricMapInitializer& def); \
87  /** ID used to initialize class registration (just ignore it) */ \
88  static const size_t m_private_map_register_id; \
89 /** @} */
90 
91 /** Registers one map class into TMetricMapInitializer factory.
92  * One or several alternative class names can be provided, separated with
93  * whitespaces or commas */
94 #define MAP_DEFINITION_REGISTER(_CLASSNAME_STRINGS, _CLASSNAME_WITH_NS) \
95  const size_t _CLASSNAME_WITH_NS::m_private_map_register_id = \
96  mrpt::maps::internal::TMetricMapTypesRegistry::Instance().doRegister( \
97  _CLASSNAME_STRINGS, &_CLASSNAME_WITH_NS::MapDefinition, \
98  &_CLASSNAME_WITH_NS::internal_CreateFromMapDefinition); \
99  mrpt::maps::TMetricMapInitializer* _CLASSNAME_WITH_NS::MapDefinition() \
100  { \
101  return new _CLASSNAME_WITH_NS::TMapDefinition; \
102  } \
103  _CLASSNAME_WITH_NS* _CLASSNAME_WITH_NS::CreateFromMapDefinition( \
104  const mrpt::maps::TMetricMapInitializer& def) \
105  { \
106  return dynamic_cast<_CLASSNAME_WITH_NS*>( \
107  _CLASSNAME_WITH_NS::internal_CreateFromMapDefinition(def)); \
108  }
109 
110 } // namespace internal
111 } // namespace maps
112 } // namespace mrpt
Virtual base for specifying the kind and parameters of one map (normally, to be inserted into mrpt::m...
mrpt::maps::TMetricMapInitializer * factoryMapDefinition(const std::string &className) const
Return nullptr if not found.
mrpt::maps::CMetricMap * factoryMapObjectFromDefinition(const mrpt::maps::TMetricMapInitializer &mi) const
Return nullptr if not found.
GLsizei const GLchar ** string
Definition: glext.h:4116
const TListRegisteredMaps & getAllRegistered() const
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:53
GLuint const GLchar * name
Definition: glext.h:4068
std::function< mrpt::maps::CMetricMap *(const mrpt::maps::TMetricMapInitializer &)> MapCtorFromDefFunctor
size_t doRegister(const std::string &name, MapDefCtorFunctor func1, MapCtorFromDefFunctor func2)
Return the index of the class in the list (not important, just used as a trick to initialize static m...
Class factory & registry for map classes.
std::map< std::string, std::pair< MapDefCtorFunctor, MapCtorFromDefFunctor > > TListRegisteredMaps
std::function< mrpt::maps::TMetricMapInitializer *(void)> MapDefCtorFunctor



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 0a2592f5f Fri May 24 16:11:07 2019 +0200 at vie may 24 16:20:17 CEST 2019