From: coderhyme Date: Wed, 1 Jul 2015 01:48:24 +0000 (+0900) Subject: Add missing methods to ResourceAttributes and test for one of them X-Git-Tag: 1.2.0+RC1~1430^2~91 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=95d595c0c4d8bc1a314ad1780bcf2fbc6f2490b6;p=platform%2Fupstream%2Fiotivity.git Add missing methods to ResourceAttributes and test for one of them Add missing move constructor definition and rval reference key accessor Change-Id: I6ac5725fc223accdab8fbaea397f6567674264f9 Signed-off-by: coderhyme Reviewed-on: https://gerrit.iotivity.org/gerrit/1466 Reviewed-by: Madan Lanka Tested-by: jenkins-iotivity Reviewed-by: Uze Choi --- diff --git a/service/resource-manipulation/modules/common/primitiveResource/include/ResourceAttributes.h b/service/resource-manipulation/modules/common/primitiveResource/include/ResourceAttributes.h index 0a11c8a..b8e7f31 100755 --- a/service/resource-manipulation/modules/common/primitiveResource/include/ResourceAttributes.h +++ b/service/resource-manipulation/modules/common/primitiveResource/include/ResourceAttributes.h @@ -74,13 +74,13 @@ namespace OIC template< typename T > using mpl_begin = typename boost::mpl::begin::type; - template< typename T > + template< typename T, typename V = void > using enable_if_supported = typename std::enable_if< - is_supported_type_helper< T >::type::value >::type; + is_supported_type_helper< T >::type::value, V >::type; - template< typename T > - using disable_if_unsupported = typename std::enable_if< - !is_supported_type_helper< T >::type::value >::type; + template< typename T, typename V = void > + using enable_if_unsupported = typename std::enable_if< + !is_supported_type_helper< T >::type::value, V >::type; template< typename VISITOR > class KeyValueVisitorHelper: public boost::static_visitor< > @@ -119,7 +119,7 @@ namespace OIC } Value& operator=(const Value&); - Value& operator=(Value&&) = default; + Value& operator=(Value&&); template< typename T, typename = enable_if_supported< T > > Value& operator=(T&& rhs) @@ -148,8 +148,8 @@ namespace OIC return m_data->which() == rhs.m_data->which(); } - template< typename T, enable_if_supported< T >* = nullptr > - bool isTypeOf() const + template< typename T > + enable_if_supported< T, bool > isTypeOf() const { using iter = typename boost::mpl::find< ValueVariant::types, T >::type; @@ -157,8 +157,8 @@ namespace OIC == boost::mpl::distance< mpl_begin< ValueVariant::types >, iter >::value; } - template< typename T, disable_if_unsupported< T >* = nullptr > - bool isTypeOf() const + template< typename T > + enable_if_unsupported< T, bool > isTypeOf() const { return false; } @@ -168,7 +168,8 @@ namespace OIC friend bool operator==(const Value&, const Value&); template< typename T > - friend bool operator==(const Value&, const T&); + friend typename std::enable_if< ResourceAttributes::is_supported_type< T >::value, + bool >::type operator==(const Value&, const T&); bool operator==(const char*) const; @@ -227,6 +228,7 @@ namespace OIC const_iterator cend() const; Value& operator[](const std::string&); + Value& operator[](std::string&&); Value& at(const std::string&); const Value& at(const std::string&) const; @@ -264,11 +266,9 @@ namespace OIC }; template< typename T > - bool operator==(const ResourceAttributes::Value& lhs, const T& rhs) + typename std::enable_if< ResourceAttributes::is_supported_type< T >::value, bool >::type + operator==(const ResourceAttributes::Value& lhs, const T& rhs) { - using TypeChecker = typename std::enable_if< - ResourceAttributes::is_supported_type< T >::value >::type; - return lhs.equals< T >(rhs); } diff --git a/service/resource-manipulation/modules/common/primitiveResource/src/ResourceAttributes.cpp b/service/resource-manipulation/modules/common/primitiveResource/src/ResourceAttributes.cpp index ae7dd48..6e07704 100755 --- a/service/resource-manipulation/modules/common/primitiveResource/src/ResourceAttributes.cpp +++ b/service/resource-manipulation/modules/common/primitiveResource/src/ResourceAttributes.cpp @@ -111,6 +111,13 @@ namespace OIC return *this; } + auto ResourceAttributes::Value::operator=(Value&& rhs) -> Value& + { + *m_data = ValueVariant{}; + m_data->swap(*rhs.m_data); + return *this; + } + auto ResourceAttributes::Value::operator=(const char* rhs) -> Value& { *m_data = std::string{ rhs }; @@ -318,6 +325,11 @@ namespace OIC return m_keyValues[key]; } + auto ResourceAttributes::operator[](std::string&& key) -> Value& + { + return m_keyValues[std::move(key)]; + } + auto ResourceAttributes::at(const std::string& key) -> Value& { try diff --git a/service/resource-manipulation/modules/common/primitiveResource/unittests/ResourceAttributesTest.cpp b/service/resource-manipulation/modules/common/primitiveResource/unittests/ResourceAttributesTest.cpp index cb66ae1..fd06beb 100644 --- a/service/resource-manipulation/modules/common/primitiveResource/unittests/ResourceAttributesTest.cpp +++ b/service/resource-manipulation/modules/common/primitiveResource/unittests/ResourceAttributesTest.cpp @@ -232,7 +232,17 @@ TEST(ResourceAttributesValueTest, MovedValueHasNull) ASSERT_EQ(nullptr, one); } -TEST(ResourceAttributesValueTest, SameValueIsEqual) +TEST(ResourceAttributesValueTest, MovedValueWithAssignmentHasNull) +{ + ResourceAttributes::Value one { 1 }; + ResourceAttributes::Value another; + + another = std::move(one); + + ASSERT_EQ(nullptr, one); +} + +TEST(ResourceAttributesValueTest, SameValuesAreEqual) { ResourceAttributes::Value one { 1 }; ResourceAttributes::Value another { 1 };