gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-2191-ga4742ac
a Global And Modular Bsm Inference Tool
yaml_description_database.hpp
Go to the documentation of this file.
1 // GAMBIT: Global and Modular BSM Inference Tool
2 // *********************************************
23 
24 #include <yaml-cpp/yaml.h>
25 #include <vector>
26 #include <sstream>
27 #include <utility>
28 
33 
34 #ifndef __yaml_description_database_hpp__
35 #define __yaml_description_database_hpp__
36 
37 namespace Gambit
38 {
41  {
45  std::map<str, std::set<std::pair<str,str> > > modset;
47  std::map<str, std::set<std::pair<str,str> > > beset;
52  };
53 
55  struct model_info
56  {
60  std::vector<str> parameters;
62  int nparams;
66  std::vector<str> lineage;
68  std::vector<str> descendants;
73  };
74 
76  YAML::Emitter& operator << (YAML::Emitter&, const capability_info&);
77 
79  YAML::Emitter& operator << (YAML::Emitter&, const model_info&);
80 
84  {
85 
86  public:
87 
90 
92  DescriptionDatabase(const str& filename);
93 
95  DescriptionDatabase(const YAML::Node &descriptions);
96 
98  DescriptionDatabase(YAML::Node &&descriptions);
99 
102  template <typename... args>
103  bool hasKey(const args&... keys) const
104  {
105  return getVariadicNode(descriptions, keys...);
106  }
107 
108  template<typename TYPE, typename... args>
109  TYPE getValue(const args&... keys) const
110  {
111  const YAML::Node node = getVariadicNode(descriptions, keys...);
112  if (not node)
113  {
114  std::ostringstream os;
115  os << "No entry for [" << stringifyVariadic(keys...) << "]\n Node contents: " << descriptions;
116  utils_error().raise(LOCAL_INFO,os.str());
117  }
118  return node.as<TYPE>();
119  }
121 
122 
124  template<typename... args>
125  void loadFile(const str& filename)
126  {
127  try {
128  descriptions = YAML::LoadFile(filename);
129  }
130  catch (YAML::Exception &e) {
131  std::ostringstream msg;
132  msg << "Error reading descriptions file \""<<filename<<"\"! ";
133  msg << "Please check that file exists!" << endl;
134  msg << "(yaml-cpp error: "<<e.what()<<" )";
135  utils_error().raise(LOCAL_INFO,msg.str());
136  }
137  }
138 
140  std::map<str,int> check_for_duplicates();
141 
143  std::vector<str> get_all_values(str key);
144 
145  private:
146 
147  YAML::Node descriptions;
148 
149  };
150 
151 } // end Gambit namespace
152 
153 
154 #endif //defined __yaml_description_database_hpp__
bool hasKey(const args &... keys) const
Getters for key/value pairs (which is all the options node should contain)
std::map< str, std::set< std::pair< str, str > > > modset
Set of modules and module functions in which capability is used, along with corresponding result type...
def check_for_duplicates(fout, group)
Definition: hdf5tools.py:71
void loadFile(const str &filename)
Load descriptions from file.
int nparams
Number of parameters ( parameters.size() )
EXPORT_SYMBOLS error & utils_error()
Utility errors.
bool has_description
Flag to check if description is missing.
std::vector< str > parameters
Parameter names.
Helper struct to carry around model information.
bool has_description
Flag to check if description is missing.
#define LOCAL_INFO
Definition: local_info.hpp:34
General small utility classes, typedefs, etc.
Variadic utilty functions which work with YAML objects.
const std::string stringifyVariadic()
const YAML::Node getVariadicNode(const YAML::Node &node)
std::map< str, std::set< std::pair< str, str > > > beset
Set of backends and backend functions in which capability is used, along with corresponding type sign...
Variadic utilty functions.
std::string str
Shorthand for a standard string.
Definition: Analysis.hpp:35
Helper struct to carry around capability information.
TYPE getValue(const args &... keys) const
A small wrapper object for &#39;description database&#39; nodes.
std::vector< str > descendants
All children and later descendants.
std::vector< str > lineage
Parent and all ancestor models.
YAML::Emitter & operator<<(YAML::Emitter &, const capability_info &)
Emitter for the capability_info struct.
Exception objects required for standalone compilation.
str description
Full description of capability.
str parent
Parent model name.
TODO: see if we can use this one:
Definition: Analysis.hpp:33
str description
Full description of capability.