16 template<
class Element>
19 template<
class Element>
25 template<
class Element>
29 _type_handle(type_handle)
36 template<
class Element>
42 To new_array(n, type_handle);
43 ((To *)(temp._void_ptr))->
swap(new_array);
50 template<
class Element>
54 _type_handle(type_handle)
56 ((To *)(this->_void_ptr))->reserve(n);
57 insert(begin(), n, value);
63 template<
class Element>
67 _type_handle(copy._type_handle)
74 template<
class Element>
78 _type_handle(type_handle)
85 template<
class Element>
89 _type_handle(from._type_handle)
96 template<
class Element>
100 _type_handle(type_handle)
107 template<
class Element>
110 if ((this->_void_ptr) ==
nullptr) {
111 return _empty_array.begin();
113 return ((To *)(this->_void_ptr))->begin();
119 template<
class Element>
122 if ((this->_void_ptr) ==
nullptr) {
123 return _empty_array.begin();
125 return ((To *)(this->_void_ptr))->end();
131 template<
class Element>
134 if ((this->_void_ptr) ==
nullptr) {
135 return _empty_array.rbegin();
137 return ((To *)(this->_void_ptr))->rbegin();
143 template<
class Element>
146 if ((this->_void_ptr) ==
nullptr) {
147 return _empty_array.rbegin();
149 return ((To *)(this->_void_ptr))->rend();
155 template<
class Element>
158 return ((this->_void_ptr) ==
nullptr) ? 0 : ((To *)(this->_void_ptr))->size();
164 template<
class Element>
167 nassertd((this->_void_ptr) !=
nullptr) {
170 return ((To *)(this->_void_ptr))->max_size();
176 template<
class Element>
179 return ((this->_void_ptr) ==
nullptr) ? true : ((To *)(this->_void_ptr))->empty();
185 template<
class Element>
187 reserve(
typename PointerToArray<Element>::size_type n) {
188 if ((this->_void_ptr) ==
nullptr) {
191 ((To *)(this->_void_ptr))->reserve(n);
197 template<
class Element>
199 resize(
typename PointerToArray<Element>::size_type n) {
200 if ((this->_void_ptr) ==
nullptr) {
203 ((To *)(this->_void_ptr))->resize(n);
209 template<
class Element>
212 nassertr((this->_void_ptr) !=
nullptr, 0);
213 return ((To *)(this->_void_ptr))->capacity();
219 template<
class Element>
222 nassertd((this->_void_ptr) !=
nullptr) {
225 nassertd(!((To *)(this->_void_ptr))->empty()) {
226 ((To *)(this->_void_ptr))->push_back(Element());
228 return ((To *)(this->_void_ptr))->front();
234 template<
class Element>
237 nassertd((this->_void_ptr) !=
nullptr) {
240 nassertd(!((To *)(this->_void_ptr))->empty()) {
241 ((To *)(this->_void_ptr))->push_back(Element());
243 return ((To *)(this->_void_ptr))->back();
249 template<
class Element>
251 insert(iterator position,
const Element &x) {
252 if ((this->_void_ptr) ==
nullptr) {
256 nassertr(position >= ((To *)(this->_void_ptr))->begin() &&
257 position <= ((To *)(this->_void_ptr))->end(), position);
258 return ((To *)(this->_void_ptr))->insert(position, x);
264 template<
class Element>
266 insert(iterator position, size_type n,
const Element &x) {
267 if ((this->_void_ptr) ==
nullptr) {
271 nassertv(position >= ((To *)(this->_void_ptr))->begin() &&
272 position <= ((To *)(this->_void_ptr))->end());
273 ((To *)(this->_void_ptr))->insert(position, n, x);
279 template<
class Element>
281 erase(iterator position) {
282 nassertv((this->_void_ptr) !=
nullptr);
283 nassertv(position >= ((To *)(this->_void_ptr))->begin() &&
284 position <= ((To *)(this->_void_ptr))->end());
285 ((To *)(this->_void_ptr))->erase(position);
291 template<
class Element>
293 erase(iterator first, iterator last) {
294 nassertv((this->_void_ptr) !=
nullptr);
295 nassertv(first >= ((To *)(this->_void_ptr))->begin() && first <= ((To *)(this->_void_ptr))->end());
296 nassertv(last >= ((To *)(this->_void_ptr))->begin() && last <= ((To *)(this->_void_ptr))->end());
297 ((To *)(this->_void_ptr))->erase(first, last);
300 #if !defined(WIN32_VC) && !defined(WIN64_VC) 304 template<
class Element>
307 nassertd((this->_void_ptr) !=
nullptr) {
310 nassertd(!((To *)(this->_void_ptr))->empty()) {
311 ((To *)(this->_void_ptr))->push_back(Element());
313 nassertr(n < ((To *)(this->_void_ptr))->size(), ((To *)(this->_void_ptr))->
operator[](0));
314 return ((To *)(this->_void_ptr))->operator[](n);
320 template<
class Element>
323 return operator[]((size_type)n);
330 template<
class Element>
333 if ((this->_void_ptr) ==
nullptr) {
336 ((To *)(this->_void_ptr))->push_back(x);
342 template<
class Element>
345 nassertd((this->_void_ptr) !=
nullptr) {
348 nassertv(!((To *)(this->_void_ptr))->empty());
349 ((To *)(this->_void_ptr))->pop_back();
356 template<
class Element>
359 nassertd((this->_void_ptr) !=
nullptr) {
362 nassertv(!((To *)(this->_void_ptr))->empty());
363 ((To *)(this->_void_ptr))->
clear();
372 template<
class Element>
374 operator Element *()
const {
375 To *vec = (To *)(this->_void_ptr);
376 return ((vec ==
nullptr)||(vec->empty())) ? nullptr : &(vec->front());
383 template<
class Element>
386 To *vec = (To *)(this->_void_ptr);
387 return ((vec ==
nullptr)||(vec->empty())) ? nullptr : &(vec->front());
394 template<
class Element>
397 if ((this->_void_ptr) ==
nullptr) {
400 return *((To *)(this->_void_ptr));
407 template<
class Element>
410 return (To *)(this->_void_ptr);
419 template<
class Element>
431 template<
class Element>
434 nassertv(n < ((To *)(this->_void_ptr))->size());
445 template<
class Element>
458 template<
class Element>
471 template<
class Element>
474 n = std::min(n, size());
477 return std::string((
const char *)(
p() + n),
sizeof(Element) *
count);
490 template<
class Element>
493 nassertv((data.length() %
sizeof(Element)) == 0);
494 nassertv(n <= size() && n +
count <= size());
495 if ((this->_void_ptr) ==
nullptr) {
498 size_type ncount = data.length() /
sizeof(Element);
499 if (ncount <
count) {
501 erase(begin() + n + ncount, begin() + n +
count);
502 }
else if (
count < ncount) {
504 insert(begin() + n +
count, ncount -
count, Element());
509 memcpy(
p() + n, data.data(),
sizeof(Element) * ncount);
516 template<
class Element>
519 return (this->_void_ptr);
525 template<
class Element>
534 template<
class Element>
537 return ((this->_void_ptr) ==
nullptr) ? 0 : ((To *)(this->_void_ptr))->
get_ref_count();
543 template<
class Element>
546 if ((this->_void_ptr) ==
nullptr) {
549 ((To *)(this->_void_ptr))->
ref();
555 template<
class Element>
558 nassertr((this->_void_ptr) !=
nullptr,
true);
559 return ((To *)(this->_void_ptr))->unref();
565 template<
class Element>
568 return ((this->_void_ptr) ==
nullptr) ? 0 : ((To *)(this->_void_ptr))->
get_node_ref_count();
574 template<
class Element>
577 if ((this->_void_ptr) ==
nullptr) {
580 ((To *)(this->_void_ptr))->
node_ref();
586 template<
class Element>
589 nassertr((this->_void_ptr) !=
nullptr,
true);
590 return ((To *)(this->_void_ptr))->node_unref();
596 template<
class Element>
599 if ((this->_void_ptr) !=
nullptr) {
600 return std::count(begin(), end(), value);
609 template<
class Element>
619 template<
class Element>
622 _type_handle = copy._type_handle;
630 template<
class Element>
633 _type_handle = from._type_handle;
642 template<
class Element>
653 template<
class Element>
657 _type_handle(type_handle)
664 template<
class Element>
668 _type_handle(type_handle)
675 template<
class Element>
679 _type_handle(copy._type_handle)
686 template<
class Element>
690 _type_handle(copy._type_handle)
697 template<
class Element>
701 _type_handle(from._type_handle)
708 template<
class Element>
712 _type_handle(from._type_handle)
719 template<
class Element>
723 _type_handle(type_handle)
730 template<
class Element>
733 if ((this->_void_ptr) ==
nullptr) {
734 return _empty_array.begin();
736 return ((To *)(this->_void_ptr))->begin();
742 template<
class Element>
745 if ((this->_void_ptr) ==
nullptr) {
746 return _empty_array.begin();
748 return ((To *)(this->_void_ptr))->end();
754 template<
class Element>
757 if ((this->_void_ptr) ==
nullptr) {
758 return _empty_array.rbegin();
760 return ((To *)(this->_void_ptr))->rbegin();
766 template<
class Element>
769 if ((this->_void_ptr) ==
nullptr) {
770 return _empty_array.rbegin();
772 return ((To *)(this->_void_ptr))->rend();
778 template<
class Element>
781 return ((this->_void_ptr) ==
nullptr) ? 0 : ((To *)(this->_void_ptr))->size();
787 template<
class Element>
790 nassertd((this->_void_ptr) !=
nullptr) {
793 return ((To *)(this->_void_ptr))->max_size();
799 template<
class Element>
802 return ((this->_void_ptr) ==
nullptr) ? true : ((To *)(this->_void_ptr))->empty();
808 template<
class Element>
811 nassertd((this->_void_ptr) !=
nullptr) {
814 return ((To *)(this->_void_ptr))->capacity();
820 template<
class Element>
823 nassertd((this->_void_ptr) !=
nullptr) {
826 nassertd(!((To *)(this->_void_ptr))->empty()) {
827 ((To *)(this->_void_ptr))->push_back(Element());
829 return ((To *)(this->_void_ptr))->front();
835 template<
class Element>
838 nassertd((this->_void_ptr) !=
nullptr) {
841 nassertd(!((To *)(this->_void_ptr))->empty()) {
842 ((To *)(this->_void_ptr))->push_back(Element());
844 return ((To *)(this->_void_ptr))->back();
847 #if !defined(WIN32_VC) && !defined(WIN64_VC) 851 template<
class Element>
854 nassertd((this->_void_ptr) !=
nullptr) {
857 nassertd(!((To *)(this->_void_ptr))->empty()) {
858 ((To *)(this->_void_ptr))->push_back(Element());
860 nassertr(n < ((To *)(this->_void_ptr))->size(), ((To *)(this->_void_ptr))->
operator[](0));
861 return ((To *)(this->_void_ptr))->operator[](n);
867 template<
class Element>
870 return operator[]((size_type)n);
880 template<
class Element>
882 operator
const Element *()
const {
883 const To *vec = (
const To *)(this->_void_ptr);
884 return ((vec ==
nullptr)||(vec->empty())) ? nullptr : &(vec->front());
891 template<
class Element>
894 const To *vec = (
const To *)(this->_void_ptr);
895 return ((vec ==
nullptr)||(vec->empty())) ? nullptr : &(vec->front());
902 template<
class Element>
905 nassertd((this->_void_ptr) !=
nullptr) {
908 return *(
const To *)(this->_void_ptr);
915 template<
class Element>
918 return (
const To *)(this->_void_ptr);
925 template<
class Element>
929 non_const = (To *)(this->_void_ptr);
939 template<
class Element>
952 template<
class Element>
965 template<
class Element>
968 n = std::min(n, size());
971 return std::string((
const char *)(
p() + n),
sizeof(Element) *
count);
977 template<
class Element>
980 return ((this->_void_ptr) ==
nullptr) ? 0 : ((To *)(this->_void_ptr))->
get_ref_count();
986 template<
class Element>
989 if ((this->_void_ptr) ==
nullptr) {
992 ((To *)(this->_void_ptr))->
ref();
998 template<
class Element>
1001 nassertr((this->_void_ptr) !=
nullptr,
true);
1002 return ((To *)(this->_void_ptr))->unref();
1008 template<
class Element>
1011 return ((this->_void_ptr) ==
nullptr) ? 0 : ((To *)(this->_void_ptr))->
get_node_ref_count();
1017 template<
class Element>
1020 if ((this->_void_ptr) ==
nullptr) {
1023 ((To *)(this->_void_ptr))->
node_ref();
1029 template<
class Element>
1032 nassertr((this->_void_ptr) !=
nullptr,
true);
1033 return ((To *)(this->_void_ptr))->node_unref();
1039 template<
class Element>
1042 if ((this->_void_ptr) !=
nullptr) {
1043 return std::count(begin(), end(), value);
1052 template<
class Element>
1062 template<
class Element>
1065 _type_handle = copy._type_handle;
1073 template<
class Element>
1076 _type_handle = copy._type_handle;
1084 template<
class Element>
1087 _type_handle = from._type_handle;
1095 template<
class Element>
1098 _type_handle = from._type_handle;
1107 template<
class Element>
Element * p() const
Function p() is similar to the function from PointerTo.
std::string get_data() const
This method exists mainly to access the data of the array easily from a high-level language such as P...
int get_node_ref_count() const
Returns the node_ref of the underlying vector.
void clear()
To empty the PTA, use the clear() method, since assignment to NULL is problematic (given the ambiguit...
void node_ref() const
Increments the node_ref of the underlying vector.
void * get_void_ptr() const
Returns the reference to memory where the vector is stored.
int get_ref_count() const
Returns the reference count of the underlying vector.
const Element & get_element(size_type n) const
This method exists mainly to access the elements of the array easily from a high-level language such ...
void set_element(size_type n, const Element &value)
This method exists mainly to access the elements of the array easily from a high-level language such ...
bool node_unref() const
Decrements the node_ref of the underlying vector.
A special kind of PointerTo that stores an array of the indicated element type, instead of a single e...
static PointerToArray< Element > empty_array(size_type n, TypeHandle type_handle=get_type_handle(Element))
Return an empty array of size n.
std::string get_data() const
This method exists mainly to access the data of the array easily from a high-level language such as P...
ReferenceCountedVector< Element > * v0() const
To access the internal ReferenceCountedVector object, for very low-level fiddling.
void make_empty()
Empties the array pointed to.
void set_void_ptr(void *p)
Sets this PTA to point to the pointer passed in.
void swap(PointerToVoid &other) noexcept
Swaps the contents of this PointerTo with the other, without touching the reference counts.
void ref() const
Increments the reference count of the underlying vector.
PointerToArray< Element > cast_non_const() const
Casts away the constness of the CPTA(Element), and returns an equivalent PTA(Element).
void set_data(const std::string &data)
This method exists mainly to access the data of the array easily from a high-level language such as P...
const pvector< Element > & v() const
To access the vector itself, for more direct fiddling with some of the vector's esoteric functionalit...
const Element * p() const
Function p() is similar to the function from ConstPointerTo.
pvector< Element > & v() const
To access the vector itself, for more direct fiddling with some of the vector's esoteric functionalit...
void node_ref() const
Increments the node_ref of the underlying vector.
bool unref() const
Decrements the reference count of the underlying vector.
This is the base class for PointerToArray and ConstPointerToArray.
void clear()
To empty the PTA, use the clear() method, since assignment to NULL is problematic (given the ambiguit...
int get_ref_count() const
Returns the reference count of the underlying vector.
int get_node_ref_count() const
Returns the node_ref of the underlying vector.
std::string get_subdata(size_type n, size_type count) const
This method exists mainly to access the data of the array easily from a high-level language such as P...
const ReferenceCountedVector< Element > * v0() const
To access the internal ReferenceCountedVector object, for very low-level fiddling.
TypeHandle is the identifier used to differentiate C++ class types.
size_t count(const Element &) const
Counts the frequency at which the given element occurs in the vector.
This defines the object that is actually stored and reference-counted internally by a PointerToArray.
size_t count(const Element &) const
Counts the frequency at which the given element occurs in the vector.
std::string get_subdata(size_type n, size_type count) const
This method exists mainly to access the data of the array easily from a high-level language such as P...
void ref() const
Increments the reference count of the underlying vector.
Similar to PointerToArray, except that its contents may not be modified.
const Element & get_element(size_type n) const
This method exists mainly to access the elements of the array easily from a high-level language such ...
void set_subdata(size_type n, size_type count, const std::string &data)
This method exists mainly to access the data of the array easily from a high-level language such as P...
bool node_unref() const
Decrements the node_ref of the underlying vector.
bool unref() const
Decrements the reference count of the underlying vector.