@@ -56,23 +56,12 @@ class EXIV2API Xmpdatum : public Metadatum {
5656 @brief Assign std::string \em value to the %Xmpdatum.
5757 Calls setValue(const std::string&).
5858 */
59- Xmpdatum& operator =(const std::string& value);
60- /* !
61- @brief Assign a boolean \em value to the %Xmpdatum.
62- Translates the value to a string "true" or "false".
63- */
64- Xmpdatum& operator =(bool value);
65- /* !
66- @brief Assign a \em value of any type with an output operator
67- to the %Xmpdatum. Calls operator=(const std::string&).
68- */
6959 template <typename T>
7060 Xmpdatum& operator =(const T& value);
7161 /* !
7262 @brief Assign Value \em value to the %Xmpdatum.
7363 Calls setValue(const Value*).
7464 */
75- Xmpdatum& operator =(const Value& value);
7665 void setValue (const Value* pValue) override ;
7766 /* !
7867 @brief Set the value to the string \em value. Uses Value::read(const
@@ -398,12 +387,49 @@ class EXIV2API XmpParser {
398387
399388// *****************************************************************************
400389// free functions, template and inline definitions
390+
391+ #if __cpp_if_constexpr
401392template <typename T>
402393Xmpdatum& Xmpdatum::operator =(const T& value) {
403- setValue (Exiv2::toString (value));
394+ if constexpr (std::is_same_v<T, bool >)
395+ setValue (value ? " True" : " False" );
396+ else if constexpr (std::is_convertible_v<T, std::string>)
397+ setValue (value);
398+ else if constexpr (std::is_base_of_v<Value, T>)
399+ setValue (&value);
400+ else
401+ setValue (Exiv2::toString (value));
404402 return *this ;
405403}
404+ #else
405+ template <typename T>
406+ std::enable_if_t <std::is_convertible<T, std::string>::value> operatorHelper (Xmpdatum* xmp, const T& value) {
407+ xmp->setValue (value);
408+ }
409+
410+ template <typename T>
411+ std::enable_if_t <std::is_base_of<Value, T>::value> operatorHelper (Xmpdatum* xmp, const T& value) {
412+ xmp->setValue (&value);
413+ }
406414
415+ template <typename T>
416+ std::enable_if_t <std::is_same<T, bool >::value> operatorHelper (Xmpdatum* xmp, const T& value) {
417+ xmp->setValue (value ? " True" : " False" );
418+ }
419+
420+ template <typename T>
421+ std::enable_if_t <!(std::is_convertible<T, std::string>::value || std::is_base_of<Value, T>::value ||
422+ std::is_same<T, bool >::value)>
423+ operatorHelper (Xmpdatum* xmp, const T& value) {
424+ xmp->setValue (Exiv2::toString (value));
425+ }
426+
427+ template <typename T>
428+ Xmpdatum& Xmpdatum::operator =(const T& value) {
429+ operatorHelper (this , value);
430+ return *this ;
431+ }
432+ #endif
407433} // namespace Exiv2
408434
409435#endif // EXIV2_XMP_EXIV2_HPP
0 commit comments