Some minor cleanup

This commit is contained in:
Alexander Bock
2017-03-05 20:08:24 -05:00
parent 9b92a4e9ca
commit dcc9d6228d
9 changed files with 52 additions and 33 deletions

View File

@@ -1,3 +1,3 @@
return {
"kameleonmetadatatojson"
}
"kameleonmetadatatojson"
}

View File

@@ -26,11 +26,14 @@
#define __OPENSPACE_CORE___TASK___H__
#include <functional>
#include <ghoul/misc/dictionary.h>
#include <openspace/documentation/documentation.h>
#include <memory>
namespace ghoul { class Dictionary; }
namespace openspace {
namespace documentation { struct Documentation; }
class Task {
public:
using ProgressCallback = std::function<void(float)>;
@@ -38,7 +41,10 @@ public:
virtual ~Task() = default;
virtual void perform(const ProgressCallback& onProgress) = 0;
virtual std::string description() = 0;
static std::unique_ptr<Task> createFromDictionary(const ghoul::Dictionary& dictionary);
static std::unique_ptr<Task> createFromDictionary(
const ghoul::Dictionary& dictionary
);
static documentation::Documentation documentation();
};

View File

@@ -30,12 +30,13 @@
#include <openspace/util/task.h>
namespace openspace {
class TaskLoader {
public:
std::vector<std::unique_ptr<Task>> tasksFromDictionary(const ghoul::Dictionary& dictionary);
std::vector<std::unique_ptr<Task>> tasksFromFile(const std::string& path);
};
}
} // namespace openspace
#endif // __OPENSPACE_CORE___TASKLOADER___H__

View File

@@ -30,6 +30,8 @@
#include <openspace/documentation/documentation.h>
#include <ghoul/misc/dictionary.h>
namespace {
const char* KeyInFilenamePrefix = "InFilenamePrefix";
const char* KeyInFilenameSuffix = "InFilenameSuffix";

View File

@@ -23,6 +23,7 @@
****************************************************************************************/
#include <modules/kameleonvolume/tasks/kameleondocumentationtask.h>
#include <modules/kameleonvolume/kameleonvolumereader.h>
#include <openspace/openspace.h>
@@ -58,7 +59,8 @@ KameleonDocumentationTask::KameleonDocumentationTask(const ghoul::Dictionary& di
}
std::string KameleonDocumentationTask::description() {
return "Extract metadata from cdf-file " + _inputPath + " and output html documentation to " + _outputPath;
return "Extract metadata from cdf-file " + _inputPath +
" and output html documentation to " + _outputPath;
}
void KameleonDocumentationTask::perform(const Task::ProgressCallback & progressCallback) {

View File

@@ -27,6 +27,8 @@
#include <openspace/util/task.h>
#include <string>
namespace openspace {
class KameleonDocumentationTask : public Task {
@@ -35,6 +37,7 @@ public:
std::string description() override;
void perform(const Task::ProgressCallback& progressCallback) override;
static documentation::Documentation documentation();
private:
std::string _inputPath;
std::string _outputPath;

View File

@@ -23,11 +23,14 @@
****************************************************************************************/
#include <modules/kameleonvolume/tasks/kameleonmetadatatojsontask.h>
#include <modules/kameleonvolume/kameleonvolumereader.h>
#include <string>
#include <openspace/documentation/verifier.h>
#include <ghoul/misc/dictionaryjsonformatter.h>
#include <ghoul/filesystem/filesystem.h>
#include <fstream>
namespace {
@@ -37,7 +40,9 @@ namespace {
namespace openspace {
KameleonMetadataToJsonTask::KameleonMetadataToJsonTask(const ghoul::Dictionary& dictionary) {
KameleonMetadataToJsonTask::KameleonMetadataToJsonTask(
const ghoul::Dictionary& dictionary)
{
openspace::documentation::testSpecificationAndThrow(
documentation(),
dictionary,
@@ -49,13 +54,15 @@ KameleonMetadataToJsonTask::KameleonMetadataToJsonTask(const ghoul::Dictionary&
}
std::string KameleonMetadataToJsonTask::description() {
return "Extract metadata from cdf-file " + _inputPath + " and write as json to " + _outputPath;
return "Extract metadata from cdf-file " + _inputPath +
" and write as json to " + _outputPath;
}
void KameleonMetadataToJsonTask::perform(const Task::ProgressCallback & progressCallback) {
void KameleonMetadataToJsonTask::perform(const Task::ProgressCallback& progressCallback) {
KameleonVolumeReader reader(_inputPath);
ghoul::Dictionary dictionary = reader.readMetaData();
progressCallback(0.5f);
ghoul::DictionaryJsonFormatter formatter;
std::string json = formatter.format(dictionary);
std::ofstream output(_outputPath);
@@ -63,8 +70,7 @@ void KameleonMetadataToJsonTask::perform(const Task::ProgressCallback & progress
progressCallback(1.0f);
}
documentation::Documentation KameleonMetadataToJsonTask::documentation()
{
documentation::Documentation KameleonMetadataToJsonTask::documentation() {
using namespace documentation;
return {
"KameleonMetadataToJsonTask",
@@ -89,6 +95,4 @@ documentation::Documentation KameleonMetadataToJsonTask::documentation()
};
}
} // namespace openspace

View File

@@ -27,6 +27,8 @@
#include <openspace/util/task.h>
#include <string>
namespace openspace {
class KameleonMetadataToJsonTask : public Task {
@@ -35,6 +37,7 @@ public:
std::string description() override;
void perform(const Task::ProgressCallback& progressCallback) override;
static documentation::Documentation documentation();
private:
std::string _inputPath;
std::string _outputPath;

View File

@@ -23,22 +23,20 @@
****************************************************************************************/
#include <openspace/util/task.h>
#include <ghoul/misc/dictionary.h>
#include <openspace/documentation/documentation.h>
#include <openspace/documentation/verifier.h>
#include <openspace/util/factorymanager.h>
#include <ghoul/logging/logmanager.h>
namespace {
const std::string _loggerCat = "Task";
}
namespace openspace {
documentation::Documentation Task::documentation() {
using namespace openspace::documentation;
return{
"Renderable",
"renderable",
using namespace documentation;
return {
"Task",
"core_task",
{
{
"Type",
@@ -54,17 +52,17 @@ documentation::Documentation Task::documentation() {
}
std::unique_ptr<Task> Task::createFromDictionary(const ghoul::Dictionary& dictionary) {
openspace::documentation::testSpecificationAndThrow(documentation::Documentation(), dictionary, "Task");
openspace::documentation::testSpecificationAndThrow(
documentation::Documentation(),
dictionary,
"Task"
);
std::string taskType = dictionary.value<std::string>("Type");
auto factory = FactoryManager::ref().factory<Task>();
std::unique_ptr<Task> task = factory->create(taskType, dictionary);
if (task == nullptr) {
LERROR("Failed to create a Task object of type '" << taskType << "'");
return nullptr;
}
return std::move(task);
return task;
}
}
} // namespace openspace