ASCO Aerial Autonomy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
type_map.h
Go to the documentation of this file.
1 #pragma once
2 // get type info for each storage object
3 #include <typeindex>
4 // store objects
5 #include <unordered_map>
6 
12 template <class GenericObjectT> class TypeMap {
17  std::unordered_map<std::type_index, GenericObjectT *> object_storage_map_;
18 
19 public:
27  template <class ObjectT> void setObject(ObjectT &object) {
28  object_storage_map_[typeid(ObjectT)] = &object;
29  }
37  template <class ObjectT> ObjectT *getObject() {
38  return static_cast<ObjectT *>(object_storage_map_[typeid(ObjectT)]);
39  }
40 
48  template <class ObjectT> const ObjectT *getObject() const {
49  return (
50  static_cast<const ObjectT *>(object_storage_map_.at(typeid(ObjectT))));
51  }
52 };
ObjectT * getObject()
return the object stored
Definition: type_map.h:37
const ObjectT * getObject() const
return a const oject pointer stored
Definition: type_map.h:48
Store objects with a common base class.
Definition: type_map.h:12
void setObject(ObjectT &object)
Store the object with base class as GenericObjectT.
Definition: type_map.h:27