libMesh
Classes | Static Public Member Functions | Protected Member Functions | List of all members
libMesh::Singleton Class Reference

Base class for all library singleton objects. More...

#include <libmesh_singleton.h>

Inheritance diagram for libMesh::Singleton:
[legend]

Classes

class  Setup
 Abstract base class for runtime singleton setup. More...
 

Static Public Member Functions

static void setup ()
 Setup function. More...
 
static void cleanup ()
 Cleanup function. More...
 

Protected Member Functions

 Singleton ()
 Constructor. More...
 
virtual ~Singleton ()
 Destructor. More...
 

Detailed Description

Base class for all library singleton objects.

Author
Benjamin S. Kirk
Date
2013

Base class for all library singleton objects.

Definition at line 35 of file libmesh_singleton.h.

Constructor & Destructor Documentation

◆ Singleton()

libMesh::Singleton::Singleton ( )
protected

Constructor.

Adds the derived object to the singleton cache list.

Definition at line 65 of file libmesh_singleton.C.

66 {
67  SingletonMutex::scoped_lock lock(singleton_mtx);
68 
69  get_singleton_cache().push_back (this);
70 }

◆ ~Singleton()

virtual libMesh::Singleton::~Singleton ( )
inlineprotectedvirtual

Destructor.

Definition at line 47 of file libmesh_singleton.h.

47 {}

Member Function Documentation

◆ cleanup()

void libMesh::Singleton::cleanup ( )
static

Cleanup function.

Removes all dynamically created Singleton objects.

Definition at line 96 of file libmesh_singleton.C.

97 {
98  SingletonMutex::scoped_lock lock(singleton_mtx);
99 
100  SingletonList & singleton_cache = get_singleton_cache();
101 
102  for (auto & item : as_range(singleton_cache.rbegin(),
103  singleton_cache.rend()))
104  {
105  libmesh_assert (item);
106  delete item;
107  item = nullptr;
108  }
109 
110  singleton_cache.clear();
111 }

References libMesh::as_range(), and libMesh::libmesh_assert().

◆ setup()

void libMesh::Singleton::setup ( )
static

Setup function.

Initializes any derived Singleton::Setup objects. objects.

Definition at line 81 of file libmesh_singleton.C.

82 {
83  SingletonMutex::scoped_lock lock(setup_mtx);
84 
85  SetupList & setup_cache = get_setup_cache();
86 
87  for (auto & item : setup_cache)
88  {
89  libmesh_assert (item);
90  item->setup();
91  }
92 }

References libMesh::libmesh_assert().

Referenced by libMesh::LibMeshInit::LibMeshInit().


The documentation for this class was generated from the following files:
libMesh::libmesh_assert
libmesh_assert(ctx)
libMesh::as_range
SimpleRange< IndexType > as_range(const std::pair< IndexType, IndexType > &p)
Helper function that allows us to treat a homogenous pair as a range.
Definition: simple_range.h:57