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 FBaseColIMultiMap.h
20 * @brief This is the header file for the %IMultiMap interface.
22 * This header file contains the declarations of the %IMultiMap interface.
24 #ifndef _FBASE_COL_IMULTI_MAP_H_
25 #define _FBASE_COL_IMULTI_MAP_H_
27 #include <FBaseColICollection.h>
28 #include <FBaseColTypes.h>
29 #include <FBaseColIMapEnumerator.h>
30 #include <FBaseObject.h>
33 namespace Tizen { namespace Base { namespace Collection
40 * @interface IMultiMap
41 * @brief This interface represents a collection of key-value pairs.
45 * The %IMultiMap interface abstracts a collection of key-value pairs.
46 * There is no limit on the number of elements with the same key, but duplicated elements with the same key are not allowed.
47 * The key and value cannot be a @c null reference.
49 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/base/hashmap_multihashmap.htm">HashMap and MultiHashMap</a>.
52 class _OSP_EXPORT_ IMultiMap
53 : public virtual ICollection
57 * This polymorphic destructor should be overridden if required. @n
58 * This way, the destructors of the derived classes are called when the destructor of this interface is called.
62 virtual ~IMultiMap(void) {}
66 * Adds the specified key-value pair to the map.
68 * @brief <i> [Deprecated] </i>
69 * @deprecated This method is deprecated because it has a problem of const reference argument.
70 * Instead of using this method, use Add(Object* pKey, Object* pValue).
73 * @return An error code
74 * @param[in] key The key to add
75 * @param[in] value The corresponding value to add
76 * @exception E_SUCCESS The method is successful.
77 * @exception E_INVALID_ARG A specified input parameter is invalid, or
78 * the comparer has failed to compare the keys.
79 * @exception E_OBJ_ALREADY_EXIST The specified @c key and @c value already exist.
80 * @remarks This method performs a shallow copy. It adds just the pointer; not the element itself.
84 result Add(const Object& key, const Object& value)
86 return Add(const_cast< Object* >(&key), const_cast< Object* >(&value));
90 * Adds the specified key-value pair to the map.
94 * @return An error code
95 * @param[in] pKey The pointer to key to add
96 * @param[in] pValue The pointer to corresponding value to add
97 * @exception E_SUCCESS The method is successful.
98 * @exception E_INVALID_ARG A specified input parameter is invalid, or
99 * the comparer has failed to compare the keys.
100 * @exception E_OBJ_ALREADY_EXIST The specified @c pKey and @c pValue already exist.
101 * @remarks This method performs a shallow copy. It adds just the pointer; not the element itself.
104 virtual result Add(Object* pKey, Object* pValue) = 0;
107 * Gets the number of values stored in the map.
111 * @return The number of values currently stored in the map
113 virtual int GetCount(void) const = 0;
116 * Gets the number of values with keys matching the specified key.
120 * @return The number of values with keys matching the specified key
121 * @param[in] key The key to locate in the map
122 * @param[out] count The number of values with keys matching the specified key
123 * @exception E_SUCCESS The method is successful.
124 * @exception E_INVALID_ARG The specified input parameter is invalid, or
125 * the comparer has failed to compare the keys.
126 * @exception E_OBJ_NOT_FOUND The specified @c key is not found in the map.
128 virtual result GetCount(const Object& key, int& count) const = 0;
131 * Gets an enumerator of the values associated with the specified key.
135 * @return An instance of the IEnumerator derived class with the values associated with the specified key, @n
136 * else @c null if an exception occurs
137 * @param[in] key The key to locate in the map
138 * @exception E_SUCCESS The method is successful.
139 * @exception E_INVALID_ARG A specified input parameter is invalid, or
140 * the comparer has failed to compare the keys.
141 * @exception E_OBJ_NOT_FOUND The specified @c key is not found in the map.
142 * @remarks The specific error code can be accessed using the GetLastResult() method.
144 virtual IEnumerator* GetValuesN(const Object& key) const = 0;
147 * Gets a list of all unique keys in the map.
151 * @return A pointer to a list of all unique keys in the map, @n
152 * else @c null if an exception occurs
153 * @remarks The %IList stores just the pointers to the elements in the map, not the elements themselves.
154 * @remarks The specific error code can be accessed using the GetLastResult() method.
157 virtual IList* GetKeysN(void) const = 0;
160 * Gets a list of all the values in the map.
164 * @return A pointer to a list of all the values in the map, @n
165 * else @c null if an exception occurs
166 * @remarks The IList stores just the pointers to the elements in the map, not the elements themselves.
167 * @remarks The specific error code can be accessed using the GetLastResult() method.
170 virtual IList* GetValuesN(void) const = 0;
173 * Removes all the values associated with the specified key.
177 * @return An error code
178 * @param[in] key The key for which the associated values need to remove
179 * @param[in] forceDeletion Set to @c true to deallocate the object, @n
181 * @exception E_SUCCESS The method is successful.
182 * @exception E_INVALID_ARG A specified input parameter is invalid, or
183 * the comparer has failed to compare the keys.
184 * @exception E_OBJ_NOT_FOUND The specified @c key is not found in the map.
185 * @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
186 * The element deleter style is recommended rather than using the @c forceDeletetion argument in the remove method. @n
187 * If both an element deleter and forceDeleteion are set, the remove operation follows @c forceDeletion setting.
188 * @remarks Remove(key, @b true) internally works as the below code:
190 * DeleterFunctionType deleter = GetDeleter();
191 * SetDeleter(SingleObjectDeleter);
193 * SetDeleter(deleter);
195 * @remarks Remove(key, @b false) internally works as the below code:
197 * DeleterFunctionType deleter = GetDeleter();
198 * SetDeleter(NoOpDeleter);
200 * SetDeleter(deleter);
204 result Remove(const Object& key, bool forceDeletion)
206 DeleterFunctionType deleter = GetDeleter();
210 SetDeleter(SingleObjectDeleter);
214 SetDeleter(NoOpDeleter);
217 result r = Remove(key);
223 * Removes all the values associated with the specified key.
227 * @return An error code
228 * @param[in] key The key for which the associated values need to remove
229 * @exception E_SUCCESS The method is successful.
230 * @exception E_INVALID_ARG A specified input parameter is invalid, or
231 * the comparer has failed to compare the keys.
232 * @exception E_OBJ_NOT_FOUND The specified @c key is not found in the map.
235 virtual result Remove(const Object& key) = 0;
238 * Removes the specified value associated with the specified key. @n
239 * The key is also removed if there are no more values associated with it.
243 * @return An error code
244 * @param[in] key The key for which the mapping is to remove from the map
245 * @param[in] value The value to remove
246 * @param[in] forceDeletion Set to @c true to deallocate the object, @n
248 * @exception E_SUCCESS The method is successful.
249 * @exception E_INVALID_ARG A specified input parameter is invalid, or
250 * the comparer has failed to compare the keys.
251 * @exception E_OBJ_NOT_FOUND The @c key and @c value pair is not found in the map.
252 * @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
253 * The element deleter style is recommended rather than using the @c forceDeletetion argument in the remove method. @n
254 * If both an element deleter and forceDeleteion are set, the remove operation follows @c forceDeletion setting.
255 * @remarks Remove(key, value, @b true) internally works as the below code:
257 * DeleterFunctionType deleter = GetDeleter();
258 * SetDeleter(SingleObjectDeleter);
259 * Remove(key, value);
260 * SetDeleter(deleter);
262 * @remarks Remove(key, value, @b false) internally works as the below code:
264 * DeleterFunctionType deleter = GetDeleter();
265 * SetDeleter(NoOpDeleter);
266 * Remove(key, value);
267 * SetDeleter(deleter);
271 result Remove(const Object& key, const Object& value, bool forceDeletion)
273 DeleterFunctionType deleter = GetDeleter();
277 SetDeleter(SingleObjectDeleter);
281 SetDeleter(NoOpDeleter);
284 result r = Remove(key, value);
290 * Removes the specified value associated with the specified key. @n
291 * The key is also removed if there are no more values associated with it.
295 * @return An error code
296 * @param[in] key The key for which the mapping is to remove from the map
297 * @param[in] value The value to remove
298 * @exception E_SUCCESS The method is successful.
299 * @exception E_INVALID_ARG A specified input parameter is invalid, or
300 * the comparer has failed to compare the keys.
301 * @exception E_OBJ_NOT_FOUND The @c key and @c value pair is not found in the map.
304 virtual result Remove(const Object& key, const Object& value) = 0;
307 * Removes all the object pointers in the collection. @n
308 * If the @c forceDeletion parameter is set to @c true, the method also removes all the objects. This method can be called before deleting the collection.
312 * @param[in] forceDeletion Set to @c true to deallocate all objects, @n
314 * @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
315 * The element deleter style is recommended rather than using the @c forceDeletetion argument in the remove method. @n
316 * If both an element deleter and forceDeleteion are set, the remove operation follows @c forceDeletion setting.
317 * @remarks RemoveAll(@b true) internally works as the below code:
319 * DeleterFunctionType deleter = GetDeleter();
320 * SetDeleter(SingleObjectDeleter);
322 * SetDeleter(deleter);
324 * @remarks RemoveAll(@b false) internally works as the below code:
326 * DeleterFunctionType deleter = GetDeleter();
327 * SetDeleter(NoOpDeleter);
329 * SetDeleter(deleter);
332 void RemoveAll(bool forceDeletion)
334 DeleterFunctionType deleter = GetDeleter();
338 SetDeleter(SingleObjectDeleter);
342 SetDeleter(NoOpDeleter);
350 * Removes all the object pointers in the collection. @n
351 * This method can be called before deleting the collection.
355 virtual void RemoveAll(void) = 0;
358 * Replaces the specified value associated with the specified key with a new value.
362 * @return An error code
363 * @param[in] key The key for which the associated value needs to replace
364 * @param[in] value The value associated with the key
365 * @param[in] newValue The new value
366 * @param[in] forceDeletion Set to @c true to deallocate the object, @n
368 * @exception E_SUCCESS The method is successful.
369 * @exception E_INVALID_ARG A specified input parameter is invalid, or
370 * the comparer has failed to compare the keys.
371 * @exception E_OBJ_NOT_FOUND The key-value pair is not found in the map.
372 * @remarks Use the Add() method to add a new key-value pair.
373 * @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
374 * The element deleter style is recommended rather than using the @c forceDeletetion argument in the set method. @n
375 * If both an element deleter and forceDeleteion are set, the set operation follows @c forceDeletion setting.
376 * @remarks SetValue(key, value, newValue, @b true) internally works as the below code:
378 * DeleterFunctionType deleter = GetDeleter();
379 * SetDeleter(SingleObjectDeleter);
380 * SetValue(key, value, const_cast< Object* >(&newValue));
381 * SetDeleter(deleter);
383 * @remarks SetValue(key, value, newValue, @b false) internally works as the below code:
385 * DeleterFunctionType deleter = GetDeleter();
386 * SetDeleter(NoOpDeleter);
387 * SetValue(key, value, const_cast< Object* >(&newValue));
388 * SetDeleter(deleter);
393 result SetValue(const Object& key, const Object& value, const Object& newValue, bool forceDeletion = false)
395 DeleterFunctionType deleter = GetDeleter();
399 SetDeleter(SingleObjectDeleter);
403 SetDeleter(NoOpDeleter);
406 result r = SetValue(key, value, const_cast< Object* >(&newValue));
412 * Replaces the specified value associated with the specified key with a new value.
416 * @return An error code
417 * @param[in] key The key for which the associated value needs to replace
418 * @param[in] value The value associated with the key
419 * @param[in] pNewValue The pointer to new value
420 * @exception E_SUCCESS The method is successful.
421 * @exception E_INVALID_ARG A specified input parameter is invalid, or
422 * the comparer has failed to compare the keys.
423 * @exception E_OBJ_NOT_FOUND The key-value pair is not found in the map.
424 * @remarks Use the Add() method to add a new key-value pair.
428 virtual result SetValue(const Object& key, const Object& value, Object* pNewValue) = 0;
432 * Checks whether the map contains the specified key-value pair.
434 * @brief <i> [Deprecated] </i>
435 * @deprecated This method is deprecated because it transfers a result of comparison in out-parameter form.
436 * The return type will be changed into boolean type and this method will return the result.
437 * Instead of using this method, use bool Contains(const Object& key, const Object& value).
440 * @return An error code
441 * @param[in] key The key to locate
442 * @param[in] value The value to locate
443 * @param[out] out Set to @c true if the map contains the specified key-value pair, @n
445 * @exception E_SUCCESS The method is successful.
446 * @exception E_INVALID_ARG A specified input parameter is invalid, or
447 * the comparer has failed to compare the keys.
449 * @see ContainsValue()
452 result Contains(const Object& key, const Object& value, bool& out) const
454 out = Contains(key, value);
455 result r = GetLastResult();
460 * Checks whether the map contains the specified key-value pair.
464 * @return @c true if the map contains the specified key-value pair, @n
466 * @param[in] key The key to locate
467 * @param[in] value The value to locate
468 * @exception E_SUCCESS The method is successful.
469 * @exception E_INVALID_ARG A specified input parameter is invalid, or
470 * the comparer has failed to compare the keys.
471 * @remarks The specific error code can be accessed using the GetLastResult() method.
473 * @see ContainsValue()
475 virtual bool Contains(const Object& key, const Object& value) const = 0;
479 * Checks whether the map contains the specified key.
481 * @brief <i> [Deprecated] </i>
482 * @deprecated This method is deprecated because it transfers a result of comparison in out-parameter form.
483 * The return type will be changed into boolean type and this method will return the result.
484 * Instead of using this method, use bool ContainsKey(const Object& key).
487 * @return An error code
488 * @param[in] key The key to locate
489 * @param[out] out Set to @c true if the map contains the specified key, @n
491 * @exception E_SUCCESS The method is successful.
492 * @exception E_INVALID_ARG A specified input parameter is invalid, or
493 * the comparer has failed to compare the keys.
494 * @see ContainsValue()
498 result ContainsKey(const Object& key, bool& out) const
500 out = ContainsKey(key);
501 result r = GetLastResult();
506 * Checks whether the map contains the specified key.
510 * @return @c true if the map contains the specified key, @n
512 * @param[in] key The key to locate
513 * @exception E_SUCCESS The method is successful.
514 * @exception E_INVALID_ARG A specified input parameter is invalid, or
515 * the comparer has failed to compare the keys.
516 * @remarks The specific error code can be accessed using the GetLastResult() method.
517 * @see ContainsValue()
520 virtual bool ContainsKey(const Object& key) const = 0;
523 * Checks whether the map contains the specified value.
527 * @return @c true if the map contains the specified value, @n
529 * @param[in] value The value to locate
534 virtual bool ContainsValue(const Object& value) const = 0;
537 * Gets an enumerator of the map.
541 * @return An instance of the IMapEnumerator class for the map, @n
542 * else @c null if an exception occurs
543 * @exception E_SUCCESS The method is successful.
544 * @remarks If a key has multiple values, the enumeration proceeds as follows: @n
545 * {A: a}, {B: b}, {B: c}, {B, d}, {C: e}, ...
546 * @remarks The specific error code can be accessed using the GetLastResult() method.
548 * @see IMapEnumerator
550 virtual IMapEnumerator* GetMapEnumeratorN(void) const = 0;
553 * Gets the element deleter of the collection.
557 * @return A function pointer to the existing element deleter
559 virtual DeleterFunctionType GetDeleter(void) const = 0;
563 // This method is for internal use only. Using this method can cause behavioral, security-related,
564 // and consistency-related issues in the application.
565 // This method is reserved and may change its name at any time without prior notice.
569 virtual void IMultiMap_Reserved1(void) { }
573 // This method is for internal use only. Using this method can cause behavioral, security-related,
574 // and consistency-related issues in the application.
575 // This method is reserved and may change its name at any time without prior notice.
579 virtual void IMultiMap_Reserved2(void) { }
583 * Sets the element deleter of the collection.
587 * @param[in] deleter A function pointer to the element deleter to set
589 virtual void SetDeleter(DeleterFunctionType deleter) = 0;
593 }}} // Tizen::Base::Collection
595 #endif // _FBASE_COL_IMULTI_MAP_H_