PetaVision  Alpha
ObjectMapComponent.hpp
1 /*
2  * ObjectMapComponent.hpp
3  *
4  * Created on: Nov 20, 2017
5  * Author: pschultz
6  */
7 
8 #ifndef OBJECTMAPCOMPONENT
9 #define OBJECTMAPCOMPONENT
10 
11 #include "columns/BaseObject.hpp"
12 #include <map>
13 
14 namespace PV {
15 
23  public:
24  ObjectMapComponent(char const *name, HyPerCol *hc) { initialize(name, hc); }
25 
26  virtual ~ObjectMapComponent() {}
27 
28  virtual void setObjectType() override { mObjectType = "ObjectMapComponent"; }
29 
30  void setObjectMap(std::map<std::string, Observer *> const &table) { mObjectMap = table; }
31 
32  template <typename S>
33  S *lookup(std::string const &name) const {
34  S *lookupResult = nullptr;
35  auto findResult = mObjectMap.find(name);
36  if (findResult != mObjectMap.end()) {
37  auto observerPtr = findResult->second;
38  lookupResult = dynamic_cast<S *>(observerPtr);
39  }
40  return lookupResult;
41  }
42 
43  protected:
45 
46  int initialize(char const *name, HyPerCol *hc) { return BaseObject::initialize(name, hc); }
47 
48  protected:
49  std::map<std::string, Observer *> mObjectMap;
50 
51 }; // class ObjectMapComponent
52 
53 } // namespace PV
54 
55 #endif // OBJECTMAPCOMPONENT