Make addFITSKeywordAsProperty work

This commit is contained in:
2023-03-09 17:43:50 +01:00
parent 3a1582e887
commit b5f6e6c4f6
3 changed files with 25 additions and 4 deletions
+3 -3
View File
@@ -34,6 +34,7 @@ namespace LibXISF
std::vector<std::string> splitString(const std::string &str, char delimiter); std::vector<std::string> splitString(const std::string &str, char delimiter);
void deserializeVariant(const pugi::xml_node &node, Variant &variant, const ByteArray &data); void deserializeVariant(const pugi::xml_node &node, Variant &variant, const ByteArray &data);
void serializeVariant(pugi::xml_node &node, const Variant &variant); void serializeVariant(pugi::xml_node &node, const Variant &variant);
Variant variantFromString(Variant::Type type, const String &str);
static std::unordered_map<String, Image::Type> imageTypeToEnum; static std::unordered_map<String, Image::Type> imageTypeToEnum;
static std::unordered_map<Image::Type, String> imageTypeToString; static std::unordered_map<Image::Type, String> imageTypeToString;
@@ -344,13 +345,12 @@ void Image::addFITSKeyword(const FITSKeyword &keyword)
_fitsKeywords.push_back(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)) if(fitsNameToPropertyIdTypeConvert.count(name))
{ {
auto &c = fitsNameToPropertyIdTypeConvert.at(name); auto &c = fitsNameToPropertyIdTypeConvert.at(name);
Property prop(c.first, value); Property prop(c.first, variantFromString(c.second, value));
//prop.value.convert(c.second);
updateProperty(prop); updateProperty(prop);
return true; return true;
} }
+1 -1
View File
@@ -299,7 +299,7 @@ public:
/** Add image property while doing automatic conversion of FITS name to XISF property /** Add image property while doing automatic conversion of FITS name to XISF property
* For example OBSERVER => Observer:Name, SITELAT => Observation:Location:Latitude * 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(); void* imageData();
const void* imageData() const; const void* imageData() const;
+21
View File
@@ -371,6 +371,27 @@ void serializeVariant(pugi::xml_node &node, const Variant &variant)
node.append_attribute("value").set_value(ss.str().c_str()); 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<Int32>(str.c_str(), str.c_str() + str.size()); break;
case Variant::Type::Float32: variant = fromChars<Float32>(str.c_str(), str.c_str() + str.size()); break;
case Variant::Type::Float64: variant = fromChars<Float64>(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 Variant::Type Variant::type() const
{ {