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 }; 38 39 class ListWrapper 40 { 41 public: 42 ListWrapper(); 43 virtual ~ListWrapper(); 44 45 // Returns the number of elements stored in the list. 46 unsigned int GetSize() const; 47 48 // Puts a pointer to anything last in the list. 49 int PushBack(const void* ptr); 50 // Puts a pointer to anything first in the list. 51 int PushFront(const void* ptr); 52 53 // Puts a copy of the specified integer last in the list. 54 int PushBack(const unsigned int item_id); 55 // Puts a copy of the specified integer first in the list. 56 int PushFront(const unsigned int item_id); 57 58 // Pops the first ListItem from the list 59 int PopFront(); 60 61 // Pops the last ListItem from the list 62 int PopBack(); 63 64 // Returns true if the list is empty 65 bool Empty() const; 66 67 // Returns a pointer to the first ListItem in the list. 68 ListItem* First() const; 69 70 // Returns a pointer to the last ListItem in the list. 71 ListItem* Last() const; 72 73 // Returns a pointer to the ListItem stored after item in the list. 74 ListItem* Next(ListItem* item) const; 75 76 // Returns a pointer to the ListItem stored before item in the list. 77 ListItem* Previous(ListItem* item) const; 78 79 // Removes item from the list. 80 int Erase(ListItem* item); 81 82 // Insert list item after existing_previous_item. Please note that new_item 83 // must be created using new ListItem(). The map will take ownership of 84 // new_item following a successfull insert. If insert fails new_item will 85 // not be released by the List 86 int Insert(ListItem* existing_previous_item, 87 ListItem* new_item); 88 89 // Insert list item before existing_next_item. Please note that new_item 90 // must be created using new ListItem(). The map will take ownership of 91 // new_item following a successfull insert. If insert fails new_item will 92 // not be released by the List 93 int InsertBefore(ListItem* existing_next_item, 94 ListItem* new_item); 95 96 private: 97 void PushBackImpl(ListItem* item); 98 void PushFrontImpl(ListItem* item); 99 100 CriticalSectionWrapper* critical_section_; 101 ListItem* first_; 102 ListItem* last_; 103 unsigned int size_; 104 }; 105 } //namespace webrtc 106 107 #endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_LIST_WRAPPER_H_ 108