// GenFem - A high-level finite element library
// Copyright (C) 2010-2026 Eric Bechet
//
// See the LICENSE file for license information and contributions.
// Please report all bugs and problems to <bechet@cadxfem.org>.
//
// Initial design: Frederic Duboeuf (rev.1287)


#ifndef _GEN_SINGLETON_H_
#define _GEN_SINGLETON_H_

template <typename T> class Singleton
{
private:
  static T* singleton;

protected:
  Singleton() {}
  ~Singleton() {}
public:
  static T* getInstance()
  {
    if (NULL == singleton) // creating singleton
      singleton = new T; // else singleton already created
    return (static_cast<T*> (singleton));
  }
  static void kill()
  {
    if (NULL != singleton)
    {
      delete singleton;
      singleton = NULL;
    }
  }
};

template<typename T> T* Singleton<T>::singleton = NULL;

#endif // _GEN_SINGLETON_H_