libMesh::Singleton Class Reference

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

#include <libmesh_singleton.h>

Inheritance diagram for libMesh::Singleton:

Classes

class  Setup
 

Static Public Member Functions

static void setup ()
 
static void cleanup ()
 

Protected Member Functions

 Singleton ()
 
virtual ~Singleton ()
 

Detailed Description

Base class for all library singleton objects.

Base class for all library singleton objects.

Author
Benjamin S. Kirk
Date
2013

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.

References libMesh::as_range().

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 }
SimpleRange< I > as_range(const std::pair< I, I > &p)
Definition: simple_range.h:57

◆ setup()

void libMesh::Singleton::setup ( )
static

Setup function. Initializes any derived Singleton::Setup objects. objects.

Definition at line 81 of file libmesh_singleton.C.

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

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 }

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