Panda3D
 All Classes Functions Variables Enumerations
memoryUsagePointerCounts.I
1 // Filename: memoryUsagePointerCounts.I
2 // Created by: drose (04Jun01)
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 
16 ////////////////////////////////////////////////////////////////////
17 // Function: MemoryUsagePointerCounts::Constructor
18 // Access: Public
19 // Description:
20 ////////////////////////////////////////////////////////////////////
21 INLINE MemoryUsagePointerCounts::
22 MemoryUsagePointerCounts() {
23  _count = 0;
24  _unknown_size_count = 0;
25  _size = 0;
26 }
27 
28 ////////////////////////////////////////////////////////////////////
29 // Function: MemoryUsagePointerCounts::Copy Constructor
30 // Access: Public
31 // Description:
32 ////////////////////////////////////////////////////////////////////
33 INLINE MemoryUsagePointerCounts::
34 MemoryUsagePointerCounts(const MemoryUsagePointerCounts &copy) :
35  _count(copy._count),
36  _unknown_size_count(copy._unknown_size_count),
37  _size(copy._size)
38 {
39 }
40 
41 ////////////////////////////////////////////////////////////////////
42 // Function: MemoryUsagePointerCounts::Copy Assignment
43 // Access: Public
44 // Description:
45 ////////////////////////////////////////////////////////////////////
46 INLINE void MemoryUsagePointerCounts::
47 operator = (const MemoryUsagePointerCounts &copy) {
48  _count = copy._count;
49  _unknown_size_count = copy._unknown_size_count;
50  _size = copy._size;
51 }
52 
53 ////////////////////////////////////////////////////////////////////
54 // Function: MemoryUsagePointerCounts::clear
55 // Access: Public
56 // Description: Resets the counter to empty.
57 ////////////////////////////////////////////////////////////////////
58 INLINE void MemoryUsagePointerCounts::
59 clear() {
60  _count = 0;
61  _unknown_size_count = 0;
62  _size = 0;
63 }
64 
65 ////////////////////////////////////////////////////////////////////
66 // Function: MemoryUsagePointerCounts::is_size_unknown
67 // Access: Public
68 // Description: Returns true if none of the pointers in the count
69 // have a known size, or false if at least one of them
70 // does.
71 ////////////////////////////////////////////////////////////////////
72 INLINE bool MemoryUsagePointerCounts::
73 is_size_unknown() const {
74  return _unknown_size_count == _count;
75 }
76 
77 ////////////////////////////////////////////////////////////////////
78 // Function: MemoryUsagePointerCounts::get_size
79 // Access: Public
80 // Description: Returns the total allocated size of all pointers in
81 // the count whose size is known.
82 ////////////////////////////////////////////////////////////////////
83 INLINE size_t MemoryUsagePointerCounts::
84 get_size() const {
85  return _size;
86 }
87 
88 ////////////////////////////////////////////////////////////////////
89 // Function: MemoryUsagePointerCounts::get_count
90 // Access: Public
91 // Description: Returns the total number of pointers in the count.
92 ////////////////////////////////////////////////////////////////////
93 INLINE int MemoryUsagePointerCounts::
94 get_count() const {
95  return _count;
96 }
97 
98 ////////////////////////////////////////////////////////////////////
99 // Function: MemoryUsagePointerCounts::Ordering Operator
100 // Access: Public
101 // Description:
102 ////////////////////////////////////////////////////////////////////
103 INLINE bool MemoryUsagePointerCounts::
104 operator < (const MemoryUsagePointerCounts &other) const {
105  if (is_size_unknown() != other.is_size_unknown()) {
106  return is_size_unknown() > other.is_size_unknown();
107  }
108 
109  if (get_size() != other.get_size()) {
110  return get_size() < other.get_size();
111  }
112 
113  if (get_count() != other.get_count()) {
114  return get_count() != other.get_count();
115  }
116 
117  return false;
118 }
119 
120 INLINE ostream &
121 operator << (ostream &out, const MemoryUsagePointerCounts &c) {
122  c.output(out);
123  return out;
124 }