Singleton

A template class that provides an implementation of the Singleton pattern.  Any class may derive from Singleton to become a Singleton.  This pattern should not be abused.

Project

DatabaseCore

Include

Singleton.h

Usage

    class MySingleton : public Singleton<MySingleton>
    {
    public:
        /* ... */
    private:
        MySingleton();

        //since the constructor is private, Singleton must be a friend
        //so that this class can be instantiated.
        friend class Singleton<MySingleton>;
    };
·
Summary
A template class that provides an implementation of the Singleton pattern.
The one and only one method of accessing a Singleton.
The Singleton constructor.
The Singleton destructor.
The Singleton copy constructor.
The Singleton assignment operator.

Public

Summary
The one and only one method of accessing a Singleton.

Static Functions

get

static T &get()

The one and only one method of accessing a Singleton.  The get method has a static instance of the Singleton class.

Returns

The Singleton object.

Protected

Summary
The Singleton constructor.
The Singleton destructor.

Constructors

Singleton

Singleton()

The Singleton constructor.  It is protected so that the Singleton cannot be instantiated unless it is derived from.

Destructor

~Singleton

virtual ~Singleton()

The Singleton destructor.  It is protected so that the Singleton cannot be instantiated unless it is derived from.

Private

Summary
The Singleton copy constructor.
The Singleton assignment operator.

Copy Constructor

Singleton

Singleton(const Singleton &)

The Singleton copy constructor.  It is private and never instantiated so that any developer trying to make a copy of a singleton object will get a compiler error.

Operators

operator=

Singleton &operator=(const Singleton &)

The Singleton assignment operator.  It is private and never instantiated so that any developer trying to create a Singleton by assigning it will get a compiler error.

static T &get()
The one and only one method of accessing a Singleton.
Singleton()
The Singleton constructor.
virtual ~Singleton()
The Singleton destructor.
Singleton &operator=(const Singleton &)
The Singleton assignment operator.
DatabaseCore provides a set of commonly used Singletons and namespaces that handle important, but mundane aspects of game management, such as available player colors, configuration options, image maniplulation, file paths, and playing sounds.