Embedded Template Library 1.0
Loading...
Searching...
No Matches
etl::singleton_base< T > Class Template Reference

#include <singleton_base.h>

Static Public Member Functions

static Tinstance ()
 
static bool is_valid ()
 Returns whether an instance has been attached to singleton<T> or not.
 

Protected Member Functions

 singleton_base (T &theInstance)
 
 ~singleton_base ()
 Removes the internal reference to the instance passed in the constructor.
 

Detailed Description

template<typename T>
class etl::singleton_base< T >

Base class for singletons.

Template Parameters
TAny type that wants to expose the instance() interface.

This class is designed to work as a generic base class for any class that wants to provide a singleton interface. It'll also work for classes that do not have a default constructor.

Usage example:

class Origin : singleton<Origin> { public: Origin(int x, int y) : singleton<Origin>(*this) {}

int getX() const; } theOrigin(0, 0);

int x = Origin::instance().getX();

Note:

It is important that a call to instance() will not create the instance of the class. It needs to be created by the user before calling instance(). This way, the user has better control over the instance lifetime instead of e.g. lazy initialization.

Constructor & Destructor Documentation

◆ singleton_base()

template<typename T >
etl::singleton_base< T >::singleton_base ( T theInstance)
inlineexplicitprotected

Constructs the instance of singleton. theInstance Reference to T, which will be returned when instance() is called.


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