CMS 3D CMS Logo

IgState Class Reference

A shared application object state. More...

#include <Iguana/Framework/interface/IgState.h>

List of all members.

Public Member Functions

IgStatechild (unsigned index) const
 Return the child state number index.
unsigned children (void) const
 Return the number of child states.
void detach (IgStateKey index)
 Detach an element at key index.
IgStateElementelement (unsigned index) const
 Return the element state number index.
unsigned elements (void) const
 Return the number of elements in this state.
void erase (IgStateKey index)
 Erase any element at key index.
IgStateElementget (IgStateKey index, IgState **context=0) const
 Get an element at key index in this state.
 IgState (IgState *parent=0)
 Construct a new state without any elements and attach it to parent.
IgStateparent (void) const
 Get the parent of this state, or null if there is none.
void put (IgStateKey index, IgStateElement *element)
 Add the element element to this state at key index.
IgStateroot (void) const
 Get the root of this state tree.
 ~IgState (void)
 Destroy the state, all its sub-states and all elements recorded in it.

Private Types

typedef std::vector< IgState * > Children
typedef std::vector
< IgStateElement * > 
Elements

Private Member Functions

void addChild (IgState *child)
 Add a child to this state.
void detachChild (IgState *child)
 Remove a child from this state.
 IgState (const IgState &x)
IgStateoperator= (const IgState &x)

Private Attributes

Children m_children
Elements m_elements
IgStatem_parent


Detailed Description

A shared application object state.

IgState manages a collection of IgStateElement objects as a state that can shared among various clients. The general idea is that IgState does not know about specific items that need to be shared among the clients, but the clients know how to look up specific extensions in the state. IgState is merely a means up keeping the state data together in a way that clients do not need to care about its origin.

State objects can be chained in a tree-like structure. This allows an IgStateElement setting in the child to override the definition in the parent, or to be scoped purely into the child. State elements that cannot be found in the child are looked up in the parent until a definition is found or the state tree root is reached. Elements can be introduced anywhere on the path, which can be used to give them appropriate scope.

Destroying a state destroys all the elements in it.

Definition at line 39 of file IgState.h.


Member Typedef Documentation

typedef std::vector<IgState *> IgState::Children [private]

Definition at line 58 of file IgState.h.

typedef std::vector<IgStateElement *> IgState::Elements [private]

Definition at line 59 of file IgState.h.


Constructor & Destructor Documentation

IgState::IgState ( IgState parent = 0  ) 

Construct a new state without any elements and attach it to parent.

Definition at line 45 of file IgState.cc.

References addChild(), and m_parent.

00046     : m_parent (parent)
00047 { if (m_parent) m_parent->addChild (this); }

IgState::~IgState ( void   ) 

Destroy the state, all its sub-states and all elements recorded in it.

Definition at line 50 of file IgState.cc.

References detachChild(), i, m_children, m_elements, and m_parent.

00051 {
00052     if (m_parent)
00053         m_parent->detachChild (this);
00054 
00055     while (! m_children.empty ())
00056         delete m_children.front ();
00057 
00058     for (Elements::size_type i = 0; i < m_elements.size (); ++i)
00059         delete m_elements [i];
00060 }

IgState::IgState ( const IgState x  )  [private]


Member Function Documentation

void IgState::addChild ( IgState child  )  [private]

Add a child to this state.

Invoked by the child constructor.

Definition at line 21 of file IgState.cc.

References ASSERT, find(), and m_children.

Referenced by IgState().

00022 {
00023     ASSERT (child);
00024     ASSERT (std::find (m_children.begin (), m_children.end (), child)
00025             == m_children.end ());
00026 
00027     m_children.push_back (child);
00028 }

IgState * IgState::child ( unsigned  index  )  const

Return the child state number index.

index must be less than children(). Note that no meaning should be attached to the order of child states, they just happen to be indexed from zero to children()-1.

Definition at line 90 of file IgState.cc.

References ASSERT, and m_children.

Referenced by IgQtAppDumpStateInfo::populate().

00091 { ASSERT (index < m_children.size ()); return m_children [index]; }

unsigned IgState::children ( void   )  const

Return the number of child states.

Definition at line 82 of file IgState.cc.

References m_children.

Referenced by IgQtAppDumpStateInfo::populate().

00083 { return m_children.size (); }

void IgState::detach ( IgStateKey  index  ) 

Detach an element at key index.

This is equivalent to put(index,0) except that it does not destroy the element, just erases any memory of it in the state. This method should be called by element destructors.

Definition at line 154 of file IgState.cc.

References ASSERT, and m_elements.

Referenced by Ig2DViewPropertiesCategory::~Ig2DViewPropertiesCategory(), Ig3DAnimsCategory::~Ig3DAnimsCategory(), Ig3DLightsCategory::~Ig3DLightsCategory(), Ig3DShapeManager::~Ig3DShapeManager(), Ig3DViewpointsCategory::~Ig3DViewpointsCategory(), IgBrowserManager::~IgBrowserManager(), IgCommonViewPropertiesCategory::~IgCommonViewPropertiesCategory(), IgConfigElement::~IgConfigElement(), IgDocumentData::~IgDocumentData(), IgDocumentDataManager::~IgDocumentDataManager(), IgExaminerViewerCategory::~IgExaminerViewerCategory(), IgFileFetcher::~IgFileFetcher(), IgFileManager::~IgFileManager(), IgGL2PSPrintCategory::~IgGL2PSPrintCategory(), IgGLRenderCategory::~IgGLRenderCategory(), IgLegoViewPropertiesCategory::~IgLegoViewPropertiesCategory(), IgModelManager::~IgModelManager(), IgNTupleAppMain::~IgNTupleAppMain(), IgNTupleAppSetup::~IgNTupleAppSetup(), IgQtAppContextService::~IgQtAppContextService(), IgQtAppCrashAlertService::~IgQtAppCrashAlertService(), IgQtAppDebugService::~IgQtAppDebugService(), IgQtAppHelpService::~IgQtAppHelpService(), IgQtAppImageService::~IgQtAppImageService(), IgQtApplicationCategory::~IgQtApplicationCategory(), IgQtAppLoopService::~IgQtAppLoopService(), IgQtAppMenuService::~IgQtAppMenuService(), IgQtAppStatusBarService::~IgQtAppStatusBarService(), IgQtAppToolBarService::~IgQtAppToolBarService(), IgQtAppWindowService::~IgQtAppWindowService(), IgQtObjectMenuService::~IgQtObjectMenuService(), IgRPhiViewPropertiesCategory::~IgRPhiViewPropertiesCategory(), IgRZViewPropertiesCategory::~IgRZViewPropertiesCategory(), IgSceneManagerCategory::~IgSceneManagerCategory(), IgServerPool::~IgServerPool(), IgSessionManager::~IgSessionManager(), IgSocketDriverInfo::~IgSocketDriverInfo(), IgSpareViewPropertiesCategory::~IgSpareViewPropertiesCategory(), IgTwigConfigElement::~IgTwigConfigElement(), IgWebServiceRegistry::~IgWebServiceRegistry(), VisAppearanceService::~VisAppearanceService(), VisConfiguration::~VisConfiguration(), VisContent::~VisContent(), VisCSCChamberSelectorImplService::~VisCSCChamberSelectorImplService(), VisCSCStackPlotService::~VisCSCStackPlotService(), VisEventMenu::~VisEventMenu(), VisEventProcessorService::~VisEventProcessorService(), VisEventSetupService::~VisEventSetupService(), VisExceptionService::~VisExceptionService(), VisG4EventStatus::~VisG4EventStatus(), VisG4ExampleSetup::~VisG4ExampleSetup(), VisG4VisManager::~VisG4VisManager(), VisL1FilterService::~VisL1FilterService(), VisMainProgram::~VisMainProgram(), VisQueue::~VisQueue(), VisQueueProcessor::~VisQueueProcessor(), VisSimQtActions::~VisSimQtActions(), and VisTwigFactroyService::~VisTwigFactroyService().

00155 {
00156     ASSERT (index <= m_elements.size ());
00157     ASSERT (m_elements [index]);
00158     m_elements [index] = 0;
00159 }

void IgState::detachChild ( IgState child  )  [private]

Remove a child from this state.

Invoked by the child destructor.

Definition at line 32 of file IgState.cc.

References ASSERT, find(), and m_children.

Referenced by ~IgState().

00033 {
00034     ASSERT (child);
00035     Children::iterator pos
00036         = std::find (m_children.begin (), m_children.end (), child);
00037 
00038     ASSERT (pos != m_children.end ());
00039 
00040     m_children.erase (pos);
00041 }

IgStateElement * IgState::element ( unsigned  index  )  const

Return the element state number index.

index must be less than elements(). The element might be 0 as not all elements in this vector are initialized because of loading and un-loading of libraiies.

Definition at line 174 of file IgState.cc.

References ASSERT, and m_elements.

Referenced by get(), and IgQtAppDumpStateInfo::populate().

00175 { ASSERT (index < m_elements.size ()); return m_elements [index]; }

unsigned IgState::elements ( void   )  const

Return the number of elements in this state.

This is not the actual elements in the vector, some of them might be 0 because of loading and un-loading of libraries.

Definition at line 165 of file IgState.cc.

References m_elements.

Referenced by IgQtAppDumpStateInfo::populate().

00166 { return m_elements.size (); }

void IgState::erase ( IgStateKey  index  ) 

Erase any element at key index.

This is equivalent to put(index,0).

Definition at line 146 of file IgState.cc.

References put().

00147 { put (index, 0); }

IgStateElement * IgState::get ( IgStateKey  index,
IgState **  context = 0 
) const

Get an element at key index in this state.

Returns a pointer to the element in this or any of the parent states. If no such element has been recorded, returns null. If context is non-null, it will be set to point to the state in which the element was found (or null if no element is found).

Definition at line 100 of file IgState.cc.

References element(), if(), in, m_elements, and parent().

Referenced by IgPluginLoader::load().

00101 {
00102     IgState             *in = const_cast<IgState *> (this);
00103     IgStateElement      *element = 0;
00104 
00105     for ( ; in && ! element; in = in->parent ())
00106         if (index < in->m_elements.size ())
00107             element = in->m_elements [index];
00108 
00109     if (context)
00110         *context = in;
00111 
00112     return element;
00113 }

IgState& IgState::operator= ( const IgState x  )  [private]

IgState * IgState::parent ( void   )  const

Get the parent of this state, or null if there is none.

Definition at line 77 of file IgState.cc.

References m_parent.

Referenced by IgQtAppContextService::focusIn(), IgQtAppContextService::focusOut(), and get().

00078 { return m_parent; }

void IgState::put ( IgStateKey  index,
IgStateElement element 
)

Add the element element to this state at key index.

The value will be set in this state. If there is a different element at the same index, it will be destroyed. element may be null, in which case the element is effectively removed from this state; the next lookup will then search for the element in the parent (i.e. it will not be remembered to be null in this state).

Definition at line 123 of file IgState.cc.

References ASSERT, and m_elements.

Referenced by erase(), Ig2DViewPropertiesCategory::Ig2DViewPropertiesCategory(), Ig3DAnimsCategory::Ig3DAnimsCategory(), Ig3DClipsCategory::Ig3DClipsCategory(), Ig3DFieldPlanesCategory::Ig3DFieldPlanesCategory(), Ig3DGridCategory::Ig3DGridCategory(), Ig3DLightsCategory::Ig3DLightsCategory(), Ig3DNodeCategory::Ig3DNodeCategory(), Ig3DShapeManager::Ig3DShapeManager(), Ig3DSlicersCategory::Ig3DSlicersCategory(), Ig3DViewpointsCategory::Ig3DViewpointsCategory(), IgArgsElement::IgArgsElement(), IgBrowserManager::IgBrowserManager(), IgCommonViewPropertiesCategory::IgCommonViewPropertiesCategory(), IgConfigElement::IgConfigElement(), IgDocumentData::IgDocumentData(), IgDocumentDataManager::IgDocumentDataManager(), IgEnvsElement::IgEnvsElement(), IgExaminerViewerCategory::IgExaminerViewerCategory(), IgFileFetcher::IgFileFetcher(), IgFileManager::IgFileManager(), IgGL2PSPrintCategory::IgGL2PSPrintCategory(), IgGLRenderCategory::IgGLRenderCategory(), IgLegoViewPropertiesCategory::IgLegoViewPropertiesCategory(), IgModelManager::IgModelManager(), IgNTupleAppMain::IgNTupleAppMain(), IgNTupleAppSetup::IgNTupleAppSetup(), IgOIVExtension::IgOIVExtension(), IgPluginLoader::IgPluginLoader(), IgQtAppActiveService::IgQtAppActiveService(), IgQtAppContextService::IgQtAppContextService(), IgQtAppCrashAlertService::IgQtAppCrashAlertService(), IgQtAppDebugService::IgQtAppDebugService(), IgQtAppHelpService::IgQtAppHelpService(), IgQtAppImageService::IgQtAppImageService(), IgQtApplicationCategory::IgQtApplicationCategory(), IgQtAppLoopService::IgQtAppLoopService(), IgQtAppMenuService::IgQtAppMenuService(), IgQtAppStatusBarService::IgQtAppStatusBarService(), IgQtAppToolBarService::IgQtAppToolBarService(), IgQtAppWindowService::IgQtAppWindowService(), IgQtObjectMenuService::IgQtObjectMenuService(), IgRPhiViewPropertiesCategory::IgRPhiViewPropertiesCategory(), IgRZViewPropertiesCategory::IgRZViewPropertiesCategory(), IgSceneManagerCategory::IgSceneManagerCategory(), IgSelectionService::IgSelectionService(), IgServerPool::IgServerPool(), IgSessionManager::IgSessionManager(), IgSocketDriverInfo::IgSocketDriverInfo(), IgSpareViewPropertiesCategory::IgSpareViewPropertiesCategory(), IgStudioCentre::IgStudioCentre(), IgTwigConfigElement::IgTwigConfigElement(), IgWebServiceRegistry::IgWebServiceRegistry(), IgServerSocket::initialize(), VisAppearanceService::VisAppearanceService(), VisApplicationMain::VisApplicationMain(), VisConfiguration::VisConfiguration(), VisContent::VisContent(), VisCSCChamberSelectorImplService::VisCSCChamberSelectorImplService(), VisCSCStackPlotService::VisCSCStackPlotService(), VisEventMenu::VisEventMenu(), VisEventProcessorService::VisEventProcessorService(), VisEventSetupService::VisEventSetupService(), VisExceptionService::VisExceptionService(), VisG4EventStatus::VisG4EventStatus(), VisG4ExampleSetup::VisG4ExampleSetup(), VisG4UIManager::VisG4UIManager(), VisG4VisManager::VisG4VisManager(), VisL1FilterService::VisL1FilterService(), VisMagFieldDemoMain::VisMagFieldDemoMain(), VisMainProgram::VisMainProgram(), VisQueue::VisQueue(), VisQueueProcessor::VisQueueProcessor(), VisSimMain::VisSimMain(), VisSimQtActions::VisSimQtActions(), and VisTwigFactroyService::VisTwigFactroyService().

00124 {
00125     if (index >= m_elements.size ())
00126     {
00127         if (! element)
00128             return;
00129         else
00130             m_elements.resize (index+1, 0);
00131     }
00132 
00133     if (m_elements [index] != element)
00134     {
00135         // Destructor must call detach()
00136         delete m_elements [index];
00137         ASSERT (m_elements [index] == 0);
00138     }
00139 
00140     m_elements [index] = element;
00141 }

IgState * IgState::root ( void   )  const

Get the root of this state tree.

If this state has no parent(), returns pointer to this.

Definition at line 66 of file IgState.cc.

References m_parent, and s.

00067 {
00068     IgState *s = const_cast<IgState *> (this);
00069     while (s->m_parent)
00070         s = s->m_parent;
00071 
00072     return s;
00073 }


Member Data Documentation

Children IgState::m_children [private]

Definition at line 65 of file IgState.h.

Referenced by addChild(), child(), children(), detachChild(), and ~IgState().

Elements IgState::m_elements [private]

Definition at line 66 of file IgState.h.

Referenced by detach(), element(), elements(), get(), put(), and ~IgState().

IgState* IgState::m_parent [private]

Definition at line 64 of file IgState.h.

Referenced by IgState(), parent(), root(), and ~IgState().


The documentation for this class was generated from the following files:
Generated on Tue Jun 9 18:25:46 2009 for CMSSW by  doxygen 1.5.4