2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FBaseColIList.h
20 * @brief This is the header file for the %IList interface.
22 * This header file contains the declarations of the %IList interface.
24 #ifndef _FBASE_COL_ILIST_H_
25 #define _FBASE_COL_ILIST_H_
27 #include <FBaseColIBidirectionalEnumerator.h>
28 #include <FBaseColICollection.h>
29 #include <FBaseColIComparer.h>
30 #include <FBaseColTypes.h>
31 #include <FBaseObject.h>
33 namespace Tizen { namespace Base { namespace Collection
38 * @brief This interface represents a collection of objects that can be individually accessed by an index.
42 * The %IList interface represents a collection of objects that can be individually accessed by an index.
45 class _OSP_EXPORT_ IList
46 : public virtual ICollection
50 * This polymorphic destructor should be overridden if required. @n
51 * This way, the destructors of the derived classes are called when the destructor of this interface is called.
55 virtual ~IList(void) {}
59 * Adds the specified object to the list.
61 * @brief <i> [Deprecated] </i>
62 * @deprecated This method is deprecated because it has a problem of const reference argument.
63 * Instead of using this method, use Add(Object* pObj).
66 * @return An error code
67 * @param[in] obj The object to add
68 * @exception E_SUCCESS The method is successful.
69 * @exception E_OUT_OF_MEMORY The memory is insufficient.
70 * @remarks In a collection of contiguous elements, such as a list, the elements
71 * that follow the insertion point move down to accommodate the new element.
72 * If the collection is indexed, the indexes of the elements that are moved
73 * are also updated. This behavior does not apply to collections where
74 * elements are conceptually grouped into buckets, such as a hashtable.
75 * This method performs a shallow copy. It adds the pointer only; not the element itself.
79 result Add(const Object& obj)
81 return Add(const_cast< Object* >(&obj));
85 * Adds the specified object to the list.
89 * @return An error code
90 * @param[in] pObj The pointer to object to add
91 * @exception E_SUCCESS The method is successful.
92 * @exception E_INVALID_ARG The specified input parameter is invalid.
93 * @remarks In a collection of contiguous elements, such as a list, the elements
94 * that follow the insertion point move down to accommodate the new element.
95 * If the collection is indexed, the indexes of the elements that are moved
96 * are also updated. This behavior does not apply to collections where
97 * elements are conceptually grouped into buckets, such as a hashtable.
98 * This method performs a shallow copy. It adds the pointer only; not the element itself.
101 virtual result Add(Object* pObj) = 0;
104 * Adds the elements of the specified collection to the end of the list.
108 * @return An error code
109 * @param[in] collection The collection to add to the list
110 * @exception E_SUCCESS The method is successful.
111 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified operation, or
112 * the specified @c collection is modified during the operation of this method.
113 * @remarks This method performs a shallow copy. It adds the pointer only; not the element itself.
116 virtual result AddItems(const ICollection& collection) = 0;
119 * Searches for an object in this list. @n
120 * Gets the index of the object if found.
124 * @return An error code
125 * @param[in] obj The object to locate
126 * @param[out] index The index of the object
127 * @exception E_SUCCESS The method is successful.
128 * @exception E_OBJ_NOT_FOUND The specified @c obj is not found.
130 virtual result IndexOf(const Object& obj, int& index) const = 0;
134 * Inserts an object at the specified location in the list.
136 * @brief <i> [Deprecated] </i>
137 * @deprecated This method is deprecated because it has a problem of const reference argument.
138 * Instead of using this method, use InsertAt(const Object* pObj, int index).
141 * @return An error code
142 * @param[in] obj The object to insert
143 * @param[in] index The index at which the object must be inserted
144 * @exception E_SUCCESS The method is successful.
145 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
146 * the @c index is greater than the number of elements in the list or less than @c 0.
147 * @remarks If the @c index equals the number of elements in the list, the new element
148 * is added at the end of the list.
149 * This method performs a shallow copy. It inserts the pointer only; not the element itself.
154 result InsertAt(const Object& obj, int index)
156 return InsertAt(const_cast< Object* >(&obj), index);
160 * Inserts an object at the specified location in the list.
164 * @return An error code
165 * @param[in] pObj The pointer to object to insert
166 * @param[in] index The index at which the object must be inserted
167 * @exception E_SUCCESS The method is successful.
168 * @exception E_INVALID_ARG The specified input parameter is invalid.
169 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
170 * the @c index is greater than the number of elements in the list or less than @c 0.
171 * @remarks If the @c index equals the number of elements in the list, the new element
172 * is added at the end of the list.
173 * This method performs a shallow copy. It inserts the pointer only; not the element itself.
177 virtual result InsertAt(Object* pObj, int index) = 0;
180 * Searches for an object starting from the specified index. @n
181 * Gets the index of the object if found.
185 * @return An error code
186 * @param[in] obj The object to locate
187 * @param[in] startIndex The starting index for the search @n
188 * It must be less than the number of elements.
189 * @param[out] index The index of the object
190 * @exception E_SUCCESS The method is successful.
191 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
192 * the specified @c startIndex is either equal to or greater than the number of elements in the list or less than @c 0.
193 * @exception E_OBJ_NOT_FOUND The specified @c obj is not found.
196 virtual result IndexOf(const Object& obj, int startIndex, int& index) const = 0;
199 * Searches for an object within the specified range. @n
200 * Gets the index of the object if found.
204 * @return An error code
205 * @param[in] obj The object to locate
206 * @param[in] startIndex The starting index of the range
207 * @param[in] count The number of elements to read
208 * @param[out] index The index of the object
209 * @exception E_SUCCESS The method is successful.
210 * @exception E_OUT_OF_RANGE Either of the following conditions has occurred: @n
211 * - The specified index is outside the bounds of the data structure. @n
212 * - The specified @c startIndex is either equal to or greater than the number of elements in the list or less than @c 0. @n
213 * - The @c count is greater than the number of elements starting from @c startIndex
215 * @exception E_OBJ_NOT_FOUND The specified @c obj is not found.
218 virtual result IndexOf(const Object& obj, int startIndex, int count, int& index) const = 0;
221 * Searches for the last occurrence of an object in this list. @n
222 * Gets the index of the object if found.
226 * @return An error code
227 * @param[in] obj The object to locate
228 * @param[out] index The index of the last occurrence of the specified object
229 * @exception E_SUCCESS The method is successful.
230 * @exception E_OBJ_NOT_FOUND The specified @c obj is not found.
233 virtual result LastIndexOf(const Object& obj, int& index) const = 0;
236 * Inserts the elements of a collection in the list at the specified location.
240 * @return An error code
241 * @param[in] collection The collection to insert
242 * @param[in] startIndex The starting index at which the collection must be inserted
243 * @exception E_SUCCESS The method is successful.
244 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
245 * the @c startIndex is greater than the number of elements in the list or less than @c 0.
246 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified operation, or
247 * the specified @c collection is modified during the operation of this method.
248 * @remarks If the @c startIndex equals the number of elements in the list, the new elements
249 * are added at the end of the list.
250 * This method performs a shallow copy. It inserts just the pointer; not the element itself.
254 virtual result InsertItemsFrom(const ICollection& collection, int startIndex) = 0;
257 * Gets the object at the specified location.
261 * @return The object at the specified location, @n
262 * else @c null if the @c index is not valid
263 * @param[in] index The index of the object to get
264 * @exception E_SUCCESS The method is successful.
265 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
266 * the specified @c index is either equal to or greater than the number of elements in the list or less than @c 0.
267 * @remarks The specific error code can be accessed using the GetLastResult() method.
270 virtual const Object* GetAt(int index) const = 0;
273 * Gets the object at the specified location.
277 * @return The object at the specified location, @n
278 * else @c null if the @c index is not valid
279 * @param[in] index The index of the object to get
280 * @exception E_SUCCESS The method is successful.
281 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
282 * the specified @c index is either equal to or greater than the number of elements in the list or less than @c 0.
283 * @remarks The specific error code can be accessed using the GetLastResult() method.
286 virtual Object* GetAt(int index) = 0;
289 * Gets all the elements of the list within the specified range.
293 * @return A pointer to an %IList with elements lying within the specified range, @n
294 * else @c null if an exception occurs
295 * @param[in] startIndex The starting index of the range
296 * @param[in] count The number of elements to read
297 * @exception E_SUCCESS The method is successful.
298 * @exception E_OUT_OF_RANGE Either of the following conditions has occurred: @n
299 * - The specified index is outside the bounds of the data structure. @n
300 * - The specified @c startIndex is either equal to or greater than the number of elements in the list or less than @c 0. @n
301 * - The @c count is greater than the number of elements in the list starting from @c startIndex
303 * @remarks The %IList stores just the pointers to the elements in the list, not the elements themselves.
304 * The specific error code can be accessed using the GetLastResult() method.
306 virtual IList* GetItemsN(int startIndex, int count) const = 0;
309 * Removes the first occurrence of the specified object.
313 * @return An error code
314 * @param[in] obj The object to remove
315 * @param[in] forceDeletion Set to @c true to deallocate the object, @n
317 * @exception E_SUCCESS The method is successful.
318 * @exception E_OBJ_NOT_FOUND The specified @c obj is not found.
319 * @remarks Based on the specified element deleter, the remove operation not only gets rid of an element from a list, but also deletes its object instance.@n
320 * The element deleter style is recommended rather than using the @c forceDeletetion argument in the remove method.@n
321 * If both an element deleter and forceDeleteion are set, the remove operation follows @c forceDeletion setting.
322 * @remarks Remove(obj, @b true) internally works as the below code:
324 * DeleterFunctionType deleter = GetDeleter();
325 * SetDeleter(SingleObjectDeleter);
327 * SetDeleter(deleter);
329 * @remarks Remove(obj, @b false) internally works as the below code:
331 * DeleterFunctionType deleter = GetDeleter();
332 * SetDeleter(NoOpDeleter);
334 * SetDeleter(deleter);
339 result Remove(const Object& obj, bool forceDeletion)
341 DeleterFunctionType deleter = GetDeleter();
345 SetDeleter(SingleObjectDeleter);
349 SetDeleter(NoOpDeleter);
352 result r = Remove(obj);
358 * Removes the first occurrence of the specified object.
362 * @return An error code
363 * @param[in] obj The object to remove
364 * @exception E_SUCCESS The method is successful.
365 * @exception E_OBJ_NOT_FOUND The specified @c obj is not found.
369 virtual result Remove(const Object& obj) = 0;
372 * Removes the object at the specified location.
376 * @return An error code
377 * @param[in] index The index at which the object must be removed
378 * @param[in] forceDeletion Set to @c true to deallocate the object, @n
380 * @exception E_SUCCESS The method is successful.
381 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
382 * the specified @c index is either equal to or greater than the number of elements in the list or less than @c 0.
383 * @remarks Based on the specified element deleter, the remove operation not only gets rid of an element from a list, but also deletes its object instance.@n
384 * The element deleter style is recommended rather than using the @c forceDeletetion argument in the remove method.@n
385 * If both an element deleter and forceDeleteion are set, the remove operation follows @c forceDeletion setting.
386 * @remarks RemoveAt(index, @b true) internally works as the below code:
388 * DeleterFunctionType deleter = GetDeleter();
389 * SetDeleter(SingleObjectDeleter);
391 * SetDeleter(deleter);
393 * @remarks RemoveAt(index, @b false) internally works as the below code:
395 * DeleterFunctionType deleter = GetDeleter();
396 * SetDeleter(NoOpDeleter);
398 * SetDeleter(deleter);
401 result RemoveAt(int index, bool forceDeletion)
403 DeleterFunctionType deleter = GetDeleter();
407 SetDeleter(SingleObjectDeleter);
411 SetDeleter(NoOpDeleter);
414 result r = RemoveAt(index);
420 * Removes the object at the specified location.
424 * @return An error code
425 * @param[in] index The index at which the object must be removed
426 * @exception E_SUCCESS The method is successful.
427 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
428 * the specified @c index is either equal to or greater than the number of elements in the list or less than @c 0.
430 virtual result RemoveAt(int index) = 0;
433 * Removes all the elements within the specified range.
437 * @return An error code
438 * @param[in] startIndex The starting index of the range
439 * @param[in] count The number of elements in the range
440 * @param[in] forceDeletion Set to @c true to deallocate the object, @n
442 * @exception E_SUCCESS The method is successful.
443 * @exception E_OUT_OF_RANGE Either of the following conditions has occurred: @n
444 * - The specified index is outside the bounds of the data structure. @n
445 * - The specified @c startIndex is either equal to or greater than the number of elements in the list or less than @c 0. @n
446 * - The @c count is greater than the number of elements starting from @c startIndex
448 * @remarks Based on the specified element deleter, the remove operation not only gets rid of an element from a list, but also deletes its object instance.@n
449 * The element deleter style is recommended rather than using the @c forceDeletetion argument in the remove method.@n
450 * If both an element deleter and forceDeleteion are set, the remove operation follows @c forceDeletion setting.
451 * @remarks RemoveItems(startIndex, count, @b true) internally works as the below code:
453 * DeleterFunctionType deleter = GetDeleter();
454 * SetDeleter(SingleObjectDeleter);
455 * RemoveItems(startIndex, count);
456 * SetDeleter(deleter);
458 * @remarks RemoveItems(startIndex, count, @b false) internally works as the below code:
460 * DeleterFunctionType deleter = GetDeleter();
461 * SetDeleter(NoOpDeleter);
462 * RemoveItems(startIndex, count);
463 * SetDeleter(deleter);
467 result RemoveItems(int startIndex, int count, bool forceDeletion)
469 DeleterFunctionType deleter = GetDeleter();
473 SetDeleter(SingleObjectDeleter);
477 SetDeleter(NoOpDeleter);
480 result r = RemoveItems(startIndex, count);
486 * Removes all the elements within the specified range.
490 * @return An error code
491 * @param[in] startIndex The starting index of the range
492 * @param[in] count The number of elements in the range
493 * @exception E_SUCCESS The method is successful.
494 * @exception E_OUT_OF_RANGE Either of the following conditions has occurred: @n
495 * - The specified index is outside the bounds of the data structure. @n
496 * - The specified @c startIndex is either equal to or greater than the number of elements in the list or less than @c 0. @n
497 * - The @c count is greater than the number of elements starting from @c startIndex
501 virtual result RemoveItems(int startIndex, int count) = 0;
504 * Removes all the elements from the list that are common to the specified collection.
508 * @return An error code
509 * @param[in] collection The collection to be removed from this list
510 * @param[in] forceDeletion Set to @c true to deallocate the object, @n
512 * @exception E_SUCCESS The method is successful.
513 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified operation, or
514 * the specified @c collection is modified during the operation of this method.
515 * @remarks Based on the specified element deleter, the remove operation not only gets rid of an element from a list, but also deletes its object instance.@n
516 * The element deleter style is recommended rather than using the @c forceDeletetion argument in the remove method.@n
517 * If both an element deleter and forceDeleteion are set, the remove operation follows @c forceDeletion setting.
518 * @remarks RemoveItems(collection, @b true) internally works as the below code:
520 * DeleterFunctionType deleter = GetDeleter();
521 * SetDeleter(SingleObjectDeleter);
522 * RemoveItems(collection);
523 * SetDeleter(deleter);
525 * @remarks RemoveItems(collection, @b false) internally works as the below code:
527 * DeleterFunctionType deleter = GetDeleter();
528 * SetDeleter(NoOpDeleter);
529 * RemoveItems(collection);
530 * SetDeleter(deleter);
535 result RemoveItems(const ICollection& collection, bool forceDeletion)
537 DeleterFunctionType deleter = GetDeleter();
541 SetDeleter(SingleObjectDeleter);
545 SetDeleter(NoOpDeleter);
548 result r = RemoveItems(collection);
554 * Removes all the elements from the list that are common to the specified collection.
558 * @return An error code
559 * @param[in] collection The collection to remove from this list
560 * @exception E_SUCCESS The method is successful.
561 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified operation, or
562 * the specified @c collection is modified during the operation of this method.
566 virtual result RemoveItems(const ICollection& collection) = 0;
569 * Removes all the object pointers in the collection. @n
570 * If the deallocate param is set to @c true, it removes all the objects in the collection. @n
571 * This method can be called just before deleting the collection.
575 * @return An error code
576 * @param[in] forceDeletion Set to @c true to deallocate all the objects, @n
578 * @remarks Based on the specified element deleter, the remove operation not only gets rid of an element from a list, but also deletes its object instance.@n
579 * The element deleter style is recommended rather than using the @c forceDeletetion argument in the remove method.@n
580 * If both an element deleter and forceDeleteion are set, the remove operation follows @c forceDeletion setting.
581 * @remarks RemoveAll(@b true) internally works as the below code:
583 * DeleterFunctionType deleter = GetDeleter();
584 * SetDeleter(SingleObjectDeleter);
586 * SetDeleter(deleter);
588 * @remarks RemoveAll(@b false) internally works as the below code:
590 * DeleterFunctionType deleter = GetDeleter();
591 * SetDeleter(NoOpDeleter);
593 * SetDeleter(deleter);
596 void RemoveAll(bool forceDeletion)
598 DeleterFunctionType deleter = GetDeleter();
602 SetDeleter(SingleObjectDeleter);
606 SetDeleter(NoOpDeleter);
614 * Removes all the object pointers in the collection. @n
615 * This method can be called just before deleting the collection.
619 virtual void RemoveAll(void) = 0;
622 * Replaces the object at the specified index with the specified object.
626 * @return An error code
627 * @param[in] obj The new object
628 * @param[in] index The index at which the new object must be set
629 * @param[in] forceDeletion Set to @c true to deallocate the object, @n
631 * @exception E_SUCCESS The method is successful.
632 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
633 * the specified @c index is either equal to or greater than the number of elements in the list or less than @c 0.
634 * @remarks Based on the specified element deleter, the set operation not only gets rid of an element from a list, but also deletes its object instance.@n
635 * The element deleter style is recommended rather than using the @c forceDeletetion argument in the set method.@n
636 * If both an element deleter and forceDeleteion are set, the set operation follows @c forceDeletion setting.
637 * @remarks SetAt(obj, index, @b true) internally works as the below code:
639 * DeleterFunctionType deleter = GetDeleter();
640 * SetDeleter(SingleObjectDeleter);
641 * SetAt(const_cast< Object* >(&obj), index);
642 * SetDeleter(deleter);
644 * @remarks SetAt(obj, index, @b false) internally works as the below code:
646 * DeleterFunctionType deleter = GetDeleter();
647 * SetDeleter(NoOpDeleter);
648 * SetAt(const_cast< Object* >(&obj), index);
649 * SetDeleter(deleter);
653 result SetAt(const Object& obj, int index, bool forceDeletion = false)
655 DeleterFunctionType deleter = GetDeleter();
659 SetDeleter(SingleObjectDeleter);
663 SetDeleter(NoOpDeleter);
666 result r = SetAt(const_cast< Object* >(&obj), index);
672 * Replaces the object at the specified index with the specified object.
676 * @return An error code
677 * @param[in] pObj The pointer to new object
678 * @param[in] index The index at which the new object must be set
679 * @exception E_SUCCESS The method is successful.
680 * @exception E_INVALID_ARG The specified input parameter is invalid.
681 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
682 * the specified @c index is either equal to or greater than the number of elements in the list or less than @c 0.
685 virtual result SetAt(Object* pObj, int index) = 0;
688 * Sorts the elements of this list using the comparer provided.
692 * @return An error code
693 * @param[in] comparer The IComparer implementation to use when comparing elements
694 * @exception E_SUCCESS The method is successful.
695 * @exception E_INVALID_ARG The specified input parameter is invalid.
697 virtual result Sort(const IComparer& comparer) = 0;
700 * Checks whether the list contains the specified object.
704 * @return @c true if the list contains the specified object, @n
706 * @param[in] obj The object to locate
708 virtual bool Contains(const Object& obj) const = 0;
712 * Checks whether the list contains all the elements of the specified collection.
714 * @brief <i> [Deprecated] </i>
715 * @deprecated This method is deprecated because it transfers a result of comparison in out-parameter form.
716 * The return type will be changed into boolean type and this method will return the result.
717 * Instead of using this method, use bool ContainsAll(const ICollection& collection).
720 * @return An error code
721 * @param[in] collection The collection to check for containment in this list
722 * @param[out] out Set to @c true if the list contains all the elements of the specified collection, @n
724 * @exception E_SUCCESS The method is successful.
725 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified operation, or
726 * the specified @c collection is modified during the operation of this method.
727 * @remarks If the given @c collection is empty, the @c out parameter is set to @c true.
731 result ContainsAll(const ICollection& collection, bool& out) const
733 out = ContainsAll(collection);
734 result r = GetLastResult();
739 * Checks whether the list contains all the elements of the specified collection.
743 * @return @c true if the list contains all the elements of the specified collection, @n
745 * @param[in] collection The collection to check for containment in this list
746 * @exception E_SUCCESS The method is successful.
747 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified operation, or
748 * the specified @c collection is modified during the operation of this method.
749 * @remarks The specific error code can be accessed using the GetLastResult() method.
750 * @remarks If the given @c collection is empty, this method will return @c true.
753 virtual bool ContainsAll(const ICollection& collection) const = 0;
756 * Gets a bidirectional enumerator (an instance of the IBidirectionalEnumerator derived class) of this list.
760 * @return A pointer to a bidirectional enumerator interface of the %IList derived class, @n
761 * else @c null if an exception occurs
762 * @remarks Use this method to obtain a bidirectional enumerator (an instance of the IBidirectionalEnumerator derived class)
763 * to iterate over a collection (an instance of the %IList derived class).
764 * The specific error code can be accessed using GetLastResult() method.
765 * @see Tizen::Base::Collection::IBidirectionalEnumerator
767 virtual IBidirectionalEnumerator* GetBidirectionalEnumeratorN(void) const = 0;
770 * This method is for distinguishing between ArrayList and LinkedList.
774 * @return @c true if it is an ArrayList, @n
775 * else @c false if it is a LinkedList.
777 virtual bool IsRandomAccessible(void) const
783 * Gets the element deleter of the collection.
787 * @return An function pointer to the existing element deleter
789 virtual DeleterFunctionType GetDeleter(void) const = 0;
793 // This method is for internal use only. Using this method can cause behavioral, security-related,
794 // and consistency-related issues in the application.
795 // This method is reserved and may change its name at any time without prior notice.
799 virtual void IList_Reserved1(void) {}
802 // This method is for internal use only. Using this method can cause behavioral, security-related,
803 // and consistency-related issues in the application.
804 // This method is reserved and may change its name at any time without prior notice.
808 virtual void IList_Reserved2(void) {}
812 * Sets the element deleter of the collection.
816 * @param[in] deleter A function pointer to the element deleter to set
818 virtual void SetDeleter(DeleterFunctionType deleter) = 0;
822 }}} // Tizen::Base::Collection
824 #endif // _FBASE_COL_ILIST_H_