Adapt to removal of Singleton

This commit is contained in:
Alexander Bock
2018-11-05 14:17:42 -05:00
parent a130b0b7a0
commit cf593bd060
13 changed files with 98 additions and 23 deletions

View File

@@ -26,7 +26,6 @@
#define __OPENSPACE_CORE___DOCUMENTATIONENGINE___H__
#include <openspace/documentation/documentationgenerator.h>
#include <ghoul/designpattern/singleton.h>
#include <openspace/documentation/documentation.h>
#include <ghoul/misc/exception.h>
@@ -38,9 +37,7 @@ namespace openspace::documentation {
* produced in the application an write them out as a documentation file for human
* consumption.
*/
class DocumentationEngine : public ghoul::Singleton<DocumentationEngine>
, public DocumentationGenerator
{
class DocumentationEngine : public DocumentationGenerator {
public:
/**
* This exception is thrown by the addDocumentation method if a provided Documentation
@@ -80,6 +77,10 @@ public:
*/
std::vector<Documentation> documentations() const;
static void initialize();
static void deinitialize();
static bool isInitialized();
/**
* Returns a static reference to the main singleton DocumentationEngine.
*

View File

@@ -27,7 +27,7 @@
#include <openspace/mission/mission.h>
#include <ghoul/designpattern/singleton.h>
#include <ghoul/misc/assert.h>
#include <ghoul/misc/exception.h>
#include <map>
#include <string>

View File

@@ -25,8 +25,6 @@
#ifndef __OPENSPACE_CORE___SPICEMANAGER___H__
#define __OPENSPACE_CORE___SPICEMANAGER___H__
#include <ghoul/designpattern/singleton.h>
#include <ghoul/glm.h>
#include <ghoul/misc/boolean.h>
#include <ghoul/misc/exception.h>
@@ -40,9 +38,7 @@ namespace openspace {
namespace scripting { struct LuaLibrary; }
class SpiceManager : public ghoul::Singleton<SpiceManager> {
friend class ghoul::Singleton<SpiceManager>;
class SpiceManager {
public:
BooleanType(UseException);
@@ -150,6 +146,11 @@ public:
*/
static TerminatorType terminatorTypeFromString(const std::string& type);
static void initialize();
static void deinitialize();
static bool isInitialized();
static SpiceManager& ref();
/**
* Loads one or more SPICE kernels into a program. The provided path can either be a
* binary, text-kernel, or meta-kernel which gets loaded into the kernel pool. The
@@ -1055,6 +1056,8 @@ private:
/// The last assigned kernel-id, used to determine the next free kernel id
KernelHandle _lastAssignedKernel = KernelHandle(0);
static SpiceManager* _instance;
};
} // namespace openspace

View File

@@ -25,8 +25,6 @@
#ifndef __OPENSPACE_CORE___TRANSFORMATIONMANAGER___H__
#define __OPENSPACE_CORE___TRANSFORMATIONMANAGER___H__
#include <ghoul/designpattern/singleton.h>
#include <ghoul/glm.h>
#include <memory>
#include <set>
@@ -36,13 +34,17 @@ namespace ccmc { class Kameleon; }
namespace openspace {
class TransformationManager : public ghoul::Singleton<TransformationManager> {
friend class ghoul::Singleton<TransformationManager>;
class TransformationManager {
public:
TransformationManager();
~TransformationManager();
static void initialize();
static void deinitialize();
static bool isInitialized();
static TransformationManager& ref();
glm::dmat3 frameTransformationMatrix(const std::string& from, const std::string& to,
double ephemerisTime) const;
@@ -55,6 +57,8 @@ private:
//#endif
std::set<std::string> _kameleonFrames;
std::set<std::string> _dipoleFrames;
static TransformationManager* _instance;
};
} // namespace openspace

View File

@@ -62,6 +62,21 @@ DocumentationEngine::DocumentationEngine()
)
{}
void DocumentationEngine::initialize() {
ghoul_assert(!isInitialized(), "DocumentationEngine is already initialized");
_instance = new DocumentationEngine;
}
void DocumentationEngine::deinitialize() {
ghoul_assert(isInitialized(), "DocumentationEngine is not initialized");
delete _instance;
_instance = nullptr;
}
bool DocumentationEngine::isInitialized() {
return _instance != nullptr;
}
DocumentationEngine& DocumentationEngine::ref() {
if (_instance == nullptr) {
_instance = new DocumentationEngine;

View File

@@ -183,7 +183,7 @@ std::unique_ptr<ghoul::logging::Log> createLog(const ghoul::Dictionary& dictiona
LogLevelStamping(logLevelStamp),
cssFiles,
jsFiles,
ghoul::logging::levelFromString(logLevel)
ghoul::from_string<ghoul::logging::LogLevel>(logLevel)
);
}
}
@@ -206,7 +206,7 @@ std::unique_ptr<ghoul::logging::Log> createLog(const ghoul::Dictionary& dictiona
DateStamping(dateStamp),
CategoryStamping(categoryStamp),
LogLevelStamping(logLevelStamp),
ghoul::logging::levelFromString(logLevel)
ghoul::from_string<ghoul::logging::LogLevel>(logLevel)
);
}
}

View File

@@ -73,6 +73,7 @@
#include <ghoul/logging/consolelog.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/logging/visualstudiooutputlog.h>
#include <ghoul/misc/stringconversion.h>
#include <ghoul/opengl/debugcontext.h>
#include <ghoul/opengl/shaderpreprocessor.h>
#include <ghoul/opengl/texture.h>
@@ -223,7 +224,7 @@ void OpenSpaceEngine::initialize() {
ghoul::logging::LogManager::deinitialize();
}
ghoul::logging::LogLevel level = ghoul::logging::levelFromString(
ghoul::logging::LogLevel level = ghoul::from_string<ghoul::logging::LogLevel>(
global::configuration.logging.level
);
bool immediateFlush = global::configuration.logging.forceImmediateFlush;
@@ -550,8 +551,8 @@ void OpenSpaceEngine::initializeGL() {
if (global::configuration.isLoggingOpenGLCalls) {
using namespace ghoul::logging;
LogLevel level = levelFromString(global::configuration.logging.level);
if (level > LogLevel::Trace) {
LogLevel lvl = ghoul::from_string<LogLevel>(global::configuration.logging.level);
if (lvl > LogLevel::Trace) {
LWARNING(
"Logging OpenGL calls is enabled, but the selected log level does "
"not include TRACE, so no OpenGL logs will be printed");

View File

@@ -53,6 +53,7 @@
#include <ghoul/io/texture/texturereader.h>
#include <ghoul/io/texture/texturereadercmap.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/misc/stringconversion.h>
#include <ghoul/opengl/programobject.h>
#include <ghoul/systemcapabilities/openglcapabilitiescomponent.h>
@@ -1161,7 +1162,7 @@ void RenderEngine::renderScreenLog() {
break;
}
const std::string lvl = "(" + ghoul::logging::stringFromLevel(e->level) + ")";
const std::string lvl = "(" + ghoul::to_string(e->level) + ")";
const std::string& message = e->message.substr(0, MessageLength);
nr += std::count(message.begin(), message.end(), '\n');

View File

@@ -25,6 +25,7 @@
#include <openspace/util/histogram.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/misc/assert.h>
#include <cmath>
namespace {

View File

@@ -26,6 +26,7 @@
#include <ghoul/fmt.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/misc/assert.h>
#include <ghoul/misc/misc.h>
#include <algorithm>
#include <vector>

View File

@@ -87,6 +87,9 @@ namespace {
#include "spicemanager_lua.inl"
namespace openspace {
SpiceManager* SpiceManager::_instance = nullptr;
SpiceManager::SpiceException::SpiceException(const std::string& msg)
: ghoul::RuntimeError(msg, "Spice")
@@ -184,6 +187,27 @@ SpiceManager::~SpiceManager() {
errprt_c("SET", 0, const_cast<char*>("DEFAULT")); // NOLINT
}
void SpiceManager::initialize() {
ghoul_assert(!isInitialized(), "SpiceManager is already initialized");
_instance = new SpiceManager;
}
void SpiceManager::deinitialize() {
ghoul_assert(isInitialized(), "SpiceManager is not initialized");
delete _instance;
_instance = nullptr;
}
bool SpiceManager::isInitialized() {
return _instance != nullptr;
}
SpiceManager& SpiceManager::ref() {
ghoul_assert(isInitialized(), "SpiceManager is not initialized");
return *_instance;
}
SpiceManager::KernelHandle SpiceManager::loadKernel(std::string filePath) {
ghoul_assert(!filePath.empty(), "Empty file path");
ghoul_assert(

View File

@@ -26,6 +26,7 @@
#include <openspace/util/spicemanager.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/misc/assert.h>
#ifdef OPENSPACE_MODULE_KAMELEON_ENABLED
#ifdef WIN32
@@ -42,7 +43,9 @@
namespace openspace {
TransformationManager::TransformationManager(){
TransformationManager* TransformationManager::_instance = nullptr;
TransformationManager::TransformationManager() {
#ifdef OPENSPACE_MODULE_KAMELEON_ENABLED
_kameleon = std::make_shared<ccmc::Kameleon>();
#else
@@ -63,6 +66,27 @@ TransformationManager::~TransformationManager() { // NOLINT
#endif
}
void TransformationManager::initialize() {
ghoul_assert(!isInitialized(), "TransformationManager is already initialized");
_instance = new TransformationManager;
}
void TransformationManager::deinitialize() {
ghoul_assert(isInitialized(), "TransformationManager is not initialized");
delete _instance;
_instance = nullptr;
}
bool TransformationManager::isInitialized() {
return _instance != nullptr;
}
TransformationManager& TransformationManager::ref() {
ghoul_assert(isInitialized(), "TransformationManager is not initialized");
return *_instance;
}
glm::dmat3 TransformationManager::kameleonTransformationMatrix(
[[maybe_unused]] const std::string& from,
[[maybe_unused]] const std::string& to,