Browse Source

get_element, set_element

David Rose 21 years ago
parent
commit
0105b1fd89
2 changed files with 34 additions and 0 deletions
  1. 31 0
      panda/src/express/pointerToArray.I
  2. 3 0
      panda/src/express/pointerToArray.h

+ 31 - 0
panda/src/express/pointerToArray.I

@@ -312,6 +312,37 @@ operator [](int n) const {
 }
 #endif
 
+////////////////////////////////////////////////////////////////////
+//     Function: PointerToArray::get_element
+//       Access: Published
+//  Description: This method exists mainly to access the elements of
+//               the array easily from a high-level language such as
+//               Python, especially on Windows, where the above index
+//               element accessor methods can't be defined because of
+//               a confusion with the pointer typecast operator.
+////////////////////////////////////////////////////////////////////
+template<class Element>
+INLINE TYPENAME PointerToArray<Element>::const_reference PointerToArray<Element>::
+get_element(size_type n) const {
+  return (*this)[n];
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: PointerToArray::set_element
+//       Access: Published
+//  Description: This method exists mainly to access the elements of
+//               the array easily from a high-level language such as
+//               Python, especially on Windows, where the above index
+//               element accessor methods can't be defined because of
+//               a confusion with the pointer typecast operator.
+////////////////////////////////////////////////////////////////////
+template<class Element>
+INLINE void PointerToArray<Element>::
+set_element(size_type n, const_reference value) {
+  nassertv(n < _ptr->size());
+  (*this)[n] = value;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: PointerToArray::push_back
 //       Access: Published

+ 3 - 0
panda/src/express/pointerToArray.h

@@ -152,6 +152,9 @@ PUBLISHED:
   INLINE reference operator [](size_type n) const;
   INLINE reference operator [](int n) const;
 #endif
+  INLINE const_reference get_element(size_type n) const;
+  INLINE void set_element(size_type n, const_reference value);
+
   INLINE void push_back(const Element &x);
   INLINE void pop_back();
   INLINE void make_empty();