00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 template<class Element>
00020 pvector<Element> PointerToArray<Element>::_empty_array;
00021
00022 template<class Element>
00023 pvector<Element> ConstPointerToArray<Element>::_empty_array;
00024
00025
00026
00027
00028
00029
00030 template<class Element>
00031 INLINE PointerToArray<Element>::
00032 PointerToArray() :
00033 PointerToBase<RefCountObj<pvector<Element> > >((RefCountObj<pvector<Element> > *)NULL)
00034 {
00035 }
00036
00037
00038 template<class Element>
00039 INLINE PointerToArray<Element>
00040 PointerToArray<Element>::empty_array(size_type n) {
00041 PointerToArray<Element> temp;
00042 temp.reserve(n);
00043 temp._ptr->insert(temp._ptr->begin(), n, Element());
00044 return temp;
00045 }
00046
00047
00048
00049
00050
00051
00052 template<class Element>
00053 INLINE PointerToArray<Element>::
00054 PointerToArray(size_type n, const Element &value) :
00055 PointerToBase<RefCountObj<pvector<Element> > >(new RefCountObj<pvector<Element> >) {
00056 _ptr->reserve(n);
00057 insert(begin(), n, value);
00058 }
00059
00060
00061
00062
00063
00064
00065 template<class Element>
00066 INLINE PointerToArray<Element>::
00067 PointerToArray(const PointerToArray<Element> ©) :
00068 PointerToBase<RefCountObj<pvector<Element> > >(copy)
00069 {
00070 }
00071
00072
00073
00074
00075
00076
00077 template<class Element>
00078 INLINE TYPENAME PointerToArray<Element>::iterator PointerToArray<Element>::
00079 begin() const {
00080 if (_ptr == NULL) {
00081 return _empty_array.begin();
00082 }
00083 return _ptr->begin();
00084 }
00085
00086
00087
00088
00089
00090
00091 template<class Element>
00092 INLINE TYPENAME PointerToArray<Element>::iterator PointerToArray<Element>::
00093 end() const {
00094 if (_ptr == NULL) {
00095 return _empty_array.begin();
00096 }
00097 return _ptr->end();
00098 }
00099
00100
00101
00102
00103
00104
00105 template<class Element>
00106 INLINE TYPENAME PointerToArray<Element>::reverse_iterator PointerToArray<Element>::
00107 rbegin() const {
00108 if (_ptr == NULL) {
00109 return _empty_array.rbegin();
00110 }
00111 return _ptr->rbegin();
00112 }
00113
00114
00115
00116
00117
00118
00119 template<class Element>
00120 INLINE TYPENAME PointerToArray<Element>::reverse_iterator PointerToArray<Element>::
00121 rend() const {
00122 if (_ptr == NULL) {
00123 return _empty_array.rbegin();
00124 }
00125 return _ptr->rend();
00126 }
00127
00128
00129
00130
00131
00132
00133 template<class Element>
00134 INLINE TYPENAME PointerToArray<Element>::size_type PointerToArray<Element>::
00135 size() const {
00136 return (_ptr == NULL) ? 0 : _ptr->size();
00137 }
00138
00139
00140
00141
00142
00143
00144 template<class Element>
00145 INLINE TYPENAME PointerToArray<Element>::size_type PointerToArray<Element>::
00146 max_size() const {
00147 nassertd(_ptr != NULL) {
00148 ((PointerToArray<Element> *)this)->reassign(new RefCountObj<pvector<Element> >);
00149 }
00150 return _ptr->max_size();
00151 }
00152
00153
00154
00155
00156
00157
00158 template<class Element>
00159 INLINE bool PointerToArray<Element>::
00160 empty() const {
00161 return (_ptr == NULL) ? true : _ptr->empty();
00162 }
00163
00164
00165
00166
00167
00168
00169 template<class Element>
00170 INLINE void PointerToArray<Element>::
00171 reserve(TYPENAME PointerToArray<Element>::size_type n) {
00172 if (_ptr == NULL) {
00173 reassign(new RefCountObj<pvector<Element> >);
00174 }
00175 _ptr->reserve(n);
00176 }
00177
00178
00179
00180
00181
00182
00183 template<class Element>
00184 INLINE TYPENAME PointerToArray<Element>::size_type PointerToArray<Element>::
00185 capacity() const {
00186 nassertr(_ptr != NULL, 0);
00187 return _ptr->capacity();
00188 }
00189
00190
00191
00192
00193
00194
00195 template<class Element>
00196 INLINE TYPENAME PointerToArray<Element>::reference PointerToArray<Element>::
00197 front() const {
00198 nassertd(_ptr != NULL) {
00199 ((PointerToArray<Element> *)this)->reassign(new RefCountObj<pvector<Element> >);
00200 }
00201 nassertd(!_ptr->empty()) {
00202 _ptr->push_back(Element());
00203 }
00204 return _ptr->front();
00205 }
00206
00207
00208
00209
00210
00211
00212 template<class Element>
00213 INLINE TYPENAME PointerToArray<Element>::reference PointerToArray<Element>::
00214 back() const {
00215 nassertd(_ptr != NULL) {
00216 ((PointerToArray<Element> *)this)->reassign(new RefCountObj<pvector<Element> >);
00217 }
00218 nassertd(!_ptr->empty()) {
00219 _ptr->push_back(Element());
00220 }
00221 return _ptr->back();
00222 }
00223
00224
00225
00226
00227
00228
00229 template<class Element>
00230 INLINE TYPENAME PointerToArray<Element>::iterator PointerToArray<Element>::
00231 insert(iterator position, const Element &x) const {
00232 nassertr(_ptr != NULL, position);
00233 nassertr(position >= _ptr->begin() &&
00234 position <= _ptr->end(), position);
00235 return _ptr->insert(position, x);
00236 }
00237
00238
00239
00240
00241
00242
00243 template<class Element>
00244 INLINE void PointerToArray<Element>::
00245 insert(iterator position, size_type n, const Element &x) const {
00246 nassertv(_ptr != NULL);
00247 nassertv(position >= _ptr->begin() &&
00248 position <= _ptr->end());
00249 _ptr->insert(position, n, x);
00250 }
00251
00252
00253
00254
00255
00256
00257 template<class Element>
00258 INLINE void PointerToArray<Element>::
00259 erase(iterator position) const {
00260 nassertd(_ptr != NULL) {
00261 ((PointerToArray<Element> *)this)->reassign(new RefCountObj<pvector<Element> >);
00262 }
00263 nassertv(position >= _ptr->begin() &&
00264 position <= _ptr->end());
00265 _ptr->erase(position);
00266 }
00267
00268
00269
00270
00271
00272
00273 template<class Element>
00274 INLINE void PointerToArray<Element>::
00275 erase(iterator first, iterator last) const {
00276 nassertd(_ptr != NULL) {
00277 ((PointerToArray<Element> *)this)->reassign(new RefCountObj<pvector<Element> >);
00278 }
00279 nassertv(first >= _ptr->begin() && first <= _ptr->end());
00280 nassertv(last >= _ptr->begin() && last <= _ptr->end());
00281 _ptr->erase(first, last);
00282 }
00283
00284 #if !defined(WIN32_VC)
00285
00286
00287
00288
00289
00290 template<class Element>
00291 INLINE TYPENAME PointerToArray<Element>::reference PointerToArray<Element>::
00292 operator [](size_type n) const {
00293 nassertd(_ptr != NULL) {
00294 ((PointerToArray<Element> *)this)->reassign(new RefCountObj<pvector<Element> >);
00295 }
00296 nassertd(!_ptr->empty()) {
00297 _ptr->push_back(Element());
00298 }
00299 nassertr(n < _ptr->size(), _ptr->operator[](0));
00300 return _ptr->operator[](n);
00301 }
00302
00303
00304
00305
00306
00307
00308 template<class Element>
00309 INLINE TYPENAME PointerToArray<Element>::reference PointerToArray<Element>::
00310 operator [](int n) const {
00311 return operator[]((size_type)n);
00312 }
00313 #endif
00314
00315
00316
00317
00318
00319
00320 template<class Element>
00321 INLINE void PointerToArray<Element>::
00322 push_back(const Element &x) {
00323 if (_ptr == NULL) {
00324 reassign(new RefCountObj<pvector<Element> >);
00325 }
00326 _ptr->push_back(x);
00327 }
00328
00329
00330
00331
00332
00333
00334 template<class Element>
00335 INLINE void PointerToArray<Element>::
00336 pop_back() {
00337 nassertd(_ptr != NULL) {
00338 ((PointerToArray<Element> *)this)->reassign(new RefCountObj<pvector<Element> >);
00339 }
00340 nassertv(!_ptr->empty());
00341 _ptr->pop_back();
00342 }
00343
00344
00345
00346
00347
00348
00349
00350
00351 template<class Element>
00352 INLINE void PointerToArray<Element>::
00353 make_empty() {
00354 nassertd(_ptr != NULL) {
00355 ((PointerToArray<Element> *)this)->reassign(new RefCountObj<pvector<Element> >);
00356 }
00357 nassertv(!_ptr->empty());
00358 _ptr->clear();
00359 }
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370 template<class Element>
00371 INLINE PointerToArray<Element>::
00372 operator Element *() const {
00373 return (_ptr == NULL) ? (Element *)NULL : &(_ptr->front());
00374 }
00375
00376
00377
00378
00379
00380
00381
00382
00383 template<class Element>
00384 INLINE Element *PointerToArray<Element>::
00385 p() const {
00386 return (_ptr == NULL) ? (Element *)NULL : &(_ptr->front());
00387 }
00388
00389
00390
00391
00392
00393
00394
00395 template<class Element>
00396 INLINE pvector<Element> &PointerToArray<Element>::
00397 v() const {
00398 nassertd(_ptr != NULL) {
00399 ((PointerToArray<Element> *)this)->reassign(new RefCountObj<pvector<Element> >);
00400 }
00401 return *_ptr;
00402 }
00403
00404
00405
00406
00407
00408
00409
00410 template<class Element>
00411 INLINE void* PointerToArray<Element>::
00412 get_void_ptr() const
00413 {
00414 return PointerToBase<RefCountObj<pvector<Element> > >::_ptr;
00415 }
00416
00417
00418
00419
00420
00421
00422 template<class Element>
00423 INLINE void PointerToArray<Element>::
00424 set_void_ptr(void* p)
00425 {
00426 reassign((RefCountObj<pvector<Element> > *)p);
00427 }
00428
00429
00430
00431
00432
00433 template<class Element>
00434 INLINE int PointerToArray<Element>::
00435 get_ref_count() const {
00436 return (_ptr == NULL) ? 0 : _ptr->get_ref_count();
00437 }
00438
00439
00440
00441
00442
00443
00444 template<class Element>
00445 INLINE PointerToArray<Element> &PointerToArray<Element>::
00446 operator = (RefCountObj<pvector<Element> > *ptr) {
00447 reassign(ptr);
00448 return *this;
00449 }
00450
00451
00452
00453
00454
00455
00456 template<class Element>
00457 INLINE PointerToArray<Element> &PointerToArray<Element>::
00458 operator = (const PointerToArray<Element> ©) {
00459 reassign(copy);
00460 return *this;
00461 }
00462
00463
00464
00465
00466
00467
00468
00469
00470 template<class Element>
00471 INLINE void PointerToArray<Element>::
00472 clear() {
00473 reassign((RefCountObj<pvector<Element> > *)NULL);
00474 }
00475
00476
00477
00478
00479
00480
00481
00482
00483 template<class Element>
00484 INLINE ConstPointerToArray<Element>::
00485 ConstPointerToArray() :
00486 PointerToBase<RefCountObj<pvector<Element> > >((RefCountObj<pvector<Element> > *)NULL)
00487 {
00488 }
00489
00490
00491
00492
00493
00494
00495 template<class Element>
00496 INLINE ConstPointerToArray<Element>::
00497 ConstPointerToArray(const PointerToArray<Element> ©) :
00498 PointerToBase<RefCountObj<pvector<Element> > >(copy)
00499 {
00500 }
00501
00502
00503
00504
00505
00506
00507 template<class Element>
00508 INLINE ConstPointerToArray<Element>::
00509 ConstPointerToArray(const ConstPointerToArray<Element> ©) :
00510 PointerToBase<RefCountObj<pvector<Element> > >(copy)
00511 {
00512 }
00513
00514
00515
00516
00517
00518
00519 template<class Element>
00520 INLINE TYPENAME ConstPointerToArray<Element>::iterator ConstPointerToArray<Element>::
00521 begin() const {
00522 if (_ptr == NULL) {
00523 return _empty_array.begin();
00524 }
00525 return _ptr->begin();
00526 }
00527
00528
00529
00530
00531
00532
00533 template<class Element>
00534 INLINE TYPENAME ConstPointerToArray<Element>::iterator ConstPointerToArray<Element>::
00535 end() const {
00536 if (_ptr == NULL) {
00537 return _empty_array.begin();
00538 }
00539 return _ptr->end();
00540 }
00541
00542
00543
00544
00545
00546
00547 template<class Element>
00548 INLINE TYPENAME ConstPointerToArray<Element>::reverse_iterator ConstPointerToArray<Element>::
00549 rbegin() const {
00550 if (_ptr == NULL) {
00551 return _empty_array.rbegin();
00552 }
00553 return _ptr->rbegin();
00554 }
00555
00556
00557
00558
00559
00560
00561 template<class Element>
00562 INLINE TYPENAME ConstPointerToArray<Element>::reverse_iterator ConstPointerToArray<Element>::
00563 rend() const {
00564 if (_ptr == NULL) {
00565 return _empty_array.rbegin();
00566 }
00567 return _ptr->rend();
00568 }
00569
00570
00571
00572
00573
00574
00575 template<class Element>
00576 INLINE TYPENAME ConstPointerToArray<Element>::size_type ConstPointerToArray<Element>::
00577 size() const {
00578 return (_ptr == NULL) ? 0 : _ptr->size();
00579 }
00580
00581
00582
00583
00584
00585
00586 template<class Element>
00587 INLINE TYPENAME ConstPointerToArray<Element>::size_type ConstPointerToArray<Element>::
00588 max_size() const {
00589 nassertd(_ptr != NULL) {
00590 ((ConstPointerToArray<Element> *)this)->reassign(new RefCountObj<pvector<Element> >);
00591 }
00592 return _ptr->max_size();
00593 }
00594
00595
00596
00597
00598
00599
00600 template<class Element>
00601 INLINE bool ConstPointerToArray<Element>::
00602 empty() const {
00603 return (_ptr == NULL) ? true : _ptr->empty();
00604 }
00605
00606
00607
00608
00609
00610
00611 template<class Element>
00612 INLINE TYPENAME ConstPointerToArray<Element>::size_type ConstPointerToArray<Element>::
00613 capacity() const {
00614 nassertd(_ptr != NULL) {
00615 ((ConstPointerToArray<Element> *)this)->reassign(new RefCountObj<pvector<Element> >);
00616 }
00617 return _ptr->capacity();
00618 }
00619
00620 #ifndef WIN32_VC
00621
00622
00623
00624
00625
00626 template<class Element>
00627 INLINE TYPENAME ConstPointerToArray<Element>::reference ConstPointerToArray<Element>::
00628 operator [](size_type n) const {
00629 nassertd(_ptr != NULL) {
00630 ((ConstPointerToArray<Element> *)this)->reassign(new RefCountObj<pvector<Element> >);
00631 }
00632 nassertd(!_ptr->empty()) {
00633 _ptr->push_back(Element());
00634 }
00635 nassertr(n < _ptr->size(), _ptr->operator[](0));
00636 return _ptr->operator[](n);
00637 }
00638
00639
00640
00641
00642
00643
00644 template<class Element>
00645 INLINE TYPENAME ConstPointerToArray<Element>::reference ConstPointerToArray<Element>::
00646 operator [](int n) const {
00647 return operator[]((size_type)n);
00648 }
00649 #endif
00650
00651
00652
00653
00654
00655
00656 template<class Element>
00657 INLINE TYPENAME ConstPointerToArray<Element>::reference ConstPointerToArray<Element>::
00658 front() const {
00659 nassertd(_ptr != NULL) {
00660 ((ConstPointerToArray<Element> *)this)->reassign(new RefCountObj<pvector<Element> >);
00661 }
00662 nassertd(!_ptr->empty()) {
00663 _ptr->push_back(Element());
00664 }
00665 return _ptr->front();
00666 }
00667
00668
00669
00670
00671
00672
00673 template<class Element>
00674 INLINE TYPENAME ConstPointerToArray<Element>::reference ConstPointerToArray<Element>::
00675 back() const {
00676 nassertd(_ptr != NULL) {
00677 ((ConstPointerToArray<Element> *)this)->reassign(new RefCountObj<pvector<Element> >);
00678 }
00679 nassertd(!_ptr->empty()) {
00680 _ptr->push_back(Element());
00681 }
00682 return _ptr->back();
00683 }
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694 template<class Element>
00695 INLINE ConstPointerToArray<Element>::
00696 operator const Element *() const {
00697 return (_ptr == NULL) ? (const Element *)NULL : &(_ptr->front());
00698 }
00699
00700
00701
00702
00703
00704
00705
00706
00707 template<class Element>
00708 INLINE const Element *ConstPointerToArray<Element>::
00709 p() const {
00710 return (_ptr == NULL) ? (const Element *)NULL : &(_ptr->front());
00711 }
00712
00713
00714
00715
00716
00717
00718
00719 template<class Element>
00720 INLINE const pvector<Element> &ConstPointerToArray<Element>::
00721 v() const {
00722 nassertd(_ptr != NULL) {
00723 ((ConstPointerToArray<Element> *)this)->reassign(new RefCountObj<pvector<Element> >);
00724 }
00725 return *_ptr;
00726 }
00727
00728
00729
00730
00731
00732
00733 template<class Element>
00734 INLINE int ConstPointerToArray<Element>::
00735 get_ref_count() const {
00736 return (_ptr == NULL) ? 0 : _ptr->get_ref_count();
00737 }
00738
00739
00740
00741
00742
00743
00744 template<class Element>
00745 INLINE ConstPointerToArray<Element> &ConstPointerToArray<Element>::
00746 operator = (RefCountObj<pvector<Element> > *ptr) {
00747 reassign(ptr);
00748 return *this;
00749 }
00750
00751
00752
00753
00754
00755
00756 template<class Element>
00757 INLINE ConstPointerToArray<Element> &ConstPointerToArray<Element>::
00758 operator = (const PointerToArray<Element> ©) {
00759 reassign(copy);
00760 return *this;
00761 }
00762
00763
00764
00765
00766
00767
00768 template<class Element>
00769 INLINE ConstPointerToArray<Element> &ConstPointerToArray<Element>::
00770 operator = (const ConstPointerToArray<Element> ©) {
00771 reassign(copy);
00772 return *this;
00773 }
00774
00775
00776
00777
00778
00779
00780
00781
00782 template<class Element>
00783 INLINE void ConstPointerToArray<Element>::
00784 clear() {
00785 reassign((RefCountObj<pvector<Element> > *)NULL);
00786 }
00787