1/*
2 *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3 *
4 *  Use of this source code is governed by a BSD-style license
5 *  that can be found in the LICENSE file in the root of the source
6 *  tree. An additional intellectual property rights grant can be found
7 *  in the file PATENTS.  All contributing project authors may
8 *  be found in the AUTHORS file in the root of the source tree.
9 */
10
11#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_MAP_WRAPPER_H_
12#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_MAP_WRAPPER_H_
13
14#include <map>
15
16#include "constructor_magic.h"
17
18namespace webrtc {
19class MapItem
20{
21friend class MapWrapper;
22
23public:
24    MapItem(int id, void* ptr);
25    virtual ~MapItem();
26    void* GetItem();
27    int GetId();
28    unsigned int GetUnsignedId();
29    void SetItem(void* ptr);
30
31private:
32    int   item_id_;
33    void* item_pointer_;
34};
35
36class MapWrapper
37{
38public:
39    MapWrapper();
40    ~MapWrapper();
41
42    // Puts a pointer to anything in the map and associates it with id. Note, id
43    // needs to be unique for all items in the map.
44    int Insert(int id, void* ptr);
45
46    // Removes item from map.
47    int Erase(MapItem* item);
48
49    // Finds item with associated with id and removes it from the map.
50    int Erase(int id);
51
52    // Returns the number of elements stored in the map.
53    int Size() const;
54
55    // Returns a pointer to the first MapItem in the map.
56    MapItem* First() const;
57
58    // Returns a pointer to the last MapItem in the map.
59    MapItem* Last() const;
60
61    // Returns a pointer to the MapItem stored after item in the map.
62    MapItem* Next(MapItem* item) const;
63
64    // Returns a pointer to the MapItem stored before item in the map.
65    MapItem* Previous(MapItem* item) const;
66
67    // Returns a pointer to the MapItem associated with id from the map.
68    MapItem* Find(int id) const;
69
70private:
71    std::map<int, MapItem*>    map_;
72};
73} // namespace webrtc
74
75#endif  // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_MAP_WRAPPER_H_
76