00001
00007 #ifndef ___PARAMMAP_H___
00008 #define ___PARAMMAP_H___
00009
00010 #include "polymorph.h"
00011 #include "pointerlookup.h"
00012 #include "msg.h"
00013
00014
00018 class ParamMap : public PointerLookup<Typeless> {
00019 public:
00020 typedef ParamMap self;
00021 virtual ~ParamMap() { }
00022
00028 template <class T>
00029 const T* get(const char* name, T*& x,
00030 const bool warn=true, const bool warn_unknown=true) const {
00031
00032 const Typeless* p = getptr(name);
00033 const Polymorph<T>* pp = dynamic_cast<const Polymorph<T>*>(p);
00034
00035 if (warn_unknown && !pp)
00036 message(Msg::Error,"ParamMap: No parameter (or constant) `" +
00037 string(name) + "' is defined");
00038
00039 else if (warn && p && !pp)
00040 message(Msg::Error,"ParamMap: Parameter `" +
00041 string(name) + "' does not have the expected type");
00042
00043 return x = (pp ? pp->valueptr() : 0);
00044 }
00045
00046
00049 template <class T>
00050 T get_with_default(const char* name, const T& default_val,
00051 const bool warn=true, const bool warn_unknown=false) const {
00052 T* p=0;
00053 get(name,p,warn,warn_unknown);
00054 return (p ? *p : default_val);
00055 }
00056
00070 virtual ParamMap* new_child(const string name_="", const bool owned=false)=0;
00071
00077 virtual const ParamMap& get_child(const string& name_="") const=0;
00078 virtual ParamMap& get_child(const string& name_="")=0;
00079
00080 private:
00081 virtual void message(Msg::MessageLevel, const string&) const { };
00082 };
00083
00084
00085 #endif