Home | History | Annotate | Download | only in interface
      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_LIST_WRAPPER_H_
     12 #define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_LIST_WRAPPER_H_
     13 
     14 #include "constructor_magic.h"
     15 
     16 namespace webrtc {
     17 class CriticalSectionWrapper;
     18 
     19 class ListItem
     20 {
     21 friend class ListWrapper;
     22 
     23 public:
     24     ListItem(const void* ptr);
     25     ListItem(const unsigned int item);
     26     virtual ~ListItem();
     27     void* GetItem() const;
     28     unsigned int GetUnsignedItem() const;
     29 
     30 protected:
     31     ListItem* next_;
     32     ListItem* prev_;
     33 
     34 private:
     35     const void*         item_ptr_;
     36     const unsigned int  item_;
     37     DISALLOW_COPY_AND_ASSIGN(ListItem);
     38 };
     39 
     40 class ListWrapper
     41 {
     42 public:
     43     ListWrapper();
     44     virtual ~ListWrapper();
     45 
     46     // Returns the number of elements stored in the list.
     47     unsigned int GetSize() const;
     48 
     49     // Puts a pointer to anything last in the list.
     50     int PushBack(const void* ptr);
     51     // Puts a pointer to anything first in the list.
     52     int PushFront(const void* ptr);
     53 
     54     // Puts a copy of the specified integer last in the list.
     55     int PushBack(const unsigned int item_id);
     56     // Puts a copy of the specified integer first in the list.
     57     int PushFront(const unsigned int item_id);
     58 
     59     // Pops the first ListItem from the list
     60     int PopFront();
     61 
     62     // Pops the last ListItem from the list
     63     int PopBack();
     64 
     65     // Returns true if the list is empty
     66     bool Empty() const;
     67 
     68     // Returns a pointer to the first ListItem in the list.
     69     ListItem* First() const;
     70 
     71     // Returns a pointer to the last ListItem in the list.
     72     ListItem* Last() const;
     73 
     74     // Returns a pointer to the ListItem stored after item in the list.
     75     ListItem* Next(ListItem* item) const;
     76 
     77     // Returns a pointer to the ListItem stored before item in the list.
     78     ListItem* Previous(ListItem* item) const;
     79 
     80     // Removes item from the list.
     81     int Erase(ListItem* item);
     82 
     83     // Insert list item after existing_previous_item. Please note that new_item
     84     // must be created using new ListItem(). The map will take ownership of
     85     // new_item following a successfull insert. If insert fails new_item will
     86     // not be released by the List
     87     int Insert(ListItem* existing_previous_item,
     88                ListItem* new_item);
     89 
     90     // Insert list item before existing_next_item. Please note that new_item
     91     // must be created using new ListItem(). The map will take ownership of
     92     // new_item following a successfull insert. If insert fails new_item will
     93     // not be released by the List
     94     int InsertBefore(ListItem* existing_next_item,
     95                      ListItem* new_item);
     96 
     97 private:
     98     void PushBackImpl(ListItem* item);
     99     void PushFrontImpl(ListItem* item);
    100 
    101     CriticalSectionWrapper* critical_section_;
    102     ListItem* first_;
    103     ListItem* last_;
    104     unsigned int size_;
    105     DISALLOW_COPY_AND_ASSIGN(ListWrapper);
    106 };
    107 } //namespace webrtc
    108 
    109 #endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_LIST_WRAPPER_H_
    110