Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/express/pointerToArray.I

Go to the documentation of this file.
00001 // Filename: pointerToArray.I
00002 // Created by:  drose (07Jan00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
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 //     Function: PointerToArray::Constructor
00027 //       Access: Published
00028 //  Description:
00029 ////////////////////////////////////////////////////////////////////
00030 template<class Element>
00031 INLINE PointerToArray<Element>::
00032 PointerToArray() :
00033   PointerToBase<RefCountObj<pvector<Element> > >((RefCountObj<pvector<Element> > *)NULL)
00034 {
00035 }
00036 
00037 // return an empty array of size n
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 //     Function: PointerToArray::Constructor
00049 //       Access: Published
00050 //  Description:
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 //     Function: PointerToArray::Copy Constructor
00062 //       Access: Published
00063 //  Description:
00064 ////////////////////////////////////////////////////////////////////
00065 template<class Element>
00066 INLINE PointerToArray<Element>::
00067 PointerToArray(const PointerToArray<Element> &copy) :
00068   PointerToBase<RefCountObj<pvector<Element> > >(copy)
00069 {
00070 }
00071 
00072 ////////////////////////////////////////////////////////////////////
00073 //     Function: PointerToArray::begin
00074 //       Access: Public
00075 //  Description:
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 //     Function: PointerToArray::end
00088 //       Access: Public
00089 //  Description:
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 //     Function: PointerToArray::rbegin
00102 //       Access: Public
00103 //  Description:
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 //     Function: PointerToArray::rend
00116 //       Access: Public
00117 //  Description:
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 //     Function: PointerToArray::size
00130 //       Access: Published
00131 //  Description:
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 //     Function: PointerToArray::max_size
00141 //       Access: Public
00142 //  Description:
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 //     Function: PointerToArray::empty
00155 //       Access: Public
00156 //  Description:
00157 ////////////////////////////////////////////////////////////////////
00158 template<class Element>
00159 INLINE bool PointerToArray<Element>::
00160 empty() const {
00161   return (_ptr == NULL) ? true : _ptr->empty();
00162 }
00163 
00164 ////////////////////////////////////////////////////////////////////
00165 //     Function: PointerToArray::reserve
00166 //       Access: Public
00167 //  Description:
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 //     Function: PointerToArray::capacity
00180 //       Access: Public
00181 //  Description:
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 //     Function: PointerToArray::front
00192 //       Access: Public
00193 //  Description:
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 //     Function: PointerToArray::back
00209 //       Access: Public
00210 //  Description:
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 //     Function: PointerToArray::insert
00226 //       Access: Public
00227 //  Description:
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 //     Function: PointerToArray::insert
00240 //       Access: Public
00241 //  Description:
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 //     Function: PointerToArray::erase
00254 //       Access: Public
00255 //  Description:
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 //     Function: PointerToArray::erase
00270 //       Access: Public
00271 //  Description:
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 //     Function: PointerToArray::Indexing operator
00287 //       Access: Published
00288 //  Description:
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 //     Function: PointerToArray::Indexing operator
00305 //       Access: Published
00306 //  Description:
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 //     Function: PointerToArray::push_back
00317 //       Access: Published
00318 //  Description:
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 //     Function: PointerToArray::pop_back
00331 //       Access: Published
00332 //  Description:
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 //     Function: PointerToArray::make_empty
00346 //       Access: Published
00347 //  Description: Empties the array pointed to.  This is different from
00348 //               clear(), which reassigns the pointer to a NULL
00349 //               pointer.
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 //     Function: PointerToArray::Typecast operator
00363 //       Access: Public
00364 //  Description: The pointer typecast operator is convenient for
00365 //               maintaining the fiction that we actually have a
00366 //               C-style array.  It returns the address of the first
00367 //               element in the array, unless the pointer is
00368 //               unassigned, in which case it returns NULL.
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 //     Function: PointerToArray::p
00378 //       Access: Public
00379 //  Description: Function p() is similar to the function from
00380 //               PointerTo.  It does the same thing: it returns the
00381 //               same thing as the typecast operator, above.
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 //     Function: PointerToArray::v
00391 //       Access: Public
00392 //  Description: To access the vector itself, for more direct fiddling
00393 //               with some of the vector's esoteric functionality.
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 //     Function: PointerToArray::get_void_ptr
00406 //       Access: Public
00407 //  Description: Returns the reference to memory where the vector
00408 //               is stored.  To be used only with get_void_ptr
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 //     Function: PointerToArray::set_void_ptr
00419 //       Access: Public
00420 //  Description: Sets this PTA to point to the pointer passed in
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 //     Function: PointerToArray::get_ref_count
00430 //       Access: Public
00431 //  Description: Returns the reference count of the underlying vector.
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 //     Function: PointerToArray::Assignment operator
00441 //       Access: Public
00442 //  Description:
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 //     Function: PointerToArray::Assignment operator
00453 //       Access: Public
00454 //  Description:
00455 ////////////////////////////////////////////////////////////////////
00456 template<class Element>
00457 INLINE PointerToArray<Element> &PointerToArray<Element>::
00458 operator = (const PointerToArray<Element> &copy) {
00459   reassign(copy);
00460   return *this;
00461 }
00462 
00463 ////////////////////////////////////////////////////////////////////
00464 //     Function: PointerToArray::clear
00465 //       Access: Public
00466 //  Description: To empty the PTA, use the clear() method, since
00467 //               assignment to NULL is problematic (given the
00468 //               ambiguity of the pointer type of NULL).
00469 ////////////////////////////////////////////////////////////////////
00470 template<class Element>
00471 INLINE void PointerToArray<Element>::
00472 clear() {
00473   reassign((RefCountObj<pvector<Element> > *)NULL);
00474 }
00475 
00476 
00477 
00478 ////////////////////////////////////////////////////////////////////
00479 //     Function: ConstPointerToArray::Constructor
00480 //       Access: Public
00481 //  Description:
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 //     Function: ConstPointerToArray::Copy Constructor
00492 //       Access: Public
00493 //  Description:
00494 ////////////////////////////////////////////////////////////////////
00495 template<class Element>
00496 INLINE ConstPointerToArray<Element>::
00497 ConstPointerToArray(const PointerToArray<Element> &copy) :
00498   PointerToBase<RefCountObj<pvector<Element> > >(copy)
00499 {
00500 }
00501 
00502 ////////////////////////////////////////////////////////////////////
00503 //     Function: ConstPointerToArray::Copy Constructor
00504 //       Access: Public
00505 //  Description:
00506 ////////////////////////////////////////////////////////////////////
00507 template<class Element>
00508 INLINE ConstPointerToArray<Element>::
00509 ConstPointerToArray(const ConstPointerToArray<Element> &copy) :
00510   PointerToBase<RefCountObj<pvector<Element> > >(copy)
00511 {
00512 }
00513 
00514 ////////////////////////////////////////////////////////////////////
00515 //     Function: ConstPointerToArray::begin
00516 //       Access: Public
00517 //  Description:
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 //     Function: ConstPointerToArray::end
00530 //       Access: Public
00531 //  Description:
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 //     Function: ConstPointerToArray::rbegin
00544 //       Access: Public
00545 //  Description:
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 //     Function: ConstPointerToArray::rend
00558 //       Access: Public
00559 //  Description:
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 //     Function: ConstPointerToArray::size
00572 //       Access: Public
00573 //  Description:
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 //     Function: ConstPointerToArray::max_size
00583 //       Access: Public
00584 //  Description:
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 //     Function: ConstPointerToArray::empty
00597 //       Access: Public
00598 //  Description:
00599 ////////////////////////////////////////////////////////////////////
00600 template<class Element>
00601 INLINE bool ConstPointerToArray<Element>::
00602 empty() const {
00603   return (_ptr == NULL) ? true : _ptr->empty();
00604 }
00605 
00606 ////////////////////////////////////////////////////////////////////
00607 //     Function: ConstPointerToArray::capacity
00608 //       Access: Public
00609 //  Description:
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 //     Function: ConstPointerToArray::Indexing operator
00623 //       Access: Public
00624 //  Description:
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 //     Function: ConstPointerToArray::Indexing operator
00641 //       Access: Published
00642 //  Description:
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 //     Function: ConstPointerToArray::front
00653 //       Access: Public
00654 //  Description:
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 //     Function: ConstPointerToArray::back
00670 //       Access: Public
00671 //  Description:
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 //     Function: ConstPointerToArray::Typecast operator
00687 //       Access: Public
00688 //  Description: The pointer typecast operator is convenient for
00689 //               maintaining the fiction that we actually have a
00690 //               C-style array.  It returns the address of the first
00691 //               element in the array, unless the pointer is
00692 //               unassigned, in which case it returns NULL.
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 //     Function: ConstPointerToArray::p
00702 //       Access: Public
00703 //  Description: Function p() is similar to the function from
00704 //               ConstPointerTo.  It does the same thing: it returns the
00705 //               same thing as the typecast operator, above.
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 //     Function: ConstPointerToArray::v
00715 //       Access: Public
00716 //  Description: To access the vector itself, for more direct fiddling
00717 //               with some of the vector's esoteric functionality.
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 //     Function: ConstPointerToArray::get_ref_count
00730 //       Access: Public
00731 //  Description: Returns the reference count of the underlying vector.
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 //     Function: ConstPointerToArray::Assignment operator
00741 //       Access: Public
00742 //  Description:
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 //     Function: ConstPointerToArray::Assignment operator
00753 //       Access: Public
00754 //  Description:
00755 ////////////////////////////////////////////////////////////////////
00756 template<class Element>
00757 INLINE ConstPointerToArray<Element> &ConstPointerToArray<Element>::
00758 operator = (const PointerToArray<Element> &copy) {
00759   reassign(copy);
00760   return *this;
00761 }
00762 
00763 ////////////////////////////////////////////////////////////////////
00764 //     Function: ConstPointerToArray::Assignment operator
00765 //       Access: Public
00766 //  Description:
00767 ////////////////////////////////////////////////////////////////////
00768 template<class Element>
00769 INLINE ConstPointerToArray<Element> &ConstPointerToArray<Element>::
00770 operator = (const ConstPointerToArray<Element> &copy) {
00771   reassign(copy);
00772   return *this;
00773 }
00774 
00775 ////////////////////////////////////////////////////////////////////
00776 //     Function: ConstPointerToArray::clear
00777 //       Access: Public
00778 //  Description: To empty the PTA, use the clear() method, since
00779 //               assignment to NULL is problematic (given the
00780 //               ambiguity of the pointer type of NULL).
00781 ////////////////////////////////////////////////////////////////////
00782 template<class Element>
00783 INLINE void ConstPointerToArray<Element>::
00784 clear() {
00785   reassign((RefCountObj<pvector<Element> > *)NULL);
00786 }
00787 

Generated on Fri May 2 00:38:32 2003 for Panda by doxygen1.3