Add missing methods to ResourceAttributes and test for one of them
authorcoderhyme <jhyo.kim@samsung.com>
Wed, 1 Jul 2015 01:48:24 +0000 (10:48 +0900)
committerUze Choi <uzchoi@samsung.com>
Thu, 2 Jul 2015 09:06:43 +0000 (09:06 +0000)
Add missing move constructor definition and rval reference key accessor

Change-Id: I6ac5725fc223accdab8fbaea397f6567674264f9
Signed-off-by: coderhyme <jhyo.kim@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1466
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
service/resource-manipulation/modules/common/primitiveResource/include/ResourceAttributes.h
service/resource-manipulation/modules/common/primitiveResource/src/ResourceAttributes.cpp
service/resource-manipulation/modules/common/primitiveResource/unittests/ResourceAttributesTest.cpp

index 0a11c8a..b8e7f31 100755 (executable)
@@ -74,13 +74,13 @@ namespace OIC
             template< typename T >
             using mpl_begin = typename boost::mpl::begin<T>::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);
         }
 
index ae7dd48..6e07704 100755 (executable)
@@ -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
index cb66ae1..fd06beb 100644 (file)
@@ -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 };