Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OSGPriorityAction.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *             Copyright (C) 2000-2002 by the OpenSG Forum                   *
00006  *                                                                           *
00007  *                            www.opensg.org                                 *
00008  *                                                                           *
00009  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
00010  *                                                                           *
00011 \*---------------------------------------------------------------------------*/
00012 /*---------------------------------------------------------------------------*\
00013  *                                License                                    *
00014  *                                                                           *
00015  * This library is free software; you can redistribute it and/or modify it   *
00016  * under the terms of the GNU Library General Public License as published    *
00017  * by the Free Software Foundation, version 2.                               *
00018  *                                                                           *
00019  * This library is distributed in the hope that it will be useful, but       *
00020  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00022  * Library General Public License for more details.                          *
00023  *                                                                           *
00024  * You should have received a copy of the GNU Library General Public         *
00025  * License along with this library; if not, write to the Free Software       *
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00027  *                                                                           *
00028 \*---------------------------------------------------------------------------*/
00029 /*---------------------------------------------------------------------------*\
00030  *                                Changes                                    *
00031  *                                                                           *
00032  *                                                                           *
00033  *                                                                           *
00034  *                                                                           *
00035  *                                                                           *
00036  *                                                                           *
00037 \*---------------------------------------------------------------------------*/
00038 
00039 #ifndef _OSGPRIORITYACTION_H_
00040 #define _OSGPRIORITYACTION_H_
00041 #ifdef __sgi
00042 #pragma once
00043 #endif
00044 
00045 //----------------------------------------------------------------------------
00046 //    Includes
00047 //----------------------------------------------------------------------------
00048 
00049 #include <OSGConfig.h>
00050 #include <OSGSystemDef.h>
00051 
00052 #include "OSGNewActionBase.h"
00053 #include "OSGActorBase.h"
00054 
00055 #include <list>
00056 #include <vector>
00057 #include <queue>
00058 
00059 OSG_BEGIN_NAMESPACE
00060 
00061 class ExtendActorBase;
00062 class BasicActorBase;
00063 
00064 class OSG_SYSTEMLIB_DLLMAPPING PriorityAction : public NewActionBase
00065 {
00066     /*==== PUBLIC ===========================================================*/
00067   public:
00068 #ifdef OSG_NEWACTION_STATISTICS
00069     /*-----------------------------------------------------------------------*/
00073     static StatElemDesc<StatIntElem> statStateClones;
00074     static StatElemDesc<StatIntElem> statStateRestores;
00075 
00077 #endif /* OSG_NEWACTION_STATISTICS */
00078     /*-----------------------------------------------------------------------*/
00082     virtual ~PriorityAction(void);
00083 
00085     /*-----------------------------------------------------------------------*/
00089     static PriorityAction *create(void);
00090 
00092     /*-----------------------------------------------------------------------*/
00096     virtual ResultE apply(NodePtr pRoot);
00097 
00099     /*==== PROTECTED ========================================================*/
00100   protected:
00101     /*-----------------------------------------------------------------------*/
00105     PriorityAction(void);
00106 
00108     /*-----------------------------------------------------------------------*/
00112     virtual void addExtendEvent(ExtendActorBase *pActor, UInt32 actorIndex);
00113     virtual void subExtendEvent(ExtendActorBase *pActor, UInt32 actorIndex);
00114 
00115     virtual void addBasicEvent (BasicActorBase  *pActor, UInt32 actorIndex);
00116     virtual void subBasicEvent (BasicActorBase  *pActor, UInt32 actorIndex);
00117 
00118     virtual void startEvent    (void                                      );
00119     virtual void stopEvent     (void                                      );
00120 
00121     virtual void beginEditStateEvent(ActorBase *pActor, UInt32 actorId);
00122     virtual void endEditStateEvent  (ActorBase *pActor, UInt32 actorId);
00123 
00125     /*==== PRIVATE ==========================================================*/
00126   private:
00127     /*-----------------------------------------------------------------------*/
00131     typedef NewActionBase             Inherited;
00132     typedef ActorBase::ActorBaseState ActorBaseState;
00133 
00134 #ifdef OSG_NEWACTION_STATESLOTINTERFACE
00135 
00136     class StateRefCount
00137     {
00138       public:
00139         inline          StateRefCount(const StateRefCount &source    );
00140 
00141         inline explicit StateRefCount(      UInt32         stateSlot );
00142         inline explicit StateRefCount(      UInt32         stateSlot,
00143                                             Int32          refCount  );
00144 
00145         inline UInt32 getStateSlot(void            ) const;
00146         inline void   setStateSlot(UInt32 stateSlot);
00147 
00148         inline Int32  getRefCount (void            ) const;
00149         inline void   incRefCount (Int32  inc      );
00150         inline void   decRefCount (Int32  dec      );
00151 
00152       private:
00153         UInt32 _stateSlot;
00154         Int32  _refCount;
00155     };
00156 
00157 #else /* OSG_NEWACTION_STATESLOTINTERFACE */
00158 
00159     typedef std::list<ActorBaseState *> StateStore;
00160     typedef StateStore::iterator        StateStoreIt;
00161     typedef StateStore::const_iterator  StateStoreConstIt;
00162 
00163     class StateRefCount;
00164     class NodeQueueEntry;
00165     friend class StateRefCount;
00166     friend class NodeQueueEntry;
00167 
00168     class StateRefCount
00169     {
00170       public:
00171         inline          StateRefCount(const StateRefCount &source  );
00172 
00173         inline explicit StateRefCount(const StateStoreIt  &itState );
00174         inline explicit StateRefCount(const StateStoreIt  &itState,
00175                                             Int32          refCount);
00176 
00177         inline StateStoreIt getState(      void                 ) const;
00178         inline void         setState(const StateStoreIt &itState);
00179 
00180         inline Int32        getRefCount(void         ) const;
00181         inline void         incRefCount(Int32 inc = 1);
00182         inline void         decRefCount(Int32 dec = 1);
00183 
00184       private:
00185         StateStoreIt _itState;
00186         Int32        _refCount;
00187     };
00188 
00189 #endif /* OSG_NEWACTION_STATESLOTINTERFACE */
00190 
00191     typedef std::list<StateRefCount>           StateRefCountStore;
00192     typedef StateRefCountStore::iterator       StateRefCountStoreIt;
00193     typedef StateRefCountStore::const_iterator StateRefCountStoreConstIt;
00194 
00195     class NodeQueueEntry
00196     {
00197       public:
00198         inline NodeQueueEntry(const NodeQueueEntry       &source         );
00199 
00200         inline NodeQueueEntry(const NodePtr              &pNode,
00201                                     PriorityType          priority,
00202                                     UInt32                passCount,
00203                               const StateRefCountStoreIt &itStateRefCount);
00204 
00205         inline NodePtr              getNode         (void) const;
00206         inline PriorityType         getPriority     (void) const;
00207         inline UInt32               getPassCount    (void) const;
00208         inline StateRefCountStoreIt getStateRefCount(void) const;
00209 
00210         struct LessCompare
00211         {
00212             inline bool operator()(const NodeQueueEntry &leftArg,
00213                                    const NodeQueueEntry &rightArg);
00214         };
00215 
00216       private:
00217         NodePtr              _pNode;
00218         PriorityType         _priority;
00219         UInt32               _passCount;
00220         StateRefCountStoreIt _itStateRefCount;
00221     };
00222 
00223     // std::priority_queue<...> does not have clear(), for some reason...
00224     // so we use a vector and the pqFOO helper methods below  -cneumann
00225     typedef std::vector<NodeQueueEntry> NodePriorityQueue;
00226     typedef NodeQueueEntry::LessCompare NodePriorityQueueComp;
00227 
00228            ResultE traverseEnter  (      void                          );
00229            void    enqueueChildren(const NodePtr &pNode, ResultE result);
00230 
00232     /*-----------------------------------------------------------------------*/
00236     inline ResultE enterNode(const NodePtr &pNode, UInt32 pass);
00237 
00238     inline StateRefCountStoreIt cloneState(void                                );
00239     inline StateRefCountStoreIt getState  (void                                );
00240     inline void                 setState  (StateRefCountStoreIt itStateRefCount);
00241 
00242     inline void incRefCount(StateRefCountStoreIt itStateRefCount, Int32 inc = 1);
00243     inline void decRefCount(StateRefCountStoreIt itStateRefCount, Int32 dec = 1);
00244 
00245     inline const NodeQueueEntry &pqTop  (      void                 ) const;
00246 
00247     inline       void            pqPush (const NodeQueueEntry &entry);
00248     inline       void            pqPop  (      void                 );
00249 
00250     inline       bool            pqEmpty(      void                 ) const;
00251     inline       void            pqClear(      void                 );
00252 
00254     /*-----------------------------------------------------------------------*/
00255 
00256     ExtendActorStore      _extendEnterActors;
00257     BasicActorStore       _basicEnterActors;
00258 
00259     NodePriorityQueue     _nodePrioQueue;
00260     NodePriorityQueueComp _nodePrioQueueComp;
00261 
00262     bool                  _stateClonedFlag;
00263 
00264 #ifndef OSG_NEWACTION_STATESLOTINTERFACE
00265     StateStore           _stateStore;
00266 #endif
00267 
00268     StateRefCountStore   _stateRefCountStore;
00269     StateRefCountStoreIt _itInitialState;
00270     StateRefCountStoreIt _itActiveState;
00271 };
00272 
00273 OSG_END_NAMESPACE
00274 
00275 #include "OSGPriorityAction.inl"
00276 
00277 #define OSGPRIORITYACTION_HEADER_CVSID "@(#)$Id: OSGPriorityAction.h,v 1.7 2005/07/19 23:11:33 dirk Exp $"
00278 
00279 #endif /* _OSGPRIORITYACTION_H_ */

Generated on Thu Aug 25 04:08:45 2005 for OpenSG by  doxygen 1.4.3