Add missing methods to ResourceAttributes
authorcoderhyme <jhyo.kim@samsung.com>
Sat, 4 Jul 2015 02:33:16 +0000 (11:33 +0900)
committerUze Choi <uzchoi@samsung.com>
Mon, 6 Jul 2015 09:24:49 +0000 (09:24 +0000)
operator!=(Not equal) methods for ResourceAttributes and ResourceAttributes::Value.
swap method for ResourceAttributes::Value

Change-Id: I83d259e4034cf5b2926c10ac969ab85fd081dde8
Signed-off-by: coderhyme <jhyo.kim@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1514
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 40af425..77819d1 100755 (executable)
@@ -165,6 +165,8 @@ namespace OIC
 
                 std::string toString() const;
 
+                void swap(Value&);
+
                 friend bool operator==(const Value&, const Value&);
 
                 template< typename T >
@@ -265,6 +267,10 @@ namespace OIC
             using type = boost::mpl::contains<ValueVariant::types, typename std::decay< T >::type>;
         };
 
+
+
+        bool operator!=(const ResourceAttributes::Value&, const ResourceAttributes::Value&);
+
         template< typename T >
         typename std::enable_if< ResourceAttributes::is_supported_type< T >::value, bool >::type
         operator==(const ResourceAttributes::Value& lhs, const T& rhs)
@@ -273,6 +279,15 @@ namespace OIC
         }
 
         template< typename T >
+        typename std::enable_if< ResourceAttributes::is_supported_type< T >::value, bool >::type
+        operator!=(const T& lhs, const ResourceAttributes::Value& rhs)
+        {
+            return !(rhs == lhs);
+        }
+
+        bool operator!=(const char*, const ResourceAttributes::Value&);
+
+        template< typename T >
         bool operator==(const T& lhs, const ResourceAttributes::Value& rhs)
         {
             return rhs == lhs;
@@ -280,6 +295,8 @@ namespace OIC
 
         bool operator==(const char* lhs, const ResourceAttributes::Value& rhs);
 
+        bool operator!=(const ResourceAttributes&, const ResourceAttributes&);
+
         class ResourceAttributes::KeyValuePair
         {
         private:
index 3b1b156..c065101 100755 (executable)
@@ -28,7 +28,7 @@
 namespace
 {
 
-    class ToStringVisitor : public boost::static_visitor<std::string>
+    class ToStringVisitor: public boost::static_visitor< std::string >
     {
     public:
         ToStringVisitor() = default;
@@ -73,6 +73,17 @@ namespace OIC
     namespace Service
     {
 
+        bool operator!=(const ResourceAttributes::Value& lhs, const ResourceAttributes::Value& rhs)
+        {
+            return !(lhs == rhs);
+        }
+
+        bool operator!=(const char* lhs, const ResourceAttributes::Value& rhs)
+        {
+            return !(rhs == lhs);
+        }
+
+
         bool operator==(const char* lhs, const ResourceAttributes::Value& rhs)
         {
             return rhs == lhs;
@@ -88,6 +99,11 @@ namespace OIC
             return lhs.m_values == rhs.m_values;
         }
 
+        bool operator!=(const ResourceAttributes& lhs, const ResourceAttributes& rhs)
+        {
+            return !(lhs == rhs);
+        }
+
         ResourceAttributes::Value::Value() :
                 m_data{ new ValueVariant{} }
         {
@@ -140,6 +156,11 @@ namespace OIC
             return boost::apply_visitor(ToStringVisitor(), *m_data);
         }
 
+        void ResourceAttributes::Value::swap(Value& rhs)
+        {
+            m_data.swap(rhs.m_data);
+        }
+
         auto ResourceAttributes::KeyValuePair::KeyVisitor::operator() (iterator* iter) const
                 -> result_type {
             return iter->m_cur->first;
@@ -166,8 +187,8 @@ namespace OIC
             return iter->m_cur->second;
         }
 
-        auto ResourceAttributes::KeyValuePair::ConstValueVisitor::operator() (const_iterator* iter) const
-                -> result_type {
+        auto ResourceAttributes::KeyValuePair::ConstValueVisitor::operator() (const_iterator* iter)
+            const -> result_type {
             return iter->m_cur->second;
         }
 
@@ -187,7 +208,8 @@ namespace OIC
         }
 
 
-        ResourceAttributes::KeyValuePair::KeyValuePair(boost::variant<iterator*, const_iterator*>&& ref) :
+        ResourceAttributes::KeyValuePair::KeyValuePair(boost::variant<iterator*,
+                const_iterator*>&& ref) :
                 m_iterRef{ ref }
         {
         }
@@ -248,12 +270,14 @@ namespace OIC
         {
         }
 
-        ResourceAttributes::const_iterator::const_iterator(const ResourceAttributes::iterator& iter) :
+        ResourceAttributes::const_iterator::const_iterator(
+                const ResourceAttributes::iterator& iter) :
                 m_cur{ iter.m_cur }, m_keyValuePair{ this }
         {
         }
 
-        auto ResourceAttributes::const_iterator::operator=(const ResourceAttributes::iterator& iter) -> const_iterator& {
+        auto ResourceAttributes::const_iterator::operator=(const ResourceAttributes::iterator& iter)
+            -> const_iterator& {
             m_cur = iter.m_cur;
             return *this;
         }
@@ -415,7 +439,7 @@ namespace OIC
         }
 
         void replaceAttributeValueRecursively(ResourceAttributes::Value& dest,
-                     const ResourceAttributes::Value& value)
+                const ResourceAttributes::Value& value)
         {
             static_assert(ResourceAttributes::is_supported_type< ResourceAttributes >::value,
                     "ResourceAttributes doesn't have ResourceAttributes recursively.");
index 30aaf1c..00fff7d 100644 (file)
@@ -250,8 +250,13 @@ TEST(ResourceAttributesValueTest, SameValuesAreEqual)
     ASSERT_EQ(one, another);
 }
 
+TEST(ResourceAttributesValueTest, DifferentValuesAreNotEqual)
+{
+    ResourceAttributes::Value one { 1 };
+    ResourceAttributes::Value another { 2 };
 
-
+    ASSERT_NE(one, another);
+}
 
 TEST(ResourceAttributesConverterTest, OCRepresentationCanBeConvertedIntoResourceAttributes)
 {