gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-252-gf9a3f78
a Global And Modular Bsm Inference Tool
Gambit::DescriptionDatabase Class Reference

A small wrapper object for 'description database' nodes. More...

#include <yaml_description_database.hpp>

Public Member Functions

 DescriptionDatabase ()
 Default constructor. More...
 
 DescriptionDatabase (const str &filename)
 Construct from file. More...
 
 DescriptionDatabase (const YAML::Node &descriptions)
 Copy constructor. More...
 
 DescriptionDatabase (YAML::Node &&descriptions)
 Move constructor. More...
 
template<typename... args>
void loadFile (const str &filename)
 Load descriptions from file. More...
 
std::map< str, intcheck_for_duplicates ()
 Check 'descriptions' for duplicate keys. More...
 
std::vector< strget_all_values (str key)
 Return vector of descriptions matching key (for retrieving values with non-unique keys) More...
 
template<typename... args>
bool hasKey (const args &... keys) const
 Getters for key/value pairs (which is all the options node should contain) More...
 
template<typename TYPE , typename... args>
TYPE getValue (const args &... keys) const
 

Private Attributes

YAML::Node descriptions
 

Detailed Description

A small wrapper object for 'description database' nodes.

The descriptions are extracted from, e.g., capabilities.dat

Definition at line 83 of file yaml_description_database.hpp.

Constructor & Destructor Documentation

◆ DescriptionDatabase() [1/4]

Gambit::DescriptionDatabase::DescriptionDatabase ( )

Default constructor.

Member functions for DescriptionDatabase class.

Default constructor

Definition at line 100 of file yaml_description_database.cpp.

100 {}

◆ DescriptionDatabase() [2/4]

Gambit::DescriptionDatabase::DescriptionDatabase ( const str filename)

Construct from file.

Definition at line 103 of file yaml_description_database.cpp.

References loadFile().

104  {
105  loadFile(filename);
106  }
void loadFile(const str &filename)
Load descriptions from file.
Here is the call graph for this function:

◆ DescriptionDatabase() [3/4]

Gambit::DescriptionDatabase::DescriptionDatabase ( const YAML::Node &  descriptions)

Copy constructor.

Definition at line 109 of file yaml_description_database.cpp.

◆ DescriptionDatabase() [4/4]

Gambit::DescriptionDatabase::DescriptionDatabase ( YAML::Node &&  descriptions)

Move constructor.

Definition at line 112 of file yaml_description_database.cpp.

112 : descriptions(std::move(desc)) {}

Member Function Documentation

◆ check_for_duplicates()

std::map< str, int > Gambit::DescriptionDatabase::check_for_duplicates ( )

Check 'descriptions' for duplicate keys.

Definition at line 115 of file yaml_description_database.cpp.

References descriptions.

Referenced by Gambit::gambit_core::check_databases().

116  {
117  std::set<str> found; //found keys
118  std::map<str,int> duplicates; //name and number of duplicates
119  for(YAML::const_iterator it=descriptions.begin();it!=descriptions.end();++it)
120  {
121  str name = it->first.as<str>();
122  if(found.find(name)==found.end())
123  {
124  found.insert(name);
125  duplicates[name] = 0;
126  }
127  else
128  {
129  duplicates[name] = duplicates[name] + 1;
130  }
131  }
132  return duplicates;
133  }
std::string str
Shorthand for a standard string.
Definition: Analysis.hpp:35
Here is the caller graph for this function:

◆ get_all_values()

std::vector< str > Gambit::DescriptionDatabase::get_all_values ( str  key)

Return vector of descriptions matching key (for retrieving values with non-unique keys)

Definition at line 136 of file yaml_description_database.cpp.

References descriptions.

Referenced by Gambit::gambit_core::check_databases().

137  {
138  std::vector<str> values;
139  for(YAML::const_iterator it=descriptions.begin();it!=descriptions.end();++it)
140  {
141  if(key==it->first.as<str>())
142  {
143  values.push_back(it->second.as<str>());
144  }
145  }
146  return values;
147  }
std::string str
Shorthand for a standard string.
Definition: Analysis.hpp:35
Here is the caller graph for this function:

◆ getValue()

template<typename TYPE , typename... args>
TYPE Gambit::DescriptionDatabase::getValue ( const args &...  keys) const
inline

Definition at line 109 of file yaml_description_database.hpp.

References Gambit::getVariadicNode(), LOCAL_INFO, Gambit::stringifyVariadic(), and Gambit::utils_error().

Referenced by Gambit::gambit_core::check_databases().

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  }
EXPORT_SYMBOLS error & utils_error()
Utility errors.
#define LOCAL_INFO
Definition: local_info.hpp:34
const std::string stringifyVariadic()
const YAML::Node getVariadicNode(const YAML::Node &node)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasKey()

template<typename... args>
bool Gambit::DescriptionDatabase::hasKey ( const args &...  keys) const
inline

Getters for key/value pairs (which is all the options node should contain)

Definition at line 103 of file yaml_description_database.hpp.

References Gambit::getVariadicNode().

Referenced by Gambit::gambit_core::check_databases().

104  {
105  return getVariadicNode(descriptions, keys...);
106  }
const YAML::Node getVariadicNode(const YAML::Node &node)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ loadFile()

template<typename... args>
void Gambit::DescriptionDatabase::loadFile ( const str filename)
inline

Load descriptions from file.

Definition at line 125 of file yaml_description_database.hpp.

References hdf5tools::check_for_duplicates(), LOCAL_INFO, and Gambit::utils_error().

Referenced by DescriptionDatabase().

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  }
EXPORT_SYMBOLS error & utils_error()
Utility errors.
#define LOCAL_INFO
Definition: local_info.hpp:34
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ descriptions

YAML::Node Gambit::DescriptionDatabase::descriptions
private

Definition at line 147 of file yaml_description_database.hpp.

Referenced by check_for_duplicates(), and get_all_values().


The documentation for this class was generated from the following files: