All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TfStacked< Derived, PerThread, Holder > Class Template Reference

A TfStacked is used where a class needs to keep a stack of the objects currently in existence. More...

Public Types

typedef Holder Storage
 
typedef Storage::Stack Stack
 

Public Member Functions

 TfStacked ()
 Pushes this stacked object onto the stack. More...
 
 ~TfStacked ()
 Pops this stacked object from the stack. More...
 

Static Public Member Functions

static Derived const * GetStackTop ()
 Returns the top of the stack. More...
 
static Derived const * GetStackPrevious ()
 Returns the element under the top of the stack. More...
 
static Stack const & GetStack ()
 Returns a const reference to the entire stack. More...
 
static bool IsStackTop (Derived const *p)
 Returns true if p is the top of the stack. More...
 

Friends

class TfStackedAccess
 

Detailed Description

template<class Derived, bool PerThread = true, class Holder = Tf_StackedStorage<Derived, PerThread>>
class TfStacked< Derived, PerThread, Holder >

A TfStacked is used where a class needs to keep a stack of the objects currently in existence.

This class follows the CRTP and is a base class that is parameterized on its derived classes.

TfStacked is thread-safe by default and each thread will get its own stack. This behavior may be disabled by passing false for the PerThread template parameter.

Derived classes must instantiate the stack themselves by putting

TF_INSTANTIATE_STACKED(YourStackedClass)

in a single .cpp file.

Note that Stacked objects that differ only by PerThread will not share stacks.

Definition at line 137 of file stacked.h.

Constructor & Destructor Documentation

TfStacked ( )
inline

Pushes this stacked object onto the stack.

Definition at line 146 of file stacked.h.

~TfStacked ( )
inline

Pops this stacked object from the stack.

Definition at line 151 of file stacked.h.

Member Function Documentation

static Stack const& GetStack ( )
inlinestatic

Returns a const reference to the entire stack.

Definition at line 176 of file stacked.h.

static Derived const* GetStackPrevious ( )
inlinestatic

Returns the element under the top of the stack.

If the stack contains only one element, or is empty, returns 0. Derived classes can befriend TfStackedAccess and hide (override) _InitializeStack() to pre-populate the stack if desired. This way, a stack can be made never to be empty.

Definition at line 169 of file stacked.h.

static Derived const* GetStackTop ( )
inlinestatic

Returns the top of the stack.

If the stack is empty, returns 0. Derived classes can befriend TfStackedAccess and hide (override) _InitializeStack() to pre-populate the stack if desired. This way, a stack can be made never to be empty.

Definition at line 159 of file stacked.h.

static bool IsStackTop ( Derived const *  p)
inlinestatic

Returns true if p is the top of the stack.

Definition at line 181 of file stacked.h.


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