ParameterTable.cpp
Go to the documentation of this file.
1 
2 #include <algorithm>
3 #include "ParameterTable.h"
4 #include "Exceptions.h"
5 
6 namespace NeutrinoFluxReweight{
7 
9  if(m_vectorMode){
10  m_vector.push_back(p);
11  }
12  else{
13  table[p.first] = p.second;
14  }
15  }
16 
18  mapify();
19  Parameter pOut;
21 
22  if(it!=table.end()){
23  pOut.first = name;
24  pOut.second = it->second;
25  }
26  else{
27  throw NoParameterFound(name);
28  }
29  return pOut;
30 
31  }
32 
34  mapify();
35 
36  double val;
38 
39  if(it!=table.end()){
40  val = it->second;
41  }
42  else{
43  throw NoParameterFound(name);
44  }
45 
46  return val;
47 
48  }
49 
51  mapify();
52  return table.find(name)!=table.end();
53  }
54 
56  {
57  // If we're already out of vector mode, there's nothing to do
58  if(!m_vectorMode) return;
59 
60  // Sort the vector, populate the flat_map from it, and then clear
61  // the vector
62  std::sort(m_vector.begin(), m_vector.end());
63  table=boost::interprocess::flat_map<std::string, double>(m_vector.begin(), m_vector.end());
64  m_vector.clear();
65  // Magic to force the memory to be released: clear() doesn't do that
66  std::vector<std::pair<std::string, double> >().swap(m_vector);
67  // We're no longer in vector mode, so we won't run this function
68  // again
69  m_vectorMode=false;
70  }
71 
72 }
static QCString name
Definition: declinfo.cpp:673
Parameter getParameter(const std::string &name) const
get a parameter by name. throw an exception of a well defined type if we don&#39;t have it ...
std::string string
Definition: nybbler.cc:12
double getParameterValue(const std::string &name) const
get the value of a parameter. throw an exception of a well defined type if we don&#39;t have it ...
bool hasParameter(const std::string &name) const
is the named parameter in the table?
intermediate_table::const_iterator const_iterator
std::pair< std::string, double > Parameter
void mapify() const
Move the parameters from the vector to the map.
void swap(Handle< T > &a, Handle< T > &b)
p
Definition: test.py:223
std::vector< std::pair< std::string, double > > m_vector
boost::interprocess::flat_map< std::string, double > table
void setParameter(Parameter p)
add a parameter to the table or, if already there, reset its value