Implementation of ImmutableString
[platform/framework/native/appfw.git] / inc / FBaseColPairIteratorT.h
index dafebc8..eabc784 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_PAIR_ITERATOR_T_H_
 #define _FBASE_COL_PAIR_ITERATOR_T_H_
 
-#include <algorithm>   // std::swap (Before C++11)
+#include <algorithm>    // std::swap (Before C++11)
 #include <iterator>
 #include <utility>
 #include <unique_ptr.h>
@@ -38,20 +37,44 @@ namespace Tizen { namespace Base { namespace Collection
 {
 /**
  * @class      PairIteratorT
- * @brief      This 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.
+ * @brief      This class provides an iterator that is used to convert %IMap or %IMultiMap to STL containers. @n
+ *                     %StlConverter provides static methods to get this iterator from %IMap or %IMultiMap.
  *
  * @since      2.1
  *
- * @remarks    This 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.
  */
 
-template < typename K, typename V >
+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.
         *
@@ -125,13 +148,13 @@ public:
        }
 
        /**
-        * This is copy constructor of %PairIteratorT class.
+        * This is the copy constructor of the %PairIteratorT class.
         *
         * @since               2.1
         *
         * @param[in]   rhs                                     A reference to the %PairIteratorT instance
         * @exception   E_SUCCESS                       The method is successful.
-        * @exception   E_INVALID_ARG           Both @c __pMap and @c __pMultiMap are null.
+        * @exception   E_INVALID_ARG           Both @c __pMap and @c __pMultiMap are @c null.
         * @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.
@@ -164,19 +187,19 @@ public:
        }
 
        /**
-        * This is assignment operator of %PairIteratorT class.
+        * This is assignment operator of the %PairIteratorT class.
         *
         * @since               2.1
         *
         * @return              A reference to the %PairIteratorT instance
         * @param[in]   rhs                                     A reference to the %PairIteratorT instance on the right-hand side of the operator
         * @exception   E_SUCCESS                       The method is successful.
-        * @exception   E_INVALID_ARG           Both @c __pMap and @c __pMultiMap are null.
-        * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified operation or
+        * @exception   E_INVALID_ARG           Both @c __pMap and @c __pMultiMap are @c null.
+        * @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.
         */
-       PairIteratorT< K, V >& operator=(const PairIteratorT< K, V >& rhs)
+       PairIteratorT< K, V >& operator =(const PairIteratorT< K, V >& rhs)
        {
                PairIteratorT< K, V > tmp(rhs);
                tmp.swap(*this);
@@ -184,28 +207,28 @@ public:
        }
 
        /**
-        * This is the indirection operator for %PairIteratorT class.
+        * This is the indirection operator for the %PairIteratorT class.
         *
         * @since               2.1
         *
         * @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 %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*());
+               return &(operator *());
        }
 
        /**
@@ -216,16 +239,18 @@ public:
         * @return              A reference to the %PairIteratorT instance
         * @exception   E_SUCCESS                       The method is successful.
         * @exception   E_OUT_OF_RANGE          The enumerator has passed the end of the collection.
-        * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified operation or
+        * @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.
         */
-       PairIteratorT< K, V >& operator++(void)
+       PairIteratorT< K, V >& operator ++(void)
        {
                TryReturnResult(!__isPostEnd, *this, E_OUT_OF_RANGE, "[%s] It already reached the end.", GetErrorMessage(E_OUT_OF_RANGE));
 
                result r = __pEnum->MoveNext();
-               TryCatchResult(r == E_SUCCESS, __isPostEnd = true; __currentObj.first = null; __currentObj.second = null,
+               TryCatchResult(r == E_SUCCESS, __isPostEnd = true;
+                       __currentObj.first = null;
+                       __currentObj.second = null,
                        r, "[%s] It already reached the end.", GetErrorMessage(r));
 
                __currentObj.first = static_cast< K >(__pEnum->GetKey());
@@ -244,19 +269,19 @@ CATCH:
         * @return              A %PairIteratorT instance
         * @exception   E_SUCCESS                       The method is successful.
         * @exception   E_OUT_OF_RANGE          The enumerator has passed the end of the collection.
-        * @exception   E_INVALID_OPERATION     The current state of the instance prohibits the execution of the specified operation or
+        * @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.
         */
-       PairIteratorT< K, V > operator++(int)
+       PairIteratorT< K, V > operator ++(int)
        {
                PairIteratorT< K, V > tempIter = *this;
-               operator++();
+               operator ++();
                return tempIter;
        }
 
        /**
-        *      Checks the two %PairIteratorT instances for equality
+        *      Checks the two %PairIteratorT instances for equality.
         *
         *      @since          2.1
         *
@@ -264,7 +289,7 @@ CATCH:
         *                              else @c false
         *      @param[in]      rhs     A reference to the %PairIteratorT instance on the right-hand side of the operator
         */
-       bool operator==(const PairIteratorT< K, V >& rhs) const
+       bool operator ==(const PairIteratorT< K, V >& rhs) const
        {
                if (__pMap != rhs.__pMap)
                {
@@ -300,17 +325,17 @@ CATCH:
         *
         *      @since          2.1
         *
-        *      @return         @c true if every member of the specified %PairIteratorT instance is not equal to the calling instance's members, @n
+        *      @return         @c true if any member of the specified %PairIteratorT instance is not equal to the calling instance's members, @n
         *                              else @c false
         *      @param[in]      rhs     A reference to the %PairIteratorT instance on the right-hand side of the operator
         */
-       bool operator!=(const PairIteratorT< K, V >& rhs) const
+       bool operator !=(const PairIteratorT< K, V >& rhs) const
        {
-               return !operator==(rhs);
+               return !operator ==(rhs);
        }
 
        /**
-        *      Exchanges values of the two %PairIteratorT instances
+        *      Swaps values of the two %PairIteratorT instances.
         *
         *      @since          2.1
         *
@@ -330,10 +355,10 @@ private:
        const IMap* __pMap;
        const IMultiMap* __pMultiMap;
        bool __isPostEnd;
-       int __index;
+       difference_type __index;
        std::unique_ptr< IMapEnumerator > __pEnum;
-       std::pair< K, V > __currentObj;
-};     // PairIteratorT
+       value_type __currentObj;
+};  // PairIteratorT
 
 }}} // Tizen::Base::Collection