Some work on the Decoder and ImageParser to make the ownership of data more clear

This commit is contained in:
Alexander Bock
2016-09-12 19:50:59 +02:00
parent 0376300732
commit 32ca42ebaa
12 changed files with 65 additions and 61 deletions

View File

@@ -22,18 +22,22 @@
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
****************************************************************************************/
#include <ghoul/logging/logmanager.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/filesystem/directory.h>
#include <openspace/util/time.h>
#include <openspace/util/spicemanager.h>
#include <modules/newhorizons/util/labelparser.h>
#include <modules/newhorizons/util/decoder.h>
#include <openspace/util/spicemanager.h>
#include <openspace/util/time.h>
#include <ghoul/filesystem/directory.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/logging/logmanager.h>
#include <fstream>
#include <iterator>
#include <iomanip>
#include <limits>
#include <modules/newhorizons/util/labelparser.h>
namespace {
const std::string _loggerCat = "LabelParser";
@@ -54,24 +58,24 @@ LabelParser::LabelParser(std::string name, std::string fileName,
//get the different instrument types
const std::vector<std::string>& decoders = translationDictionary.keys();
//for each decoder (assuming might have more if hong makes changes)
for (int i = 0; i < decoders.size(); i++){
for (int i = 0; i < decoders.size(); ++i) {
ghoul::Dictionary typeDictionary;
translationDictionary.getValue(decoders[i], typeDictionary);
//create dictionary containing all {playbookKeys , spice IDs}
if (decoders[i] == "Instrument"){
if (decoders[i] == "Instrument") {
//for each playbook call -> create a Decoder object
const std::vector<std::string>& keys = typeDictionary.keys();
for (int j = 0; j < keys.size(); j++){
std::vector<std::string> keys = typeDictionary.keys();
for (int j = 0; j < keys.size(); ++j){
std::string currentKey = decoders[i] + "." + keys[j];
ghoul::Dictionary decoderDictionary;
translationDictionary.getValue(currentKey, decoderDictionary);
ghoul::Dictionary decoderDictionary =
translationDictionary.value<ghoul::Dictionary>(currentKey);
Decoder *decoder = Decoder::createFromDictionary(decoderDictionary, decoders[i]);
auto decoder = Decoder::createFromDictionary(decoderDictionary, decoders[i]);
//insert decoder to map - this will be used in the parser to determine
//behavioral characteristics of each instrument
_fileTranslation[keys[j]] = decoder;
_fileTranslation[keys[j]] = std::move(decoder);
}
}
if (decoders[i] == "Target"){
@@ -91,17 +95,17 @@ LabelParser::LabelParser(std::string name, std::string fileName,
for (int j = 0; j < keys.size(); j++){
ghoul::Dictionary itemDictionary;
convertDictionary.getValue(keys[j], itemDictionary);
Decoder *decoder = Decoder::createFromDictionary(itemDictionary, decoders[i]);
auto decoder = Decoder::createFromDictionary(itemDictionary, decoders[i]);
//insert decoder to map - this will be used in the parser to determine
//behavioral characteristics of each instrument
_fileTranslation[keys[j]] = decoder;
_fileTranslation[keys[j]] = std::move(decoder);
};
}
}
}
std::string LabelParser::decode(std::string line){
for (auto key : _fileTranslation){
for (auto& key : _fileTranslation){
std::size_t value = line.find(key.first);
if (value != std::string::npos){
std::string toTranslate = line.substr(value);
@@ -121,7 +125,7 @@ std::string LabelParser::decode(std::string line){
}
std::string LabelParser::encode(std::string line) {
for (auto key : _fileTranslation) {
for (auto& key : _fileTranslation) {
std::size_t value = line.find(key.first);
if (value != std::string::npos) {
return line.substr(value);