gambit is hosted by Hepforge, IPPP Durham
GAMBIT  v1.5.0-252-gf9a3f78
a Global And Modular Bsm Inference Tool
yaml_description_database.cpp
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 namespace Gambit
35 {
37  YAML::Emitter& operator << (YAML::Emitter& out, const capability_info& info)
38  {
39  std::vector< std::pair<str, std::map<str, std::set<std::pair<str,str> > > > > origins;
40  origins.push_back(std::pair<str, std::map<str, std::set<std::pair<str,str> > > >("modules", info.modset));
41  origins.push_back(std::pair<str, std::map<str, std::set<std::pair<str,str> > > >("backends", info.beset));
42  out << YAML::BeginMap;
43  out << YAML::Key << "name" << YAML::Value << info.name;
44  out << YAML::Key << "description";
45  out << YAML::Literal << info.description; // Long string format
46  for (std::vector< std::pair<str, std::map<str, std::set<std::pair<str,str> > > > >::const_iterator it = origins.begin(); it != origins.end(); ++it)
47  {
48  out << YAML::Key << it->first << YAML::Value << YAML::BeginSeq;
49  for (std::map<str, std::set<std::pair<str,str> > >::const_iterator jt = it->second.begin(); jt != it->second.end(); ++jt)
50  {
51  out << YAML::BeginMap << YAML::Key << jt->first << YAML::Value << YAML::BeginSeq;
52  for (std::set<std::pair<str,str> >::const_iterator kt = jt->second.begin(); kt != jt->second.end(); ++kt)
53  {
54  out << YAML::BeginMap << YAML::Key << kt->first << YAML::Value << kt->second << YAML::EndMap;
55  }
56  out << YAML::EndSeq << YAML::EndMap;
57  }
58  out << YAML::EndSeq;
59  }
60  out << YAML::EndMap;
61  out << YAML::Newline;
62  return out;
63  }
64 
66  YAML::Emitter& operator << (YAML::Emitter& out, const model_info& info)
67  {
68  out << YAML::BeginMap;
69  out << YAML::Key << "name" << YAML::Value << info.name;
70  out << YAML::Key << "nparams" << YAML::Value << info.nparams;
71  out << YAML::Key << "parameters"<< YAML::Value << YAML::BeginSeq;
72  for (std::vector<std::string>::const_iterator jt = info.parameters.begin(); jt != info.parameters.end(); ++jt)
73  {
74  out << *jt;
75  }
76  out << YAML::EndSeq;
77  out << YAML::Key << "parent" << YAML::Value << info.parent;
78  out << YAML::Key << "lineage" << YAML::Value << YAML::BeginSeq;
79  for (std::vector<std::string>::const_iterator jt = info.lineage.begin(); jt !=info.lineage.end(); ++jt)
80  {
81  out << *jt;
82  }
83  out << YAML::EndSeq;
84  out << YAML::Key << "descendants" << YAML::Value << YAML::BeginSeq;
85  for (std::vector<std::string>::const_iterator jt = info.descendants.begin(); jt !=info.descendants.end(); ++jt)
86  {
87  out << *jt;
88  }
89  out << YAML::EndSeq;
90  out << YAML::Key << "description";
91  out << YAML::Literal << info.description; // Long string format
92  out << YAML::EndMap;
93  out << YAML::Newline;
94  return out;
95  }
96 
98 
101 
104  {
105  loadFile(filename);
106  }
107 
109  DescriptionDatabase::DescriptionDatabase(const YAML::Node &desc) : descriptions(desc) {}
110 
112  DescriptionDatabase::DescriptionDatabase(YAML::Node &&desc) : descriptions(std::move(desc)) {}
113 
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  }
134 
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  }
148 } // end Gambit namespace
149 
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...
void loadFile(const str &filename)
Load descriptions from file.
int nparams
Number of parameters ( parameters.size() )
std::vector< str > parameters
Parameter names.
Helper struct to carry around model information.
STL namespace.
General small utility classes, typedefs, etc.
Small wrapper object for parsing and emitting capability/model etc.
std::vector< str > get_all_values(str key)
Return vector of descriptions matching key (for retrieving values with non-unique keys) ...
std::map< str, int > check_for_duplicates()
Check &#39;descriptions&#39; for duplicate keys.
DescriptionDatabase()
Default constructor.
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.
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.