Add IPC sync result for SerialPort::Write()
[platform/framework/native/appfw.git] / inc / FBaseColIteratorT.h
index b380468..ffc9cf7 100644 (file)
@@ -36,12 +36,12 @@ namespace Tizen { namespace Base { namespace Collection
 /**
  * @class      IteratorT
  * @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.
+ *                     %StlConverter provides static methods to get this iterator from %IList.
  *
  * @since      2.1
  *
- * @remarks  The %IteratorT class satisfies only the requirements of the C++ standard library InputIterator concept due to limitations of the %Tizen collection. @n
- *                        This class can be used with the C++ standard library algorithms which require only the 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.
@@ -49,30 +49,47 @@ namespace Tizen { namespace Base { namespace Collection
 
 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.
+        * Initializes an instance of %IteratorT class.
         *
         * @since               2.1
         *
         * @param[in]   list             A reference to the IList instance to convert
-        * @param[in]   isPostEnd        The boolean value that checks the end of the list
+        * @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
                        {
@@ -99,7 +116,6 @@ public:
                , __isPostEnd(rhs.__isPostEnd)
                , __index(rhs.__index)
                , __pEnum(__pList->GetBidirectionalEnumeratorN())
-               , __currentObj(rhs.__currentObj)
        {
                if (!__isPostEnd)
                {
@@ -115,7 +131,7 @@ public:
        }
 
        /**
-        * This is the assignment operator of the %IteratorT class.
+        * This is an assignment operator of the %IteratorT class.
         *
         * @since               2.1
         *
@@ -130,26 +146,26 @@ public:
        }
 
        /**
-        * This is the indirection operator of the %IteratorT class.
+        * This is the indirection operator for the %IteratorT class.
         *
         * @since       2.1
         *
         * @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());
        }
 
        /**
-        * This is the structure dereference operator of the %IteratorT class.
+        * This is a structure dereference operator for the %IteratorT class.
         *
         * @since       2.1
         *
         * @return              A T type pointer that is equivalent to the pointer address
         */
-       T* operator ->(void) const
+       pointer operator ->(void) const
        {
                return &(operator *());
        }
@@ -162,9 +178,8 @@ public:
         * @return              A reference to the %IteratorT type instance
         * @exception   E_SUCCESS                       The method is successful.
         * @exception   E_OUT_OF_RANGE          The iterator is outside the bounds of the list.
-        * @exception   E_INVALID_OPERATION     Either of the following conditions has occurred:
-        *                                                                      - The current state of the instance prohibits the execution of the specified operation.
-        *                                                                      - The collection is modified after the enumerator is created.
+        * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified operation, or
+        *                                                                      the collection is modified after the enumerator is created.
         * @remarks             The specific error code can be accessed using GetLastResult() method.
         */
        IteratorT< T >& operator ++(void)
@@ -175,12 +190,9 @@ 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:
                ++__index;
                return *this;
@@ -194,9 +206,8 @@ CATCH:
         * @return              An %IteratorT instance
         * @exception   E_SUCCESS                       The method is successful.
         * @exception   E_OUT_OF_RANGE          The iterator is outside the bounds of the list.
-        * @exception   E_INVALID_OPERATION     Either of the following conditions has occurred:
-        *                                                                      - The current state of the instance prohibits the execution of the specified operation.
-        *                                                                      - The collection is modified after the enumerator is created.
+        * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified operation, or
+        *                                                                      the collection is modified after the enumerator is created.
         * @remarks             The specific error code can be accessed using GetLastResult() method.
         */
        IteratorT< T > operator ++(int)
@@ -214,9 +225,8 @@ CATCH:
         * @return              A reference to the %IteratorT type instance
         * @exception   E_SUCCESS                       The method is successful.
         * @exception   E_OUT_OF_RANGE          The iterator is outside the bounds of the list.
-        * @exception   E_INVALID_OPERATION     Either of the following conditions has occurred:
-        *                                                                      - The current state of the instance prohibits the execution of the specified operation.
-        *                                                                      - The collection is modified after the enumerator is created.
+        * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified operation, or
+        *                                                                      the collection is modified after the enumerator is created.
         * @remarks             The specific error code can be accessed using GetLastResult() method.
         */
        IteratorT< T >& operator --(void)
@@ -226,15 +236,13 @@ CATCH:
                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;
@@ -248,9 +256,8 @@ CATCH:
         * @return              An %IteratorT instance
         * @exception   E_SUCCESS                       The method is successful.
         * @exception   E_OUT_OF_RANGE          The iterator is outside the bounds of the list.
-        * @exception   E_INVALID_OPERATION     Either of the following conditions has occurred:
-        *                                                                      - The current state of the instance prohibits the execution of the specified operation.
-        *                                                                      - The collection is modified after the enumerator is created.
+        * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified operation, or
+        *                                                                      the collection is modified after the enumerator is created.
         * @remarks             The specific error code can be accessed using GetLastResult() method.
         */
        IteratorT< T > operator --(int)
@@ -287,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();
        }
 
        /**
@@ -322,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