Main MRPT website > C++ reference for MRPT 1.4.0
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-2016, 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
14#include <mrpt/obs/obs_frwds.h>
15#include <map>
16#include <string>
17
18namespace mrpt
19{
20 namespace maps
21 {
22 struct TMetricMapInitializer;
23 namespace internal
24 {
25 typedef mrpt::maps::TMetricMapInitializer* (*MapDefCtorFunctor)(void);
26 typedef mrpt::maps::CMetricMap* (*MapCtorFromDefFunctor)(const mrpt::maps::TMetricMapInitializer&);
27
28 /** Class factory & registry for map classes. Used from mrpt::maps::TMetricMapInitializer */
30 {
31 public:
33 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 members)
34 mrpt::maps::TMetricMapInitializer* factoryMapDefinition(const std::string &className) const; //!< Return NULL if not found
36 typedef std::map<std::string,std::pair<MapDefCtorFunctor,MapCtorFromDefFunctor> > TListRegisteredMaps;
37 const TListRegisteredMaps & getAllRegistered() const { return m_registry;}
38 private:
39 TMetricMapTypesRegistry() {} // Access thru singleton in Instance()
41 };
42
43 /** Add a MAP_DEFINITION_START() ... MAP_DEFINITION_END() block inside the declaration of each metric map */
44 #define MAP_DEFINITION_START(_CLASS_NAME_,_LINKAGE_) \
45 public: \
46 /** @name Map Definition Interface stuff (see mrpt::maps::TMetricMapInitializer) @{ */ \
47 struct _LINKAGE_ TMapDefinitionBase : public mrpt::maps::TMetricMapInitializer { \
48 TMapDefinitionBase() : TMetricMapInitializer(CLASS_ID(_CLASS_NAME_)) { } \
49 };\
50 struct _LINKAGE_ TMapDefinition : public TMapDefinitionBase { \
51
52 #define MAP_DEFINITION_END(_CLASS_NAME_,_LINKAGE_) \
53 TMapDefinition();\
54 protected: \
55 void loadFromConfigFile_map_specific(const mrpt::utils::CConfigFileBase &source, const std::string &sectionNamePrefix) MRPT_OVERRIDE; \
56 void dumpToTextStream_map_specific(mrpt::utils::CStream &out) const MRPT_OVERRIDE; \
57 }; \
58 /** Returns default map definition initializer. See mrpt::maps::TMetricMapInitializer */ \
59 static mrpt::maps::TMetricMapInitializer* MapDefinition(); \
60 /** Constructor from a map definition structure: initializes the map and its parameters accordingly */ \
61 static _CLASS_NAME_* CreateFromMapDefinition(const mrpt::maps::TMetricMapInitializer &def); \
62 static mrpt::maps::CMetricMap* internal_CreateFromMapDefinition(const mrpt::maps::TMetricMapInitializer &def); \
63 /** ID used to initialize class registration (just ignore it) */ \
64 static const size_t m_private_map_register_id; \
65 /** @} */
66
67 /** Registers one map class into TMetricMapInitializer factory.
68 * One or several alternative class names can be provided, separated with whitespaces or commas */
69 #define MAP_DEFINITION_REGISTER(_CLASSNAME_STRINGS, _CLASSNAME_WITH_NS) \
70 const size_t _CLASSNAME_WITH_NS::m_private_map_register_id = mrpt::maps::internal::TMetricMapTypesRegistry::Instance().doRegister(_CLASSNAME_STRINGS,&_CLASSNAME_WITH_NS::MapDefinition,&_CLASSNAME_WITH_NS::internal_CreateFromMapDefinition); \
71 mrpt::maps::TMetricMapInitializer* _CLASSNAME_WITH_NS::MapDefinition() { return new _CLASSNAME_WITH_NS::TMapDefinition; } \
72 _CLASSNAME_WITH_NS* _CLASSNAME_WITH_NS::CreateFromMapDefinition(const mrpt::maps::TMetricMapInitializer &def) \
73 { return dynamic_cast<_CLASSNAME_WITH_NS*>(_CLASSNAME_WITH_NS::internal_CreateFromMapDefinition(def)); }
74
75 } // end NS internal
76 } // End of namespace
77} // End of namespace
78
Declares a virtual base class for all metric maps storage classes.
mrpt::maps::TMetricMapInitializer *(* MapDefCtorFunctor)(void)
mrpt::maps::CMetricMap *(* MapCtorFromDefFunctor)(const mrpt::maps::TMetricMapInitializer &)
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Virtual base for specifying the kind and parameters of one map (normally, to be inserted into mrpt::m...
Class factory & registry for map classes.
std::map< std::string, std::pair< MapDefCtorFunctor, MapCtorFromDefFunctor > > TListRegisteredMaps
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...
mrpt::maps::TMetricMapInitializer * factoryMapDefinition(const std::string &className) const
Return NULL if not found.
mrpt::maps::CMetricMap * factoryMapObjectFromDefinition(const mrpt::maps::TMetricMapInitializer &mi) const
Return NULL if not found.
static TMetricMapTypesRegistry & Instance()
const TListRegisteredMaps & getAllRegistered() const



Page generated by Doxygen 1.9.2 for MRPT 1.4.0 SVN: at Mon Sep 20 00:21:40 UTC 2021