00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef CPPPARSER
00016
00017 template<class Element>
00018 pvector<Element> PointerToArray<Element>::_empty_array;
00019
00020 template<class Element>
00021 pvector<Element> ConstPointerToArray<Element>::_empty_array;
00022
00023
00024
00025
00026
00027
00028 template<class Element>
00029 INLINE PointerToArray<Element>::
00030 PointerToArray(TypeHandle type_handle) :
00031 PointerToArrayBase<Element>((ReferenceCountedVector<Element> *)NULL),
00032 _type_handle(type_handle)
00033 {
00034 }
00035
00036
00037
00038
00039
00040
00041 template<class Element>
00042 INLINE PointerToArray<Element>
00043 PointerToArray<Element>::empty_array(size_type n, TypeHandle type_handle) {
00044 PointerToArray<Element> temp(type_handle);
00045 temp.reassign(new ReferenceCountedVector<Element>(type_handle));
00046
00047 To new_array(n, type_handle);
00048 ((To *)(temp._void_ptr))->swap(new_array);
00049 return temp;
00050 }
00051
00052
00053
00054
00055
00056
00057 template<class Element>
00058 INLINE PointerToArray<Element>::
00059 PointerToArray(size_type n, const Element &value, TypeHandle type_handle) :
00060 PointerToArrayBase<Element>(new ReferenceCountedVector<Element>(type_handle)),
00061 _type_handle(type_handle)
00062 {
00063 ((To *)(this->_void_ptr))->reserve(n);
00064 insert(begin(), n, value);
00065 }
00066
00067
00068
00069
00070
00071
00072 template<class Element>
00073 INLINE PointerToArray<Element>::
00074 PointerToArray(const PointerToArray<Element> ©) :
00075 PointerToArrayBase<Element>(copy),
00076 _type_handle(copy._type_handle)
00077 {
00078 }
00079
00080 #ifdef HAVE_PYTHON
00081
00082
00083
00084
00085
00086
00087 template<class Element>
00088 PointerToArray<Element>::
00089 PointerToArray(PyObject *self, PyObject *sequence) :
00090 PointerToArrayBase<Element>((ReferenceCountedVector<Element> *)NULL),
00091 _type_handle(get_type_handle(Element))
00092 {
00093
00094
00095 ((Dtool_PyInstDef *)self)->_ptr_to_object = this;
00096
00097 if (!PySequence_Check(sequence)) {
00098
00099 PyErr_SetString(PyExc_TypeError, "PointerToArray constructor requires a sequence");
00100 return;
00101 }
00102
00103 if (PyString_CheckExact(sequence)) {
00104
00105
00106
00107 int size = PyString_Size(sequence);
00108 if (size % sizeof(Element) != 0) {
00109 ostringstream stream;
00110 stream << "Buffer not a multiple of " << sizeof(Element) << " bytes";
00111 string str = stream.str();
00112 PyErr_SetString(PyExc_ValueError, str.c_str());
00113 return;
00114 }
00115
00116 int num_elements = size / sizeof(Element);
00117 insert(begin(), num_elements, Element());
00118
00119
00120
00121 if (size != 0) {
00122 const char *data = PyString_AsString(sequence);
00123 memcpy(p(), data, size);
00124 }
00125 return;
00126 }
00127
00128
00129
00130 int size = PySequence_Size(sequence);
00131 for (int i = 0; i < size; ++i) {
00132 PyObject *item = PySequence_GetItem(sequence, i);
00133 if (item == NULL) {
00134 return;
00135 }
00136 PyObject *result = PyObject_CallMethod(self, (char *)"pushBack", (char *)"O", item);
00137 Py_DECREF(item);
00138 if (result == NULL) {
00139
00140 ostringstream stream;
00141 stream << "Element " << i << " in sequence passed to PointerToArray constructor could not be added";
00142 string str = stream.str();
00143 PyErr_SetString(PyExc_TypeError, str.c_str());
00144 return;
00145 }
00146 Py_DECREF(result);
00147 }
00148 }
00149 #endif // HAVE_PYTHON
00150
00151
00152
00153
00154
00155
00156 template<class Element>
00157 INLINE TYPENAME PointerToArray<Element>::iterator PointerToArray<Element>::
00158 begin() const {
00159 if ((this->_void_ptr) == NULL) {
00160 return _empty_array.begin();
00161 }
00162 return ((To *)(this->_void_ptr))->begin();
00163 }
00164
00165
00166
00167
00168
00169
00170 template<class Element>
00171 INLINE TYPENAME PointerToArray<Element>::iterator PointerToArray<Element>::
00172 end() const {
00173 if ((this->_void_ptr) == NULL) {
00174 return _empty_array.begin();
00175 }
00176 return ((To *)(this->_void_ptr))->end();
00177 }
00178
00179
00180
00181
00182
00183
00184 template<class Element>
00185 INLINE TYPENAME PointerToArray<Element>::reverse_iterator PointerToArray<Element>::
00186 rbegin() const {
00187 if ((this->_void_ptr) == NULL) {
00188 return _empty_array.rbegin();
00189 }
00190 return ((To *)(this->_void_ptr))->rbegin();
00191 }
00192
00193
00194
00195
00196
00197
00198 template<class Element>
00199 INLINE TYPENAME PointerToArray<Element>::reverse_iterator PointerToArray<Element>::
00200 rend() const {
00201 if ((this->_void_ptr) == NULL) {
00202 return _empty_array.rbegin();
00203 }
00204 return ((To *)(this->_void_ptr))->rend();
00205 }
00206
00207
00208
00209
00210
00211
00212 template<class Element>
00213 INLINE TYPENAME PointerToArray<Element>::size_type PointerToArray<Element>::
00214 size() const {
00215 return ((this->_void_ptr) == NULL) ? 0 : ((To *)(this->_void_ptr))->size();
00216 }
00217
00218
00219
00220
00221
00222
00223 template<class Element>
00224 INLINE TYPENAME PointerToArray<Element>::size_type PointerToArray<Element>::
00225 max_size() const {
00226 nassertd((this->_void_ptr) != NULL) {
00227 ((PointerToArray<Element> *)this)->reassign(new ReferenceCountedVector<Element>(_type_handle));
00228 }
00229 return ((To *)(this->_void_ptr))->max_size();
00230 }
00231
00232
00233
00234
00235
00236
00237 template<class Element>
00238 INLINE bool PointerToArray<Element>::
00239 empty() const {
00240 return ((this->_void_ptr) == NULL) ? true : ((To *)(this->_void_ptr))->empty();
00241 }
00242
00243
00244
00245
00246
00247
00248 template<class Element>
00249 INLINE void PointerToArray<Element>::
00250 reserve(TYPENAME PointerToArray<Element>::size_type n) {
00251 if ((this->_void_ptr) == NULL) {
00252 ((PointerToArray<Element> *)this)->reassign(new ReferenceCountedVector<Element>(_type_handle));
00253 }
00254 ((To *)(this->_void_ptr))->reserve(n);
00255 }
00256
00257
00258
00259
00260
00261
00262 template<class Element>
00263 INLINE void PointerToArray<Element>::
00264 resize(TYPENAME PointerToArray<Element>::size_type n) {
00265 if ((this->_void_ptr) == NULL) {
00266 ((PointerToArray<Element> *)this)->reassign(new ReferenceCountedVector<Element>(_type_handle));
00267 }
00268 ((To *)(this->_void_ptr))->resize(n);
00269 }
00270
00271
00272
00273
00274
00275
00276 template<class Element>
00277 INLINE TYPENAME PointerToArray<Element>::size_type PointerToArray<Element>::
00278 capacity() const {
00279 nassertr((this->_void_ptr) != NULL, 0);
00280 return ((To *)(this->_void_ptr))->capacity();
00281 }
00282
00283
00284
00285
00286
00287
00288 template<class Element>
00289 INLINE TYPENAME PointerToArray<Element>::reference PointerToArray<Element>::
00290 front() const {
00291 nassertd((this->_void_ptr) != NULL) {
00292 ((PointerToArray<Element> *)this)->reassign(new ReferenceCountedVector<Element>(_type_handle));
00293 }
00294 nassertd(!((To *)(this->_void_ptr))->empty()) {
00295 ((To *)(this->_void_ptr))->push_back(Element());
00296 }
00297 return ((To *)(this->_void_ptr))->front();
00298 }
00299
00300
00301
00302
00303
00304
00305 template<class Element>
00306 INLINE TYPENAME PointerToArray<Element>::reference PointerToArray<Element>::
00307 back() const {
00308 nassertd((this->_void_ptr) != NULL) {
00309 ((PointerToArray<Element> *)this)->reassign(new ReferenceCountedVector<Element>(_type_handle));
00310 }
00311 nassertd(!((To *)(this->_void_ptr))->empty()) {
00312 ((To *)(this->_void_ptr))->push_back(Element());
00313 }
00314 return ((To *)(this->_void_ptr))->back();
00315 }
00316
00317
00318
00319
00320
00321
00322 template<class Element>
00323 INLINE TYPENAME PointerToArray<Element>::iterator PointerToArray<Element>::
00324 insert(iterator position, const Element &x) {
00325 if ((this->_void_ptr) == NULL) {
00326 ((PointerToArray<Element> *)this)->reassign(new ReferenceCountedVector<Element>(_type_handle));
00327 position = end();
00328 }
00329 nassertr(position >= ((To *)(this->_void_ptr))->begin() &&
00330 position <= ((To *)(this->_void_ptr))->end(), position);
00331 return ((To *)(this->_void_ptr))->insert(position, x);
00332 }
00333
00334
00335
00336
00337
00338
00339 template<class Element>
00340 INLINE void PointerToArray<Element>::
00341 insert(iterator position, size_type n, const Element &x) {
00342 if ((this->_void_ptr) == NULL) {
00343 ((PointerToArray<Element> *)this)->reassign(new ReferenceCountedVector<Element>(_type_handle));
00344 position = end();
00345 }
00346 nassertv(position >= ((To *)(this->_void_ptr))->begin() &&
00347 position <= ((To *)(this->_void_ptr))->end());
00348 ((To *)(this->_void_ptr))->insert(position, n, x);
00349 }
00350
00351
00352
00353
00354
00355
00356 template<class Element>
00357 INLINE void PointerToArray<Element>::
00358 erase(iterator position) {
00359 nassertv((this->_void_ptr) != NULL);
00360 nassertv(position >= ((To *)(this->_void_ptr))->begin() &&
00361 position <= ((To *)(this->_void_ptr))->end());
00362 ((To *)(this->_void_ptr))->erase(position);
00363 }
00364
00365
00366
00367
00368
00369
00370 template<class Element>
00371 INLINE void PointerToArray<Element>::
00372 erase(iterator first, iterator last) {
00373 nassertv((this->_void_ptr) != NULL);
00374 nassertv(first >= ((To *)(this->_void_ptr))->begin() && first <= ((To *)(this->_void_ptr))->end());
00375 nassertv(last >= ((To *)(this->_void_ptr))->begin() && last <= ((To *)(this->_void_ptr))->end());
00376 ((To *)(this->_void_ptr))->erase(first, last);
00377 }
00378
00379 #if !defined(WIN32_VC) && !defined(WIN64_VC)
00380
00381
00382
00383
00384
00385 template<class Element>
00386 INLINE TYPENAME PointerToArray<Element>::reference PointerToArray<Element>::
00387 operator [](size_type n) const {
00388 nassertd((this->_void_ptr) != NULL) {
00389 ((PointerToArray<Element> *)this)->reassign(new ReferenceCountedVector<Element>(_type_handle));
00390 }
00391 nassertd(!((To *)(this->_void_ptr))->empty()) {
00392 ((To *)(this->_void_ptr))->push_back(Element());
00393 }
00394 nassertr(n < ((To *)(this->_void_ptr))->size(), ((To *)(this->_void_ptr))->operator[](0));
00395 return ((To *)(this->_void_ptr))->operator[](n);
00396 }
00397
00398
00399
00400
00401
00402
00403 template<class Element>
00404 INLINE TYPENAME PointerToArray<Element>::reference PointerToArray<Element>::
00405 operator [](int n) const {
00406 return operator[]((size_type)n);
00407 }
00408 #endif
00409
00410
00411
00412
00413
00414
00415 template<class Element>
00416 INLINE void PointerToArray<Element>::
00417 push_back(const Element &x) {
00418 if ((this->_void_ptr) == NULL) {
00419 ((PointerToArray<Element> *)this)->reassign(new ReferenceCountedVector<Element>(_type_handle));
00420 }
00421 ((To *)(this->_void_ptr))->push_back(x);
00422 }
00423
00424
00425
00426
00427
00428
00429 template<class Element>
00430 INLINE void PointerToArray<Element>::
00431 pop_back() {
00432 nassertd((this->_void_ptr) != NULL) {
00433 ((PointerToArray<Element> *)this)->reassign(new ReferenceCountedVector<Element>(_type_handle));
00434 }
00435 nassertv(!((To *)(this->_void_ptr))->empty());
00436 ((To *)(this->_void_ptr))->pop_back();
00437 }
00438
00439
00440
00441
00442
00443
00444
00445
00446 template<class Element>
00447 INLINE void PointerToArray<Element>::
00448 make_empty() {
00449 nassertd((this->_void_ptr) != NULL) {
00450 ((PointerToArray<Element> *)this)->reassign(new ReferenceCountedVector<Element>(_type_handle));
00451 }
00452 nassertv(!((To *)(this->_void_ptr))->empty());
00453 ((To *)(this->_void_ptr))->clear();
00454 }
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465 template<class Element>
00466 INLINE PointerToArray<Element>::
00467 operator Element *() const {
00468 To *vec = (To *)(this->_void_ptr);
00469 return ((vec == NULL)||(vec->empty())) ? (Element *)NULL : &(vec->front());
00470 }
00471
00472
00473
00474
00475
00476
00477
00478
00479 template<class Element>
00480 INLINE Element *PointerToArray<Element>::
00481 p() const {
00482 To *vec = (To *)(this->_void_ptr);
00483 return ((vec == NULL)||(vec->empty())) ? (Element *)NULL : &(vec->front());
00484 }
00485
00486
00487
00488
00489
00490
00491
00492 template<class Element>
00493 INLINE pvector<Element> &PointerToArray<Element>::
00494 v() const {
00495 if ((this->_void_ptr) == NULL) {
00496 ((PointerToArray<Element> *)this)->reassign(new ReferenceCountedVector<Element>(_type_handle));
00497 }
00498 return *((To *)(this->_void_ptr));
00499 }
00500
00501
00502
00503
00504
00505
00506
00507 template<class Element>
00508 INLINE ReferenceCountedVector<Element> *PointerToArray<Element>::
00509 v0() const {
00510 return (To *)(this->_void_ptr);
00511 }
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522 template<class Element>
00523 INLINE const Element &PointerToArray<Element>::
00524 get_element(size_type n) const {
00525 return (*this)[n];
00526 }
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537 template<class Element>
00538 INLINE void PointerToArray<Element>::
00539 set_element(size_type n, const Element &value) {
00540 nassertv(n < ((To *)(this->_void_ptr))->size());
00541 (*this)[n] = value;
00542 }
00543
00544
00545
00546
00547
00548
00549
00550 template<class Element>
00551 INLINE const Element &PointerToArray<Element>::
00552 __getitem__(size_type n) const {
00553 return (*this)[n];
00554 }
00555
00556
00557
00558
00559
00560
00561
00562 template<class Element>
00563 INLINE void PointerToArray<Element>::
00564 __setitem__(size_type n, const Element &value) {
00565 nassertv(n < ((To *)(this->_void_ptr))->size());
00566 (*this)[n] = value;
00567 }
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579 template<class Element>
00580 INLINE string PointerToArray<Element>::
00581 get_data() const {
00582 return get_subdata(0, size());
00583 }
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595 template<class Element>
00596 INLINE void PointerToArray<Element>::
00597 set_data(const string &data) {
00598 set_subdata(0, size(), data);
00599 }
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612 template<class Element>
00613 INLINE string PointerToArray<Element>::
00614 get_subdata(size_type n, size_type count) const {
00615 n = min(n, size());
00616 count = max(count, n);
00617 count = min(count, size() - n);
00618 return string((const char *)(p() + n), sizeof(Element) * count);
00619 }
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636 template<class Element>
00637 INLINE void PointerToArray<Element>::
00638 set_subdata(size_type n, size_type count, const string &data) {
00639 nassertv((data.length() % sizeof(Element)) == 0);
00640 nassertv(n <= size() && n + count <= size());
00641 if ((this->_void_ptr) == NULL) {
00642 ((PointerToArray<Element> *)this)->reassign(new ReferenceCountedVector<Element>(_type_handle));
00643 }
00644 size_type ncount = data.length() / sizeof(Element);
00645 if (ncount < count) {
00646
00647 erase(begin() + n + ncount, begin() + n + count);
00648 } else if (count < ncount) {
00649
00650 insert(begin() + n + count, ncount - count, Element());
00651 }
00652
00653
00654
00655
00656 memcpy(p() + n, data.data(), sizeof(Element) * ncount);
00657 }
00658
00659
00660
00661
00662
00663
00664
00665 template<class Element>
00666 INLINE void *PointerToArray<Element>::
00667 get_void_ptr() const {
00668 return (this->_void_ptr);
00669 }
00670
00671
00672
00673
00674
00675
00676 template<class Element>
00677 INLINE void PointerToArray<Element>::
00678 set_void_ptr(void *p) {
00679 ((PointerToArray<Element> *)this)->reassign((To *)p);
00680 }
00681
00682
00683
00684
00685
00686
00687 template<class Element>
00688 INLINE int PointerToArray<Element>::
00689 get_ref_count() const {
00690 return ((this->_void_ptr) == NULL) ? 0 : ((To *)(this->_void_ptr))->get_ref_count();
00691 }
00692
00693
00694
00695
00696
00697
00698 template<class Element>
00699 INLINE int PointerToArray<Element>::
00700 get_node_ref_count() const {
00701 return ((this->_void_ptr) == NULL) ? 0 : ((To *)(this->_void_ptr))->get_node_ref_count();
00702 }
00703
00704
00705
00706
00707
00708
00709 template<class Element>
00710 INLINE void PointerToArray<Element>::
00711 node_ref() const {
00712 if ((this->_void_ptr) == NULL) {
00713 ((PointerToArray<Element> *)this)->reassign(new ReferenceCountedVector<Element>(_type_handle));
00714 }
00715 ((To *)(this->_void_ptr))->node_ref();
00716 }
00717
00718
00719
00720
00721
00722
00723 template<class Element>
00724 INLINE bool PointerToArray<Element>::
00725 node_unref() const {
00726 nassertr((this->_void_ptr) != NULL, true);
00727 return ((To *)(this->_void_ptr))->node_unref();
00728 }
00729
00730
00731
00732
00733
00734
00735 template<class Element>
00736 INLINE PointerToArray<Element> &PointerToArray<Element>::
00737 operator = (ReferenceCountedVector<Element> *ptr) {
00738 ((PointerToArray<Element> *)this)->reassign(ptr);
00739 return *this;
00740 }
00741
00742
00743
00744
00745
00746
00747 template<class Element>
00748 INLINE PointerToArray<Element> &PointerToArray<Element>::
00749 operator = (const PointerToArray<Element> ©) {
00750 _type_handle = copy._type_handle;
00751 ((PointerToArray<Element> *)this)->reassign(copy);
00752 return *this;
00753 }
00754
00755
00756
00757
00758
00759
00760
00761
00762 template<class Element>
00763 INLINE void PointerToArray<Element>::
00764 clear() {
00765 ((PointerToArray<Element> *)this)->reassign((ReferenceCountedVector<Element> *)NULL);
00766 }
00767
00768
00769
00770
00771
00772
00773
00774
00775 template<class Element>
00776 INLINE ConstPointerToArray<Element>::
00777 ConstPointerToArray(TypeHandle type_handle) :
00778 PointerToArrayBase<Element>((ReferenceCountedVector<Element> *)NULL),
00779 _type_handle(type_handle)
00780 {
00781 }
00782
00783
00784
00785
00786
00787
00788 template<class Element>
00789 INLINE ConstPointerToArray<Element>::
00790 ConstPointerToArray(const PointerToArray<Element> ©) :
00791 PointerToArrayBase<Element>(copy),
00792 _type_handle(copy._type_handle)
00793 {
00794 }
00795
00796
00797
00798
00799
00800
00801 template<class Element>
00802 INLINE ConstPointerToArray<Element>::
00803 ConstPointerToArray(const ConstPointerToArray<Element> ©) :
00804 PointerToArrayBase<Element>(copy),
00805 _type_handle(copy._type_handle)
00806 {
00807 }
00808
00809
00810
00811
00812
00813
00814 template<class Element>
00815 INLINE TYPENAME ConstPointerToArray<Element>::iterator ConstPointerToArray<Element>::
00816 begin() const {
00817 if ((this->_void_ptr) == NULL) {
00818 return _empty_array.begin();
00819 }
00820 return ((To *)(this->_void_ptr))->begin();
00821 }
00822
00823
00824
00825
00826
00827
00828 template<class Element>
00829 INLINE TYPENAME ConstPointerToArray<Element>::iterator ConstPointerToArray<Element>::
00830 end() const {
00831 if ((this->_void_ptr) == NULL) {
00832 return _empty_array.begin();
00833 }
00834 return ((To *)(this->_void_ptr))->end();
00835 }
00836
00837
00838
00839
00840
00841
00842 template<class Element>
00843 INLINE TYPENAME ConstPointerToArray<Element>::reverse_iterator ConstPointerToArray<Element>::
00844 rbegin() const {
00845 if ((this->_void_ptr) == NULL) {
00846 return _empty_array.rbegin();
00847 }
00848 return ((To *)(this->_void_ptr))->rbegin();
00849 }
00850
00851
00852
00853
00854
00855
00856 template<class Element>
00857 INLINE TYPENAME ConstPointerToArray<Element>::reverse_iterator ConstPointerToArray<Element>::
00858 rend() const {
00859 if ((this->_void_ptr) == NULL) {
00860 return _empty_array.rbegin();
00861 }
00862 return ((To *)(this->_void_ptr))->rend();
00863 }
00864
00865
00866
00867
00868
00869
00870 template<class Element>
00871 INLINE TYPENAME ConstPointerToArray<Element>::size_type ConstPointerToArray<Element>::
00872 size() const {
00873 return ((this->_void_ptr) == NULL) ? 0 : ((To *)(this->_void_ptr))->size();
00874 }
00875
00876
00877
00878
00879
00880
00881 template<class Element>
00882 INLINE TYPENAME ConstPointerToArray<Element>::size_type ConstPointerToArray<Element>::
00883 max_size() const {
00884 nassertd((this->_void_ptr) != NULL) {
00885 ((ConstPointerToArray<Element> *)this)->reassign(new ReferenceCountedVector<Element>(_type_handle));
00886 }
00887 return ((To *)(this->_void_ptr))->max_size();
00888 }
00889
00890
00891
00892
00893
00894
00895 template<class Element>
00896 INLINE bool ConstPointerToArray<Element>::
00897 empty() const {
00898 return ((this->_void_ptr) == NULL) ? true : ((To *)(this->_void_ptr))->empty();
00899 }
00900
00901
00902
00903
00904
00905
00906 template<class Element>
00907 INLINE TYPENAME ConstPointerToArray<Element>::size_type ConstPointerToArray<Element>::
00908 capacity() const {
00909 nassertd((this->_void_ptr) != NULL) {
00910 ((ConstPointerToArray<Element> *)this)->reassign(new ReferenceCountedVector<Element>(_type_handle));
00911 }
00912 return ((To *)(this->_void_ptr))->capacity();
00913 }
00914
00915
00916
00917
00918
00919
00920 template<class Element>
00921 INLINE TYPENAME ConstPointerToArray<Element>::reference ConstPointerToArray<Element>::
00922 front() const {
00923 nassertd((this->_void_ptr) != NULL) {
00924 ((ConstPointerToArray<Element> *)this)->reassign(new ReferenceCountedVector<Element>(_type_handle));
00925 }
00926 nassertd(!((To *)(this->_void_ptr))->empty()) {
00927 ((To *)(this->_void_ptr))->push_back(Element());
00928 }
00929 return ((To *)(this->_void_ptr))->front();
00930 }
00931
00932
00933
00934
00935
00936
00937 template<class Element>
00938 INLINE TYPENAME ConstPointerToArray<Element>::reference ConstPointerToArray<Element>::
00939 back() const {
00940 nassertd((this->_void_ptr) != NULL) {
00941 ((ConstPointerToArray<Element> *)this)->reassign(new ReferenceCountedVector<Element>(_type_handle));
00942 }
00943 nassertd(!((To *)(this->_void_ptr))->empty()) {
00944 ((To *)(this->_void_ptr))->push_back(Element());
00945 }
00946 return ((To *)(this->_void_ptr))->back();
00947 }
00948
00949 #if !defined(WIN32_VC) && !defined(WIN64_VC)
00950
00951
00952
00953
00954
00955 template<class Element>
00956 INLINE TYPENAME ConstPointerToArray<Element>::reference ConstPointerToArray<Element>::
00957 operator [](size_type n) const {
00958 nassertd((this->_void_ptr) != NULL) {
00959 ((ConstPointerToArray<Element> *)this)->reassign(new ReferenceCountedVector<Element>(_type_handle));
00960 }
00961 nassertd(!((To *)(this->_void_ptr))->empty()) {
00962 ((To *)(this->_void_ptr))->push_back(Element());
00963 }
00964 nassertr(n < ((To *)(this->_void_ptr))->size(), ((To *)(this->_void_ptr))->operator[](0));
00965 return ((To *)(this->_void_ptr))->operator[](n);
00966 }
00967
00968
00969
00970
00971
00972
00973 template<class Element>
00974 INLINE TYPENAME ConstPointerToArray<Element>::reference ConstPointerToArray<Element>::
00975 operator [](int n) const {
00976 return operator[]((size_type)n);
00977 }
00978 #endif
00979
00980
00981
00982
00983
00984
00985
00986
00987
00988
00989 template<class Element>
00990 INLINE ConstPointerToArray<Element>::
00991 operator const Element *() const {
00992 const To *vec = (const To *)(this->_void_ptr);
00993 return ((vec == NULL)||(vec->empty())) ? (const Element *)NULL : &(vec->front());
00994 }
00995
00996
00997
00998
00999
01000
01001
01002
01003 template<class Element>
01004 INLINE const Element *ConstPointerToArray<Element>::
01005 p() const {
01006 const To *vec = (const To *)(this->_void_ptr);
01007 return ((vec == NULL)||(vec->empty())) ? (const Element *)NULL : &(vec->front());
01008 }
01009
01010
01011
01012
01013
01014
01015
01016 template<class Element>
01017 INLINE const pvector<Element> &ConstPointerToArray<Element>::
01018 v() const {
01019 nassertd((this->_void_ptr) != NULL) {
01020 ((ConstPointerToArray<Element> *)this)->reassign(new ReferenceCountedVector<Element>(_type_handle));
01021 }
01022 return *(const To *)(this->_void_ptr);
01023 }
01024
01025
01026
01027
01028
01029
01030
01031 template<class Element>
01032 INLINE const ReferenceCountedVector<Element> *ConstPointerToArray<Element>::
01033 v0() const {
01034 return (const To *)(this->_void_ptr);
01035 }
01036
01037
01038
01039
01040
01041
01042
01043 template<class Element>
01044 INLINE PointerToArray<Element> ConstPointerToArray<Element>::
01045 cast_non_const() const {
01046 PointerToArray<Element> non_const;
01047 non_const = (To *)(this->_void_ptr);
01048 return non_const;
01049 }
01050
01051
01052
01053
01054
01055
01056
01057
01058
01059
01060 template<class Element>
01061 INLINE const Element &ConstPointerToArray<Element>::
01062 get_element(size_type n) const {
01063 return (*this)[n];
01064 }
01065
01066
01067
01068
01069
01070
01071
01072 template<class Element>
01073 INLINE const Element &ConstPointerToArray<Element>::
01074 __getitem__(size_type n) const {
01075 return (*this)[n];
01076 }
01077
01078
01079
01080
01081
01082
01083
01084
01085
01086
01087
01088 template<class Element>
01089 INLINE string ConstPointerToArray<Element>::
01090 get_data() const {
01091 return get_subdata(0, size());
01092 }
01093
01094
01095
01096
01097
01098
01099
01100
01101
01102
01103
01104
01105 template<class Element>
01106 INLINE string ConstPointerToArray<Element>::
01107 get_subdata(size_type n, size_type count) const {
01108 n = min(n, size());
01109 count = max(count, n);
01110 count = min(count, size() - n);
01111 return string((const char *)(p() + n), sizeof(Element) * count);
01112 }
01113
01114
01115
01116
01117
01118
01119 template<class Element>
01120 INLINE int ConstPointerToArray<Element>::
01121 get_ref_count() const {
01122 return ((this->_void_ptr) == NULL) ? 0 : ((To *)(this->_void_ptr))->get_ref_count();
01123 }
01124
01125
01126
01127
01128
01129
01130 template<class Element>
01131 INLINE int ConstPointerToArray<Element>::
01132 get_node_ref_count() const {
01133 return ((this->_void_ptr) == NULL) ? 0 : ((To *)(this->_void_ptr))->get_node_ref_count();
01134 }
01135
01136
01137
01138
01139
01140
01141 template<class Element>
01142 INLINE void ConstPointerToArray<Element>::
01143 node_ref() const {
01144 if ((this->_void_ptr) == NULL) {
01145 ((ConstPointerToArray<Element> *)this)->reassign(new ReferenceCountedVector<Element>(_type_handle));
01146 }
01147 ((To *)(this->_void_ptr))->node_ref();
01148 }
01149
01150
01151
01152
01153
01154
01155 template<class Element>
01156 INLINE bool ConstPointerToArray<Element>::
01157 node_unref() const {
01158 nassertr((this->_void_ptr) != NULL, true);
01159 return ((To *)(this->_void_ptr))->node_unref();
01160 }
01161
01162
01163
01164
01165
01166
01167 template<class Element>
01168 INLINE ConstPointerToArray<Element> &ConstPointerToArray<Element>::
01169 operator = (ReferenceCountedVector<Element> *ptr) {
01170 ((ConstPointerToArray<Element> *)this)->reassign(ptr);
01171 return *this;
01172 }
01173
01174
01175
01176
01177
01178
01179 template<class Element>
01180 INLINE ConstPointerToArray<Element> &ConstPointerToArray<Element>::
01181 operator = (const PointerToArray<Element> ©) {
01182 _type_handle = copy._type_handle;
01183 ((ConstPointerToArray<Element> *)this)->reassign(copy);
01184 return *this;
01185 }
01186
01187
01188
01189
01190
01191
01192 template<class Element>
01193 INLINE ConstPointerToArray<Element> &ConstPointerToArray<Element>::
01194 operator = (const ConstPointerToArray<Element> ©) {
01195 _type_handle = copy._type_handle;
01196 ((ConstPointerToArray<Element> *)this)->reassign(copy);
01197 return *this;
01198 }
01199
01200
01201
01202
01203
01204
01205
01206
01207 template<class Element>
01208 INLINE void ConstPointerToArray<Element>::
01209 clear() {
01210 ((ConstPointerToArray<Element> *)this)->reassign((ReferenceCountedVector<Element> *)NULL);
01211 }
01212
01213 #endif // CPPPARSER