16template<
class Element>
19template<
class Element>
25template<
class Element>
29 _type_handle(type_handle)
36template<
class Element>
42 To new_array(n, type_handle);
43 ((To *)(temp._void_ptr))->swap(new_array);
50template<
class Element>
54 _type_handle(type_handle)
56 ((To *)(this->_void_ptr))->reserve(n);
57 insert(begin(), n, value);
63template<
class Element>
67 _type_handle(copy._type_handle)
74template<
class Element>
78 _type_handle(type_handle)
85template<
class Element>
89 _type_handle(from._type_handle)
96template<
class Element>
100 _type_handle(type_handle)
107template<
class Element>
110 if ((this->_void_ptr) ==
nullptr) {
111 return _empty_array.begin();
113 return ((To *)(this->_void_ptr))->begin();
119template<
class Element>
122 if ((this->_void_ptr) ==
nullptr) {
123 return _empty_array.begin();
125 return ((To *)(this->_void_ptr))->end();
131template<
class Element>
134 if ((this->_void_ptr) ==
nullptr) {
135 return _empty_array.rbegin();
137 return ((To *)(this->_void_ptr))->rbegin();
143template<
class Element>
146 if ((this->_void_ptr) ==
nullptr) {
147 return _empty_array.rbegin();
149 return ((To *)(this->_void_ptr))->rend();
155template<
class Element>
158 return ((this->_void_ptr) ==
nullptr) ? 0 : ((To *)(this->_void_ptr))->size();
164template<
class Element>
167 nassertd((this->_void_ptr) !=
nullptr) {
170 return ((To *)(this->_void_ptr))->max_size();
176template<
class Element>
179 return ((this->_void_ptr) ==
nullptr) ? true : ((To *)(this->_void_ptr))->empty();
185template<
class Element>
187reserve(
typename PointerToArray<Element>::size_type n) {
188 if ((this->_void_ptr) ==
nullptr) {
191 ((To *)(this->_void_ptr))->reserve(n);
197template<
class Element>
199resize(
typename PointerToArray<Element>::size_type n) {
200 if ((this->_void_ptr) ==
nullptr) {
203 ((To *)(this->_void_ptr))->resize(n);
209template<
class Element>
212 nassertr((this->_void_ptr) !=
nullptr, 0);
213 return ((To *)(this->_void_ptr))->capacity();
219template<
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();
234template<
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();
249template<
class Element>
251insert(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);
264template<
class Element>
266insert(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);
279template<
class Element>
281erase(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);
291template<
class Element>
293erase(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)
304template<
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);
320template<
class Element>
323 return operator[]((size_type)n);
330template<
class Element>
333 if ((this->_void_ptr) ==
nullptr) {
336 ((To *)(this->_void_ptr))->push_back(x);
342template<
class Element>
345 nassertd((this->_void_ptr) !=
nullptr) {
348 nassertv(!((To *)(this->_void_ptr))->empty());
349 ((To *)(this->_void_ptr))->pop_back();
356template<
class Element>
359 nassertd((this->_void_ptr) !=
nullptr) {
362 nassertv(!((To *)(this->_void_ptr))->empty());
363 ((To *)(this->_void_ptr))->clear();
372template<
class Element>
374operator Element *()
const {
375 To *vec = (To *)(this->_void_ptr);
376 return ((vec ==
nullptr)||(vec->empty())) ? nullptr : &(vec->front());
383template<
class Element>
386 To *vec = (To *)(this->_void_ptr);
387 return ((vec ==
nullptr)||(vec->empty())) ? nullptr : &(vec->front());
394template<
class Element>
397 if ((this->_void_ptr) ==
nullptr) {
400 return *((To *)(this->_void_ptr));
407template<
class Element>
410 return (To *)(this->_void_ptr);
419template<
class Element>
431template<
class Element>
434 nassertv(n < ((To *)(this->_void_ptr))->size());
445template<
class Element>
448 return get_subdata(0, size());
458template<
class Element>
461 set_subdata(0, size(), data);
471template<
class Element>
474 n = (std::min)(n, size());
475 count = (std::max)(count, n);
476 count = (std::min)(count, size() - n);
477 return std::string((
const char *)(p() + n),
sizeof(Element) * count);
490template<
class Element>
492set_subdata(size_type n, size_type count,
const std::string &data) {
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);
516template<
class Element>
519 return (this->_void_ptr);
525template<
class Element>
534template<
class Element>
537 return ((this->_void_ptr) ==
nullptr) ? 0 : ((To *)(this->_void_ptr))->get_ref_count();
543template<
class Element>
546 if ((this->_void_ptr) ==
nullptr) {
549 ((To *)(this->_void_ptr))->ref();
555template<
class Element>
558 nassertr((this->_void_ptr) !=
nullptr,
true);
559 return ((To *)(this->_void_ptr))->unref();
565template<
class Element>
568 return ((this->_void_ptr) ==
nullptr) ? 0 : ((To *)(this->_void_ptr))->get_node_ref_count();
574template<
class Element>
577 if ((this->_void_ptr) ==
nullptr) {
580 ((To *)(this->_void_ptr))->node_ref();
586template<
class Element>
589 nassertr((this->_void_ptr) !=
nullptr,
true);
590 return ((To *)(this->_void_ptr))->node_unref();
596template<
class Element>
598count(
const Element &value)
const {
599 if ((this->_void_ptr) !=
nullptr) {
600 return std::count(begin(), end(), value);
609template<
class Element>
619template<
class Element>
622 _type_handle = copy._type_handle;
630template<
class Element>
633 _type_handle = from._type_handle;
642template<
class Element>
653template<
class Element>
657 _type_handle(type_handle)
664template<
class Element>
668 _type_handle(type_handle)
675template<
class Element>
679 _type_handle(copy._type_handle)
686template<
class Element>
690 _type_handle(copy._type_handle)
697template<
class Element>
701 _type_handle(from._type_handle)
708template<
class Element>
712 _type_handle(from._type_handle)
719template<
class Element>
723 _type_handle(type_handle)
730template<
class Element>
733 if ((this->_void_ptr) ==
nullptr) {
734 return _empty_array.begin();
736 return ((To *)(this->_void_ptr))->begin();
742template<
class Element>
745 if ((this->_void_ptr) ==
nullptr) {
746 return _empty_array.begin();
748 return ((To *)(this->_void_ptr))->end();
754template<
class Element>
757 if ((this->_void_ptr) ==
nullptr) {
758 return _empty_array.rbegin();
760 return ((To *)(this->_void_ptr))->rbegin();
766template<
class Element>
769 if ((this->_void_ptr) ==
nullptr) {
770 return _empty_array.rbegin();
772 return ((To *)(this->_void_ptr))->rend();
778template<
class Element>
781 return ((this->_void_ptr) ==
nullptr) ? 0 : ((To *)(this->_void_ptr))->size();
787template<
class Element>
790 nassertd((this->_void_ptr) !=
nullptr) {
793 return ((To *)(this->_void_ptr))->max_size();
799template<
class Element>
802 return ((this->_void_ptr) ==
nullptr) ? true : ((To *)(this->_void_ptr))->empty();
808template<
class Element>
811 nassertd((this->_void_ptr) !=
nullptr) {
814 return ((To *)(this->_void_ptr))->capacity();
820template<
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();
835template<
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)
851template<
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);
867template<
class Element>
870 return operator[]((size_type)n);
880template<
class Element>
882operator
const Element *()
const {
883 const To *vec = (
const To *)(this->_void_ptr);
884 return ((vec ==
nullptr)||(vec->empty())) ? nullptr : &(vec->front());
891template<
class Element>
894 const To *vec = (
const To *)(this->_void_ptr);
895 return ((vec ==
nullptr)||(vec->empty())) ? nullptr : &(vec->front());
902template<
class Element>
905 nassertd((this->_void_ptr) !=
nullptr) {
908 return *(
const To *)(this->_void_ptr);
915template<
class Element>
918 return (
const To *)(this->_void_ptr);
925template<
class Element>
929 non_const = (To *)(this->_void_ptr);
939template<
class Element>
952template<
class Element>
955 return get_subdata(0, size());
965template<
class Element>
968 n = (std::min)(n, size());
969 count = (std::max)(count, n);
970 count = (std::min)(count, size() - n);
971 return std::string((
const char *)(p() + n),
sizeof(Element) * count);
977template<
class Element>
980 return ((this->_void_ptr) ==
nullptr) ? 0 : ((To *)(this->_void_ptr))->get_ref_count();
986template<
class Element>
989 if ((this->_void_ptr) ==
nullptr) {
992 ((To *)(this->_void_ptr))->ref();
998template<
class Element>
1001 nassertr((this->_void_ptr) !=
nullptr,
true);
1002 return ((To *)(this->_void_ptr))->unref();
1008template<
class Element>
1011 return ((this->_void_ptr) ==
nullptr) ? 0 : ((To *)(this->_void_ptr))->get_node_ref_count();
1017template<
class Element>
1020 if ((this->_void_ptr) ==
nullptr) {
1023 ((To *)(this->_void_ptr))->node_ref();
1029template<
class Element>
1032 nassertr((this->_void_ptr) !=
nullptr,
true);
1033 return ((To *)(this->_void_ptr))->node_unref();
1039template<
class Element>
1041count(
const Element &value)
const {
1042 if ((this->_void_ptr) !=
nullptr) {
1043 return std::count(begin(), end(), value);
1052template<
class Element>
1062template<
class Element>
1065 _type_handle = copy._type_handle;
1073template<
class Element>
1076 _type_handle = copy._type_handle;
1084template<
class Element>
1087 _type_handle = from._type_handle;
1095template<
class Element>
1098 _type_handle = from._type_handle;
1107template<
class Element>
Similar to PointerToArray, except that its contents may not be modified.
int get_ref_count() const
Returns the reference count of the underlying vector.
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...
bool node_unref() const
Decrements the node_ref of the underlying vector.
const Element * p() const
Function p() is similar to the function from ConstPointerTo.
void clear()
To empty the PTA, use the clear() method, since assignment to NULL is problematic (given the ambiguit...
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.
size_t count(const Element &) const
Counts the frequency at which the given element occurs in the vector.
void node_ref() const
Increments the node_ref of the underlying vector.
int get_node_ref_count() const
Returns the node_ref of the underlying vector.
const pvector< Element > & v() const
To access the vector itself, for more direct fiddling with some of the vector's esoteric functionalit...
bool unref() const
Decrements 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 ...
PointerToArray< Element > cast_non_const() const
Casts away the constness of the CPTA(Element), and returns an equivalent PTA(Element).
void ref() const
Increments the reference count of the underlying vector.
This is the base class for PointerToArray and ConstPointerToArray.
A special kind of PointerTo that stores an array of the indicated element type, instead of a single e...
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...
size_t count(const Element &) const
Counts the frequency at which the given element occurs in the vector.
pvector< Element > & v() const
To access the vector itself, for more direct fiddling with some of the vector's esoteric functionalit...
void set_void_ptr(void *p)
Sets this PTA to point to the pointer passed in.
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...
int get_ref_count() const
Returns the reference count of the underlying vector.
static PointerToArray< Element > empty_array(size_type n, TypeHandle type_handle=get_type_handle(Element))
Return an empty array of size n.
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...
ReferenceCountedVector< Element > * v0() const
To access the internal ReferenceCountedVector object, for very low-level fiddling.
int get_node_ref_count() const
Returns the node_ref 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 clear()
To empty the PTA, use the clear() method, since assignment to NULL is problematic (given the ambiguit...
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 ...
void * get_void_ptr() const
Returns the reference to memory where the vector is stored.
void ref() const
Increments the reference count of the underlying vector.
void make_empty()
Empties the array pointed to.
bool unref() const
Decrements the reference count of the underlying vector.
Element * p() const
Function p() is similar to the function from PointerTo.
bool node_unref() const
Decrements the node_ref of the underlying vector.
void node_ref() const
Increments the node_ref of the underlying vector.
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...
This defines the object that is actually stored and reference-counted internally by a PointerToArray.
TypeHandle is the identifier used to differentiate C++ class types.
This is our own Panda specialization on the default STL vector.