Add IPC sync result for SerialPort::Write()
[platform/framework/native/appfw.git] / inc / FBaseColIteratorT.h
index 67ad607..ffc9cf7 100644 (file)
@@ -40,8 +40,8 @@ namespace Tizen { namespace Base { namespace Collection
  *
  * @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.
@@ -49,9 +49,28 @@ 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 class.
         *
@@ -60,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
                        {
@@ -99,7 +116,6 @@ public:
                , __isPostEnd(rhs.__isPostEnd)
                , __index(rhs.__index)
                , __pEnum(__pList->GetBidirectionalEnumeratorN())
-               , __currentObj(rhs.__currentObj)
        {
                if (!__isPostEnd)
                {
@@ -136,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());
        }
 
        /**
@@ -149,7 +165,7 @@ public:
         *
         * @return              A T type pointer that is equivalent to the pointer address
         */
-       T* operator ->(void) const
+       pointer operator ->(void) const
        {
                return &(operator *());
        }
@@ -174,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;
@@ -223,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;
@@ -283,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();
        }
 
        /**
@@ -318,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