2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file FBaseColIListT.h
19 * @brief This is the header file for the %IListT interface.
21 * This header file contains the declarations of the %IListT interface.
23 #ifndef _FBASE_COL_ILIST_T_H_
24 #define _FBASE_COL_ILIST_T_H_
26 #include <FBaseColIBidirectionalEnumeratorT.h>
27 #include <FBaseColICollectionT.h>
28 #include <FBaseColIComparerT.h>
30 namespace Tizen { namespace Base { namespace Collection
35 * @brief This interface represents a template-based collection of objects that can be individually accessed by an index.
39 * The %IListT interface represents a template-based collection of objects that can be individually accessed by an index.
42 template< class Type >
44 : public virtual ICollectionT< Type >
48 * This polymorphic destructor should be overridden if required. @n
49 * This way, the destructors of the derived classes are called when the destructor of this interface is called.
53 virtual ~IListT(void) {}
56 * Adds the specified object to the list.
60 * @return An error code
61 * @param[in] obj The object to add
62 * @exception E_SUCCESS The method is successful.
63 * @exception E_OUT_OF_MEMORY The memory is insufficient.
64 * @remarks In a collection of contiguous elements, such as a list, the elements
65 * that follow the insertion point move down to accommodate the new element.
66 * If the collection is indexed, the indexes of the elements that are moved
67 * are also updated. This behavior does not apply to collections where
68 * elements are conceptually grouped into buckets, such as a hashtable.
71 virtual result Add(const Type& obj) = 0;
74 * Adds the elements of the specified collection to the end of the list.
78 * @return An error code
79 * @param[in] collection The collection to add
80 * @exception E_SUCCESS The method is successful.
81 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified operation, or
82 * the specified @c collection is modified during the operation of this method.
85 virtual result AddItems(const ICollectionT< Type >& collection) = 0;
88 * Searches for an object in this list. @n
89 * Gets the index of the object if found.
93 * @return An error code
94 * @param[in] obj The object to locate
95 * @param[out] index The index of the object
96 * @exception E_SUCCESS The method is successful.
97 * @exception E_OBJ_NOT_FOUND The specified @c obj is not found.
99 virtual result IndexOf(const Type& obj, int& index) const = 0;
102 * Searches for an object starting from the specified index. @n
103 * Gets the index of the object if found.
107 * @return An error code
108 * @param[in] obj The object to locate
109 * @param[in] startIndex The starting index for the search @n
110 * It must be less than the number of elements.
111 * @param[out] index The index of the object
112 * @exception E_SUCCESS The method is successful.
113 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
114 * the specified @c startIndex is either equal to or greater than the number of elements in the list or less than @c 0.
115 * @exception E_OBJ_NOT_FOUND The specified @c obj is not found.
118 virtual result IndexOf(const Type& obj, int startIndex, int& index) const = 0;
121 * Searches for an object within the specified range. @n
122 * Gets the index of the object if found.
126 * @return An error code
127 * @param[in] obj The object to locate
128 * @param[in] startIndex The starting index of the range
129 * @param[in] count The number of elements to read
130 * @param[out] index The index of the object
131 * @exception E_SUCCESS The method is successful.
132 * @exception E_OUT_OF_RANGE Either of the following conditions has occurred: @n
133 * - The specified index is outside the bounds of the data structure. @n
134 * - The specified @c startIndex is either equal to or greater than the number of elements in the list or less than @c 0. @n
135 * - The @c count is greater than the number of elements starting from @c startIndex
137 * @exception E_OBJ_NOT_FOUND The specified @c obj is not found.
140 virtual result IndexOf(const Type& obj, int startIndex, int count, int& index) const = 0;
143 * Searches for the last occurrence of an object in this list. @n
144 * Gets the index of the object if found.
148 * @return An error code
149 * @param[in] obj The object to locate
150 * @param[out] index The index of the last occurrence of the specified object
151 * @exception E_SUCCESS The method is successful.
152 * @exception E_OBJ_NOT_FOUND The specified @c obj is not found.
155 virtual result LastIndexOf(const Type& obj, int& index) const = 0;
158 * Inserts an object at the specified location in the list.
162 * @return An error code
163 * @param[in] obj The object to insert
164 * @param[in] index The index at which the object must be inserted
165 * @exception E_SUCCESS The method is successful.
166 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
167 * the @c index is greater than the number of elements in the list or less than @c 0.
168 * @remarks If the @c index equals the number of elements in the list, the new element
169 * is added at the end of the list.
173 virtual result InsertAt(const Type& obj, int index) = 0;
176 * Inserts the elements of a collection in the list at the specified location.
180 * @return An error code
181 * @param[in] collection The collection to insert
182 * @param[in] startIndex The starting index at which the collection must be inserted
183 * @exception E_SUCCESS The method is successful.
184 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
185 * the @c startIndex is greater than the number of elements in the list or less than @c 0.
186 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified operation, or
187 * the specified @c collection is modified during the operation of this method.
188 * @remarks If the @c startIndex equals the number of elements in the list, the new elements
189 * are added at the end of the list.
193 virtual result InsertItemsFrom(const ICollectionT< Type >& collection, int startIndex) = 0;
196 * Gets the object at the specified location.
200 * @return An error code
201 * @param[in] index The index of the object to get
202 * @param[out] obj The object obtained from the list
203 * @exception E_SUCCESS The method is successful.
204 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
205 * the specified @c index is either equal to or greater than the number of elements in the list or less than @c 0.
208 virtual result GetAt(int index, Type& obj) const = 0;
211 * Gets the object at the specified location.
215 * @return An error code
216 * @param[in] index The index of the object to get
217 * @param[out] obj The object obtained from the list
218 * @exception E_SUCCESS The method is successful.
219 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
220 * the specified @c index is either equal to or greater than the number of elements in the list or less than @c 0.
223 virtual result GetAt(int index, Type& obj) = 0;
226 * Gets all the elements of the list within the specified range.
230 * @return A pointer to %IListT with elements lying within the specified range, @n
231 * else @c null if an exception occurs
232 * @param[in] startIndex The starting index of the range
233 * @param[in] count The number of elements to read
234 * @exception E_SUCCESS The method is successful.
235 * @exception E_OUT_OF_RANGE Either of the following conditions has occurred: @n
236 * - The specified index is outside the bounds of the data structure. @n
237 * - The specified @c startIndex is either equal to or greater than the number of elements in the list or less than @c 0. @n
238 * - The @c count is greater than the number of elements in the list starting from @c startIndex
240 * @remarks The specific error code can be accessed using the GetLastResult() method.
242 virtual IListT< Type >* GetItemsN(int startIndex, int count) const = 0;
245 * Removes the first occurrence of the specified object.
249 * @return An error code
250 * @param[in] obj The object to remove
251 * @exception E_SUCCESS The method is successful.
252 * @exception E_OBJ_NOT_FOUND The object is not found.
254 virtual result Remove(const Type& obj) = 0;
257 * Removes the object at the specified location.
261 * @return An error code
262 * @param[in] index The index at which the object must be removed
263 * @exception E_SUCCESS The method is successful.
264 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
265 * the specified @c index is either equal to or greater than the number of elements in the list or less than @c 0.
267 virtual result RemoveAt(int index) = 0;
270 * Removes all the elements from the list that are common to the specified collection.
274 * @return An error code
275 * @param[in] collection The collection to remove from this list
276 * @exception E_SUCCESS The method is successful.
277 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified operation, or
278 * the specified @c collection is modified during the operation of this method.
282 virtual result RemoveItems(const ICollectionT< Type >& collection) = 0;
285 * Removes all the elements within the specified range.
289 * @return An error code
290 * @param[in] startIndex The starting index of the range
291 * @param[in] count The number of elements in the range
292 * @exception E_SUCCESS The method is successful.
293 * @exception E_OUT_OF_RANGE Either of the following conditions has occurred: @n
294 * - The specified index is outside the bounds of the data structure. @n
295 * - The specified @c startIndex is either equal to or greater than the number of elements in the list or less than @c 0. @n
296 * - The @c count is greater than the number of elements starting from @c startIndex
299 * @see InsertItemsFrom()
301 virtual result RemoveItems(int startIndex, int count) = 0;
304 * Removes all the elements in the list.
308 virtual void RemoveAll(void) = 0;
311 * Sets the object at the specified index with the specified object.
315 * @return An error code
316 * @param[in] obj The new object
317 * @param[in] index The index at which the new object must be set
318 * @exception E_SUCCESS The method is successful.
319 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
320 * the specified @c index is either equal to or greater than the number of elements in the list or less than @c 0.
323 virtual result SetAt(const Type& obj, int index) = 0;
326 * Sorts the elements of this list using the comparer provided.
330 * @return An error code
331 * @param[in] comparer The IComparerT implementation to use when comparing elements
332 * @exception E_SUCCESS The method is successful.
333 * @exception E_INVALID_ARG The specified input parameter is invalid.
335 virtual result Sort(const IComparerT< Type >& comparer) = 0;
338 * Checks whether the list contains the specified object.
342 * @return @c true if the list contains the specified object, @n
344 * @param[in] obj The object to locate
346 virtual bool Contains(const Type& obj) const = 0;
349 * Checks whether the list contains all the elements of the specified collection.
353 * @return An error code
354 * @param[in] collection The collection to check for containment in this list
355 * @param[out] out Set to @c true if the list contains all the elements of the specified collection, @n
357 * @exception E_SUCCESS The method is successful.
358 * @exception E_INVALID_OPERATION The current state of the instance prohibits the execution of the specified operation, or
359 * the specified @c collection is modified during the operation of this method.
360 * @remarks If the given @c collection is empty, the @c out parameter is set to @c true.
363 virtual result ContainsAll(const ICollectionT< Type >& collection, bool& out) const = 0;
366 * Gets a bidirectional enumerator (an instance of the IBidirectionalEnumeratorT derived class) of this list.
370 * @return A pointer to a bidirectional enumerator interface of the %IListT derived class, @n
371 * else @c null if an exception occurs
372 * @exception E_SUCCESS The method is successful.
373 * @exception E_OUT_OF_MEMORY The memory is insufficient.
374 * @remarks Use this method to obtain a bidirectional enumerator (an instance of the IBidirectionalEnumeratorT derived class)
375 * to iterate over a collection (an instance of the %IListT derived class).
376 * @remarks The specific error code can be accessed using the GetLastResult() method.
377 * @see Tizen::Base::Collection::IBidirectionalEnumeratorT
379 virtual IBidirectionalEnumeratorT< Type >* GetBidirectionalEnumeratorN(void) const = 0;
383 }}} // Tizen::Base::Collection
385 #endif // _FBASE_COL_ILIST_T_H_