[3.0][ACR]Modify IteratorT/RandomIteratorT/PairIteratorT to satisfy the reqirements...
authordahyeong.kim <dahyeong.kim@samsung.com>
Fri, 30 Aug 2013 07:40:54 +0000 (16:40 +0900)
committerdahyeong.kim <dahyeong.kim@samsung.com>
Mon, 23 Sep 2013 12:53:17 +0000 (21:53 +0900)
Change-Id: Iaf577f040be75d6f949450869ac865e1feade5a5
Signed-off-by: dahyeong.kim <dahyeong.kim@samsung.com>
12 files changed:
inc/FBaseColArrayList.h
inc/FBaseColIEnumerator.h
inc/FBaseColIList.h
inc/FBaseColIteratorT.h
inc/FBaseColLinkedList.h
inc/FBaseColPairIteratorT.h
inc/FBaseColRandomIteratorT.h
inc/FBaseColStlConverter.h
inc/FBaseObject.h
src/base/FBaseObject.cpp
src/base/collection/FBaseColArrayList.cpp
src/base/collection/FBaseColLinkedList.cpp

index a789693..6b5ec78 100644 (file)
@@ -260,6 +260,20 @@ public:
        virtual Object* GetAt(int index);
 
        /**
+        * Gets the reference of the object at the specified @c index of this list.
+        *
+        * @since               3.0
+        *
+        * @return              The reference of the object at the specified @c index of this list
+        * @param[in]           index   The index of the object to read
+        * @exception   E_SUCCESS                               The method is successful.
+        * @exception   E_OUT_OF_RANGE                  The specified @c index is outside the bounds of the data structure, or
+        *                                                                              the specified @c index is either equal to or greater than the number of elements or less than @c 0.
+        * @remarks             The specific error code can be accessed using the GetLastResult() method.
+        */
+       virtual Object*& GetAtRef(int index);
+
+       /**
         * Gets the IList within the specified range of this list.
         *
         * @since 2.0
index 24c363b..e917dd5 100644 (file)
 #define _FBASE_COL_IENUMERATOR_H_
 
 #include <FBaseTypes.h>
-
-namespace Tizen {namespace Base
-{
-class Object;
-}}
+#include <FBaseObject.h>
 
 namespace Tizen { namespace Base { namespace Collection
 {
@@ -107,6 +103,26 @@ public:
         */
        virtual result Reset(void) = 0;
 
+       /**
+        * Gets the reference of the current object in the collection
+        *
+        * @since               3.0
+        *
+        * @return              The reference of the pointer to the current object in the collection
+        * @exception   E_SUCCESS                       The method is successful.
+        * @exception   E_INVALID_OPERATION     Either of the following conditions has occurred: @n
+        *                                                                      - The current state of the instance prohibits the execution of the specified operation. @n
+        *                                                                      - The enumerator is currently positioned before the first element
+        *                                                                      or after the last element. @n
+        *                                                                      - The collection is modified after the enumerator is created.
+        * @remarks             The specific error code can be accessed using the GetLastResult() method.
+        * @see                 GetLastResult()
+        */
+       virtual Tizen::Base::Object*& GetCurrentRef(void) const
+       {
+               return Tizen::Base::Object::pNullObj;
+       }
+
 protected:
        //
        // This method is for internal use only. Using this method can cause behavioral, security-related,
@@ -117,16 +133,6 @@ protected:
        //
        virtual void IEnumerator_Reserved1(void) { }
 
-
-       //
-       // This method is for internal use only. Using this method can cause behavioral, security-related,
-       // and consistency-related issues in the application.
-       // This method is reserved and may change its name at any time without prior notice.
-       //
-       // @since 2.0
-       //
-       virtual void IEnumerator_Reserved2(void) { }
-
 }; // IEnumerator
 
 }}} // Tizen::Base::Collection
index 21811c1..a2174b1 100644 (file)
@@ -794,6 +794,23 @@ public:
         */
        virtual DeleterFunctionType GetDeleter(void) const = 0;
 
+       /**
+        * Gets the reference of the object at the specified location.
+        *
+        * @since               3.0
+        *
+        * @return              The reference of the object at the specified location
+        * @param[in]           index                                   The index of the object to get
+        * @exception   E_SUCCESS                               The method is successful.
+        * @exception   E_OUT_OF_RANGE                  The specified index is outside the bounds of the data structure, or
+        *                                                                              the specified @c index is either equal to or greater than the number of elements in the list or less than @c 0.
+        * @remarks             The specific error code can be accessed using the GetLastResult() method.
+        */
+       virtual Object*& GetAtRef(int index)
+       {
+               return Object::pNullObj;
+       }
+
 protected:
        //
        // This method is for internal use only. Using this method can cause behavioral, security-related,
@@ -804,15 +821,6 @@ protected:
        //
        virtual void IList_Reserved1(void) {}
 
-       //
-       // This method is for internal use only. Using this method can cause behavioral, security-related,
-       // and consistency-related issues in the application.
-       // This method is reserved and may change its name at any time without prior notice.
-       //
-       // @since 2.0
-       //
-       virtual void IList_Reserved2(void) {}
-
 private:
        /**
         * Sets the element deleter of the collection.
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
index 32afbd5..cdeed37 100644 (file)
@@ -212,6 +212,20 @@ public:
        virtual Object* GetAt(int index);
 
        /**
+        * Gets the reference of the object at the specified index of the calling list.
+        *
+        * @since               3.0
+        *
+        * @return              The reference of the object at the specified index of the list
+        * @param[in]           index                                   The index of the object to read
+        * @exception   E_SUCCESS                               The method is successful.
+        * @exception   E_OUT_OF_RANGE                  The specified index is outside the bounds of the data structure, or
+        *                                                                              the specified @c index is equal to or greater than the number of elements or less than @c 0.
+        * @remarks             The specific error code can be accessed using the GetLastResult() method.
+        */
+       virtual Object*& GetAtRef(int index);
+
+       /**
         * Gets an IList with the specified range from the calling list object.
         *
         * @since 2.0
index 037fa3e..eabc784 100644 (file)
@@ -42,8 +42,8 @@ namespace Tizen { namespace Base { namespace Collection
  *
  * @since      2.1
  *
- * @remarks    The %PairIteratorT 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 %PairIteratorT class satisfies requirements of C++ standard library ForwardIterator which is not mutable.
+ *                     It does not satisfy the requirements of an OutputIterator which can be dereferenced as an lvalue.
  *
  * The %PairIteratorT class provides an iterator that is used to convert IMap or IMultiMap to STL containers.
  * StlConverter provides static methods to get this iterator from IMap or IMultiMap.
@@ -51,9 +51,30 @@ namespace Tizen { namespace Base { namespace Collection
 
 template< typename K, typename V >
 class PairIteratorT
-       : public std::iterator< std::input_iterator_tag, std::pair< K, V > >
+       : public std::iterator< std::forward_iterator_tag, std::pair< K, V > >
 {
 public:
+       typedef std::forward_iterator_tag iterator_category;
+       typedef typename std::iterator_traits< PairIteratorT< K, V > >::value_type value_type;
+       typedef typename std::iterator_traits< PairIteratorT< K, V > >::difference_type difference_type;
+       typedef typename std::iterator_traits< PairIteratorT< K, V > >::pointer pointer;
+       typedef typename std::iterator_traits< PairIteratorT< K, V > >::reference reference;
+
+       /**
+        * This is the default constructor for this class.
+        *
+        * @since               3.0
+        */
+       PairIteratorT(void)
+               : __pMap(null)
+               , __pMultiMap(null)
+               , __isPostEnd(false)
+               , __index(0)
+               , __pEnum(null)
+               , __currentObj(null)
+       {
+       }
+
        /**
         * Initializes this instance of %PairIteratorT class.
         *
@@ -192,20 +213,20 @@ public:
         *
         * @return              A std::pair type reference with K and V type
         */
-       std::pair< K, V >& operator *(void) const
+       reference operator *(void) const
        {
                AppAssertf(!__isPostEnd, "It is out of range.");
                return const_cast< std::pair< K, V >& >(__currentObj);
        }
 
        /**
-        * This is the const version structure dereference operator for the %PairIteratorT class.
+        * This is the structure dereference operator for the %PairIteratorT class.
         *
         * @since               2.1
         *
         * @return              A std::pair type pointer equivalent to the pointer address
         */
-       std::pair< K, V >* operator ->(void) const
+       pointer operator ->(void) const
        {
                return &(operator *());
        }
@@ -334,9 +355,9 @@ private:
        const IMap* __pMap;
        const IMultiMap* __pMultiMap;
        bool __isPostEnd;
-       int __index;
+       difference_type __index;
        std::unique_ptr< IMapEnumerator > __pEnum;
-       std::pair< K, V > __currentObj;
+       value_type __currentObj;
 };  // PairIteratorT
 
 }}} // Tizen::Base::Collection
index cdfae6d..49cb2e4 100644 (file)
@@ -39,8 +39,8 @@ namespace Tizen { namespace Base { namespace Collection
  *
  * @since      2.1
  *
- * @remarks    The %RandomIteratorT 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 %RandomIteratorT class satisfies requirements of the C++ standard library mutable RandomAccessIterator.
+ *                     It satisfies the requirements of an OutputIterator which can be dereferenced as an lvalue.
  *
  * The %RandomIteratorT class provides a random iterator that is used to convert IList to STL containers.
  * StlConverter provides static methods to get this random iterator from IList.
@@ -48,9 +48,26 @@ namespace Tizen { namespace Base { namespace Collection
 
 template< typename T >
 class RandomIteratorT
-       : public std::iterator< std::input_iterator_tag, T >
+       : public std::iterator< std::random_access_iterator_tag, T >
 {
 public:
+       typedef std::random_access_iterator_tag iterator_category;
+       typedef typename std::iterator_traits< RandomIteratorT< T > >::value_type value_type;
+       typedef typename std::iterator_traits< RandomIteratorT< T > >::difference_type difference_type;
+       typedef typename std::iterator_traits< RandomIteratorT< T > >::pointer pointer;
+       typedef typename std::iterator_traits< RandomIteratorT< T > >::reference reference;
+
+       /**
+        * This is the default constructor for this class.
+        *
+        * @since               3.0
+        */
+       RandomIteratorT(void)
+               : __pList(null)
+               , __index(0)
+       {
+       }
+
        /**
         * Initializes this instance of %RandomIteratorT class.
         *
@@ -61,10 +78,9 @@ public:
         * @remarks             %RandomIteratorT only supports random accessible collection for performance.
         * @see                 Tizen::Base::Collection::IList::IsRandomAccessible()
         */
-       explicit RandomIteratorT(const IList& list, int index = 0)
+       explicit RandomIteratorT(IList& list, difference_type index = 0)
                : __pList(&list)
                , __index(index)
-               , __currentObj(static_cast< T >(const_cast< Object* >(__pList->GetAt(__index))))
        {
                AppAssertf(list.IsRandomAccessible(), "The list is not randomly accessible. RandomIteratorT only supports random accessible collection.");
        }
@@ -79,7 +95,6 @@ public:
        RandomIteratorT(const RandomIteratorT< T >& rhs)
                : __pList(rhs.__pList)
                , __index(rhs.__index)
-               , __currentObj(rhs.__currentObj)
        {
        }
 
@@ -105,10 +120,10 @@ public:
         *
         * @return              A T type reference
         */
-       T& operator *(void) const
+       reference operator *(void) const
        {
                AppAssertf(__index >= 0 && __index < __pList->GetCount(), "It is out of range.");
-               return const_cast< T& >(__currentObj);
+               return reinterpret_cast< T& >(__pList->GetAtRef(__index));
        }
 
        /**
@@ -118,41 +133,37 @@ public:
         *
         * @return              A T type pointer equivalent to the pointer address
         */
-       T* operator ->(void) const
+       pointer operator ->(void) const
        {
                return &(operator *());
        }
 
        /**
-        * Increases __index by 1.
+        * Moves to the next element in the collection.
         *
         * @since               2.1
         *
         * @return              A reference to the %RandomIteratorT instance
         * @exception   E_SUCCESS                       The method is successful.
-        * @exception   E_OUT_OF_RANGE          The specified index is outside the bounds of the data structure,
-        *                                                                      or the specified index is either equal to or greater than the number of elements in the list or less than 0.
+        * @exception   E_OUT_OF_RANGE          The position of the iterator is outside the bounds of the list.
         * @remarks             The specific error code can be accessed using GetLastResult() method.
         */
        RandomIteratorT< T >& operator ++(void)
        {
+               ClearLastResult();
                ++__index;
-
-               // GetAt() will return null if __index is out of range.
-               __currentObj = static_cast< T >(const_cast< Object* >(__pList->GetAt(__index)));
-               TryReturnResult(__currentObj != null, *this, GetLastResult(), "[%s] It is out of range.", GetErrorMessage(GetLastResult()));
+               TryReturnResult(__index >= 0 && __index < __pList->GetCount(), *this, E_OUT_OF_RANGE, "[%s] It is out of range.", GetErrorMessage(E_OUT_OF_RANGE));
                return *this;
        }
 
        /**
-        * Increases __index by 1 and returns the previous state.
+        * Moves to the next element in the collection and returns the previous state.
         *
         * @since               2.1
         *
         * @return              A %RandomIteratorT instance
         * @exception   E_SUCCESS                       The method is successful.
-        * @exception   E_OUT_OF_RANGE          The specified index is outside the bounds of the data structure,
-        *                                                                      or the specified index is either equal to or greater than the number of elements in the list or less than 0.
+        * @exception   E_OUT_OF_RANGE          The position of the iterator is outside the bounds of the list.
         * @remarks             The specific error code can be accessed using GetLastResult() method.
         */
        RandomIteratorT< T > operator ++(int)
@@ -163,35 +174,31 @@ public:
        }
 
        /**
-        * Decrease __index by 1.
+        * Moves to the previous element of the collection.
         *
         * @since               2.1
         *
         * @return              A reference to the %RandomIteratorT instance
         * @exception   E_SUCCESS                       The method is successful.
-        * @exception   E_OUT_OF_RANGE          The specified index is outside the bounds of the data structure,
-        *                                                                      or the specified index is either equal to or greater than the number of elements in the list or less than 0.
+        * @exception   E_OUT_OF_RANGE          The position of the iterator is outside the bounds of the list.
         * @remarks             The specific error code can be accessed using GetLastResult() method.
         */
        RandomIteratorT< T >& operator --(void)
        {
+               ClearLastResult();
                --__index;
-
-               // GetAt() will return null if __index is out of range.
-               __currentObj = static_cast< T >(const_cast< Object* >(__pList->GetAt(__index)));
-               TryReturnResult(__currentObj != null, *this, GetLastResult(), "[%s] It is out of range.", GetErrorMessage(GetLastResult()));
+               TryReturnResult(__index >= 0 && __index < __pList->GetCount(), *this, E_OUT_OF_RANGE, "[%s] It is out of range.", GetErrorMessage(E_OUT_OF_RANGE));
                return *this;
        }
 
        /**
-        * Decrease __index by 1 and returns the previous state.
+        * Moves to the previous element of the collection and returns the previous state.
         *
         * @since               2.1
         *
         * @return              A %RandomIteratorT instance
         * @exception   E_SUCCESS                       The method is successful.
-        * @exception   E_OUT_OF_RANGE          The specified index is outside the bounds of the data structure,
-        *                                                                      or the specified index is either equal to or greater than the number of elements in the list or less than 0.
+        * @exception   E_OUT_OF_RANGE          The position of the iterator is outside the bounds of the list.
         * @remarks             The specific error code can be accessed using GetLastResult() method.
         */
        RandomIteratorT< T > operator --(int)
@@ -206,13 +213,13 @@ public:
         *
         *      @since          2.1
         *
-        *      @return         @c true if every member of the specified %RandomIteratorT instance equals the calling instance's members, @n
+        *      @return         @c true if every member of the specified %RandomIteratorT instance equals the current instance's members, @n
         *                              else @c false
         *      @param[in]      rhs     A reference to the %RandomIteratorT instance on the right-hand side of the operator
         */
        bool operator ==(const RandomIteratorT< T >& rhs) const
        {
-               return ((__pList == rhs.__pList) && (__index == rhs.__index) && (__currentObj == rhs.__currentObj));
+               return ((__pList == rhs.__pList) && (__index == rhs.__index));
        }
 
        /**
@@ -220,7 +227,7 @@ public:
         *
         *      @since          2.1
         *
-        *      @return         @c true if any member of the specified %RandomIteratorT instance is not equal to the calling instance's members, @n
+        *      @return         @c true if any member of the specified %RandomIteratorT instance is not equal to the current instance's members, @n
         *                              else @c false
         *      @param[in]      rhs     A reference to the %RandomIteratorT instance on the right-hand side of the operator
         */
@@ -230,11 +237,11 @@ public:
        }
 
        /**
-        *  Checks l-value is less than r-value.
+        *  Checks whether l-value is less than r-value.
         *
         *      @since          2.1
         *
-        *      @return         @c true if l-value of the specified %RandomIteratorT instance is less than the calling instance's members, @n
+        *      @return         @c true if the current instance is less than the specified %RandomIteratorT instance @n
         *                              else @c false
         *      @param[in]      rhs     A reference to the %RandomIteratorT instance on the right-hand side of the operator
         */
@@ -248,7 +255,7 @@ public:
         *
         *      @since          2.1
         *
-        *      @return         @c true if l-value of the specified %RandomIteratorT instance is greater than the calling instance's members, @n
+        *      @return         @c true if if the current instance is greater than the specified %RandomIteratorT instance @n
         *                              else @c false
         *      @param[in]      rhs     A reference to the %RandomIteratorT instance on the right-hand side of the operator
         */
@@ -258,52 +265,120 @@ public:
        }
 
        /**
-        * Increases __index as specified by the diff parameter.
+        *  Checks whether l-value is less than or equal to r-value.
+        *
+        *      @since          3.0
+        *
+        *      @return         @c true if the current instance is less than or equal to the specified %RandomIteratorT instance @n
+        *                              else @c false
+        *      @param[in]      rhs     A reference to the %RandomIteratorT instance on the right-hand side of the operator
+        */
+       bool operator <=(const RandomIteratorT< T >& rhs) const
+       {
+               return __index <= rhs.__index;
+       }
+
+       /**
+        *      Checks whether l-value is greater than or equal to r-value.
+        *
+        *      @since          3.0
+        *
+        *      @return         @c true if the current instance is greater than or equal to the specified %RandomIteratorT instance @n
+        *                              else @c false
+        *      @param[in]      rhs     A reference to the %RandomIteratorT instance on the right-hand side of the operator
+        */
+       bool operator >=(const RandomIteratorT< T >& rhs) const
+       {
+               return __index >= rhs.__index;
+       }
+
+       /**
+        * Gets the %RandomIteratorT instance which moves forward as much as specified @c diff parameter.
         *
         * @since               2.1
         *
         * @return              A %RandomIteratorT instance
         * @param[in]   diff                            The length to move forward
         * @exception   E_SUCCESS                       The method is successful.
-        * @exception   E_OUT_OF_RANGE          The specified index is outside the bounds of the data structure,
-        *                                                                      or the specified index is either equal to or greater than the number of elements in the list or less than 0.
+        * @exception   E_OUT_OF_RANGE          The position of the iterator is outside the bounds of the list.
         * @remarks             The specific error code can be accessed using GetLastResult() method.
         */
-       RandomIteratorT< T > operator +(int diff)
+       RandomIteratorT< T > operator +(difference_type diff)
        {
+               ClearLastResult();
                RandomIteratorT< T > tempIter = *this;
                tempIter.__index += diff;
-
-               // GetAt() will return null if __index is out of range.
-               tempIter.__currentObj = static_cast< T >(const_cast< Object* >(tempIter.__pList->GetAt(tempIter.__index)));
-               TryReturnResult(tempIter.__currentObj != null, tempIter, GetLastResult(), "[%s] It is out of range.", GetErrorMessage(GetLastResult()));
+               TryReturnResult(tempIter.__index >= 0 && tempIter.__index < __pList->GetCount(), tempIter, E_OUT_OF_RANGE, "[%s] It is out of range.", GetErrorMessage(E_OUT_OF_RANGE));
                return tempIter;
        }
 
        /**
-        * Decrease __index as specified by the diff parameter.
+        * Gets the %RandomIteratorT instance which moves backward as much as specified @c diff parameter.
         *
         * @since               2.1
         *
         * @return              A %RandomIteratorT instance
         * @param[in]   diff                            The length to move backward
         * @exception   E_SUCCESS                       The method is successful.
-        * @exception   E_OUT_OF_RANGE          The specified index is outside the bounds of the data structure,
-        *                                                                      or the specified index is either equal to or greater than the number of elements in the list or less than 0.
+        * @exception   E_OUT_OF_RANGE          The position of the iterator is outside the bounds of the list.
         * @remarks             The specific error code can be accessed using GetLastResult() method.
         */
-       RandomIteratorT< T > operator -(int diff)
+       RandomIteratorT< T > operator -(difference_type diff)
        {
+               ClearLastResult();
                RandomIteratorT< T > tempIter = *this;
                tempIter.__index -= diff;
-
-               // GetAt() will return null if __index is out of range.
-               tempIter.__currentObj = static_cast< T >(const_cast< Object* >(tempIter.__pList->GetAt(tempIter.__index)));
-               TryReturnResult(tempIter.__currentObj != null, tempIter, GetLastResult(), "[%s] It is out of range.", GetErrorMessage(GetLastResult()));
+               TryReturnResult(tempIter.__index >= 0 && tempIter.__index < __pList->GetCount(), tempIter, E_OUT_OF_RANGE, "[%s] It is out of range.", GetErrorMessage(E_OUT_OF_RANGE));
                return tempIter;
        }
 
-       int operator -(const RandomIteratorT< T >& rhs)
+       /**
+        * Moves forward as much as specified @c diff parameter.
+        *
+        * @since               3.0
+        *
+        * @return              A %RandomIteratorT instance
+        * @param[in]   diff    The length to move forward
+        * @exception   E_SUCCESS                       The method is successful.
+        * @exception   E_OUT_OF_RANGE          The position of the iterator is outside the bounds of the list.
+        * @remarks             The specific error code can be accessed using GetLastResult() method.
+        */
+       RandomIteratorT< T >& operator +=(difference_type diff)
+       {
+               ClearLastResult();
+               __index += diff;
+               TryReturnResult(__index >= 0 && __index < __pList->GetCount(), *this, E_OUT_OF_RANGE, "[%s] It is out of range.", GetErrorMessage(E_OUT_OF_RANGE));
+               return *this;
+       }
+
+       /**
+        * Moves backward as much as specified @c diff parameter.
+        *
+        * @since               3.0
+        *
+        * @return              A %RandomIteratorT instance
+        * @param[in]   diff    The length to move backward
+        * @exception   E_SUCCESS                       The method is successful.
+        * @exception   E_OUT_OF_RANGE          The position of the iterator is outside the bounds of the list.
+        * @remarks             The specific error code can be accessed using GetLastResult() method.
+        */
+       RandomIteratorT< T >& operator -=(difference_type diff)
+       {
+               ClearLastResult();
+               __index -= diff;
+               TryReturnResult(__index >= 0 && __index < __pList->GetCount(), *this, E_OUT_OF_RANGE, "[%s] It is out of range.", GetErrorMessage(E_OUT_OF_RANGE));
+               return *this;
+       }
+
+       /**
+        * Get the difference between the current instance and the specified %RandomIteratorT instance
+        *
+        * @since               3.0
+        *
+        * @return              The difference between the current instance and the specified %RandomIteratorT instance
+        * @param[in]   rhs     A reference to the %RandomIteratorT instance on the right-hand side of the operator
+        */
+       difference_type operator -(const RandomIteratorT< T >& rhs)
        {
                return __index - rhs.__index;
        }
@@ -314,18 +389,16 @@ public:
         * @since               2.1
         *
         * @return              A reference to the T type instance
-        * @param[in]   index                           An index to reach
+        * @param[in]           index                           An index to move from current position
         * @exception   E_SUCCESS                       The method is successful.
-        * @exception   E_OUT_OF_RANGE          The specified index is outside the bounds of the data structure,
-        *                                                                      or the specified index is either equal to or greater than the number of elements in the list or less than 0.
+        * @exception   E_OUT_OF_RANGE          The position of the iterator is outside the bounds of the list.
         * @remarks             The specific error code can be accessed using GetLastResult() method.
         */
-       T& operator [](int index) const
+       reference operator [](difference_type index)
        {
-               // GetAt() will return null if __index is out of range.
-               const T& tempObj = static_cast< T >(const_cast< Object* >(__pList->GetAt(index)));
-               TryReturnResult(tempObj != null, const_cast< T& >(tempObj), GetLastResult(), "[%s] It is out of range.", GetErrorMessage(GetLastResult()));
-               return const_cast< T& >(tempObj);
+               ClearLastResult();
+               TryReturnResult(__index + index >= 0 && __index + index < __pList->GetCount(), **this, E_OUT_OF_RANGE, "[%s] It is out of range.", GetErrorMessage(E_OUT_OF_RANGE));
+               return reinterpret_cast< T& >(__pList->GetAtRef(__index + index));
        }
 
        /**
@@ -339,13 +412,11 @@ public:
        {
                std::swap(__pList, rhs.__pList);
                std::swap(__index, rhs.__index);
-               std::swap(__currentObj, rhs.__currentObj);
        }
 
 private:
-       const IList* __pList;
-       int __index;
-       T __currentObj;
+       IList* __pList;
+       difference_type __index;
 }; // RandomIteratorT
 
 }}} // Tizen::Base::Collection
index 819b18b..a0d979a 100644 (file)
@@ -92,6 +92,8 @@ public:
        /**
         * Gets the STL compatible iterator referring to the first element in the IList instance.
         *
+        * @brief       <i> [Deprecated] </i>
+        * @deprecated  This method is deprecated to support mutation algorithm requiring non-const pointer.
         * @since               2.1
         *
         * @return              An IteratorT instance
@@ -100,12 +102,29 @@ public:
        template< typename T >
        static IteratorT< T > GetBeginIterator(const IList* pList)
        {
+               return GetBeginIterator< T >(const_cast< IList* >(pList));
+       }
+
+       /**
+        * Gets the STL compatible iterator referring to the first element in the IList instance.
+        *
+        * @since               3.0
+        *
+        * @return              An IteratorT instance
+        * @param[in]   pList                   A pointer to the IList instance to convert
+        * @remarks             This method does not take the ownership of the @c pList because the argument is a non-const pointer.
+        */
+       template< typename T >
+       static IteratorT< T > GetBeginIterator(IList* pList)
+       {
                return IteratorT< T >(*pList);
        }
 
        /**
         * Gets the STL compatible iterator referring to the post-end element in the IList instance.
         *
+        * @brief       <i> [Deprecated] </i>
+        * @deprecated  This method is deprecated to support mutation algorithm requiring non-const pointer.
         * @since               2.1
         *
         * @return              An IteratorT instance
@@ -114,12 +133,29 @@ public:
        template< typename T >
        static IteratorT< T > GetEndIterator(const IList* pList)
        {
+               return GetEndIterator< T >(const_cast< IList* >(pList));
+       }
+
+       /**
+        * Gets the STL compatible iterator referring to the post-end element in the IList instance.
+        *
+        * @since               3.0
+        *
+        * @return              An IteratorT instance
+        * @param[in]   pList                   A pointer to the IList instance to convert
+        * @remarks             This method does not take the ownership of the @c pList because the argument is a non-const pointer.
+        */
+       template< typename T >
+       static IteratorT< T > GetEndIterator(IList* pList)
+       {
                return IteratorT< T >(*pList, true);
        }
 
        /**
         * Gets the STL compatible random iterator referring to the first element in the IList instance.
         *
+        * @brief       <i> [Deprecated] </i>
+        * @deprecated  This method is deprecated to support mutation algorithm requiring non-const pointer.
         * @since               2.1
         *
         * @return              A RandomIteratorT instance
@@ -128,12 +164,29 @@ public:
        template< typename T >
        static RandomIteratorT< T > GetBeginRandomIterator(const IList* pList)
        {
+               return GetBeginRandomIterator< T >(const_cast< IList* >(pList));
+       }
+
+       /**
+        * Gets the STL compatible random iterator referring to the first element in the IList instance.
+        *
+        * @since               3.0
+        *
+        * @return              A RandomIteratorT instance
+        * @param[in]   pList                   A pointer to the IList instance to convert
+        * @remarks             This method does not take the ownership of the @c pList because the argument is a non-const pointer.
+        */
+       template< typename T >
+       static RandomIteratorT< T > GetBeginRandomIterator(IList* pList)
+       {
                return RandomIteratorT< T >(*pList, 0);
        }
 
        /**
         * Gets the STL compatible random iterator referring to the post-end element in the IList instance.
         *
+        * @brief       <i> [Deprecated] </i>
+        * @deprecated  This method is deprecated to support mutation algorithm requiring non-const pointer.
         * @since               2.1
         *
         * @return              A RandomIteratorT instance
@@ -142,6 +195,21 @@ public:
        template< typename T >
        static RandomIteratorT< T > GetEndRandomIterator(const IList* pList)
        {
+               return GetEndRandomIterator< T >(const_cast< IList* >(pList));
+       }
+
+       /**
+        * Gets the STL compatible random iterator referring to the post-end element in the IList instance.
+        *
+        * @since               3.0
+        *
+        * @return              A RandomIteratorT instance
+        * @param[in]   pList                   A pointer to the IList instance to convert
+        * @remarks             This method does not take the ownership of the @c pList because the argument is a non-const pointer.
+        */
+       template< typename T >
+       static RandomIteratorT< T > GetEndRandomIterator(IList* pList)
+       {
                return RandomIteratorT< T >(*pList, pList->GetCount());
        }
 
index eb21496..ec21525 100644 (file)
@@ -107,6 +107,12 @@ protected:
        //
        virtual void Object_Reserved1(void) { }
 
+public:
+       // This pointer is initalized null. It is used to return null pointer.
+       //
+       // @since 3.0
+       //
+       static Object* pNullObj;
 }; // Object
 
 }} // Tizen::Base
index a4fbb1f..9160bbe 100644 (file)
@@ -22,6 +22,7 @@
 
 namespace Tizen { namespace Base
 {
+Object* Object::pNullObj = null;
 
 Object::Object(void)
 {
@@ -61,5 +62,4 @@ Object::operator =(const Object& rhs)
 {
        return *this;
 }
-
 }} //Tizen::Base
index 9fa2a67..5a89841 100644 (file)
@@ -41,6 +41,7 @@ public:
        virtual ~_ArrayListEnumerator(void);
 
        virtual Object* GetCurrent(void) const;
+       virtual Object*& GetCurrentRef(void) const;
        virtual result MoveNext(void);
        virtual result Reset(void);
 
@@ -67,11 +68,15 @@ _ArrayListEnumerator::~_ArrayListEnumerator(void)
 Object*
 _ArrayListEnumerator::GetCurrent(void) const
 {
-       SysTryReturn(NID_BASE_COL, (__modCount == __list.__modCount), null, E_INVALID_OPERATION, "[%s] The source collection was modified after the creation of this enumerator.", GetErrorMessage(E_INVALID_OPERATION));
-       SysTryReturn(NID_BASE_COL, ((__position >= 0) && (__position < __list.__count)), null, E_INVALID_OPERATION, "[%s] Current position(%d) is before the first element or past the last element.", GetErrorMessage(E_INVALID_OPERATION), __position);
+       return GetCurrentRef();
+}
 
+Object*&
+_ArrayListEnumerator::GetCurrentRef(void) const
+{
+       SysTryReturn(NID_BASE_COL, (__modCount == __list.__modCount), pNullObj, E_INVALID_OPERATION, "[%s] The source collection was modified after the creation of this enumerator.", GetErrorMessage(E_INVALID_OPERATION));
+       SysTryReturn(NID_BASE_COL, ((__position >= 0) && (__position < __list.__count)), pNullObj, E_INVALID_OPERATION, "[%s] Current position(%d) is before the first element or past the last element.", GetErrorMessage(E_INVALID_OPERATION), __position);
        SetLastResult(E_SUCCESS);
-
        return __list.__pObjArray[__position];
 }
 
@@ -248,6 +253,15 @@ ArrayList::GetAt(int index)
        return const_cast< Object* >(pObj);
 }
 
+Object*&
+ArrayList::GetAtRef(int index)
+{
+       SysTryReturn(NID_BASE_COL, index >= 0 && index < __count, pNullObj, E_OUT_OF_RANGE, "[%s] The index(%d) MUST be greater than or equal to 0 and less than the number of elements(%d).", GetErrorMessage(E_OUT_OF_RANGE), index, __count);
+
+       SetLastResult(E_SUCCESS);
+       return __pObjArray[index];
+}
+
 IList*
 ArrayList::GetItemsN(int startIndex, int count) const
 {
index 585bd40..00e6d9e 100644 (file)
@@ -64,6 +64,7 @@ public:
        virtual ~_LinkedListEnumerator(void);
 
        virtual Object* GetCurrent(void) const;
+       virtual Object*& GetCurrentRef(void) const;
        virtual result MoveNext(void);
        virtual result Reset(void);
 
@@ -91,8 +92,14 @@ _LinkedListEnumerator::~_LinkedListEnumerator(void)
 Object*
 _LinkedListEnumerator::GetCurrent(void) const
 {
-       SysTryReturn(NID_BASE_COL, __modCount == __list.__modCount, null, E_INVALID_OPERATION, "[%s] The source collection was modified after the creation of this enumerator.", GetErrorMessage(E_INVALID_OPERATION));
-       SysTryReturn(NID_BASE_COL, __pNode != null, null, E_INVALID_OPERATION, "[%s] Current position is before the first element or past the last element.", GetErrorMessage(E_INVALID_OPERATION));
+       return GetCurrentRef();
+}
+
+Object*&
+_LinkedListEnumerator::GetCurrentRef(void) const
+{
+       SysTryReturn(NID_BASE_COL, __modCount == __list.__modCount, pNullObj, E_INVALID_OPERATION, "[%s] The source collection was modified after the creation of this enumerator.", GetErrorMessage(E_INVALID_OPERATION));
+       SysTryReturn(NID_BASE_COL, __pNode != null, pNullObj, E_INVALID_OPERATION, "[%s] Current position is before the first element or past the last element.", GetErrorMessage(E_INVALID_OPERATION));
        SetLastResult(E_SUCCESS);
        return __pNode->pObj;
 }
@@ -254,13 +261,20 @@ LinkedList::GetAt(int index) const
 Object*
 LinkedList::GetAt(int index)
 {
-       SysTryReturn(NID_BASE_COL, index >= 0 && index < __count, null, E_OUT_OF_RANGE, "[%s] The index(%d) MUST be greater than or equal to 0, and less than the number of elements(%d).", GetErrorMessage(E_OUT_OF_RANGE), index, __count);
-
        const Object* pObj = (static_cast< const LinkedList* >(this))->GetAt(index);
-       SetLastResult(E_SUCCESS);
        return const_cast< Object* >(pObj);
 }
 
+Object*&
+LinkedList::GetAtRef(int index)
+{
+       SysTryReturn(NID_BASE_COL, index >= 0 && index < __count, pNullObj, E_OUT_OF_RANGE, "[%s] The index(%d) MUST be greater than or equal to 0, and less than the number of elements(%d).", GetErrorMessage(E_OUT_OF_RANGE), index, __count);
+
+       _ListNode* pNode = GetNode(index);
+       SetLastResult(E_SUCCESS);
+       return pNode->pObj;
+}
+
 IList*
 LinkedList::GetItemsN(int startIndex, int count) const
 {