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 the keys in the map.
151 * @return A pointer to a list of all the keys in the map, @n
152 * else @c null if an exception occurs
153 * @remarks The order of the keys is the same as the corresponding values in the IList interface returned by the GetValuesN() method.
154 * @remarks The %IList stores just the pointers to the elements in the map, not the elements themselves.
155 * @remarks The specific error code can be accessed using the GetLastResult() method.
158 virtual IList* GetKeysN(void) const = 0;
161 * Gets a list of all the values in the map.
165 * @return A pointer to a list of all the values in the map, @n
166 * else @c null if an exception occurs
167 * @remarks The IList stores just the pointers to the elements in the map, not the elements themselves.
168 * @remarks The specific error code can be accessed using the GetLastResult() method.
171 virtual IList* GetValuesN(void) const = 0;
174 * Removes all the values associated with the specified key.
178 * @return An error code
179 * @param[in] key The key for which the associated values need to remove
180 * @param[in] forceDeletion Set to @c true to deallocate the object, @n
182 * @exception E_SUCCESS The method is successful.
183 * @exception E_INVALID_ARG A specified input parameter is invalid, or
184 * the comparer has failed to compare the keys.
185 * @exception E_OBJ_NOT_FOUND The specified @c key is not found in the map.
186 * @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
187 * The element deleter style is recommended rather than using the @c forceDeletetion argument in the remove method.@n
188 * If both an element deleter and forceDeleteion are set, the remove operation follows @c forceDeletion setting.
189 * @remarks Remove(key, @b true) internally works as the below code:
191 * DeleterFunctionType deleter = GetDeleter();
192 * SetDeleter(SingleObjectDeleter);
194 * SetDeleter(deleter);
196 * @remarks Remove(key, @b false) internally works as the below code:
198 * DeleterFunctionType deleter = GetDeleter();
199 * SetDeleter(NoOpDeleter);
201 * SetDeleter(deleter);
205 result Remove(const Object& key, bool forceDeletion)
207 DeleterFunctionType deleter = GetDeleter();
211 SetDeleter(SingleObjectDeleter);
215 SetDeleter(NoOpDeleter);
218 result r = Remove(key);
224 * Removes all the values associated with the specified key.
228 * @return An error code
229 * @param[in] key The key for which the associated values need to remove
230 * @exception E_SUCCESS The method is successful.
231 * @exception E_INVALID_ARG A specified input parameter is invalid, or
232 * the comparer has failed to compare the keys.
233 * @exception E_OBJ_NOT_FOUND The specified @c key is not found in the map.
236 virtual result Remove(const Object& key) = 0;
239 * Removes the specified value associated with the specified key. @n
240 * The key is also removed if there are no more values associated with it.
244 * @return An error code
245 * @param[in] key The key for which the mapping is to remove from the map
246 * @param[in] value The value to remove
247 * @param[in] forceDeletion Set to @c true to deallocate the object, @n
249 * @exception E_SUCCESS The method is successful.
250 * @exception E_INVALID_ARG A specified input parameter is invalid, or
251 * the comparer has failed to compare the keys.
252 * @exception E_OBJ_NOT_FOUND The @c key and @c value pair is not found in the map.
253 * @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
254 * The element deleter style is recommended rather than using the @c forceDeletetion argument in the remove method.@n
255 * If both an element deleter and forceDeleteion are set, the remove operation follows @c forceDeletion setting.
256 * @remarks Remove(key, value, @b true) internally works as the below code:
258 * DeleterFunctionType deleter = GetDeleter();
259 * SetDeleter(SingleObjectDeleter);
260 * Remove(key, value);
261 * SetDeleter(deleter);
263 * @remarks Remove(key, value, @b false) internally works as the below code:
265 * DeleterFunctionType deleter = GetDeleter();
266 * SetDeleter(NoOpDeleter);
267 * Remove(key, value);
268 * SetDeleter(deleter);
272 result Remove(const Object& key, const Object& value, bool forceDeletion)
274 DeleterFunctionType deleter = GetDeleter();
278 SetDeleter(SingleObjectDeleter);
282 SetDeleter(NoOpDeleter);
285 result r = Remove(key, value);
291 * Removes the specified value associated with the specified key. @n
292 * The key is also removed if there are no more values associated with it.
296 * @return An error code
297 * @param[in] key The key for which the mapping is to remove from the map
298 * @param[in] value The value to remove
299 * @exception E_SUCCESS The method is successful.
300 * @exception E_INVALID_ARG A specified input parameter is invalid, or
301 * the comparer has failed to compare the keys.
302 * @exception E_OBJ_NOT_FOUND The @c key and @c value pair is not found in the map.
305 virtual result Remove(const Object& key, const Object& value) = 0;
308 * Removes all the object pointers in the collection. @n
309 * 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.
313 * @param[in] forceDeletion Set to @c true to deallocate all objects, @n
315 * @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
316 * The element deleter style is recommended rather than using the @c forceDeletetion argument in the remove method.@n
317 * If both an element deleter and forceDeleteion are set, the remove operation follows @c forceDeletion setting.
318 * @remarks RemoveAll(@b true) internally works as the below code:
320 * DeleterFunctionType deleter = GetDeleter();
321 * SetDeleter(SingleObjectDeleter);
323 * SetDeleter(deleter);
325 * @remarks RemoveAll(@b false) internally works as the below code:
327 * DeleterFunctionType deleter = GetDeleter();
328 * SetDeleter(NoOpDeleter);
330 * SetDeleter(deleter);
333 void RemoveAll(bool forceDeletion)
335 DeleterFunctionType deleter = GetDeleter();
339 SetDeleter(SingleObjectDeleter);
343 SetDeleter(NoOpDeleter);
351 * Removes all the object pointers in the collection. @n
352 * This method can be called before deleting the collection.
356 virtual void RemoveAll(void) = 0;
359 * Replaces the specified value associated with the specified key with a new value.
363 * @return An error code
364 * @param[in] key The key for which the associated value needs to replace
365 * @param[in] value The value associated with the key
366 * @param[in] newValue The new value
367 * @param[in] forceDeletion Set to @c true to deallocate the object, @n
369 * @exception E_SUCCESS The method is successful.
370 * @exception E_INVALID_ARG A specified input parameter is invalid, or
371 * the comparer has failed to compare the keys.
372 * @exception E_OBJ_NOT_FOUND The key-value pair is not found in the map.
373 * @remarks Use the Add() method to add a new key-value pair.
374 * @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
375 * The element deleter style is recommended rather than using the @c forceDeletetion argument in the set method.@n
376 * If both an element deleter and forceDeleteion are set, the set operation follows @c forceDeletion setting.
377 * @remarks SetValue(key, value, newValue, @b true) internally works as the below code:
379 * DeleterFunctionType deleter = GetDeleter();
380 * SetDeleter(SingleObjectDeleter);
381 * SetValue(key, value, const_cast< Object* >(&newValue));
382 * SetDeleter(deleter);
384 * @remarks SetValue(key, value, newValue, @b false) internally works as the below code:
386 * DeleterFunctionType deleter = GetDeleter();
387 * SetDeleter(NoOpDeleter);
388 * SetValue(key, value, const_cast< Object* >(&newValue));
389 * SetDeleter(deleter);
394 result SetValue(const Object& key, const Object& value, const Object& newValue, bool forceDeletion = false)
396 DeleterFunctionType deleter = GetDeleter();
400 SetDeleter(SingleObjectDeleter);
404 SetDeleter(NoOpDeleter);
407 result r = SetValue(key, value, const_cast< Object* >(&newValue));
413 * Replaces the specified value associated with the specified key with a new value.
417 * @return An error code
418 * @param[in] key The key for which the associated value needs to replace
419 * @param[in] value The value associated with the key
420 * @param[in] pNewValue The pointer to new value
421 * @exception E_SUCCESS The method is successful.
422 * @exception E_INVALID_ARG A specified input parameter is invalid, or
423 * the comparer has failed to compare the keys.
424 * @exception E_OBJ_NOT_FOUND The key-value pair is not found in the map.
425 * @remarks Use the Add() method to add a new key-value pair.
429 virtual result SetValue(const Object& key, const Object& value, Object* pNewValue) = 0;
433 * Checks whether the map contains the specified key-value pair.
435 * @brief <i> [Deprecated] </i>
436 * @deprecated This method is deprecated because it transfers a result of comparison in out-parameter form.
437 * The return type will be changed into boolean type and this method will return the result.
438 * Instead of using this method, use bool Contains(const Object& key, const Object& value).
441 * @return An error code
442 * @param[in] key The key to locate
443 * @param[in] value The value to locate
444 * @param[out] out Set to @c true if the map contains the specified key-value pair, @n
446 * @exception E_SUCCESS The method is successful.
447 * @exception E_INVALID_ARG A specified input parameter is invalid, or
448 * the comparer has failed to compare the keys.
450 * @see ContainsValue()
453 result Contains(const Object& key, const Object& value, bool& out) const
455 out = Contains(key, value);
456 result r = GetLastResult();
461 * Checks whether the map contains the specified key-value pair.
465 * @return @c true if the map contains the specified key-value pair, @n
467 * @param[in] key The key to locate
468 * @param[in] value The value to locate
469 * @exception E_SUCCESS The method is successful.
470 * @exception E_INVALID_ARG A specified input parameter is invalid, or
471 * the comparer has failed to compare the keys.
472 * @remarks The specific error code can be accessed using the GetLastResult() method.
474 * @see ContainsValue()
476 virtual bool Contains(const Object& key, const Object& value) const = 0;
480 * Checks whether the map contains the specified key.
482 * @brief <i> [Deprecated] </i>
483 * @deprecated This method is deprecated because it transfers a result of comparison in out-parameter form.
484 * The return type will be changed into boolean type and this method will return the result.
485 * Instead of using this method, use bool ContainsKey(const Object& key).
488 * @return An error code
489 * @param[in] key The key to locate
490 * @param[out] out Set to @c true if the map contains the specified key, @n
492 * @exception E_SUCCESS The method is successful.
493 * @exception E_INVALID_ARG A specified input parameter is invalid, or
494 * the comparer has failed to compare the keys.
495 * @see ContainsValue()
499 result ContainsKey(const Object& key, bool& out) const
501 out = ContainsKey(key);
502 result r = GetLastResult();
507 * Checks whether the map contains the specified key.
511 * @return @c true if the map contains the specified key, @n
513 * @param[in] key The key to locate
514 * @exception E_SUCCESS The method is successful.
515 * @exception E_INVALID_ARG A specified input parameter is invalid, or
516 * the comparer has failed to compare the keys.
517 * @remarks The specific error code can be accessed using the GetLastResult() method.
518 * @see ContainsValue()
521 virtual bool ContainsKey(const Object& key) const = 0;
524 * Checks whether the map contains the specified value.
528 * @return @c true if the map contains the specified value, @n
530 * @param[in] value The value to locate
535 virtual bool ContainsValue(const Object& value) const = 0;
538 * Gets an enumerator of the map.
542 * @return An instance of the IMapEnumerator class for the map, @n
543 * else @c null if an exception occurs
544 * @exception E_SUCCESS The method is successful.
545 * @remarks If a key has multiple values, the enumeration proceeds as follows: @n
546 * {A: a}, {B: b}, {B: c}, {B, d}, {C: e}, ...
547 * @remarks The specific error code can be accessed using the GetLastResult() method.
549 * @see IMapEnumerator
551 virtual IMapEnumerator* GetMapEnumeratorN(void) const = 0;
554 * Gets the element deleter of the collection.
558 * @return An function pointer to the existing element deleter
560 virtual DeleterFunctionType GetDeleter(void) const = 0;
564 // This method is for internal use only. Using this method can cause behavioral, security-related,
565 // and consistency-related issues in the application.
566 // This method is reserved and may change its name at any time without prior notice.
570 virtual void IMultiMap_Reserved1(void) { }
574 // This method is for internal use only. Using this method can cause behavioral, security-related,
575 // and consistency-related issues in the application.
576 // This method is reserved and may change its name at any time without prior notice.
580 virtual void IMultiMap_Reserved2(void) { }
584 * Sets the element deleter of the collection.
588 * @param[in] deleter A function pointer to the element deleter to set
590 virtual void SetDeleter(DeleterFunctionType deleter) = 0;
594 }}} // Tizen::Base::Collection
596 #endif // _FBASE_COL_IMULTI_MAP_H_