lumiera::Appconfig Class Reference

Singleton to hold inevitable global flags and constants and for performing early (static) global initialization tasks. More...

#include <appconfig.hpp>

Inheritance diagram for lumiera::Appconfig:

Inheritance graph
[legend]
Collaboration diagram for lumiera::Appconfig:

Collaboration graph
[legend]

List of all members.

Static Public Member Functions

static const string & get (const string &key)
 access the configuation value for a given key.
static Appconfiginstance ()
 get the (single) Appconfig instance.
static void lifecycle (Symbol eventLabel)
 fire off all lifecycle callbacks registered under the given label

Private Types

typedef std::map< string, string > Configmap
typedef scoped_ptr< Configmap > PConfig
typedef scoped_ptr
< LifecycleRegistry
PLife

Private Member Functions

 Appconfig ()
 perform initialization on first access.

Private Attributes

PConfig configParam_
PLife lifecycleHooks_

Friends

void boost::checked_delete (Appconfig *)
 deletion prohibited
class LifecycleHook


Detailed Description

Appconfig services are available already from static initialsation code.
Warning:
don't use Appconfig in destuctors.

Definition at line 64 of file appconfig.hpp.


Constructor & Destructor Documentation

lumiera::Appconfig::Appconfig (  )  [private]

perform initialization triggered on first access.

See also:
instance()
Will execute the ON_BASIC_INIT hook, but under typical circumstances this is a NOP, because when callbacks are added to this hook, the Appconfig singleton instance has already been created. For this reason, there is special treatment for the ON_BASIC_INIT in LifecycleHook::add, causing the provided callbacks to be fired immediately. (btw, this is nothing to be worried of, because from client codes POV it just behaves like intended).

Definition at line 55 of file appconfig.cpp.

References lumiera::ON_BASIC_INIT.

00056     : configParam_  (new Configmap),
00057       lifecycleHooks_(new LifecycleRegistry)
00058   {
00059     lifecycleHooks_->execute (ON_BASIC_INIT);   // note in most cases a NOP
00060     
00061     (*configParam_)["version"] = STRINGIFY (LUMIERA_VERSION);
00062   }


Member Function Documentation

const string & lumiera::Appconfig::get ( const string &  key  )  [static]

Returns:
empty string for unknown keys, config value else

Definition at line 69 of file appconfig.cpp.

References configParam_, and instance().

00070   {
00071     try
00072       {
00073         const string& val = (*instance().configParam_)[key];
00074         WARN_IF ( isnil(val), config, "undefined config parameter \"%s\" requested.", key.c_str());
00075         return val;
00076       }
00077     catch (...)
00078       {
00079         ERROR (config, "error while accessing configuration parameter \"%s\".", key.c_str());
00080         static string NOTFOUND ("");
00081         return NOTFOUND;
00082   }   }

Here is the call graph for this function:

static Appconfig& lumiera::Appconfig::instance (  )  [inline, static]

Implemented as Meyers singleton.

Warning:
don't use it after the end of main()!

Definition at line 82 of file appconfig.hpp.

Referenced by get(), and lifecycle().

00083       {
00084         static scoped_ptr<Appconfig> theApp_ (0);
00085         if (!theApp_) theApp_.reset (new Appconfig ());
00086         return *theApp_;
00087       }

Here is the caller graph for this function:


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

Generated on Sat Aug 16 18:10:42 2008 for Lumiera by  doxygen 1.5.5