JeVois  1.5
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
jevois::Singleton< T > Class Template Reference

#include <jevois/Types/Singleton.H>

template<class T>
class jevois::Singleton< T >

A generic singleton class to enforce a single instance of an object.

The Singleton class should be inherited by any class which needs:

  1. To have only one instance
  2. To be globally accessible

Note that there are currently no guarantees on the order of destruction of Singletons, so care should be taken to never reference another Singleton in the destructor of a Singleton.

This particular implementation is from: http://stackoverflow.com/questions/1008019/c-singleton-design-pattern

The following is an example use of the Singleton:

class MyClass : public Singleton<MyClass>
{
public:
void doIt() {...}
private:
MyClass();
};
int main()
{
...
MyClass::instance().doIt();
...
}
Template Parameters
TThe class that is being made the singleton.

This class was first designed by Rand Voorhies in the Neuromorphic Robotics Toolkit.

Definition at line 91 of file Singleton.H.

Inheritance diagram for jevois::Singleton< T >:

Static Public Member Functions

static T & instance ()
 Get the global, unique instance of the class T. More...
 

Protected Member Functions

 Singleton ()
 Only classes that inherit from Singleton can construct it via its protected default constructor. More...
 

Constructor & Destructor Documentation

◆ Singleton()

template<class T >
jevois::Singleton< T >::Singleton ( )
inlineprotected

Only classes that inherit from Singleton can construct it via its protected default constructor.

Definition at line 21 of file SingletonImpl.H.

Member Function Documentation

◆ instance()

template<class T >
T & jevois::Singleton< T >::instance ( )
inlinestatic

Get the global, unique instance of the class T.

If the global, unique instance of class T has not yet been created, then this method will create it in a thread-safe manner.

Definition at line 25 of file SingletonImpl.H.


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