Panda3D
 All Classes Functions Variables Enumerations
plist.h
1 // Filename: plist.h
2 // Created by: drose (05Jun01)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef PLIST_H
16 #define PLIST_H
17 
18 #include "dtoolbase.h"
19 #include "pallocator.h"
20 #include "register_type.h"
21 #include <list>
22 
23 #ifndef USE_STL_ALLOCATOR
24 // If we're not using custom allocators, just use the standard class
25 // definition.
26 #define plist list
27 
28 #else
29 
30 ////////////////////////////////////////////////////////////////////
31 // Class : plist
32 // Description : This is our own Panda specialization on the default
33 // STL list. Its main purpose is to call the hooks
34 // for MemoryUsage to properly track STL-allocated
35 // memory.
36 ////////////////////////////////////////////////////////////////////
37 template<class Type>
38 class plist : public list<Type, pallocator_single<Type> > {
39 public:
41  typedef list<Type, allocator> base_class;
42  typedef TYPENAME base_class::size_type size_type;
43  plist(TypeHandle type_handle = plist_type_handle) : base_class(allocator(type_handle)) { }
44  plist(const plist<Type> &copy) : base_class(copy) { }
45  plist(size_type n, TypeHandle type_handle = plist_type_handle) : base_class(n, Type(), allocator(type_handle)) { }
46  plist(size_type n, const Type &value, TypeHandle type_handle = plist_type_handle) : base_class(n, value, allocator(type_handle)) { }
47 
48  typedef TYPENAME base_class::iterator iterator;
49  typedef TYPENAME base_class::const_iterator const_iterator;
50  typedef TYPENAME base_class::reverse_iterator reverse_iterator;
51  typedef TYPENAME base_class::const_reverse_iterator const_reverse_iterator;
52 
53  // This exists because libc++'s remove implementation has a bug with
54  // Panda's allocator class.
55  INLINE void remove(const Type &val) {
56  iterator it = this->begin();
57  while (it != this->end()) {
58  if (*it == val) {
59  it = this->erase(it);
60  } else {
61  ++it;
62  }
63  }
64  };
65 };
66 
67 #endif // USE_STL_ALLOCATOR
68 #endif
This is our own Panda specialization on the default STL list.
Definition: plist.h:38
This is our own Panda specialization on the default STL allocator.
Definition: pallocator.h:50
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85