gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-2191-ga4742ac
a Global And Modular Bsm Inference Tool
safe_param_map.hpp
Go to the documentation of this file.
1 // GAMBIT: Global and Modular BSM Inference Tool
2 // *********************************************
18 
19 
20 #ifndef __safe_param_map_hpp__
21 #define __safe_param_map_hpp__
22 
24 
25 #include <map>
26 #include <stdexcept>
27 
28 namespace Gambit
29 {
30 
31  namespace Models
32  {
33 
34  template<typename T>
35  class safe_param_map : public std::map<str,T>
36  {
37  public:
38  T& operator[](str key)
39  {
40  try
41  {
42  return this->at(key);
43  }
44  catch(std::out_of_range&)
45  {
46  model_error().raise("call to [] operator of Param map in a module function", "Requested parameter \""+key+"\" is not available. \n"
47  "Generally this happens because you have requested a parameter of a model that\n"
48  "is not being scanned (check that you are using the ModelInUse() function), or\n"
49  "because you have failed to declare the dependency on the model's parameters \n"
50  "in your rollcall header using ALLOW_MODEL(S) or ALLOW_MODEL_DEPENDENCE.");
51  }
52  return this->at(key); // Will only get here if someone has turned model errors into warnings. If so, they get what they deserve.
53  }
54  };
55 
56  }
57 
58 }
59 
60 
61 #endif //#defined __safe_param_map_hpp
std::string str
Definition: models.hpp:49
Exception objects required for standalone compilation.
error & model_error()
Model errors.
TODO: see if we can use this one:
Definition: Analysis.hpp:33