• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
18 namespace webrtc {
19 class MapItem
20 {
21 friend class MapWrapper;
22 
23 public:
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 
31 private:
32     int   item_id_;
33     void* item_pointer_;
34     DISALLOW_COPY_AND_ASSIGN(MapItem);
35 };
36 
37 class MapWrapper
38 {
39 public:
40     MapWrapper();
41     ~MapWrapper();
42 
43     // Puts a pointer to anything in the map and associates it with id. Note, id
44     // needs to be unique for all items in the map.
45     int Insert(int id, void* ptr);
46 
47     // Removes item from map.
48     int Erase(MapItem* item);
49 
50     // Finds item with associated with id and removes it from the map.
51     int Erase(int id);
52 
53     // Returns the number of elements stored in the map.
54     int Size() const;
55 
56     // Returns a pointer to the first MapItem in the map.
57     MapItem* First() const;
58 
59     // Returns a pointer to the last MapItem in the map.
60     MapItem* Last() const;
61 
62     // Returns a pointer to the MapItem stored after item in the map.
63     MapItem* Next(MapItem* item) const;
64 
65     // Returns a pointer to the MapItem stored before item in the map.
66     MapItem* Previous(MapItem* item) const;
67 
68     // Returns a pointer to the MapItem associated with id from the map.
69     MapItem* Find(int id) const;
70 
71 private:
72     std::map<int, MapItem*>    map_;
73     DISALLOW_COPY_AND_ASSIGN(MapWrapper);
74 };
75 } // namespace webrtc
76 
77 #endif  // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_MAP_WRAPPER_H_
78