Allow instantiating TagValue from TimeSpan and DateTime
This commit is contained in:
parent
f042d216fd
commit
c28ded1bca
19
tagvalue.h
19
tagvalue.h
|
@ -76,6 +76,8 @@ public:
|
||||||
TagValue(std::unique_ptr<char[]> &&data, std::size_t length, TagDataType type = TagDataType::Binary,
|
TagValue(std::unique_ptr<char[]> &&data, std::size_t length, TagDataType type = TagDataType::Binary,
|
||||||
TagTextEncoding encoding = TagTextEncoding::Latin1);
|
TagTextEncoding encoding = TagTextEncoding::Latin1);
|
||||||
TagValue(PositionInSet value);
|
TagValue(PositionInSet value);
|
||||||
|
TagValue(ChronoUtilities::DateTime value);
|
||||||
|
TagValue(ChronoUtilities::TimeSpan value);
|
||||||
TagValue(const TagValue &other);
|
TagValue(const TagValue &other);
|
||||||
TagValue(TagValue &&other) = default;
|
TagValue(TagValue &&other) = default;
|
||||||
~TagValue();
|
~TagValue();
|
||||||
|
@ -277,13 +279,28 @@ inline TagValue::TagValue(std::unique_ptr<char[]> &&data, std::size_t length, Ta
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Constructs a new TagValue holding a copy of the given PositionInSet \a value.
|
* \brief Constructs a new TagValue holding a copy of the given PositionInSet \a value.
|
||||||
* \param value Specifies the PositionInSet.
|
|
||||||
*/
|
*/
|
||||||
inline TagValue::TagValue(PositionInSet value)
|
inline TagValue::TagValue(PositionInSet value)
|
||||||
: TagValue(reinterpret_cast<const char *>(&value), sizeof(value), TagDataType::PositionInSet)
|
: TagValue(reinterpret_cast<const char *>(&value), sizeof(value), TagDataType::PositionInSet)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Constructs a new TagValue holding a copy of the given DateTime \a value.
|
||||||
|
*/
|
||||||
|
inline TagValue::TagValue(ChronoUtilities::DateTime value)
|
||||||
|
: TagValue(reinterpret_cast<const char *>(&value), sizeof(value), TagDataType::DateTime)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Constructs a new TagValue holding a copy of the given TimeSpan \a value.
|
||||||
|
*/
|
||||||
|
inline TagValue::TagValue(ChronoUtilities::TimeSpan value)
|
||||||
|
: TagValue(reinterpret_cast<const char *>(&value), sizeof(value), TagDataType::TimeSpan)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Returns whether both instances are not equal.
|
* \brief Returns whether both instances are not equal.
|
||||||
* \remarks Simply the negation of operator==() so check there for details.
|
* \remarks Simply the negation of operator==() so check there for details.
|
||||||
|
|
|
@ -128,6 +128,7 @@ void TagValueTests::testTimeSpan()
|
||||||
const TimeSpan fiveMinutes(TimeSpan::fromMinutes(5));
|
const TimeSpan fiveMinutes(TimeSpan::fromMinutes(5));
|
||||||
TagValue timeSpan;
|
TagValue timeSpan;
|
||||||
timeSpan.assignTimeSpan(fiveMinutes);
|
timeSpan.assignTimeSpan(fiveMinutes);
|
||||||
|
CPPUNIT_ASSERT_EQUAL(timeSpan, TagValue(timeSpan));
|
||||||
CPPUNIT_ASSERT_EQUAL(fiveMinutes, timeSpan.toTimeSpan());
|
CPPUNIT_ASSERT_EQUAL(fiveMinutes, timeSpan.toTimeSpan());
|
||||||
CPPUNIT_ASSERT_EQUAL(fiveMinutes.toString(), timeSpan.toString());
|
CPPUNIT_ASSERT_EQUAL(fiveMinutes.toString(), timeSpan.toString());
|
||||||
CPPUNIT_ASSERT_THROW(timeSpan.toInteger(), ConversionException);
|
CPPUNIT_ASSERT_THROW(timeSpan.toInteger(), ConversionException);
|
||||||
|
@ -140,6 +141,7 @@ void TagValueTests::testDateTime()
|
||||||
const DateTime now(DateTime::now());
|
const DateTime now(DateTime::now());
|
||||||
TagValue dateTime;
|
TagValue dateTime;
|
||||||
dateTime.assignDateTime(now);
|
dateTime.assignDateTime(now);
|
||||||
|
CPPUNIT_ASSERT_EQUAL(dateTime, TagValue(dateTime));
|
||||||
CPPUNIT_ASSERT_EQUAL(now, dateTime.toDateTime());
|
CPPUNIT_ASSERT_EQUAL(now, dateTime.toDateTime());
|
||||||
CPPUNIT_ASSERT_EQUAL(now.toString(), dateTime.toString());
|
CPPUNIT_ASSERT_EQUAL(now.toString(), dateTime.toString());
|
||||||
CPPUNIT_ASSERT_THROW(dateTime.toInteger(), ConversionException);
|
CPPUNIT_ASSERT_THROW(dateTime.toInteger(), ConversionException);
|
||||||
|
|
Loading…
Reference in New Issue