Choreonoid  1.5
PolymorphicFunctionSet.h
Go to the documentation of this file.
1 
5 #ifndef CNOID_UTIL_POLYMORPHIC_FUNCTION_SET_H
6 #define CNOID_UTIL_POLYMORPHIC_FUNCTION_SET_H
7 
8 #include <boost/bind.hpp>
9 
10 namespace cnoid {
11 
12 template <class Object, class Parameter> class PolymorphicFunctionSet
13 {
14  typedef boost::function<void(Parameter p)> Function;
15  struct compare {
16  bool operator ()(const std::type_info* a, const std::type_info* b) const {
17  return a->before(*b);
18  }
19  };
20  typedef std::map<const std::type_info*, Function, compare> FunctionMap;
21  FunctionMap functions;
22 
23  bool callFuntions(const std::type_info& type, Object* object, Parameter& param){
24  FunctionMap::iterator p = functions.find(&type);
25  if(p != functions.end()){
26  return p->second(param);
27  }
28  return true;
29  }
30 
31 public:
32  template <class Type> void setFunction(FunctionType f) {
33  functions[&typeid(Type)] = f;
34  }
35 
36  bool operator()(Object* object, Paramter& param) {
37  object->forEachActualType(boost::bind(&callFunctions, this, _1, object, boost::ref(param)));
38  }
39 
40 };
41 }
42 #endif
43 
Definition: PolymorphicFunctionSet.h:12
bool operator()(Object *object, Paramter &param)
Definition: PolymorphicFunctionSet.h:36
Defines the minimum processing for performing pasing file for STL.
Definition: AbstractSceneLoader.h:9
void setFunction(FunctionType f)
Definition: PolymorphicFunctionSet.h:32