diff --git a/libxisf.cpp b/libxisf.cpp index 660e7f5..e21fc4f 100644 --- a/libxisf.cpp +++ b/libxisf.cpp @@ -34,6 +34,7 @@ namespace LibXISF std::vector splitString(const std::string &str, char delimiter); void deserializeVariant(const pugi::xml_node &node, Variant &variant, const ByteArray &data); void serializeVariant(pugi::xml_node &node, const Variant &variant); +Variant variantFromString(Variant::Type type, const String &str); static std::unordered_map imageTypeToEnum; static std::unordered_map imageTypeToString; @@ -344,13 +345,12 @@ void Image::addFITSKeyword(const FITSKeyword &keyword) _fitsKeywords.push_back(keyword); } -bool Image::addFITSKeywordAsProperty(const String &name, const Variant &value) +bool Image::addFITSKeywordAsProperty(const String &name, const String &value) { if(fitsNameToPropertyIdTypeConvert.count(name)) { auto &c = fitsNameToPropertyIdTypeConvert.at(name); - Property prop(c.first, value); - //prop.value.convert(c.second); + Property prop(c.first, variantFromString(c.second, value)); updateProperty(prop); return true; } diff --git a/libxisf.h b/libxisf.h index 2587299..e9d77c8 100644 --- a/libxisf.h +++ b/libxisf.h @@ -299,7 +299,7 @@ public: /** Add image property while doing automatic conversion of FITS name to XISF property * For example OBSERVER => Observer:Name, SITELAT => Observation:Location:Latitude */ - bool addFITSKeywordAsProperty(const String &name, const Variant &value); + bool addFITSKeywordAsProperty(const String &name, const String &value); void* imageData(); const void* imageData() const; diff --git a/variant.cpp b/variant.cpp index 215abbb..91201e7 100644 --- a/variant.cpp +++ b/variant.cpp @@ -371,6 +371,27 @@ void serializeVariant(pugi::xml_node &node, const Variant &variant) node.append_attribute("value").set_value(ss.str().c_str()); } } +Variant variantFromString(Variant::Type type, const String &str) +{ + Variant variant; + switch(type) + { + case Variant::Type::Int32: variant = fromChars(str.c_str(), str.c_str() + str.size()); break; + case Variant::Type::Float32: variant = fromChars(str.c_str(), str.c_str() + str.size()); break; + case Variant::Type::Float64: variant = fromChars(str.c_str(), str.c_str() + str.size()); break; + case Variant::Type::String: variant = str; break; + case Variant::Type::TimePoint: + { + std::istringstream ss(str); + std::tm tm = {}; + ss >> std::get_time(&tm, "%Y-%m-%dT%H:%M:%SZ"); + variant = tm; + break; + } + default: break; + } + return variant; +} Variant::Type Variant::type() const {