Add namespace to common PrimitiveResource
authorcoderhyme <jhyo.kim@samsung.com>
Fri, 12 Jun 2015 06:57:34 +0000 (15:57 +0900)
committerUze Choi <uzchoi@samsung.com>
Wed, 17 Jun 2015 09:00:58 +0000 (09:00 +0000)
Change-Id: Iccb22fd14bcd2964bc2de7792d0ccb4d3b64f089
Signed-off-by: coderhyme <jhyo.kim@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1299
Reviewed-by: Hun-je Yeon <hunje.yeon@samsung.com>
Reviewed-by: Uze Choi <uzchoi@samsung.com>
Tested-by: Uze Choi <uzchoi@samsung.com>
service/basis/common/primitiveResource/include/PrimitiveException.h
service/basis/common/primitiveResource/include/PrimitiveResource.h
service/basis/common/primitiveResource/include/ResourceAttributes.h
service/basis/common/primitiveResource/include/ResponseStatement.h
service/basis/common/primitiveResource/include/internal/ResourceAtrributesConverter.h
service/basis/common/primitiveResource/src/PrimitiveResource.cpp
service/basis/common/primitiveResource/src/PrimtiveException.cpp
service/basis/common/primitiveResource/src/ResourceAttributes.cpp
service/basis/common/primitiveResource/unittests/ResourceAttributesTest.cpp
service/basis/serverBuilder/include/PrimitiveResponse.h
service/basis/serverBuilder/src/PrimitiveServerResource.cpp

index 1440ca4..73984c6 100755 (executable)
 
 #include <octypes.h>
 
-class PrimitiveException: public std::exception
+namespace OIC
 {
-public:
-    PrimitiveException() {}
-    PrimitiveException(const std::string& what) : m_what{ what } {}
-
-    const char* what() const noexcept override
+    namespace Service
     {
-        return m_what.c_str();
-    }
 
-private:
-    std::string m_what;
-};
+        class PrimitiveException: public std::exception
+        {
+        public:
+            PrimitiveException() {}
+            PrimitiveException(const std::string& what) : m_what{ what } {}
 
-class PlatformException: public PrimitiveException
-{
-public:
-    PlatformException(OCStackResult reason);
+            const char* what() const noexcept override
+            {
+                return m_what.c_str();
+            }
 
-    OCStackResult getReasonCode() const;
-    std::string getReason() const;
+        private:
+            std::string m_what;
+        };
 
-private:
-    OCStackResult m_reason;
-};
+        class PlatformException: public PrimitiveException
+        {
+        public:
+            PlatformException(OCStackResult reason);
 
+            OCStackResult getReasonCode() const;
+            std::string getReason() const;
 
-class BadGetException: public PrimitiveException
-{
-public:
-    BadGetException(const std::string& what)
-    {
+        private:
+            OCStackResult m_reason;
+        };
 
-    }
-};
 
-class InvalidKeyException: public PrimitiveException
-{
-public:
-    InvalidKeyException(const std::string& what)
-    {
+        class BadGetException: public PrimitiveException
+        {
+        public:
+            BadGetException(const std::string& what)
+            {
+
+            }
+        };
+
+        class InvalidKeyException: public PrimitiveException
+        {
+        public:
+            InvalidKeyException(const std::string& what)
+            {
+
+            }
+        };
 
     }
-};
+}
 
 #endif //__PRIMITIVEEXCEPTION_H
index f8453f1..a3a0a34 100755 (executable)
 
 #include <OCResource.h>
 
-using HeaderOption = OC::HeaderOption::OCHeaderOption;
-using HeaderOptions = std::vector<HeaderOption>;
+namespace OIC
+{
+    namespace Service
+    {
 
-class ResourceAttributes;
-class ResponseStatement;
+        using HeaderOption = OC::HeaderOption::OCHeaderOption;
+        using HeaderOptions = std::vector<HeaderOption>;
 
-class PrimitiveResource
-{
-public:
-    using Ptr = std::shared_ptr<PrimitiveResource>;
+        class ResourceAttributes;
+        class ResponseStatement;
+
+        class PrimitiveResource
+        {
+        public:
+            using Ptr = std::shared_ptr<PrimitiveResource>;
 
-    using GetCallback = std::function<void(const HeaderOptions&, const ResponseStatement&, int)>;
+            using GetCallback = std::function<void(const HeaderOptions&, const ResponseStatement&, int)>;
 
-    using SetCallback = std::function<void(const HeaderOptions&, const ResponseStatement&, int)>;
+            using SetCallback = std::function<void(const HeaderOptions&, const ResponseStatement&, int)>;
 
-    using ObserveCallback = std::function<void(const HeaderOptions&, const ResponseStatement&, int, int)>;
+            using ObserveCallback = std::function<void(const HeaderOptions&, const ResponseStatement&, int, int)>;
 
-private:
-    using BaseResource = OC::OCResource;
-    using BaseResourcePtr = BaseResource::Ptr;
+        private:
+            using BaseResource = OC::OCResource;
+            using BaseResourcePtr = BaseResource::Ptr;
 
-public:
-    static PrimitiveResource::Ptr create(const BaseResourcePtr&);
+        public:
+            static PrimitiveResource::Ptr create(const BaseResourcePtr&);
 
-    void requestGet(GetCallback);
-    void requestSet(const ResourceAttributes&, SetCallback);
-    void requestObserve(ObserveCallback);
-    void cancelObserve();
+            void requestGet(GetCallback);
+            void requestSet(const ResourceAttributes&, SetCallback);
+            void requestObserve(ObserveCallback);
+            void cancelObserve();
 
-    std::string getUri() const;
-    std::string getHost() const;
-    std::vector< std::string > getTypes() const;
-    std::vector< std::string > getInterfaces() const;
+            std::string getUri() const;
+            std::string getHost() const;
+            std::vector< std::string > getTypes() const;
+            std::vector< std::string > getInterfaces() const;
 
-    bool isObservable() const;
+            bool isObservable() const;
 
-private:
-    PrimitiveResource(const BaseResourcePtr&);
+        private:
+            PrimitiveResource(const BaseResourcePtr&);
 
-private:
-    BaseResourcePtr m_ocResource;
-};
+        private:
+            BaseResourcePtr m_ocResource;
+        };
 
-using FindCallback = std::function<void(std::shared_ptr<PrimitiveResource>)>;
+        using FindCallback = std::function<void(std::shared_ptr<PrimitiveResource>)>;
 
-void discoverResource(const std::string& host, const std::string& resourceURI,
-        OCConnectivityType connectivityType, FindCallback resourceHandler);
+        void discoverResource(const std::string& host, const std::string& resourceURI,
+                OCConnectivityType connectivityType, FindCallback resourceHandler);
 
+    }
+}
 #endif // __PRIMITIVERESOURCE_H
index 5ea16f6..297293d 100755 (executable)
 
 #include <PrimitiveException.h>
 
-class ResourceAttributes
+namespace OIC
 {
-private:
-    template< typename T > struct is_supported_type_helper;
-
-    using ValueVariant = boost::variant<
-        std::nullptr_t,
-        int,
-        double,
-        bool,
-        std::string,
-        ResourceAttributes
-    >;
-
-    template< typename T >
-    using mpl_begin = typename boost::mpl::begin<T>::type;
-
-    template< typename T >
-    using enable_if_supported = typename std::enable_if<
-            is_supported_type_helper< T >::type::value >::type;
-
-    template< typename T >
-    using disable_if_unsupported = typename std::enable_if<
-            !is_supported_type_helper< T >::type::value >::type;
-
-    template< typename VISITOR >
-    class KeyValueVisitorHelper: public boost::static_visitor< >
+    namespace Service
     {
-    public:
-        KeyValueVisitorHelper(VISITOR& visitor) :
-                m_visitor( visitor )
-        {
-        }
-
-        template< typename T >
-        void operator()(const std::string& key, const T& value) const
-        {
-            m_visitor(key, value);
-        }
-
-    private:
-        VISITOR& m_visitor;
-    };
-
-public:
-    template< typename T >
-    using is_supported_type = typename is_supported_type_helper< T >::type;
 
-    class Value
-    {
-    public:
-        Value();
-        Value(const Value&);
-        Value(Value&&);
-
-        template< typename T, typename = enable_if_supported< T > >
-        Value(T&& value) :
-                m_data{ new ValueVariant{ std::forward< T >(value) } }
+        class ResourceAttributes
         {
-        }
+        private:
+            template< typename T > struct is_supported_type_helper;
+
+            using ValueVariant = boost::variant<
+                std::nullptr_t,
+                int,
+                double,
+                bool,
+                std::string,
+                ResourceAttributes
+            >;
+
+            template< typename T >
+            using mpl_begin = typename boost::mpl::begin<T>::type;
+
+            template< typename T >
+            using enable_if_supported = typename std::enable_if<
+                    is_supported_type_helper< T >::type::value >::type;
+
+            template< typename T >
+            using disable_if_unsupported = typename std::enable_if<
+                    !is_supported_type_helper< T >::type::value >::type;
+
+            template< typename VISITOR >
+            class KeyValueVisitorHelper: public boost::static_visitor< >
+            {
+            public:
+                KeyValueVisitorHelper(VISITOR& visitor) :
+                        m_visitor( visitor )
+                {
+                }
+
+                template< typename T >
+                void operator()(const std::string& key, const T& value) const
+                {
+                    m_visitor(key, value);
+                }
+
+            private:
+                VISITOR& m_visitor;
+            };
+
+        public:
+            template< typename T >
+            using is_supported_type = typename is_supported_type_helper< T >::type;
+
+            class Value
+            {
+            public:
+                Value();
+                Value(const Value&);
+                Value(Value&&);
+
+                template< typename T, typename = enable_if_supported< T > >
+                Value(T&& value) :
+                        m_data{ new ValueVariant{ std::forward< T >(value) } }
+                {
+                }
+
+                Value& operator=(const Value&);
+                Value& operator=(Value&&) = default;
+
+                template< typename T, typename = enable_if_supported< T > >
+                Value& operator=(T&& rhs)
+                {
+                    *m_data = std::forward< T >(rhs);
+                    return *this;
+                }
+
+                Value& operator=(const char*);
+                Value& operator=(std::nullptr_t);
+
+                template< typename T >
+                typename std::add_lvalue_reference< const T >::type get() const
+                {
+                    return checkedGet< T >();
+                }
+
+                template< typename T >
+                typename std::add_lvalue_reference< T >::type get()
+                {
+                    return checkedGet< T >();
+                }
+
+                bool isTypeEqualWith(const Value& rhs) const
+                {
+                    return m_data->which() == rhs.m_data->which();
+                }
+
+                template< typename T, enable_if_supported< T >* = nullptr >
+                bool isTypeOf() const
+                {
+                    using iter = typename boost::mpl::find< ValueVariant::types, T >::type;
+
+                    return m_data->which()
+                            == boost::mpl::distance< mpl_begin< ValueVariant::types >, iter >::value;
+                }
+
+                template< typename T, disable_if_unsupported< T >* = nullptr >
+                bool isTypeOf() const
+                {
+                    return false;
+                }
+
+                std::string toString() const;
+
+                friend bool operator==(const Value&, const Value&);
+
+                template< typename T >
+                friend bool operator==(const Value&, const T&);
+
+                bool operator==(const char*) const;
+
+            private:
+                template< typename T, typename = enable_if_supported< T > >
+                typename std::add_lvalue_reference< T >::type checkedGet() const
+                {
+                    try
+                    {
+                        return boost::get< T >(*m_data);
+                    }
+                    catch (const boost::bad_get&)
+                    {
+                        throw BadGetException{ "Wrong type" };
+                    }
+                }
+
+                template< typename T, typename U >
+                bool equals(const U& rhs) const
+                {
+                    try
+                    {
+                        return get< T >() == rhs;
+                    }
+                    catch (const BadGetException&)
+                    {
+                        return false;
+                    }
+                }
+
+            public:
+                boost::scoped_ptr< ValueVariant > m_data;
+            };
+
+            class KeyValuePair;
+            class iterator;
+            class const_iterator;
+
+        public:
+            ResourceAttributes() = default;
+            ResourceAttributes(const ResourceAttributes&) = default;
+            ResourceAttributes(ResourceAttributes&&) = default;
+
+            ResourceAttributes& operator=(const ResourceAttributes&) = default;
+            ResourceAttributes& operator=(ResourceAttributes&&) = default;
+
+            iterator begin();
+            iterator end();
+
+            const_iterator begin() const;
+            const_iterator end() const;
+
+            const_iterator cbegin() const;
+            const_iterator cend() const;
+
+            Value& operator[](const std::string&);
+
+            Value& at(const std::string&);
+            const Value& at(const std::string&) const;
+
+            bool erase(const std::string&);
+
+            bool contains(const std::string&) const;
+            bool empty() const;
+            size_t size() const;
+
+            friend bool operator==(const ResourceAttributes&, const ResourceAttributes&);
+
+        private:
+            template< typename VISITOR >
+            void visit(VISITOR& visitor) const
+            {
+                KeyValueVisitorHelper< VISITOR > helper{ visitor };
 
-        Value& operator=(const Value&);
-        Value& operator=(Value&&) = default;
+                for (const auto& i : m_keyValues)
+                {
+                    boost::variant< const std::string& > key{ i.first };
+                    boost::apply_visitor(helper, key, *i.second.m_data);
+                }
+            }
 
-        template< typename T, typename = enable_if_supported< T > >
-        Value& operator=(T&& rhs)
-        {
-            *m_data = std::forward< T >(rhs);
-            return *this;
-        }
+        private:
+            std::unordered_map< std::string, Value > m_keyValues;
 
-        Value& operator=(const char*);
-        Value& operator=(std::nullptr_t);
+            friend class ResourceAttributesConverter;
+        };
 
-        template< typename T >
-        typename std::add_lvalue_reference< const T >::type get() const
+        template< typename T > struct ResourceAttributes::is_supported_type_helper
         {
-            return checkedGet< T >();
-        }
+            using type = boost::mpl::contains<ValueVariant::types, typename std::decay< T >::type>;
+        };
 
         template< typename T >
-        typename std::add_lvalue_reference< T >::type get()
+        bool operator==(const ResourceAttributes::Value& lhs, const T& rhs)
         {
-            return checkedGet< T >();
-        }
+            using TypeChecker = typename std::enable_if<
+                    ResourceAttributes::is_supported_type< T >::value >::type;
 
-        bool isTypeEqualWith(const Value& rhs) const
-        {
-            return m_data->which() == rhs.m_data->which();
+            return lhs.equals< T >(rhs);
         }
 
-        template< typename T, enable_if_supported< T >* = nullptr >
-        bool isTypeOf() const
-        {
-            using iter = typename boost::mpl::find< ValueVariant::types, T >::type;
-
-            return m_data->which()
-                    == boost::mpl::distance< mpl_begin< ValueVariant::types >, iter >::value;
-        }
-
-        template< typename T, disable_if_unsupported< T >* = nullptr >
-        bool isTypeOf() const
+        template< typename T >
+        bool operator==(const T& lhs, const ResourceAttributes::Value& rhs)
         {
-            return false;
+            return rhs == lhs;
         }
 
-        std::string toString() const;
+        bool operator==(const char* lhs, const ResourceAttributes::Value& rhs);
 
-        friend bool operator==(const Value&, const Value&);
-
-        template< typename T >
-        friend bool operator==(const Value&, const T&);
-
-        bool operator==(const char*) const;
-
-    private:
-        template< typename T, typename = enable_if_supported< T > >
-        typename std::add_lvalue_reference< T >::type checkedGet() const
+        class ResourceAttributes::KeyValuePair
         {
-            try
+        private:
+            class KeyVisitor: public boost::static_visitor< const std::string& >
             {
-                return boost::get< T >(*m_data);
-            }
-            catch (const boost::bad_get&)
-            {
-                throw BadGetException{ "Wrong type" };
-            }
-        }
+            public:
+                result_type operator()(iterator*) const;
+                result_type operator()(const_iterator*) const;
+            };
 
-        template< typename T, typename U >
-        bool equals(const U& rhs) const
-        {
-            try
+            class ValueVisitor: public boost::static_visitor< Value& >
             {
-                return get< T >() == rhs;
-            }
-            catch (const BadGetException&)
-            {
-                return false;
-            }
-        }
-
-    public:
-        boost::scoped_ptr< ValueVariant > m_data;
-    };
+            public:
+                result_type operator()(iterator*);
+                result_type operator()(const_iterator*);
+            };
 
-    class KeyValuePair;
-    class iterator;
-    class const_iterator;
-
-public:
-    ResourceAttributes() = default;
-    ResourceAttributes(const ResourceAttributes&) = default;
-    ResourceAttributes(ResourceAttributes&&) = default;
-
-    ResourceAttributes& operator=(const ResourceAttributes&) = default;
-    ResourceAttributes& operator=(ResourceAttributes&&) = default;
-
-    iterator begin();
-    iterator end();
-
-    const_iterator begin() const;
-    const_iterator end() const;
-
-    const_iterator cbegin() const;
-    const_iterator cend() const;
+            class ConstValueVisitor: public boost::static_visitor< const Value& >
+            {
+            public:
+                result_type operator()(iterator*) const;
+                result_type operator()(const_iterator*) const;
+            };
 
-    Value& operator[](const std::string&);
+        public:
+            const std::string& key() const;
+            const ResourceAttributes::Value& value() const;
+            ResourceAttributes::Value& value();
 
-    Value& at(const std::string&);
-    const Value& at(const std::string&) const;
+        private:
+            KeyValuePair(const KeyValuePair&) = default;
+            KeyValuePair(boost::variant< iterator*, const_iterator* >&&);
 
-    bool erase(const std::string&);
+            KeyValuePair& operator=(const KeyValuePair&) = default;
 
-    bool contains(const std::string&) const;
-    bool empty() const;
-    size_t size() const;
+        private:
+            boost::variant< iterator*, const_iterator* > m_iterRef;
 
-    friend bool operator==(const ResourceAttributes&, const ResourceAttributes&);
+            KeyVisitor m_keyVisitor;
+            ValueVisitor m_valueVisitor;
+            ConstValueVisitor m_constValueVisitor;
 
-private:
-    template< typename VISITOR >
-    void visit(VISITOR& visitor) const
-    {
-        KeyValueVisitorHelper< VISITOR > helper{ visitor };
+            friend class iterator;
+            friend class const_iterator;
+        };
 
-        for (const auto& i : m_keyValues)
+        class ResourceAttributes::iterator: public std::iterator< std::forward_iterator_tag,
+                ResourceAttributes::KeyValuePair >
         {
-            boost::variant< const std::string& > key{ i.first };
-            boost::apply_visitor(helper, key, *i.second.m_data);
-        }
-    }
-
-private:
-    std::unordered_map< std::string, Value > m_keyValues;
+        private:
+            using base_iterator = std::unordered_map< std::string, Value >::iterator;
 
-    friend class ResourceAttributesConverter;
-};
+        public:
+            iterator();
+            iterator(const iterator&) = default;
 
-template< typename T > struct ResourceAttributes::is_supported_type_helper
-{
-    using type = boost::mpl::contains<ValueVariant::types, typename std::decay< T >::type>;
-};
+            iterator& operator=(const iterator&) = default;
 
-template< typename T >
-bool operator==(const ResourceAttributes::Value& lhs, const T& rhs)
-{
-    using TypeChecker = typename std::enable_if<
-            ResourceAttributes::is_supported_type< T >::value >::type;
+            reference operator*();
+            pointer operator->();
 
-    return lhs.equals< T >(rhs);
-}
-
-template< typename T >
-bool operator==(const T& lhs, const ResourceAttributes::Value& rhs)
-{
-    return rhs == lhs;
-}
+            iterator& operator++();
+            iterator operator++(int);
 
-bool operator==(const char* lhs, const ResourceAttributes::Value& rhs);
+            bool operator==(const iterator&) const;
+            bool operator!=(const iterator&) const;
 
-class ResourceAttributes::KeyValuePair
-{
-private:
-    class KeyVisitor: public boost::static_visitor< const std::string& >
-    {
-    public:
-        result_type operator()(iterator*) const;
-        result_type operator()(const_iterator*) const;
-    };
+        private:
+            explicit iterator(base_iterator&&);
 
-    class ValueVisitor: public boost::static_visitor< Value& >
-    {
-    public:
-        result_type operator()(iterator*);
-        result_type operator()(const_iterator*);
-    };
+        private:
+            base_iterator m_cur;
+            ResourceAttributes::KeyValuePair m_keyValuePair;
 
-    class ConstValueVisitor: public boost::static_visitor< const Value& >
-    {
-    public:
-        result_type operator()(iterator*) const;
-        result_type operator()(const_iterator*) const;
-    };
+            friend class ResourceAttributes;
+        };
 
-public:
-    const std::string& key() const;
-    const ResourceAttributes::Value& value() const;
-    ResourceAttributes::Value& value();
-
-private:
-    KeyValuePair(const KeyValuePair&) = default;
-    KeyValuePair(boost::variant< iterator*, const_iterator* >&&);
-
-    KeyValuePair& operator=(const KeyValuePair&) = default;
-
-private:
-    boost::variant< iterator*, const_iterator* > m_iterRef;
-
-    KeyVisitor m_keyVisitor;
-    ValueVisitor m_valueVisitor;
-    ConstValueVisitor m_constValueVisitor;
-
-    friend class iterator;
-    friend class const_iterator;
-};
-
-class ResourceAttributes::iterator: public std::iterator< std::forward_iterator_tag,
-        ResourceAttributes::KeyValuePair >
-{
-private:
-    using base_iterator = std::unordered_map< std::string, Value >::iterator;
-
-public:
-    iterator();
-    iterator(const iterator&) = default;
-
-    iterator& operator=(const iterator&) = default;
-
-    reference operator*();
-    pointer operator->();
-
-    iterator& operator++();
-    iterator operator++(int);
-
-    bool operator==(const iterator&) const;
-    bool operator!=(const iterator&) const;
-
-private:
-    explicit iterator(base_iterator&&);
-
-private:
-    base_iterator m_cur;
-    ResourceAttributes::KeyValuePair m_keyValuePair;
-
-    friend class ResourceAttributes;
-};
+        class ResourceAttributes::const_iterator: public std::iterator< std::forward_iterator_tag,
+                const ResourceAttributes::KeyValuePair >
+        {
+        private:
+            using base_iterator = std::unordered_map< std::string, Value >::const_iterator;
 
-class ResourceAttributes::const_iterator: public std::iterator< std::forward_iterator_tag,
-        const ResourceAttributes::KeyValuePair >
-{
-private:
-    using base_iterator = std::unordered_map< std::string, Value >::const_iterator;
+        public:
+            const_iterator();
+            const_iterator(const const_iterator&) = default;
+            const_iterator(const ResourceAttributes::iterator&);
 
-public:
-    const_iterator();
-    const_iterator(const const_iterator&) = default;
-    const_iterator(const ResourceAttributes::iterator&);
+            const_iterator& operator=(const const_iterator&) = default;
+            const_iterator& operator=(const ResourceAttributes::iterator&);
 
-    const_iterator& operator=(const const_iterator&) = default;
-    const_iterator& operator=(const ResourceAttributes::iterator&);
+            reference operator*() const;
+            pointer operator->() const;
 
-    reference operator*() const;
-    pointer operator->() const;
+            const_iterator& operator++();
+            const_iterator operator++(int);
 
-    const_iterator& operator++();
-    const_iterator operator++(int);
+            bool operator==(const const_iterator&) const;
+            bool operator!=(const const_iterator&) const;
 
-    bool operator==(const const_iterator&) const;
-    bool operator!=(const const_iterator&) const;
+        private:
+            explicit const_iterator(base_iterator&&);
 
-private:
-    explicit const_iterator(base_iterator&&);
+        private:
+            base_iterator m_cur;
+            ResourceAttributes::KeyValuePair m_keyValuePair;
 
-private:
-    base_iterator m_cur;
-    ResourceAttributes::KeyValuePair m_keyValuePair;
+            friend class ResourceAttributes;
+        };
 
-    friend class ResourceAttributes;
-};
+    }
+}
 
 #endif // __RESOURCEATTRIBUTES_H
index 4887bc6..75485d7 100755 (executable)
 
 #include <ResourceAttributes.h>
 
-/**
- * TODO : design for future flexibility
- */
-class ResponseStatement
+namespace OIC
 {
-public:
-    static ResponseStatement create(ResourceAttributes&& attrs)
+    namespace Service
     {
-        return ResponseStatement(attrs);
-    }
 
-    explicit ResponseStatement(const ResourceAttributes& attrs) :
-            m_attrs{ attrs }
-    {
-    }
-    explicit ResponseStatement(ResourceAttributes&& attrs) :
-            m_attrs{ std::move(attrs) }
-    {
-    }
+        /**
+         * TODO : design for future flexibility
+         */
+        class ResponseStatement
+        {
+        public:
+            static ResponseStatement create(ResourceAttributes&& attrs)
+            {
+                return ResponseStatement(attrs);
+            }
 
-    ResponseStatement(ResponseStatement&&) = default;
+            explicit ResponseStatement(const ResourceAttributes& attrs) :
+                    m_attrs{ attrs }
+            {
+            }
+            explicit ResponseStatement(ResourceAttributes&& attrs) :
+                    m_attrs{ std::move(attrs) }
+            {
+            }
 
-    ResponseStatement& operator=(ResponseStatement&&) = default;
+            ResponseStatement(ResponseStatement&&) = default;
 
-//     std::string getUri() const;
-//     std::vector<std::string> getResourceTypes() const;
-//     std::vector<std::string> getResourceInterfaces() const;
+            ResponseStatement& operator=(ResponseStatement&&) = default;
 
-    const ResourceAttributes& getAttributes() const
-    {
-        return m_attrs;
-    }
+        //     std::string getUri() const;
+        //     std::vector<std::string> getResourceTypes() const;
+        //     std::vector<std::string> getResourceInterfaces() const;
+
+            const ResourceAttributes& getAttributes() const
+            {
+                return m_attrs;
+            }
 
-private:
-    ResourceAttributes m_attrs;
-};
+        private:
+            ResourceAttributes m_attrs;
+        };
+
+    }
+}
 
 #endif // __RESPONSESTATEMENT_H
index 92d8547..574be21 100644 (file)
 
 #include <OCRepresentation.h>
 
-class ResourceAttributesConverter
+namespace OIC
 {
-private:
-    ResourceAttributesConverter() = delete;
-
-    template< typename T >
-    using SupportedType = typename std::enable_if<
-    ResourceAttributes::is_supported_type< T >::type::value, T >::type;
-
-    template< typename T >
-    using UnsupportedType = typename std::enable_if<
-    !ResourceAttributes::is_supported_type< T >::type::value, T >::type;
-
-    class ResourceAttributesBuilder
+    namespace Service
     {
-    public:
-        ResourceAttributesBuilder() = default;
 
-        void insertItemTo(const OC::OCRepresentation::AttributeItem& item)
+        class ResourceAttributesConverter
         {
-            switch (item.type())
-            {
-                case OC::AttributeType::Null:
-                    return putValue(item.attrname(), nullptr);
-
-                case OC::AttributeType::Integer:
-                    return putValue(item.attrname(), item.getValue< int >());
+        private:
+            ResourceAttributesConverter() = delete;
 
-                case OC::AttributeType::Double:
-                    return putValue(item.attrname(), item.getValue< double >());
+            template< typename T >
+            using SupportedType = typename std::enable_if<
+            ResourceAttributes::is_supported_type< T >::type::value, T >::type;
 
-                case OC::AttributeType::Boolean:
-                    return putValue(item.attrname(), item.getValue< bool >());
+            template< typename T >
+            using UnsupportedType = typename std::enable_if<
+            !ResourceAttributes::is_supported_type< T >::type::value, T >::type;
 
-                case OC::AttributeType::String:
-                    return putValue(item.attrname(), item.getValue< std::string >());
+            class ResourceAttributesBuilder
+            {
+            public:
+                ResourceAttributesBuilder() = default;
+
+                void insertItemTo(const OC::OCRepresentation::AttributeItem& item)
+                {
+                    switch (item.type())
+                    {
+                        case OC::AttributeType::Null:
+                            return putValue(item.attrname(), nullptr);
+
+                        case OC::AttributeType::Integer:
+                            return putValue(item.attrname(), item.getValue< int >());
+
+                        case OC::AttributeType::Double:
+                            return putValue(item.attrname(), item.getValue< double >());
+
+                        case OC::AttributeType::Boolean:
+                            return putValue(item.attrname(), item.getValue< bool >());
+
+                        case OC::AttributeType::String:
+                            return putValue(item.attrname(), item.getValue< std::string >());
+
+                        case OC::AttributeType::OCRepresentation:
+                            return putValue(item.attrname(),
+                                    ResourceAttributesConverter::fromOCRepresentation(
+                                            item.getValue< OC::OCRepresentation >()));
+
+                        case OC::AttributeType::Vector:
+                            // ResourceAttributes doesn't support vector yet!
+                            return;
+                    }
+                }
+
+                ResourceAttributes&& extract()
+                {
+                    return std::move(m_target);
+                }
+
+            private:
+                template< typename T >
+                void putValue(const std::string key, T&& value)
+                {
+                    putValue< T >(key, std::forward< T >(value));
+                }
+
+                template< typename T >
+                void putValue(const std::string key, SupportedType< T > && value)
+                {
+                    m_target[key] = std::forward< T >(value);
+                }
+
+                template< typename T >
+                void putValue(const std::string key, UnsupportedType< T > && value)
+                {
+                }
+
+            private:
+                ResourceAttributes m_target;
+            };
+
+            class AttrVisitor
+            {
+            public:
+                AttrVisitor() = default;
+
+                template< typename T >
+                void operator()(const std::string& key, const T& value)
+                {
+                    m_target[key] = value;
+                }
+
+                void operator()(const std::string& key, const std::nullptr_t&)
+                {
+                    m_target.setNULL(key);
+                }
+
+                void operator()(const std::string& key, const ResourceAttributes& value)
+                {
+                    m_target[key] = ResourceAttributesConverter::toOCRepresentation(value);
+                }
+
+                OC::OCRepresentation&& extract()
+                {
+                    return std::move(m_target);
+                }
+
+            private:
+                OC::OCRepresentation m_target;
+            };
+
+        public:
+            static ResourceAttributes fromOCRepresentation(const OC::OCRepresentation& ocRepresentation)
+            {
+                ResourceAttributesBuilder builder;
 
-                case OC::AttributeType::OCRepresentation:
-                    return putValue(item.attrname(),
-                            ResourceAttributesConverter::fromOCRepresentation(
-                                    item.getValue< OC::OCRepresentation >()));
+                for (const auto& item : ocRepresentation)
+                {
+                    builder.insertItemTo(item);
+                }
 
-                case OC::AttributeType::Vector:
-                    // ResourceAttributes doesn't support vector yet!
-                    return;
+                return builder.extract();
             }
-        }
-
-        ResourceAttributes&& extract()
-        {
-            return std::move(m_target);
-        }
-
-    private:
-        template< typename T >
-        void putValue(const std::string key, T&& value)
-        {
-            putValue< T >(key, std::forward< T >(value));
-        }
-
-        template< typename T >
-        void putValue(const std::string key, SupportedType< T > && value)
-        {
-            m_target[key] = std::forward< T >(value);
-        }
-
-        template< typename T >
-        void putValue(const std::string key, UnsupportedType< T > && value)
-        {
-        }
-
-    private:
-        ResourceAttributes m_target;
-    };
-
-    class AttrVisitor
-    {
-    public:
-        AttrVisitor() = default;
-
-        template< typename T >
-        void operator()(const std::string& key, const T& value)
-        {
-            m_target[key] = value;
-        }
-
-        void operator()(const std::string& key, const std::nullptr_t&)
-        {
-            m_target.setNULL(key);
-        }
-
-        void operator()(const std::string& key, const ResourceAttributes& value)
-        {
-            m_target[key] = ResourceAttributesConverter::toOCRepresentation(value);
-        }
-
-        OC::OCRepresentation&& extract()
-        {
-            return std::move(m_target);
-        }
 
-    private:
-        OC::OCRepresentation m_target;
-    };
-
-public:
-    static ResourceAttributes fromOCRepresentation(const OC::OCRepresentation& ocRepresentation)
-    {
-        ResourceAttributesBuilder builder;
-
-        for (const auto& item : ocRepresentation)
-        {
-            builder.insertItemTo(item);
-        }
-
-        return builder.extract();
-    }
+            static OC::OCRepresentation toOCRepresentation(const ResourceAttributes& resourceAttributes)
+            {
+                AttrVisitor visitor;
 
-    static OC::OCRepresentation toOCRepresentation(const ResourceAttributes& resourceAttributes)
-    {
-        AttrVisitor visitor;
+                resourceAttributes.visit(visitor);
 
-        resourceAttributes.visit(visitor);
+                return visitor.extract();
+            }
+        };
 
-        return visitor.extract();
     }
-};
+}
 
 #endif // __RESOURCEATTRIBUTESCONVERTER_H
index 448a5d7..c63ced6 100755 (executable)
@@ -39,6 +39,7 @@ using namespace std::placeholders;
 
 namespace
 {
+    using namespace OIC::Service;
 
     ResponseStatement createResponseStatement(const OCRepresentation& ocRepresentation)
     {
@@ -48,68 +49,77 @@ namespace
 
 } // unnamed namespace
 
-PrimitiveResource::PrimitiveResource(const BaseResourcePtr& ocResource) :
-        m_ocResource{ ocResource }
-{
-}
-
-PrimitiveResource::Ptr PrimitiveResource::create(const BaseResourcePtr& ptr)
-{
-    return std::shared_ptr< PrimitiveResource >(new PrimitiveResource{ ptr });
-}
-
-void PrimitiveResource::requestGet(GetCallback callback)
-{
-    m_ocResource->get(QueryParamsMap(), bind(callback, _1, bind(createResponseStatement, _2), _3));
-}
-
-void PrimitiveResource::requestSet(const ResourceAttributes& attrs, SetCallback callback)
-{
-    m_ocResource->put(ResourceAttributesConverter::toOCRepresentation(attrs), QueryParamsMap{},
-            bind(callback, _1, bind(createResponseStatement, _2), _3));
-}
-
-void PrimitiveResource::requestObserve(ObserveCallback callback)
-{
-    m_ocResource->observe(ObserveType::ObserveAll, QueryParamsMap{},
-            bind(callback, _1, bind(createResponseStatement, _2), _3, _4));
-}
-
-void PrimitiveResource::cancelObserve()
-{
-    m_ocResource->cancelObserve();
-}
 
-bool PrimitiveResource::isObservable() const
+namespace OIC
 {
-    return m_ocResource->isObservable();
-}
-
-string PrimitiveResource::getUri() const
-{
-    return m_ocResource->uri();
-}
-
-string PrimitiveResource::getHost() const
-{
-    return m_ocResource->host();
-}
-
-vector< string > PrimitiveResource::getTypes() const
-{
-    return m_ocResource->getResourceTypes();
-}
-
-vector< string > PrimitiveResource::getInterfaces() const
-{
-    return m_ocResource->getResourceInterfaces();
-}
-
+    namespace Service
+    {
 
+        PrimitiveResource::PrimitiveResource(const BaseResourcePtr& ocResource) :
+                m_ocResource{ ocResource }
+        {
+        }
+
+        PrimitiveResource::Ptr PrimitiveResource::create(const BaseResourcePtr& ptr)
+        {
+            return std::shared_ptr< PrimitiveResource >(new PrimitiveResource{ ptr });
+        }
+
+        void PrimitiveResource::requestGet(GetCallback callback)
+        {
+            m_ocResource->get(QueryParamsMap(), bind(callback, _1, bind(createResponseStatement, _2), _3));
+        }
+
+        void PrimitiveResource::requestSet(const ResourceAttributes& attrs, SetCallback callback)
+        {
+            m_ocResource->put(ResourceAttributesConverter::toOCRepresentation(attrs), QueryParamsMap{},
+                    bind(callback, _1, bind(createResponseStatement, _2), _3));
+        }
+
+        void PrimitiveResource::requestObserve(ObserveCallback callback)
+        {
+            m_ocResource->observe(ObserveType::ObserveAll, QueryParamsMap{},
+                    bind(callback, _1, bind(createResponseStatement, _2), _3, _4));
+        }
+
+        void PrimitiveResource::cancelObserve()
+        {
+            m_ocResource->cancelObserve();
+        }
+
+        bool PrimitiveResource::isObservable() const
+        {
+            return m_ocResource->isObservable();
+        }
+
+        string PrimitiveResource::getUri() const
+        {
+            return m_ocResource->uri();
+        }
+
+        string PrimitiveResource::getHost() const
+        {
+            return m_ocResource->host();
+        }
+
+        vector< string > PrimitiveResource::getTypes() const
+        {
+            return m_ocResource->getResourceTypes();
+        }
+
+        vector< string > PrimitiveResource::getInterfaces() const
+        {
+            return m_ocResource->getResourceInterfaces();
+        }
+
+
+
+        void discoverResource(const std::string& host, const std::string& resourceURI,
+                OCConnectivityType connectivityType, FindCallback resourceHandler)
+        {
+            OC::OCPlatform::findResource(host, resourceURI, connectivityType,
+                    std::bind(&PrimitiveResource::create, std::placeholders::_1));
+        }
 
-void discoverResource(const std::string& host, const std::string& resourceURI,
-        OCConnectivityType connectivityType, FindCallback resourceHandler)
-{
-    OC::OCPlatform::findResource(host, resourceURI, connectivityType,
-            std::bind(&PrimitiveResource::create, std::placeholders::_1));
+    }
 }
index 535a5de..ae1a99a 100644 (file)
 
 #include <OCException.h>
 
-PlatformException::PlatformException(OCStackResult reason) :
-    PrimitiveException{ "Failed : " + OC::OCException::reason(reason) },
-    m_reason { reason }
+namespace OIC
 {
-}
+    namespace Service
+    {
 
-OCStackResult PlatformException::getReasonCode() const
-{
-    return m_reason;
-}
+        PlatformException::PlatformException(OCStackResult reason) :
+            PrimitiveException{ "Failed : " + OC::OCException::reason(reason) },
+            m_reason { reason }
+        {
+        }
 
-std::string PlatformException::getReason() const
-{
-    return  OC::OCException::reason(m_reason);
+        OCStackResult PlatformException::getReasonCode() const
+        {
+            return m_reason;
+        }
+
+        std::string PlatformException::getReason() const
+        {
+            return  OC::OCException::reason(m_reason);
+        }
+
+    }
 }
index c6f5c48..ae7dd48 100755 (executable)
 
 #include <boost/lexical_cast.hpp>
 
-class ToStringVisitor : public boost::static_visitor<std::string>
+namespace
 {
-public:
-    ToStringVisitor() = default;
-    ToStringVisitor(const ToStringVisitor&) = delete;
-    ToStringVisitor(ToStringVisitor&&) = delete;
 
-    ToStringVisitor& operator=(const ToStringVisitor&) = delete;
-    ToStringVisitor& operator=(ToStringVisitor&&) = delete;
-
-    template < typename T >
-    std::string operator()(const T& value) const
+    class ToStringVisitor : public boost::static_visitor<std::string>
     {
-        return boost::lexical_cast<std::string>(value);
-    }
+    public:
+        ToStringVisitor() = default;
+        ToStringVisitor(const ToStringVisitor&) = delete;
+        ToStringVisitor(ToStringVisitor&&) = delete;
 
-    std::string operator()(std::nullptr_t) const
-    {
-        return "";
-    }
+        ToStringVisitor& operator=(const ToStringVisitor&) = delete;
+        ToStringVisitor& operator=(ToStringVisitor&&) = delete;
 
-    std::string operator()(bool value) const
-    {
-        return value ? "true" : "false";
-    }
+        template < typename T >
+        std::string operator()(const T& value) const
+        {
+            return boost::lexical_cast<std::string>(value);
+        }
 
-    std::string operator()(const std::string& value) const
-    {
-        return value;
-    }
+        std::string operator()(std::nullptr_t) const
+        {
+            return "";
+        }
 
-    std::string operator()(const ResourceAttributes&) const
-    {
-        return "Attributes";
-    }
-};
+        std::string operator()(bool value) const
+        {
+            return value ? "true" : "false";
+        }
 
-bool operator==(const char* lhs, const ResourceAttributes::Value& rhs)
-{
-    return rhs == lhs;
-}
+        std::string operator()(const std::string& value) const
+        {
+            return value;
+        }
 
-bool operator==(const ResourceAttributes::Value& lhs, const ResourceAttributes::Value& rhs)
-{
-    return *lhs.m_data == *rhs.m_data;
-}
+        std::string operator()(const OIC::Service::ResourceAttributes&) const
+        {
+            return "Attributes";
+        }
+    };
 
-bool operator==(const ResourceAttributes& lhs, const ResourceAttributes& rhs)
-{
-    return lhs.m_keyValues == rhs.m_keyValues;
-}
+} // unnamed namespace
 
-ResourceAttributes::Value::Value() :
-        m_data{ new ValueVariant{} }
-{
-}
 
-ResourceAttributes::Value::Value(const Value& from) :
-        m_data{ new ValueVariant{ *from.m_data } }
+namespace OIC
 {
-}
+    namespace Service
+    {
 
-ResourceAttributes::Value::Value(Value&& from) :
-        m_data{ new ValueVariant{} }
-{
-    m_data->swap(*from.m_data);
-}
+        bool operator==(const char* lhs, const ResourceAttributes::Value& rhs)
+        {
+            return rhs == lhs;
+        }
 
+        bool operator==(const ResourceAttributes::Value& lhs, const ResourceAttributes::Value& rhs)
+        {
+            return *lhs.m_data == *rhs.m_data;
+        }
 
-auto ResourceAttributes::Value::operator=(const Value& rhs) -> Value&
-{
-    *m_data = *rhs.m_data;
-    return *this;
-}
+        bool operator==(const ResourceAttributes& lhs, const ResourceAttributes& rhs)
+        {
+            return lhs.m_keyValues == rhs.m_keyValues;
+        }
 
-auto ResourceAttributes::Value::operator=(const char* rhs) -> Value&
-{
-    *m_data = std::string{ rhs };
-    return *this;
-}
+        ResourceAttributes::Value::Value() :
+                m_data{ new ValueVariant{} }
+        {
+        }
 
-auto ResourceAttributes::Value::operator=(std::nullptr_t) -> Value&
-{
-    *m_data = nullptr;
-    return *this;
-}
+        ResourceAttributes::Value::Value(const Value& from) :
+                m_data{ new ValueVariant{ *from.m_data } }
+        {
+        }
 
-bool ResourceAttributes::Value::operator==(const char* rhs) const
-{
-    return equals< std::string >(rhs);
-}
+        ResourceAttributes::Value::Value(Value&& from) :
+                m_data{ new ValueVariant{} }
+        {
+            m_data->swap(*from.m_data);
+        }
 
-std::string ResourceAttributes::Value::toString() const
-{
-    return boost::apply_visitor(ToStringVisitor(), *m_data);
-}
 
-auto ResourceAttributes::KeyValuePair::KeyVisitor::operator() (iterator* iter) const
-        -> result_type {
-    return iter->m_cur->first;
-}
+        auto ResourceAttributes::Value::operator=(const Value& rhs) -> Value&
+        {
+            *m_data = *rhs.m_data;
+            return *this;
+        }
 
-auto ResourceAttributes::KeyValuePair::KeyVisitor::operator() (const_iterator* iter) const
-        -> result_type {
-    return iter->m_cur->first;
-}
+        auto ResourceAttributes::Value::operator=(const char* rhs) -> Value&
+        {
+            *m_data = std::string{ rhs };
+            return *this;
+        }
 
-auto ResourceAttributes::KeyValuePair::ValueVisitor::operator() (iterator* iter)
-        -> result_type {
-    return iter->m_cur->second;
-}
+        auto ResourceAttributes::Value::operator=(std::nullptr_t) -> Value&
+        {
+            *m_data = nullptr;
+            return *this;
+        }
 
-auto ResourceAttributes::KeyValuePair::ValueVisitor::operator() (const_iterator* iter)
-        -> result_type {
-    // should not reach here.
-    throw BadGetException("");
-}
+        bool ResourceAttributes::Value::operator==(const char* rhs) const
+        {
+            return equals< std::string >(rhs);
+        }
 
-auto ResourceAttributes::KeyValuePair::ConstValueVisitor::operator() (iterator*iter) const
-        -> result_type {
-    return iter->m_cur->second;
-}
+        std::string ResourceAttributes::Value::toString() const
+        {
+            return boost::apply_visitor(ToStringVisitor(), *m_data);
+        }
 
-auto ResourceAttributes::KeyValuePair::ConstValueVisitor::operator() (const_iterator* iter) const
-        -> result_type {
-    return iter->m_cur->second;
-}
+        auto ResourceAttributes::KeyValuePair::KeyVisitor::operator() (iterator* iter) const
+                -> result_type {
+            return iter->m_cur->first;
+        }
 
-auto ResourceAttributes::KeyValuePair::key() const -> const std::string&
-{
-    return boost::apply_visitor(m_keyVisitor, m_iterRef);
-}
+        auto ResourceAttributes::KeyValuePair::KeyVisitor::operator() (const_iterator* iter) const
+                -> result_type {
+            return iter->m_cur->first;
+        }
 
-auto ResourceAttributes::KeyValuePair::value() const -> const Value&
-{
-    return boost::apply_visitor(m_constValueVisitor, m_iterRef);
-}
+        auto ResourceAttributes::KeyValuePair::ValueVisitor::operator() (iterator* iter)
+                -> result_type {
+            return iter->m_cur->second;
+        }
 
-auto ResourceAttributes::KeyValuePair::value() -> Value&
-{
-    return boost::apply_visitor(m_valueVisitor, m_iterRef);
-}
+        auto ResourceAttributes::KeyValuePair::ValueVisitor::operator() (const_iterator* iter)
+                -> result_type {
+            // should not reach here.
+            throw BadGetException("");
+        }
 
+        auto ResourceAttributes::KeyValuePair::ConstValueVisitor::operator() (iterator*iter) const
+                -> result_type {
+            return iter->m_cur->second;
+        }
 
-ResourceAttributes::KeyValuePair::KeyValuePair(boost::variant<iterator*, const_iterator*>&& ref) :
-        m_iterRef{ ref }
-{
-}
+        auto ResourceAttributes::KeyValuePair::ConstValueVisitor::operator() (const_iterator* iter) const
+                -> result_type {
+            return iter->m_cur->second;
+        }
 
+        auto ResourceAttributes::KeyValuePair::key() const -> const std::string&
+        {
+            return boost::apply_visitor(m_keyVisitor, m_iterRef);
+        }
 
-ResourceAttributes::iterator::iterator() :
-        iterator{ base_iterator{} }
-{
-}
+        auto ResourceAttributes::KeyValuePair::value() const -> const Value&
+        {
+            return boost::apply_visitor(m_constValueVisitor, m_iterRef);
+        }
 
-ResourceAttributes::iterator::iterator(base_iterator&& iter) :
-        m_cur{ std::move(iter) },
-        m_keyValuePair{ this }
-{
-}
+        auto ResourceAttributes::KeyValuePair::value() -> Value&
+        {
+            return boost::apply_visitor(m_valueVisitor, m_iterRef);
+        }
 
-auto ResourceAttributes::iterator::operator*() -> KeyValuePair&
-{
-    return m_keyValuePair;
-}
 
-auto ResourceAttributes::iterator::iterator::operator->() -> KeyValuePair*
-{
-    return &m_keyValuePair;
-}
+        ResourceAttributes::KeyValuePair::KeyValuePair(boost::variant<iterator*, const_iterator*>&& ref) :
+                m_iterRef{ ref }
+        {
+        }
 
-auto ResourceAttributes::iterator::operator++() -> iterator&
-{
-    ++m_cur;
-    return *this;
-}
 
-auto ResourceAttributes::iterator::operator++(int) -> iterator
-{
-    iterator iter(*this);
-    ++(*this);
-    return iter;
-}
+        ResourceAttributes::iterator::iterator() :
+                iterator{ base_iterator{} }
+        {
+        }
 
-bool ResourceAttributes::iterator::operator==(const iterator& rhs) const
-{
-    return m_cur == rhs.m_cur;
-}
+        ResourceAttributes::iterator::iterator(base_iterator&& iter) :
+                m_cur{ std::move(iter) },
+                m_keyValuePair{ this }
+        {
+        }
 
-bool ResourceAttributes::iterator::operator!=(const iterator& rhs) const
-{
-    return !(*this == rhs);
-}
+        auto ResourceAttributes::iterator::operator*() -> KeyValuePair&
+        {
+            return m_keyValuePair;
+        }
 
+        auto ResourceAttributes::iterator::iterator::operator->() -> KeyValuePair*
+        {
+            return &m_keyValuePair;
+        }
 
-ResourceAttributes::const_iterator::const_iterator() :
-        const_iterator{ base_iterator{} }
-{
-}
+        auto ResourceAttributes::iterator::operator++() -> iterator&
+        {
+            ++m_cur;
+            return *this;
+        }
 
-ResourceAttributes::const_iterator::const_iterator(base_iterator&& iter) :
-        m_cur{ iter }, m_keyValuePair{ this }
-{
-}
+        auto ResourceAttributes::iterator::operator++(int) -> iterator
+        {
+            iterator iter(*this);
+            ++(*this);
+            return iter;
+        }
 
-ResourceAttributes::const_iterator::const_iterator(const ResourceAttributes::iterator& iter) :
-        m_cur{ iter.m_cur }, m_keyValuePair{ this }
-{
-}
+        bool ResourceAttributes::iterator::operator==(const iterator& rhs) const
+        {
+            return m_cur == rhs.m_cur;
+        }
 
-auto ResourceAttributes::const_iterator::operator=(const ResourceAttributes::iterator& iter) -> const_iterator& {
-    m_cur = iter.m_cur;
-    return *this;
-}
+        bool ResourceAttributes::iterator::operator!=(const iterator& rhs) const
+        {
+            return !(*this == rhs);
+        }
 
-auto ResourceAttributes::const_iterator::operator*() const -> reference
-{
-    return m_keyValuePair;
-}
-auto ResourceAttributes::const_iterator::operator->() const -> pointer
-{
-    return &m_keyValuePair;
-}
 
-auto ResourceAttributes::const_iterator::operator++() -> const_iterator&
-{
-    ++m_cur;
-    return *this;
-}
+        ResourceAttributes::const_iterator::const_iterator() :
+                const_iterator{ base_iterator{} }
+        {
+        }
 
-auto ResourceAttributes::const_iterator::operator++(int) -> const_iterator
-{
-    const_iterator iter(*this);
-    ++(*this);
-    return iter;
-}
+        ResourceAttributes::const_iterator::const_iterator(base_iterator&& iter) :
+                m_cur{ iter }, m_keyValuePair{ this }
+        {
+        }
 
-bool ResourceAttributes::const_iterator::operator==(const const_iterator& rhs) const
-{
-    return m_cur == rhs.m_cur;
-}
+        ResourceAttributes::const_iterator::const_iterator(const ResourceAttributes::iterator& iter) :
+                m_cur{ iter.m_cur }, m_keyValuePair{ this }
+        {
+        }
 
-bool ResourceAttributes::const_iterator::operator!=(const const_iterator& rhs) const
-{
-    return !(*this == rhs);
-}
+        auto ResourceAttributes::const_iterator::operator=(const ResourceAttributes::iterator& iter) -> const_iterator& {
+            m_cur = iter.m_cur;
+            return *this;
+        }
 
-auto ResourceAttributes::begin() -> iterator
-{
-    return iterator{ m_keyValues.begin() };
-}
+        auto ResourceAttributes::const_iterator::operator*() const -> reference
+        {
+            return m_keyValuePair;
+        }
+        auto ResourceAttributes::const_iterator::operator->() const -> pointer
+        {
+            return &m_keyValuePair;
+        }
 
-auto ResourceAttributes::end() -> iterator
-{
-    return iterator{ m_keyValues.end() };
-}
+        auto ResourceAttributes::const_iterator::operator++() -> const_iterator&
+        {
+            ++m_cur;
+            return *this;
+        }
 
-auto ResourceAttributes::begin() const -> const_iterator
-{
-    return const_iterator{ m_keyValues.begin() };
-}
+        auto ResourceAttributes::const_iterator::operator++(int) -> const_iterator
+        {
+            const_iterator iter(*this);
+            ++(*this);
+            return iter;
+        }
 
-auto ResourceAttributes::end() const -> const_iterator
-{
-    return const_iterator{ m_keyValues.end() };
-}
+        bool ResourceAttributes::const_iterator::operator==(const const_iterator& rhs) const
+        {
+            return m_cur == rhs.m_cur;
+        }
 
-auto ResourceAttributes::cbegin() const -> const_iterator
-{
-    return const_iterator{ m_keyValues.begin() };
-}
+        bool ResourceAttributes::const_iterator::operator!=(const const_iterator& rhs) const
+        {
+            return !(*this == rhs);
+        }
 
-auto ResourceAttributes::cend() const -> const_iterator
-{
-    return const_iterator{ m_keyValues.end() };
-}
+        auto ResourceAttributes::begin() -> iterator
+        {
+            return iterator{ m_keyValues.begin() };
+        }
 
-auto ResourceAttributes::operator[](const std::string& key) -> Value&
-{
-    return m_keyValues[key];
-}
+        auto ResourceAttributes::end() -> iterator
+        {
+            return iterator{ m_keyValues.end() };
+        }
 
-auto ResourceAttributes::at(const std::string& key) -> Value&
-{
-    try
-    {
-        return m_keyValues.at(key);
-    }
-    catch (const std::out_of_range&)
-    {
-        throw InvalidKeyException{ "No attribute named '" + key + "'" };
-    }
-}
+        auto ResourceAttributes::begin() const -> const_iterator
+        {
+            return const_iterator{ m_keyValues.begin() };
+        }
 
-auto ResourceAttributes::at(const std::string& key) const -> const Value&
-{
-    try
-    {
-        return m_keyValues.at(key);
-    }
-    catch (const std::out_of_range&)
-    {
-        throw InvalidKeyException{ "No attribute named '" + key + "'" };
-    }
-}
+        auto ResourceAttributes::end() const -> const_iterator
+        {
+            return const_iterator{ m_keyValues.end() };
+        }
 
-bool ResourceAttributes::erase(const std::string& key)
-{
-    return m_keyValues.erase(key) == 1U;
-}
+        auto ResourceAttributes::cbegin() const -> const_iterator
+        {
+            return const_iterator{ m_keyValues.begin() };
+        }
 
-bool ResourceAttributes::contains(const std::string& key) const
-{
-    return m_keyValues.find(key) != m_keyValues.end();
-}
+        auto ResourceAttributes::cend() const -> const_iterator
+        {
+            return const_iterator{ m_keyValues.end() };
+        }
 
-bool ResourceAttributes::empty() const
-{
-    return m_keyValues.empty();
-}
+        auto ResourceAttributes::operator[](const std::string& key) -> Value&
+        {
+            return m_keyValues[key];
+        }
+
+        auto ResourceAttributes::at(const std::string& key) -> Value&
+        {
+            try
+            {
+                return m_keyValues.at(key);
+            }
+            catch (const std::out_of_range&)
+            {
+                throw InvalidKeyException{ "No attribute named '" + key + "'" };
+            }
+        }
+
+        auto ResourceAttributes::at(const std::string& key) const -> const Value&
+        {
+            try
+            {
+                return m_keyValues.at(key);
+            }
+            catch (const std::out_of_range&)
+            {
+                throw InvalidKeyException{ "No attribute named '" + key + "'" };
+            }
+        }
+
+        bool ResourceAttributes::erase(const std::string& key)
+        {
+            return m_keyValues.erase(key) == 1U;
+        }
+
+        bool ResourceAttributes::contains(const std::string& key) const
+        {
+            return m_keyValues.find(key) != m_keyValues.end();
+        }
+
+        bool ResourceAttributes::empty() const
+        {
+            return m_keyValues.empty();
+        }
+
+        size_t ResourceAttributes::size() const
+        {
+            return m_keyValues.size();
+        }
 
-size_t ResourceAttributes::size() const
-{
-    return m_keyValues.size();
-}
 
-namespace OIC
-{
-    namespace Service
-    {
         bool acceptableAttributeValue(const ResourceAttributes::Value& dest,
                 const ResourceAttributes::Value& value)
         {
index 8387bd1..54dc022 100644 (file)
 
 #include <octypes.h>
 
-class ResourceAttributes;
-
 namespace OIC
 {
     namespace Service
     {
+        class ResourceAttributes;
+
         class RequestHandler;
 
         class PrimitiveGetResponse
index 6ae6275..1c22d31 100644 (file)
 
 namespace
 {
+    using namespace OIC::Service;
+
     namespace Detail
     {
         template <typename RESPONSE>
-        OCEntityHandlerResult sendResponse(OIC::Service::PrimitiveServerResource& resource,
+        OCEntityHandlerResult sendResponse(PrimitiveServerResource& resource,
                 std::shared_ptr< OC::OCResourceRequest > ocRequest,
                 const ResourceAttributes& requestAttrs, RESPONSE&& response)
         {
@@ -67,7 +69,7 @@ namespace
     }
 
     template< typename HANDLER, typename RESPONSE = typename std::decay<HANDLER>::type::result_type>
-    OCEntityHandlerResult handleRequest(OIC::Service::PrimitiveServerResource& resource,
+    OCEntityHandlerResult handleRequest(PrimitiveServerResource& resource,
             std::shared_ptr< OC::OCResourceRequest > ocRequest, HANDLER&& handler)
     {
         ResourceAttributes attrs{ ResourceAttributesConverter::fromOCRepresentation(
@@ -76,7 +78,7 @@ namespace
         if (handler)
         {
             return Detail::sendResponse(resource, ocRequest, attrs, handler(
-                    OIC::Service::PrimitiveRequest{ ocRequest->getResourceUri() }, attrs));
+                    PrimitiveRequest{ ocRequest->getResourceUri() }, attrs));
         }
 
         return Detail::sendResponse(resource, ocRequest, attrs, RESPONSE::defaultAction());