Skip to content

Commit

Permalink
Formatting only changes to remove tabs.
Browse files Browse the repository at this point in the history
Refs #8216
  • Loading branch information
martyngigg committed Mar 17, 2014
1 parent f0a3080 commit 69e528a
Showing 1 changed file with 78 additions and 78 deletions.
156 changes: 78 additions & 78 deletions Code/Mantid/Framework/Kernel/inc/MantidKernel/SingletonHolder.h
Expand Up @@ -30,84 +30,84 @@

namespace Mantid
{
namespace Kernel
{

/// prototype for function passed to atexit()
typedef void (*atexit_func_t)();

extern MANTID_KERNEL_DLL void CleanupSingletons();
extern MANTID_KERNEL_DLL void AddSingleton(atexit_func_t func);

/// class to manage an instance of an object as a singleton
template <typename T>
class SingletonHolder
{
public:
static T& Instance();

private:
static void DestroySingleton();
/// default constructor marked private so only access is via the Instance() method
SingletonHolder();

static T* pInstance;
static bool destroyed;
};

/// Implementation of the SingletonHolder create policy using the new and delete operators
template <typename T>
struct CreateUsingNew
{
/// create an object using the new operator
/// @returns New instance
static T* Create(){return new T;}
/// delete an object instantiated using Create
/// @param p :: pointer to instance to destroy
static void Destroy(T* p){delete p;}
};

/// Return a reference to the Singleton instance, creating it if it does not already exist
/// Creation is done using the CreateUsingNew policy at the moment
template <typename T>
inline T& SingletonHolder<T>::Instance()
{
if (destroyed)
{
std::string s("Attempt to use destroyed singleton ");
s += typeid(T).name();
throw std::runtime_error(s.c_str());
}
if (!pInstance)
{
// std::cerr << "creating singleton " << typeid(T).name() << std::endl;
pInstance = CreateUsingNew<T>::Create();
AddSingleton(&DestroySingleton);
//atexit(&CleanupSingletons);
}
return *pInstance;
}

/// Destroy the singleton
template <typename T>
void SingletonHolder<T>::DestroySingleton()
{
//std::cerr << "destroying singleton " << typeid(T).name() << std::endl;
assert(!destroyed);
CreateUsingNew<T>::Destroy(pInstance);
pInstance = 0;
destroyed = true;
}

/// global variable holding pointer to singleton instance
template <typename T>
T* SingletonHolder<T>::pInstance = 0;

/// variable to allow trapping of attempts to destroy a singleton more than once
template <typename T>
bool SingletonHolder<T>::destroyed = false;

}
namespace Kernel
{

/// prototype for function passed to atexit()
typedef void (*atexit_func_t)();

extern MANTID_KERNEL_DLL void CleanupSingletons();
extern MANTID_KERNEL_DLL void AddSingleton(atexit_func_t func);

/// class to manage an instance of an object as a singleton
template <typename T>
class SingletonHolder
{
public:
static T& Instance();

private:
static void DestroySingleton();
/// default constructor marked private so only access is via the Instance() method
SingletonHolder();

static T* pInstance;
static bool destroyed;
};

/// Implementation of the SingletonHolder create policy using the new and delete operators
template <typename T>
struct CreateUsingNew
{
/// create an object using the new operator
/// @returns New instance
static T* Create(){return new T;}
/// delete an object instantiated using Create
/// @param p :: pointer to instance to destroy
static void Destroy(T* p){delete p;}
};

/// Return a reference to the Singleton instance, creating it if it does not already exist
/// Creation is done using the CreateUsingNew policy at the moment
template <typename T>
inline T& SingletonHolder<T>::Instance()
{
if (destroyed)
{
std::string s("Attempt to use destroyed singleton ");
s += typeid(T).name();
throw std::runtime_error(s.c_str());
}
if (!pInstance)
{
// std::cerr << "creating singleton " << typeid(T).name() << std::endl;
pInstance = CreateUsingNew<T>::Create();
AddSingleton(&DestroySingleton);
//atexit(&CleanupSingletons);
}
return *pInstance;
}

/// Destroy the singleton
template <typename T>
void SingletonHolder<T>::DestroySingleton()
{
//std::cerr << "destroying singleton " << typeid(T).name() << std::endl;
assert(!destroyed);
CreateUsingNew<T>::Destroy(pInstance);
pInstance = 0;
destroyed = true;
}

/// global variable holding pointer to singleton instance
template <typename T>
T* SingletonHolder<T>::pInstance = 0;

/// variable to allow trapping of attempts to destroy a singleton more than once
template <typename T>
bool SingletonHolder<T>::destroyed = false;

}
}

#endif //SINGLETON_HOLDER_H
Expand Down

0 comments on commit 69e528a

Please sign in to comment.