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_SOURCE_MAP_NO_STL_H_
12#define WEBRTC_SYSTEM_WRAPPERS_SOURCE_MAP_NO_STL_H_
13
14#include "constructor_magic.h"
15
16namespace webrtc {
17class CriticalSectionWrapper;
18
19class MapNoStlItem
20{
21friend class Map;
22
23public:
24    MapNoStlItem(int id, void* ptr);
25    virtual ~MapNoStlItem();
26    void* GetItem();
27    int GetId();
28    unsigned int GetUnsignedId();
29    void SetItem(void* ptr);
30
31protected:
32    MapNoStlItem* next_;
33    MapNoStlItem* prev_;
34
35private:
36    int item_id_;
37    void* item_ptr_;
38    DISALLOW_COPY_AND_ASSIGN(MapNoStlItem);
39};
40
41class MapNoStl
42{
43public:
44    MapNoStl();
45    virtual ~MapNoStl();
46
47    // MapWrapper functions.
48    int Insert(int id, void* ptr);
49    int Erase(MapNoStlItem* item);
50    int Erase(int id);
51    int Size() const;
52    MapNoStlItem* First() const;
53    MapNoStlItem* Last() const;
54    MapNoStlItem* Next(MapNoStlItem* item) const;
55    MapNoStlItem* Previous(MapNoStlItem* item) const;
56    MapNoStlItem* Find(int id) const;
57
58private:
59    MapNoStlItem* Locate(int id) const;
60    int Remove(MapNoStlItem* item);
61
62    CriticalSection* critical_section_;
63    MapNoStlItem* first_;
64    MapNoStlItem* last_;
65    int size_;
66    DISALLOW_COPY_AND_ASSIGN(MapNoStl);
67};
68} // namespace webrtc
69
70#endif // WEBRTC_SYSTEM_WRAPPERS_SOURCE_MAP_NO_STL_H_
71