MRPT  1.9.9
TMetricMapTypesRegistry.h
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 #pragma once
11 
12 #include <mrpt/obs/obs_frwds.h>
13 #include <map>
14 #include <string>
15 #include <functional>
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() {} // 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:4101
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:54
GLuint const GLchar * name
Definition: glext.h:4054
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: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020