Panda3D

pointerToArray.I

00001 // Filename: pointerToArray.I
00002 // Created by:  drose (07Jan00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
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 //     Function: PointerToArray::Constructor
00025 //       Access: Public
00026 //  Description:
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 //     Function: PointerToArray::empty_array
00038 //       Access: Public, Static
00039 //  Description: Return an empty array of size n
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 //     Function: PointerToArray::Constructor
00054 //       Access: Public
00055 //  Description:
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 //     Function: PointerToArray::Copy Constructor
00069 //       Access: Public
00070 //  Description:
00071 ////////////////////////////////////////////////////////////////////
00072 template<class Element>
00073 INLINE PointerToArray<Element>::
00074 PointerToArray(const PointerToArray<Element> &copy) :
00075   PointerToArrayBase<Element>(copy),
00076   _type_handle(copy._type_handle)
00077 {
00078 }
00079 
00080 #ifdef HAVE_PYTHON
00081 ////////////////////////////////////////////////////////////////////
00082 //     Function: PointerToArray::Constructor
00083 //       Access: Published
00084 //  Description: This special constructor accepts a Python list of
00085 //               elements, or a Python string.
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   // We have to pre-initialize self's "this" pointer when we receive
00094   // self in the constructor--the caller can't initialize this for us.
00095   ((Dtool_PyInstDef *)self)->_ptr_to_object = this;
00096 
00097   if (!PySequence_Check(sequence)) {
00098     // If passed with a non-sequence, this isn't the right constructor.
00099     PyErr_SetString(PyExc_TypeError, "PointerToArray constructor requires a sequence");
00100     return;
00101   }
00102 
00103   if (PyString_CheckExact(sequence)) {
00104     // If we were passed a Python string, then instead of storing it
00105     // character-at-a-time, just load the whole string as a data
00106     // buffer.
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     // Hope there aren't any constructors or destructors involved
00120     // here.
00121     if (size != 0) {
00122       const char *data = PyString_AsString(sequence);
00123       memcpy(p(), data, size);
00124     }
00125     return;
00126   }
00127 
00128   // Now construct the internal list by copying the elements
00129   // one-at-a-time from Python.
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       // Unable to add item--probably it wasn't of the appropriate type.
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 //     Function: PointerToArray::begin
00153 //       Access: Public
00154 //  Description:
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 //     Function: PointerToArray::end
00167 //       Access: Public
00168 //  Description:
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 //     Function: PointerToArray::rbegin
00181 //       Access: Public
00182 //  Description:
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 //     Function: PointerToArray::rend
00195 //       Access: Public
00196 //  Description:
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 //     Function: PointerToArray::size
00209 //       Access: Published
00210 //  Description:
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 //     Function: PointerToArray::max_size
00220 //       Access: Public
00221 //  Description:
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 //     Function: PointerToArray::empty
00234 //       Access: Public
00235 //  Description:
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 //     Function: PointerToArray::reserve
00245 //       Access: Public
00246 //  Description:
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 //     Function: PointerToArray::resize
00259 //       Access: Public
00260 //  Description:
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 //     Function: PointerToArray::capacity
00273 //       Access: Public
00274 //  Description:
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 //     Function: PointerToArray::front
00285 //       Access: Public
00286 //  Description:
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 //     Function: PointerToArray::back
00302 //       Access: Public
00303 //  Description:
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 //     Function: PointerToArray::insert
00319 //       Access: Public
00320 //  Description:
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 //     Function: PointerToArray::insert
00336 //       Access: Public
00337 //  Description:
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 //     Function: PointerToArray::erase
00353 //       Access: Public
00354 //  Description:
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 //     Function: PointerToArray::erase
00367 //       Access: Public
00368 //  Description:
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 //     Function: PointerToArray::Indexing operator
00382 //       Access: Public
00383 //  Description:
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 //     Function: PointerToArray::Indexing operator
00400 //       Access: Public
00401 //  Description:
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 //     Function: PointerToArray::push_back
00412 //       Access: Public
00413 //  Description:
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 //     Function: PointerToArray::pop_back
00426 //       Access: Public
00427 //  Description:
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 //     Function: PointerToArray::make_empty
00441 //       Access: Public
00442 //  Description: Empties the array pointed to.  This is different from
00443 //               clear(), which reassigns the pointer to a NULL
00444 //               pointer.
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 //     Function: PointerToArray::Typecast operator
00458 //       Access: Public
00459 //  Description: The pointer typecast operator is convenient for
00460 //               maintaining the fiction that we actually have a
00461 //               C-style array.  It returns the address of the first
00462 //               element in the array, unless the pointer is
00463 //               unassigned, in which case it returns NULL.
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 //     Function: PointerToArray::p
00474 //       Access: Public
00475 //  Description: Function p() is similar to the function from
00476 //               PointerTo.  It does the same thing: it returns the
00477 //               same thing as the typecast operator, above.
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 //     Function: PointerToArray::v
00488 //       Access: Public
00489 //  Description: To access the vector itself, for more direct fiddling
00490 //               with some of the vector's esoteric functionality.
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 //     Function: PointerToArray::v0
00503 //       Access: Public
00504 //  Description: To access the internal ReferenceCountedVector object,
00505 //               for very low-level fiddling.  Know what you are doing!
00506 ////////////////////////////////////////////////////////////////////
00507 template<class Element>
00508 INLINE ReferenceCountedVector<Element> *PointerToArray<Element>::
00509 v0() const {
00510   return (To *)(this->_void_ptr);
00511 }
00512 
00513 ////////////////////////////////////////////////////////////////////
00514 //     Function: PointerToArray::get_element
00515 //       Access: Published
00516 //  Description: This method exists mainly to access the elements of
00517 //               the array easily from a high-level language such as
00518 //               Python, especially on Windows, where the above index
00519 //               element accessor methods can't be defined because of
00520 //               a confusion with the pointer typecast operator.
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 //     Function: PointerToArray::set_element
00530 //       Access: Published
00531 //  Description: This method exists mainly to access the elements of
00532 //               the array easily from a high-level language such as
00533 //               Python, especially on Windows, where the above index
00534 //               element accessor methods can't be defined because of
00535 //               a confusion with the pointer typecast operator.
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 //     Function: PointerToArray::__getitem__
00546 //       Access: Published
00547 //  Description: Same as get_element(), this returns the nth element
00548 //               of the array.
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 //     Function: PointerToArray::__setitem__
00558 //       Access: Published
00559 //  Description: Same as set_element(), this replaces the nth element
00560 //               of the array.
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 //     Function: PointerToArray::get_data
00571 //       Access: Published
00572 //  Description: This method exists mainly to access the data of
00573 //               the array easily from a high-level language such as
00574 //               Python.
00575 //
00576 //               It returns the entire contents of the vector as a
00577 //               block of raw data in a string.
00578 ////////////////////////////////////////////////////////////////////
00579 template<class Element>
00580 INLINE string PointerToArray<Element>::
00581 get_data() const {
00582   return get_subdata(0, size());
00583 }
00584 
00585 ////////////////////////////////////////////////////////////////////
00586 //     Function: PointerToArray::set_data
00587 //       Access: Published
00588 //  Description: This method exists mainly to access the data of
00589 //               the array easily from a high-level language such as
00590 //               Python.
00591 //
00592 //               It replaces the entire contents of the vector from a
00593 //               block of raw data in a string.
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 //     Function: PointerToArray::get_subdata
00603 //       Access: Published
00604 //  Description: This method exists mainly to access the data of
00605 //               the array easily from a high-level language such as
00606 //               Python.
00607 //
00608 //               It returns the contents of a portion of the
00609 //               vector--from element (n) through element (n + count -
00610 //               1)--as a block of raw data in a string.
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 //     Function: PointerToArray::set_subdata
00623 //       Access: Published
00624 //  Description: This method exists mainly to access the data of
00625 //               the array easily from a high-level language such as
00626 //               Python.
00627 //
00628 //               It replaces the contents of a portion of the
00629 //               vector--from element (n) through element (n + count -
00630 //               1)--as a block of raw data in a string.  The length
00631 //               of the string must be an even multiple of Element
00632 //               size bytes.  The array may be expanded or truncated
00633 //               if the length of the string does not correspond to
00634 //               exactly count elements.
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     // Reduce the array.
00647     erase(begin() + n + ncount, begin() + n + count);
00648   } else if (count < ncount) {
00649     // Expand the array.
00650     insert(begin() + n + count, ncount - count, Element());
00651   }
00652 
00653   // Now boldly replace the data.  Hope there aren't any constructors
00654   // or destructors involved here.  The user better know what she is
00655   // doing.
00656   memcpy(p() + n, data.data(), sizeof(Element) * ncount);
00657 }
00658 
00659 ////////////////////////////////////////////////////////////////////
00660 //     Function: PointerToArray::get(this->_void_ptr)
00661 //       Access: Public
00662 //  Description: Returns the reference to memory where the vector
00663 //               is stored.  To be used only with set_void_ptr
00664 ////////////////////////////////////////////////////////////////////
00665 template<class Element>
00666 INLINE void *PointerToArray<Element>::
00667 get_void_ptr() const {
00668   return (this->_void_ptr);
00669 }
00670 
00671 ////////////////////////////////////////////////////////////////////
00672 //     Function: PointerToArray::set_void_ptr
00673 //       Access: Public
00674 //  Description: Sets this PTA to point to the pointer passed in
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 //     Function: PointerToArray::get_ref_count
00684 //       Access: Public
00685 //  Description: Returns the reference count of the underlying vector.
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 //     Function: PointerToArray::get_node_ref_count
00695 //       Access: Public
00696 //  Description: Returns the node_ref of the underlying vector.
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 //     Function: PointerToArray::node_ref
00706 //       Access: Public
00707 //  Description: Increments the node_ref of the underlying vector.
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 //     Function: PointerToArray::node_unref
00720 //       Access: Public
00721 //  Description: Decrements the node_ref of the underlying vector.
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 //     Function: PointerToArray::Assignment operator
00732 //       Access: Public
00733 //  Description:
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 //     Function: PointerToArray::Assignment operator
00744 //       Access: Public
00745 //  Description:
00746 ////////////////////////////////////////////////////////////////////
00747 template<class Element>
00748 INLINE PointerToArray<Element> &PointerToArray<Element>::
00749 operator = (const PointerToArray<Element> &copy) {
00750   _type_handle = copy._type_handle;
00751   ((PointerToArray<Element> *)this)->reassign(copy);
00752   return *this;
00753 }
00754 
00755 ////////////////////////////////////////////////////////////////////
00756 //     Function: PointerToArray::clear
00757 //       Access: Public
00758 //  Description: To empty the PTA, use the clear() method, since
00759 //               assignment to NULL is problematic (given the
00760 //               ambiguity of the pointer type of NULL).
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 //     Function: ConstPointerToArray::Constructor
00772 //       Access: Public
00773 //  Description:
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 //     Function: ConstPointerToArray::Copy Constructor
00785 //       Access: Public
00786 //  Description:
00787 ////////////////////////////////////////////////////////////////////
00788 template<class Element>
00789 INLINE ConstPointerToArray<Element>::
00790 ConstPointerToArray(const PointerToArray<Element> &copy) :
00791   PointerToArrayBase<Element>(copy),
00792   _type_handle(copy._type_handle)
00793 {
00794 }
00795 
00796 ////////////////////////////////////////////////////////////////////
00797 //     Function: ConstPointerToArray::Copy Constructor
00798 //       Access: Public
00799 //  Description:
00800 ////////////////////////////////////////////////////////////////////
00801 template<class Element>
00802 INLINE ConstPointerToArray<Element>::
00803 ConstPointerToArray(const ConstPointerToArray<Element> &copy) :
00804   PointerToArrayBase<Element>(copy),
00805   _type_handle(copy._type_handle)
00806 {
00807 }
00808 
00809 ////////////////////////////////////////////////////////////////////
00810 //     Function: ConstPointerToArray::begin
00811 //       Access: Public
00812 //  Description:
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 //     Function: ConstPointerToArray::end
00825 //       Access: Public
00826 //  Description:
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 //     Function: ConstPointerToArray::rbegin
00839 //       Access: Public
00840 //  Description:
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 //     Function: ConstPointerToArray::rend
00853 //       Access: Public
00854 //  Description:
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 //     Function: ConstPointerToArray::size
00867 //       Access: Public
00868 //  Description:
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 //     Function: ConstPointerToArray::max_size
00878 //       Access: Public
00879 //  Description:
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 //     Function: ConstPointerToArray::empty
00892 //       Access: Public
00893 //  Description:
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 //     Function: ConstPointerToArray::capacity
00903 //       Access: Public
00904 //  Description:
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 //     Function: ConstPointerToArray::front
00917 //       Access: Public
00918 //  Description:
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 //     Function: ConstPointerToArray::back
00934 //       Access: Public
00935 //  Description:
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 //     Function: ConstPointerToArray::Indexing operator
00952 //       Access: Public
00953 //  Description:
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 //     Function: ConstPointerToArray::Indexing operator
00970 //       Access: Public
00971 //  Description:
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 //     Function: ConstPointerToArray::Typecast operator
00982 //       Access: Public
00983 //  Description: The pointer typecast operator is convenient for
00984 //               maintaining the fiction that we actually have a
00985 //               C-style array.  It returns the address of the first
00986 //               element in the array, unless the pointer is
00987 //               unassigned, in which case it returns NULL.
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 //     Function: ConstPointerToArray::p
00998 //       Access: Public
00999 //  Description: Function p() is similar to the function from
01000 //               ConstPointerTo.  It does the same thing: it returns the
01001 //               same thing as the typecast operator, above.
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 //     Function: ConstPointerToArray::v
01012 //       Access: Public
01013 //  Description: To access the vector itself, for more direct fiddling
01014 //               with some of the vector's esoteric functionality.
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 //     Function: ConstPointerToArray::v0
01027 //       Access: Public
01028 //  Description: To access the internal ReferenceCountedVector object,
01029 //               for very low-level fiddling.  Know what you are doing!
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 //     Function: ConstPointerToArray::cast_non_const
01039 //       Access: Public
01040 //  Description: Casts away the constness of the CPTA(Element), and
01041 //               returns an equivalent PTA(Element).
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 //     Function: ConstPointerToArray::get_element
01053 //       Access: Published
01054 //  Description: This method exists mainly to access the elements of
01055 //               the array easily from a high-level language such as
01056 //               Python, especially on Windows, where the above index
01057 //               element accessor methods can't be defined because of
01058 //               a confusion with the pointer typecast operator.
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 //     Function: ConstPointerToArray::__getitem__
01068 //       Access: Published
01069 //  Description: Same as get_element(), this returns the nth element
01070 //               of the array.
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 //     Function: ConstPointerToArray::get_data
01080 //       Access: Published
01081 //  Description: This method exists mainly to access the data of
01082 //               the array easily from a high-level language such as
01083 //               Python.
01084 //
01085 //               It returns the entire contents of the vector as a
01086 //               block of raw data in a string.
01087 ////////////////////////////////////////////////////////////////////
01088 template<class Element>
01089 INLINE string ConstPointerToArray<Element>::
01090 get_data() const {
01091   return get_subdata(0, size());
01092 }
01093 
01094 ////////////////////////////////////////////////////////////////////
01095 //     Function: ConstPointerToArray::get_subdata
01096 //       Access: Published
01097 //  Description: This method exists mainly to access the data of
01098 //               the array easily from a high-level language such as
01099 //               Python.
01100 //
01101 //               It returns the contents of a portion of the
01102 //               vector--from element (n) through element (n + count -
01103 //               1)--as a block of raw data in a string.
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 //     Function: ConstPointerToArray::get_ref_count
01116 //       Access: Public
01117 //  Description: Returns the reference count of the underlying vector.
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 //     Function: ConstPointerToArray::get_node_ref_count
01127 //       Access: Public
01128 //  Description: Returns the node_ref of the underlying vector.
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 //     Function: ConstPointerToArray::node_ref
01138 //       Access: Public
01139 //  Description: Increments the node_ref of the underlying vector.
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 //     Function: ConstPointerToArray::node_unref
01152 //       Access: Public
01153 //  Description: Decrements the node_ref of the underlying vector.
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 //     Function: ConstPointerToArray::Assignment operator
01164 //       Access: Public
01165 //  Description:
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 //     Function: ConstPointerToArray::Assignment operator
01176 //       Access: Public
01177 //  Description:
01178 ////////////////////////////////////////////////////////////////////
01179 template<class Element>
01180 INLINE ConstPointerToArray<Element> &ConstPointerToArray<Element>::
01181 operator = (const PointerToArray<Element> &copy) {
01182   _type_handle = copy._type_handle;
01183   ((ConstPointerToArray<Element> *)this)->reassign(copy);
01184   return *this;
01185 }
01186 
01187 ////////////////////////////////////////////////////////////////////
01188 //     Function: ConstPointerToArray::Assignment operator
01189 //       Access: Public
01190 //  Description:
01191 ////////////////////////////////////////////////////////////////////
01192 template<class Element>
01193 INLINE ConstPointerToArray<Element> &ConstPointerToArray<Element>::
01194 operator = (const ConstPointerToArray<Element> &copy) {
01195   _type_handle = copy._type_handle;
01196   ((ConstPointerToArray<Element> *)this)->reassign(copy);
01197   return *this;
01198 }
01199 
01200 ////////////////////////////////////////////////////////////////////
01201 //     Function: ConstPointerToArray::clear
01202 //       Access: Public
01203 //  Description: To empty the PTA, use the clear() method, since
01204 //               assignment to NULL is problematic (given the
01205 //               ambiguity of the pointer type of NULL).
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
 All Classes Functions Variables Enumerations