Protium
Math and Design Features
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Friends Macros Pages
FunctionMapped.h
Go to the documentation of this file.
1 #ifndef Protium_FunctionMapped_h_
2 #define Protium_FunctionMapped_h_
3 
4 #include <map>
5 #include <string>
6 #include <cstdlib>
7 
8 
9 namespace Protium{
10  namespace Design{
13  virtual void Set(const std::string& key, const std::string& value )=0;
14  };
15 
16  template<class Derived>
18  typedef void (Derived::*d_func)(double);
19  typedef std::map<std::string, d_func> func_map;
21 
22  void AddValueToMap(const std::string& value, d_func f){
23  d_config.insert(std::make_pair(value,f));
24  }
25  void Set(const std::string& value, const std::string& value){
26  double newValue = std::atof(value.c_str() );
27  d_func call = d_config[key];
28  if(!call) return;
29  Derived* d = dynamic_cast<Derived*>(this);
30  (d->*call)(newValue);
31  }
32  };
33  }
34 }
35 
36 
37 #endif //File Guardian
std::map< std::string, d_func > func_map
void AddValueToMap(const std::string &value, d_func f)
void Set(const std::string &value, const std::string &value)
virtual void Set(const std::string &key, const std::string &value)=0
void(Derived::* d_func)(double)