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
#define _FBASE_COL_IENUMERATOR_H_
#include <FBaseTypes.h>
-
-namespace Tizen {namespace Base
-{
-class Object;
-}}
+#include <FBaseObject.h>
namespace Tizen { namespace Base { namespace Collection
{
*/
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,
//
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
*/
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,
//
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.
*
* @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 >
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.
*
* @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
{
, __isPostEnd(rhs.__isPostEnd)
, __index(rhs.__index)
, __pEnum(__pList->GetBidirectionalEnumeratorN())
- , __currentObj(rhs.__currentObj)
{
if (!__isPostEnd)
{
*
* @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());
}
/**
*
* @return A T type pointer that is equivalent to the pointer address
*/
- T* operator ->(void) const
+ pointer operator ->(void) const
{
return &(operator *());
}
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;
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;
}
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();
}
/**
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
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
*
* @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.
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.
*
*
* @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 *());
}
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
*
* @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.
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.
*
* @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.");
}
RandomIteratorT(const RandomIteratorT< T >& rhs)
: __pList(rhs.__pList)
, __index(rhs.__index)
- , __currentObj(rhs.__currentObj)
{
}
*
* @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));
}
/**
*
* @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)
}
/**
- * 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)
*
* @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));
}
/**
*
* @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
*/
}
/**
- * 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
*/
*
* @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
*/
}
/**
- * 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;
}
* @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));
}
/**
{
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
/**
* 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
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
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
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
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());
}
//
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
namespace Tizen { namespace Base
{
+Object* Object::pNullObj = null;
Object::Object(void)
{
{
return *this;
}
-
}} //Tizen::Base
virtual ~_ArrayListEnumerator(void);
virtual Object* GetCurrent(void) const;
+ virtual Object*& GetCurrentRef(void) const;
virtual result MoveNext(void);
virtual result Reset(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];
}
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
{
virtual ~_LinkedListEnumerator(void);
virtual Object* GetCurrent(void) const;
+ virtual Object*& GetCurrentRef(void) const;
virtual result MoveNext(void);
virtual result Reset(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;
}
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
{