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