Add IPC sync result for SerialPort::Write()
[platform/framework/native/appfw.git] / inc / FBaseColIteratorT.h
index 9a0e3aa..ffc9cf7 100644 (file)
@@ -1,5 +1,4 @@
 //
-// Open Service Platform
 // Copyright (c) 2013 Samsung Electronics Co., Ltd.
 //
 // Licensed under the Apache License, Version 2.0 (the License);
@@ -25,7 +24,7 @@
 #ifndef _FBASE_COL_ITERATOR_T_H_
 #define _FBASE_COL_ITERATOR_T_H_
 
-#include <algorithm>   // std::swap (Before C++11)
+#include <algorithm>    // std::swap (Before C++11)
 #include <iterator>
 #include <unique_ptr.h>
 #include <FBaseLog.h>
@@ -36,20 +35,42 @@ namespace Tizen { namespace Base { namespace Collection
 {
 /**
  * @class      IteratorT
- * @brief      This class provides an iterator that is used to convert IList to STL containers.
- *                     StlConverter provides static methods to get this iterator from IList.
+ * @brief      This class provides an iterator that is used to convert %IList to STL containers. @n
+ *                     %StlConverter provides static methods to get this iterator from %IList.
  *
  * @since      2.1
  *
- * @remarks    The %IteratorT class satisfies only requirements of C++ standard library InputIterator concept due to limitations of %Tizen Collection.
- *                     So, this class can be used with C++ standard library algorithms which requires only InputIterator concept for their arguments.
+ * @remarks    The %IteratorT class satisfies requirements of the C++ standard library mutable BidirectionalIterator.
+ *                     It satisfies the requirements of an OutputIterator which can be dereferenced as an lvalue.
+ *
+ * The %IteratorT class provides an iterator that is used to convert IList to STL containers.
+ * StlConverter provides static methods to get this iterator from IList.
  */
 
-template < typename T >
+template< typename T >
 class IteratorT
-       : public std::iterator< std::input_iterator_tag, T >
+       : public std::iterator< std::bidirectional_iterator_tag, T >
 {
 public:
+       typedef std::bidirectional_iterator_tag iterator_category;
+       typedef typename std::iterator_traits< IteratorT< T > >::value_type value_type;
+       typedef typename std::iterator_traits< IteratorT< T > >::difference_type difference_type;
+       typedef typename std::iterator_traits< IteratorT< T > >::pointer pointer;
+       typedef typename std::iterator_traits< IteratorT< T > >::reference reference;
+
+       /**
+        * This is the default constructor for this class.
+        *
+        * @since               3.0
+        */
+       IteratorT(void)
+               : __pList(null)
+               , __isPostEnd(false)
+               , __index(0)
+               , __pEnum(null)
+       {
+       }
+
        /**
         * Initializes an instance of %IteratorT class.
         *
@@ -58,19 +79,17 @@ public:
         * @param[in]   list             A reference to the IList instance to convert
         * @param[in]   isPostEnd        A boolean value to check the end of a list
         */
-       explicit IteratorT(const IList& list, bool isPostEnd = false)
+       explicit IteratorT(IList& list, bool isPostEnd = false)
                : __pList(&list)
                , __isPostEnd(isPostEnd)
                , __index(0)
                , __pEnum(__pList->GetBidirectionalEnumeratorN())
-               , __currentObj(null)
        {
                if (__pList->GetCount() != 0)
                {
                        if (!__isPostEnd)
                        {
                                __pEnum->MoveNext();
-                               __currentObj = static_cast< T >(__pEnum->GetCurrent());
                        }
                        else
                        {
@@ -97,7 +116,6 @@ public:
                , __isPostEnd(rhs.__isPostEnd)
                , __index(rhs.__index)
                , __pEnum(__pList->GetBidirectionalEnumeratorN())
-               , __currentObj(rhs.__currentObj)
        {
                if (!__isPostEnd)
                {
@@ -120,7 +138,7 @@ public:
         * @return              A reference to the %IteratorT instance
         * @param[in]   rhs     A reference to the %IteratorT instance on the right-hand side of the operator
         */
-       IteratorT< T >& operator=(const IteratorT< T >& rhs)
+       IteratorT< T >& operator =(const IteratorT< T >& rhs)
        {
                IteratorT< T > tmp(rhs);
                tmp.swap(*this);
@@ -134,10 +152,10 @@ public:
         *
         * @return              A T type reference
         */
-       T& operator*(void) const
+       reference operator *(void) const
        {
                AppAssertf(!__isPostEnd && __index >= 0, "It is out of range.");
-               return const_cast< T& >(__currentObj);
+               return reinterpret_cast< T& >(__pEnum->GetCurrentRef());
        }
 
        /**
@@ -147,9 +165,9 @@ public:
         *
         * @return              A T type pointer that is equivalent to the pointer address
         */
-       T* operator->(void) const
+       pointer operator ->(void) const
        {
-               return &(operator*());
+               return &(operator *());
        }
 
        /**
@@ -164,7 +182,7 @@ public:
         *                                                                      the collection is modified after the enumerator is created.
         * @remarks             The specific error code can be accessed using GetLastResult() method.
         */
-       IteratorT< T >& operator++(void)
+       IteratorT< T >& operator ++(void)
        {
                const int PRE_BEGIN_IDX = -1;
                TryCatchResult(__index >= PRE_BEGIN_IDX, , E_OUT_OF_RANGE, "[%s] It is out of range.", GetErrorMessage(E_OUT_OF_RANGE));
@@ -172,12 +190,10 @@ public:
                if (__index != PRE_BEGIN_IDX)
                {
                        result r = __pEnum->MoveNext();
-                       TryCatchResult(r == E_SUCCESS, __isPostEnd = true; __currentObj = null, r, "[%s] It already reached the end.", GetErrorMessage(r));
+                       TryCatchResult(r == E_SUCCESS, __isPostEnd = true, r, "[%s] It already reached the end.", GetErrorMessage(r));
                }
 
-               __currentObj = static_cast< T >(__pEnum->GetCurrent());
-
-       CATCH:
+CATCH:
                ++__index;
                return *this;
        }
@@ -194,10 +210,10 @@ public:
         *                                                                      the collection is modified after the enumerator is created.
         * @remarks             The specific error code can be accessed using GetLastResult() method.
         */
-       IteratorT< T > operator++(int)
+       IteratorT< T > operator ++(int)
        {
                IteratorT< T > tempIter = *this;
-               operator++();
+               operator ++();
                return tempIter;
        }
 
@@ -213,22 +229,20 @@ public:
         *                                                                      the collection is modified after the enumerator is created.
         * @remarks             The specific error code can be accessed using GetLastResult() method.
         */
-       IteratorT< T >& operator--(void)
+       IteratorT< T >& operator --(void)
        {
                TryCatchResult(__index <= __pList->GetCount(), , E_OUT_OF_RANGE, "[%s] It is out of range.", GetErrorMessage(E_OUT_OF_RANGE));
 
                if (!__isPostEnd)
                {
                        result r = __pEnum->MovePrevious();
-                       TryCatchResult(r == E_SUCCESS, __currentObj = null, r, "[%s] It already reached the front.", GetErrorMessage(r));
+                       TryCatchResult(r == E_SUCCESS, , r, "[%s] It already reached the front.", GetErrorMessage(r));
                }
                else
                {
                        __isPostEnd = false;
                }
 
-               __currentObj = static_cast< T >(__pEnum->GetCurrent());
-
 CATCH:
                --__index;
                return *this;
@@ -246,10 +260,10 @@ CATCH:
         *                                                                      the collection is modified after the enumerator is created.
         * @remarks             The specific error code can be accessed using GetLastResult() method.
         */
-       IteratorT< T > operator--(int)
+       IteratorT< T > operator --(int)
        {
                IteratorT< T > tempIter = *this;
-               operator--();
+               operator --();
                return tempIter;
        }
 
@@ -262,7 +276,7 @@ CATCH:
         *                              else @c false
         *      @param[in]      rhs     A reference to the %IteratorT instance on the right-hand side of the operator
         */
-       bool operator==(const IteratorT< T >& rhs) const
+       bool operator ==(const IteratorT< T >& rhs) const
        {
                if (__pList != rhs.__pList)
                {
@@ -280,12 +294,12 @@ CATCH:
                }
                else if (__isPostEnd && rhs.__isPostEnd)
                {
-                       // In this case, __currentObj state is invalid
+                       // In this case, the current object which the iterator refers to is invalid.
                        return true;
                }
 
                // If both this->__isPostEnd and rhs.__isPostEnd are false, then reach here. This means both iterators are in the middle of the list.
-               return __currentObj == rhs.__currentObj;
+               return __pEnum->GetCurrentRef() == rhs.__pEnum->GetCurrentRef();
        }
 
        /**
@@ -297,9 +311,9 @@ CATCH:
         *                              else @c false
         *      @param[in]      rhs     A reference to the %IteratorT instance on the right-hand side of the operator
         */
-       bool operator!=(const IteratorT< T >& rhs) const
+       bool operator !=(const IteratorT< T >& rhs) const
        {
-               return !operator==(rhs);
+               return !operator ==(rhs);
        }
 
        /**
@@ -315,17 +329,15 @@ CATCH:
                std::swap(__isPostEnd, rhs.__isPostEnd);
                std::swap(__index, rhs.__index);
                std::swap(__pEnum, rhs.__pEnum);
-               std::swap(__currentObj, rhs.__currentObj);
        }
 
 private:
-       const IList* __pList;
+       IList* __pList;
        bool __isPostEnd;
-       int __index;
+       difference_type __index;
        std::unique_ptr< IBidirectionalEnumerator > __pEnum;
-       T __currentObj;
 }; // IteratorT
 
 }}} // Tizen::Base::Collection
 
-#endif //_FBASE_COL_ITERATOR_T_H_
+#endif //_FBASE_COL_ITERATOR_T_H_
\ No newline at end of file