mirror of
https://bitbucket.org/mfeemster/fractorium.git
synced 2025-07-12 03:04:51 -04:00
Misc intermediate fixes, more work on these to follow.
--Bug fixes: -Fix crash when using smooth interpolation in EmberGenome. -Print error and exit EmberGenome when sequencing if times are not sorted. --Code changes: -Another attempt at Singleton. This reverts the design to what it was before with a fix to the code that was causing it not to behave like a singleton should.
This commit is contained in:
@ -193,16 +193,13 @@ private:
|
||||
/// member variables cannot be exported across module boundaries.
|
||||
/// Derived classes should inherit from this using the CRTP, and declare a friend to it.
|
||||
/// They also should make their constructors private and destructors public.
|
||||
/// This has a severe flaw in that it cannot be used across module boundaries, else
|
||||
/// every module will have its own copy. This makes it function as a per-module
|
||||
/// singleton, which is unlikely to ever be desired.
|
||||
/// Attribution: This class is a combination of
|
||||
/// http://btorpey.github.io/blog/2014/02/12/shared-singletons/
|
||||
/// and
|
||||
/// http://enki-tech.blogspot.com/2012/08/c11-generic-singleton.html
|
||||
/// </summary>
|
||||
template <class T>
|
||||
class EMBER_API Singleton
|
||||
class Singleton
|
||||
{
|
||||
public:
|
||||
/// <summary>
|
||||
@ -213,7 +210,7 @@ public:
|
||||
template <typename... Args>
|
||||
static shared_ptr<T> Instance(Args... args)
|
||||
{
|
||||
static weak_ptr<T> staticInstance;
|
||||
auto& staticInstance = GetStaticInstance();
|
||||
auto temp = staticInstance.lock();
|
||||
|
||||
if (!temp)
|
||||
@ -224,6 +221,18 @@ public:
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
protected:
|
||||
/// <summary>
|
||||
/// Clever hack to get a static to behave like a member variable that can be seen between classes and functions in the hierarchy.
|
||||
/// Also has the added benefit that it makes this work across module boundaries.
|
||||
/// </summary>
|
||||
/// <returns>static weak_ptr reference</returns>
|
||||
static std::weak_ptr<T>& GetStaticInstance()
|
||||
{
|
||||
static std::weak_ptr<T> staticInstance;
|
||||
return staticInstance;
|
||||
}
|
||||
};
|
||||
|
||||
//Use this if the body of the destructor will be implemented in a cpp file.
|
||||
@ -231,8 +240,6 @@ public:
|
||||
friend class Singleton<x>; \
|
||||
public: \
|
||||
~x(); \
|
||||
\
|
||||
private: \
|
||||
x(const x& other) = delete; \
|
||||
const x& operator=(const x& other) = delete//Semicolon deliberately omitted to force it on the caller.
|
||||
|
||||
@ -241,33 +248,9 @@ public:
|
||||
friend class Singleton<x>; \
|
||||
public: \
|
||||
~x(){} \
|
||||
\
|
||||
private: \
|
||||
x(const x& other) = delete; \
|
||||
const x& operator=(const x& other) = delete
|
||||
|
||||
//Use this if not deriving from the Singleton class and are declaring Instance() in a header and implementing it in a cpp file.
|
||||
#define SINGLETON_INSTANCE_DECL(x) \
|
||||
static std::shared_ptr<x> Instance(); \
|
||||
x(const x& other) = delete; \
|
||||
const x& operator=(const x& other) = delete//Semicolon deliberately omitted to force it on the caller.
|
||||
|
||||
//Use this if not deriving from the Singleton class and are implementing Instance() in a cpp file.
|
||||
#define SINGLETON_INSTANCE_IMPL(x) \
|
||||
std::shared_ptr<x> x::Instance() \
|
||||
{ \
|
||||
static weak_ptr<x> staticInstance; \
|
||||
auto temp = staticInstance.lock(); \
|
||||
\
|
||||
if (!temp) \
|
||||
{ \
|
||||
temp.reset(new x()); \
|
||||
staticInstance = temp; \
|
||||
} \
|
||||
\
|
||||
return temp; \
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Open a file in binary mode and read its entire contents into a vector of bytes. Optionally null terminate.
|
||||
/// </summary>
|
||||
|
Reference in New Issue
Block a user