ifw-ccf  1.0.0
setupBase.hpp
Go to the documentation of this file.
1 
5 #ifndef CCF_COMMON_SETUPBASE_HPP_H_
6 #define CCF_COMMON_SETUPBASE_HPP_H_
7 
8 #include <ctd/file/Yaml.hpp>
9 
10 #include <ccf/common/base.hpp>
11 
12 namespace ccf::common {
13 
14  // TODO: Rename to ccf::common:Setup
15 
17  class SetupBase: public Base {
18  public:
19 
22 
24  // TODO: Return reference.
25  static SetupBase& Instance();
26 
27  ~SetupBase();
28 
34  ctd::param::ParameterSet& GetStagingSetup();
35 
38  ctd::param::ParameterSet& GetSetup();
39 
42  void GetPar(const std::string& name,
43  ctd::param::Parameter& par) const;
44 
46  // of the provided parameter object.
47  bool HasPar(const std::string& name,
48  ctd::param::Parameter& par) const;
49 
52  template <class TYPE>
53  bool HasPar(const std::string& name,
54  TYPE& value) const {
55  CCFTRACE;
56  if (m_staging_setup.HasPar(name, value)) {
57  return true;
58  } else if (m_setup.HasPar(name, value)) {
59  return true;
60  } else {
61  return false;
62  }
63  }
64 
67  template <class TYPE>
68  bool HasStagingPar(const std::string& name,
69  TYPE& value) const {
70  CCFTRACE;
71  if (m_staging_setup.HasPar(name, value)) {
72  return true;
73  } else {
74  return false;
75  }
76  }
77 
79  bool HasStagingPar(const std::string& name,
80  ctd::param::Parameter& par) const;
81 
83  template <class TYPE>
84  TYPE GetValue(const std::string& name) const {
85  CCFTRACE;
86  TYPE tmp_value;
87  if (m_staging_setup.HasPar(name, tmp_value)) {
88  return tmp_value;
89  } else if (m_setup.HasPar(name, tmp_value)) {
90  return tmp_value;
91  } else {
92  CCFTHROW("Setup parameter requested not defined: " + name);
93  }
94  }
95 
97  void Load(const std::string& filename);
98 
100  void AcceptSetup();
101 
102  protected:
103 
104  private:
105  SetupBase();
106 
107  // The New Setup object contains the parameters received for a new Setup Command,
108  // being handled.
109  ctd::file::Yaml m_staging_setup;
110 
111  // The Setup object contains the current setup, accepted and installed (in use).
112  ctd::file::Yaml m_setup;
113  };
114 
115  inline SetupBase& GetSetup() {
116  return SetupBase::Instance();
117  }
118 
119 }
120 
121 #endif // CCF_COMMON_SETUPBASE_HPP_H_
CCFTHROW
#define CCFTHROW(msg)
Throw a "rad::Exception()". The location ("CCFLOC") for the throw statement is added to the message.
Definition: base.hpp:410
ccf::common::SetupBase::Load
void Load(const std::string &filename)
Load a Setup File into the Staging Setup object (New Setup).
Definition: setupBase.cpp:53
ccf::common::SetupBase::~SetupBase
~SetupBase()
Definition: setupBase.cpp:25
ccf::common::SetupBase::GetStagingSetup
ctd::param::ParameterSet & GetStagingSetup()
Definition: setupBase.cpp:29
ccf::common::SetupBase::AcceptSetup
void AcceptSetup()
Merge the parameters in the Staging Setup (object) into the Installed Setup.
Definition: setupBase.cpp:94
ccf::common::Base
Class to be used as parent all CCF classes.
Definition: base.hpp:93
ccf::common::SetupBase::HasPar
bool HasPar(const std::string &name, ctd::param::Parameter &par) const
Check if the given parameter is defined in 1) The Staging Setup, 2) the Installed Setup....
Definition: setupBase.cpp:72
ccf::common::SetupBase::GetPar
void GetPar(const std::string &name, ctd::param::Parameter &par) const
Definition: setupBase.cpp:39
ccf::common::SetupBase::s_instance
static SetupBase * s_instance
Singleton instance.
Definition: setupBase.hpp:21
ccf::common::SetupBase::GetSetup
ctd::param::ParameterSet & GetSetup()
Definition: setupBase.cpp:34
ccf::common::SetupBase::Instance
static SetupBase & Instance()
Return reference to unique instance of the application class.
Definition: setupBase.cpp:13
ccf::common::SetupBase::GetValue
TYPE GetValue(const std::string &name) const
Get a parameter value from the configuration.
Definition: setupBase.hpp:84
ccf::common::SetupBase
Global setup class for CCF applications.
Definition: setupBase.hpp:17
ccf::common::SetupBase::HasPar
bool HasPar(const std::string &name, TYPE &value) const
Definition: setupBase.hpp:53
ccf::common::SetupBase::HasStagingPar
bool HasStagingPar(const std::string &name, TYPE &value) const
Definition: setupBase.hpp:68
base.hpp
ccf::common
Definition: appBase.cpp:8
CCFTRACE
#define CCFTRACE
TRACE log macro. Includes the location ("CCFLOC") in the log message.
Definition: base.hpp:403
ccf::common::GetSetup
SetupBase & GetSetup()
Definition: setupBase.hpp:115