From dd25d9999bd602b017f7f39915bdde0495f4956f Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Tue, 21 Feb 2023 14:39:45 -0800 Subject: [PATCH] direct init structs No need to deal with individual members Signed-off-by: Rosen Penev --- include/exiv2/value.hpp | 18 ++++++++---------- src/value.cpp | 18 ++++++------------ 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/include/exiv2/value.hpp b/include/exiv2/value.hpp index 3a63d805..eee87554 100644 --- a/include/exiv2/value.hpp +++ b/include/exiv2/value.hpp @@ -923,9 +923,9 @@ class EXIV2API DateValue : public Value { //! Simple Date helper structure struct EXIV2API Date { - int32_t year{0}; //!< Year - int32_t month{0}; //!< Month - int32_t day{0}; //!< Day + int32_t year; //!< Year + int32_t month; //!< Month + int32_t day; //!< Day }; //! @name Manipulators @@ -1014,13 +1014,11 @@ class EXIV2API TimeValue : public Value { //! Simple Time helper structure struct Time { - Time() = default; - - int32_t hour{0}; //!< Hour - int32_t minute{0}; //!< Minute - int32_t second{0}; //!< Second - int32_t tzHour{0}; //!< Hours ahead or behind UTC - int32_t tzMinute{0}; //!< Minutes ahead or behind UTC + int32_t hour; //!< Hour + int32_t minute; //!< Minute + int32_t second; //!< Second + int32_t tzHour; //!< Hours ahead or behind UTC + int32_t tzMinute; //!< Minutes ahead or behind UTC }; //! @name Manipulators diff --git a/src/value.cpp b/src/value.cpp index 2a92c733..9479176a 100644 --- a/src/value.cpp +++ b/src/value.cpp @@ -764,12 +764,11 @@ LangAltValue* LangAltValue::clone_() const { } DateValue::DateValue() : Value(date) { + date_ = {}; } DateValue::DateValue(int32_t year, int32_t month, int32_t day) : Value(date) { - date_.year = year; - date_.month = month; - date_.day = day; + date_ = {year, month, day}; } int DateValue::read(const byte* buf, size_t len, ByteOrder /*byteOrder*/) { @@ -813,9 +812,7 @@ int DateValue::read(const std::string& buf) { } void DateValue::setDate(const Date& src) { - date_.year = src.year; - date_.month = src.month; - date_.day = src.day; + date_ = src; } size_t DateValue::copy(byte* buf, ByteOrder /*byteOrder*/) const { @@ -883,14 +880,11 @@ Rational DateValue::toRational(size_t n) const { } TimeValue::TimeValue() : Value(time) { + time_ = {}; } TimeValue::TimeValue(int32_t hour, int32_t minute, int32_t second, int32_t tzHour, int32_t tzMinute) : Value(date) { - time_.hour = hour; - time_.minute = minute; - time_.second = second; - time_.tzHour = tzHour; - time_.tzMinute = tzMinute; + time_ = {hour, minute, second, tzHour, tzMinute}; } int TimeValue::read(const byte* buf, size_t len, ByteOrder /*byteOrder*/) { @@ -941,7 +935,7 @@ int TimeValue::read(const std::string& buf) { /// \todo not used internally. At least we should test it void TimeValue::setTime(const Time& src) { - std::memcpy(&time_, &src, sizeof(time_)); + time_ = src; } size_t TimeValue::copy(byte* buf, ByteOrder /*byteOrder*/) const {