aboutsummaryrefslogtreecommitdiff
path: root/src/system_wrappers/interface/list_wrapper.h
blob: 3608adaa377925632a7fdb28e46158e28c71ccad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
 *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 */

#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_LIST_WRAPPER_H_
#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_LIST_WRAPPER_H_

#include "constructor_magic.h"

namespace webrtc {
class CriticalSectionWrapper;

class ListItem
{
friend class ListWrapper;

public:
    ListItem(const void* ptr);
    ListItem(const unsigned int item);
    virtual ~ListItem();
    void* GetItem() const;
    unsigned int GetUnsignedItem() const;

protected:
    ListItem* next_;
    ListItem* prev_;

private:
    const void*         item_ptr_;
    const unsigned int  item_;
};

class ListWrapper
{
public:
    ListWrapper();
    virtual ~ListWrapper();

    // Returns the number of elements stored in the list.
    unsigned int GetSize() const;

    // Puts a pointer to anything last in the list.
    int PushBack(const void* ptr);
    // Puts a pointer to anything first in the list.
    int PushFront(const void* ptr);

    // Puts a copy of the specified integer last in the list.
    int PushBack(const unsigned int item_id);
    // Puts a copy of the specified integer first in the list.
    int PushFront(const unsigned int item_id);

    // Pops the first ListItem from the list
    int PopFront();

    // Pops the last ListItem from the list
    int PopBack();

    // Returns true if the list is empty
    bool Empty() const;

    // Returns a pointer to the first ListItem in the list.
    ListItem* First() const;

    // Returns a pointer to the last ListItem in the list.
    ListItem* Last() const;

    // Returns a pointer to the ListItem stored after item in the list.
    ListItem* Next(ListItem* item) const;

    // Returns a pointer to the ListItem stored before item in the list.
    ListItem* Previous(ListItem* item) const;

    // Removes item from the list.
    int Erase(ListItem* item);

    // Insert list item after existing_previous_item. Please note that new_item
    // must be created using new ListItem(). The map will take ownership of
    // new_item following a successfull insert. If insert fails new_item will
    // not be released by the List
    int Insert(ListItem* existing_previous_item,
               ListItem* new_item);

    // Insert list item before existing_next_item. Please note that new_item
    // must be created using new ListItem(). The map will take ownership of
    // new_item following a successfull insert. If insert fails new_item will
    // not be released by the List
    int InsertBefore(ListItem* existing_next_item,
                     ListItem* new_item);

private:
    void PushBackImpl(ListItem* item);
    void PushFrontImpl(ListItem* item);

    CriticalSectionWrapper* critical_section_;
    ListItem* first_;
    ListItem* last_;
    unsigned int size_;
};
} //namespace webrtc

#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_LIST_WRAPPER_H_