Make SpiceManager derive from Singleton

This commit is contained in:
Alexander Bock
2015-06-22 16:01:23 +02:00
parent 89923f0650
commit 1906c525e3
2 changed files with 624 additions and 647 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -42,33 +42,24 @@ namespace openspace {
SpiceManager* SpiceManager::_manager = nullptr;
void SpiceManager::initialize() {
assert(_manager == nullptr);
_manager = new SpiceManager;
_manager->_lastAssignedKernel = 0;
// Set the SPICE library to not exit the program if an error occurs
erract_c("SET", 0, const_cast<char*>("REPORT"));
// But we do not want SPICE to print the errors, we will fetch them ourselves
errprt_c("SET", 0, const_cast<char*>("NONE"));
SpiceManager::SpiceManager()
: _lastAssignedKernel(0)
{
// Set the SPICE library to not exit the program if an error occurs
erract_c("SET", 0, const_cast<char*>("REPORT"));
// But we do not want SPICE to print the errors, we will fetch them ourselves
errprt_c("SET", 0, const_cast<char*>("NONE"));
}
void SpiceManager::deinitialize() {
for (const KernelInformation& i : _manager->_loadedKernels)
unload_c(i.path.c_str());
SpiceManager::~SpiceManager() {
for (const KernelInformation& i : _manager->_loadedKernels)
unload_c(i.path.c_str());
delete _manager;
_manager = nullptr;
// Set values back to default
erract_c("SET", 0, const_cast<char*>("DEFAULT"));
errprt_c("SET", 0, const_cast<char*>("DEFAULT"));
// Set values back to default
erract_c("SET", 0, const_cast<char*>("DEFAULT"));
errprt_c("SET", 0, const_cast<char*>("DEFAULT"));
}
SpiceManager& SpiceManager::ref() {
assert(_manager != nullptr);
return *_manager;
}
SpiceManager::KernelIdentifier SpiceManager::loadKernel(const std::string& filePath) {
if (filePath.empty()) {
@@ -1068,4 +1059,4 @@ bool SpiceManager::getPlanetEllipsoid(std::string planetName, float &a, float &b
return !hasError;
}
}
}