00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef POINTERTOARRAY_H
00016 #define POINTERTOARRAY_H
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 #include "pandabase.h"
00068
00069 #include "pointerToArrayBase.h"
00070 #ifdef HAVE_PYTHON
00071 #include "py_panda.h"
00072 #endif
00073
00074 #if (defined(WIN32_VC) || defined(WIN64_VC)) && !defined(__INTEL_COMPILER)
00075
00076
00077 #pragma warning (disable : 4506)
00078 #endif
00079
00080 template <class Element>
00081 class ConstPointerToArray;
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101 template <class Element>
00102 class PointerToArray : public PointerToArrayBase<Element> {
00103 public:
00104
00105
00106
00107
00108 #ifdef CPPPARSER
00109 PUBLISHED:
00110 typedef TYPENAME pvector<Element>::size_type size_type;
00111 INLINE PointerToArray(TypeHandle type_handle = get_type_handle(Element));
00112 INLINE static PointerToArray<Element> empty_array(size_type n, TypeHandle type_handle = get_type_handle(Element));
00113 INLINE PointerToArray(const PointerToArray<Element> ©);
00114
00115 #ifdef HAVE_PYTHON
00116 PointerToArray(PyObject *self, PyObject *sequence);
00117 #endif
00118
00119 INLINE size_type size() const;
00120 INLINE void push_back(const Element &x);
00121 INLINE void pop_back();
00122 INLINE const Element &get_element(size_type n) const;
00123 INLINE void set_element(size_type n, const Element &value);
00124 INLINE const Element &__getitem__(size_type n) const;
00125 INLINE void __setitem__(size_type n, const Element &value);
00126 INLINE string get_data() const;
00127 INLINE void set_data(const string &data);
00128 INLINE string get_subdata(size_type n, size_type count) const;
00129 INLINE void set_subdata(size_type n, size_type count, const string &data);
00130 INLINE int get_ref_count() const;
00131 INLINE int get_node_ref_count() const;
00132
00133 #else // CPPPARSER
00134
00135 typedef TYPENAME PointerToArrayBase<Element>::To To;
00136 typedef TYPENAME pvector<Element>::value_type value_type;
00137 typedef TYPENAME pvector<Element>::reference reference;
00138 typedef TYPENAME pvector<Element>::const_reference const_reference;
00139 typedef TYPENAME pvector<Element>::iterator iterator;
00140 typedef TYPENAME pvector<Element>::const_iterator const_iterator;
00141 typedef TYPENAME pvector<Element>::reverse_iterator reverse_iterator;
00142 typedef TYPENAME pvector<Element>::const_reverse_iterator const_reverse_iterator;
00143 typedef TYPENAME pvector<Element>::difference_type difference_type;
00144 typedef TYPENAME pvector<Element>::size_type size_type;
00145
00146 public:
00147 INLINE PointerToArray(TypeHandle type_handle = get_type_handle(Element));
00148 INLINE static PointerToArray<Element> empty_array(size_type n, TypeHandle type_handle = get_type_handle(Element));
00149 INLINE PointerToArray(size_type n, const Element &value, TypeHandle type_handle = get_type_handle(Element));
00150 INLINE PointerToArray(const PointerToArray<Element> ©);
00151
00152 #ifdef HAVE_PYTHON
00153 PointerToArray(PyObject *self, PyObject *sequence);
00154 #endif
00155
00156 public:
00157
00158
00159
00160
00161
00162 INLINE iterator begin() const;
00163 INLINE iterator end() const;
00164 INLINE TYPENAME PointerToArray<Element>::reverse_iterator rbegin() const;
00165 INLINE TYPENAME PointerToArray<Element>::reverse_iterator rend() const;
00166
00167
00168
00169 INLINE size_type size() const;
00170 INLINE size_type max_size() const;
00171 INLINE bool empty() const;
00172
00173
00174 INLINE void reserve(size_type n);
00175 INLINE void resize(size_type n);
00176 INLINE size_type capacity() const;
00177 INLINE reference front() const;
00178 INLINE reference back() const;
00179 INLINE iterator insert(iterator position, const Element &x);
00180 INLINE void insert(iterator position, size_type n, const Element &x);
00181
00182
00183
00184
00185
00186
00187
00188
00189 INLINE void erase(iterator position);
00190 INLINE void erase(iterator first, iterator last);
00191
00192 #if !defined(WIN32_VC) && !defined (WIN64_VC)
00193 INLINE reference operator [](size_type n) const;
00194 INLINE reference operator [](int n) const;
00195 #endif
00196
00197 INLINE void push_back(const Element &x);
00198 INLINE void pop_back();
00199 INLINE void make_empty();
00200
00201 INLINE operator Element *() const;
00202 INLINE Element *p() const;
00203 INLINE pvector<Element> &v() const;
00204 INLINE ReferenceCountedVector<Element> *v0() const;
00205
00206
00207 INLINE const Element &get_element(size_type n) const;
00208 INLINE void set_element(size_type n, const Element &value);
00209 INLINE const Element &__getitem__(size_type n) const;
00210 INLINE void __setitem__(size_type n, const Element &value);
00211 INLINE string get_data() const;
00212 INLINE void set_data(const string &data);
00213 INLINE string get_subdata(size_type n, size_type count) const;
00214 INLINE void set_subdata(size_type n, size_type count, const string &data);
00215
00216
00217
00218
00219
00220
00221
00222 INLINE void *get_void_ptr() const;
00223 INLINE void set_void_ptr(void* p);
00224
00225 INLINE int get_ref_count() const;
00226
00227 INLINE int get_node_ref_count() const;
00228 INLINE void node_ref() const;
00229 INLINE bool node_unref() const;
00230
00231
00232 INLINE PointerToArray<Element> &
00233 operator = (ReferenceCountedVector<Element> *ptr);
00234 INLINE PointerToArray<Element> &
00235 operator = (const PointerToArray<Element> ©);
00236 INLINE void clear();
00237
00238 private:
00239 TypeHandle _type_handle;
00240
00241 private:
00242
00243
00244
00245
00246
00247 static pvector<Element> _empty_array;
00248 #endif // CPPPARSER
00249
00250 friend class ConstPointerToArray<Element>;
00251 };
00252
00253
00254
00255
00256
00257
00258 template <class Element>
00259 class ConstPointerToArray : public PointerToArrayBase<Element> {
00260 public:
00261
00262
00263
00264
00265 #ifdef CPPPARSER
00266 PUBLISHED:
00267 INLINE ConstPointerToArray(const PointerToArray<Element> ©);
00268 INLINE ConstPointerToArray(const ConstPointerToArray<Element> ©);
00269
00270 typedef TYPENAME pvector<Element>::size_type size_type;
00271 INLINE size_type size() const;
00272 INLINE const Element &get_element(size_type n) const;
00273 INLINE const Element &__getitem__(size_type n) const;
00274 INLINE string get_data() const;
00275 INLINE string get_subdata(size_type n, size_type count) const;
00276 INLINE int get_ref_count() const;
00277 INLINE int get_node_ref_count() const;
00278
00279 #else // CPPPARSER
00280
00281 typedef TYPENAME PointerToArrayBase<Element>::To To;
00282 typedef TYPENAME pvector<Element>::value_type value_type;
00283 typedef TYPENAME pvector<Element>::const_reference reference;
00284 typedef TYPENAME pvector<Element>::const_reference const_reference;
00285 typedef TYPENAME pvector<Element>::const_iterator iterator;
00286 typedef TYPENAME pvector<Element>::const_iterator const_iterator;
00287 #if defined(WIN32_VC) || defined(WIN64_VC)
00288
00289 typedef TYPENAME pvector<Element>::reverse_iterator reverse_iterator;
00290 #else
00291 typedef TYPENAME pvector<Element>::const_reverse_iterator reverse_iterator;
00292 #endif
00293 typedef TYPENAME pvector<Element>::const_reverse_iterator const_reverse_iterator;
00294 typedef TYPENAME pvector<Element>::difference_type difference_type;
00295 typedef TYPENAME pvector<Element>::size_type size_type;
00296
00297 INLINE ConstPointerToArray(TypeHandle type_handle = get_type_handle(Element));
00298 INLINE ConstPointerToArray(const PointerToArray<Element> ©);
00299 INLINE ConstPointerToArray(const ConstPointerToArray<Element> ©);
00300
00301
00302
00303 INLINE iterator begin() const;
00304 INLINE iterator end() const;
00305 INLINE TYPENAME ConstPointerToArray<Element>::reverse_iterator rbegin() const;
00306 INLINE TYPENAME ConstPointerToArray<Element>::reverse_iterator rend() const;
00307
00308
00309
00310
00311 INLINE size_type size() const;
00312 INLINE size_type max_size() const;
00313 INLINE bool empty() const;
00314
00315
00316 INLINE size_type capacity() const;
00317 INLINE reference front() const;
00318 INLINE reference back() const;
00319
00320 #if !defined(WIN32_VC) && !defined(WIN64_VC)
00321 INLINE reference operator [](size_type n) const;
00322 INLINE reference operator [](int n) const;
00323 #endif
00324
00325 INLINE operator const Element *() const;
00326 INLINE const Element *p() const;
00327 INLINE const pvector<Element> &v() const;
00328 INLINE const ReferenceCountedVector<Element> *v0() const;
00329 INLINE PointerToArray<Element> cast_non_const() const;
00330
00331
00332 INLINE const Element &get_element(size_type n) const;
00333 INLINE const Element &__getitem__(size_type n) const;
00334 INLINE string get_data() const;
00335 INLINE string get_subdata(size_type n, size_type count) const;
00336
00337 INLINE int get_ref_count() const;
00338
00339 INLINE int get_node_ref_count() const;
00340 INLINE void node_ref() const;
00341 INLINE bool node_unref() const;
00342
00343
00344 INLINE ConstPointerToArray<Element> &
00345 operator = (ReferenceCountedVector<Element> *ptr);
00346 INLINE ConstPointerToArray<Element> &
00347 operator = (const PointerToArray<Element> ©);
00348 INLINE ConstPointerToArray<Element> &
00349 operator = (const ConstPointerToArray<Element> ©);
00350 INLINE void clear();
00351
00352 private:
00353 TypeHandle _type_handle;
00354
00355 private:
00356
00357
00358
00359
00360
00361 static pvector<Element> _empty_array;
00362 #endif // CPPPARSER
00363
00364 friend class PointerToArray<Element>;
00365 };
00366
00367
00368
00369
00370 #define PTA(type) PointerToArray< type >
00371 #define CPTA(type) ConstPointerToArray< type >
00372
00373 #include "pointerToArray.I"
00374
00375 #endif