casacore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Static Public Member Functions | Private Member Functions | Static Private Attributes | List of all members
casacore::AppStateSource Class Reference

Allow configuration of casacore without environment variables. More...

#include <AppState.h>

Static Public Member Functions

static void initialize (AppState *init)
 
static AppStatefetch ()
 

Private Member Functions

 AppStateSource ()
 
 AppStateSource (AppStateSource const &)
 
void operator= (AppStateSource const &)
 

Static Private Attributes

static AppStateuser_state
 

Detailed Description

Allow configuration of casacore without environment variables.

Intended use:

Public interface

Review Status

Date Reviewed:
yyyy/mm/dd

Synopsis

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.

Example

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 133 of file AppState.h.

Constructor & Destructor Documentation

casacore::AppStateSource::AppStateSource ( )
inlineprivate

Definition at line 149 of file AppState.h.

casacore::AppStateSource::AppStateSource ( AppStateSource const &  )
inlineprivate

Definition at line 150 of file AppState.h.

Member Function Documentation

static AppState& casacore::AppStateSource::fetch ( )
inlinestatic

Definition at line 142 of file AppState.h.

References user_state.

static void casacore::AppStateSource::initialize ( AppState init)
inlinestatic

Definition at line 136 of file AppState.h.

References user_state.

void casacore::AppStateSource::operator= ( AppStateSource const &  )
inlineprivate

Definition at line 151 of file AppState.h.

Member Data Documentation

AppState* casacore::AppStateSource::user_state
staticprivate

Definition at line 148 of file AppState.h.

Referenced by fetch(), and initialize().


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