casa
5.7.0-16
|
Allow configuration of casacore without environment variables. More...
#include <AppState.h>
Static Public Member Functions | |
static void | initialize (AppState *init) |
static AppState & | fetch () |
Private Member Functions | |
AppStateSource () | |
AppStateSource (AppStateSource const &) | |
void | operator= (AppStateSource const &) |
Static Private Attributes | |
static AppState * | user_state |
Allow configuration of casacore without environment variables.
Public interface
This class allows packages which use casacore to configure casacore behavior without reverting to environment variables. It is composed primarly of static functions. An external application configures casacore by calling the initialize(...) member function passing in a pointer to an object which is derived from the AppState base class. AppStateSource takes ownership of the provided pointer.
When casacore no longer depends on compilers whose standard is older than C++11, the raw pointers here should be changed to unique_ptrs. The std::unique_ptr constructor is a constexpr, and it does not throw exceptions.
class MyState: public casacore::AppState { public: MyState() { }
const std::list<std::string> &dataPath() const { static std::list<std::string> my_path; return my_path; }
bool initialized() const { return true; } };
MyState &get_my_state() { if (AppStateSource::fetch().initialized() == false) casacore::AppStateSource::initialize(new MyState); return dynamic_cast<MyState&>(AppStateSource::fetch()); }
int main(int argc, char *argv[]) { MyState &state = get_my_state(); ... return 0; }
Definition at line 121 of file AppState.h.
|
inlineprivate |
Definition at line 137 of file AppState.h.
|
inlineprivate |
Definition at line 138 of file AppState.h.
|
inlinestatic |
Definition at line 130 of file AppState.h.
References user_state.
|
inlinestatic |
Definition at line 124 of file AppState.h.
References user_state.
|
inlineprivate |
Definition at line 139 of file AppState.h.
|
staticprivate |
Definition at line 136 of file AppState.h.
Referenced by fetch(), and initialize().