11 #ifndef __GA_DATAARRAYPAGETABLEIMPL_H_INCLUDED__
12 #define __GA_DATAARRAYPAGETABLEIMPL_H_INCLUDED__
34 namespace GA_Private {
47 myData = (
T *)malloc(capacity *
sizeof(
T));
58 return (inclusive ?
sizeof(*
this) : 0) + myCapacity*
sizeof(
T);
71 void ref()
const { myRefCount.
add(1); }
72 void unref() {
if(myRefCount.
add(-1) == 0)
delete this; }
78 #ifdef VERBOSE_DATAARRAY_DEBUG_OUTPUT
79 printf(
"Copying page %p capacity %d into capacity %d\n",
this, (
int)myCapacity, (
int)newcapacity);
89 memcpy(d->myData, myData, sizetocopy *
sizeof(
T));
106 template<
typename T>
static inline bool
107 ga_IsNotZero(T
a) {
return (
bool)
a; }
108 template<>
inline bool
110 template<>
inline bool
112 template<>
inline bool
114 template<>
inline bool
116 template<>
inline bool
118 template<>
inline bool
120 template<>
inline bool
134 template <
typename T,
typename TB,
int SLICE,
int VECTORSIZE>
150 const TB & scalarValue()
const {
return ((
const TB*)
rawvalue)[SLICE]; }
151 TB & scalarValue() {
return ((TB*)
rawvalue)[SLICE]; }
161 int64 mem = inclusive ?
sizeof(*this) : 0;
165 return mem +
myData.ptr->getMemoryUsage(
true);
229 return page.myData.scalarValue();
231 return ((TB*)&(page.myRawData[
offset]))[SLICE];
239 #ifdef VERBOSE_DATAARRAY_DEBUG_OUTPUT
240 printf(
"(table %p) Setting slice %d of page %d offset %d value %d (pages %d; countinlast %d; capacityinlast %d)\n",
this, (
int)SLICE, (
int)pageid, (
int)offset, (
int)v, (
int)
myPages.entries(), (
int)
countInLast(), (
int)
capacityInLast());
247 #ifdef VERBOSE_DATAARRAY_DEBUG_OUTPUT
253 bool islast = pageid ==
myPages.entries() - 1;
263 if (page.
myData.scalarValue() !=
v)
265 #ifdef VERBOSE_DATAARRAY_DEBUG_OUTPUT
266 printf(
" non-default value\n");
271 #ifdef VERBOSE_DATAARRAY_DEBUG_OUTPUT
280 #ifdef VERBOSE_DATAARRAY_DEBUG_OUTPUT
285 bool islast = pageid ==
myPages.entries() - 1;
299 #ifdef VERBOSE_DATAARRAY_DEBUG_OUTPUT
300 printf(
"(table %p) Adding to slice %d of page %d offset %d\n",
this, (
int)SLICE, (
int)pageid, (
int)offset);
308 bool islast = pageid ==
myPages.entries() - 1;
317 page.
myData.scalarValue() +=
v;
321 bool islast = pageid ==
myPages.entries() - 1;
343 #ifdef VERBOSE_DATAARRAY_DEBUG_OUTPUT
344 printf(
"(table %p) Getting page %d offset %d (slice = %d; vectorsize = %d; value[%d] = %e)\n",
this, (
int)pageid, (
int)offset, (
int)SLICE, (
int)VECTORSIZE, (
int)SLICE,
get(pageid, offset));
349 return page.
myData.value();
359 #ifdef VERBOSE_DATAARRAY_DEBUG_OUTPUT
360 printf(
"(table %p) Setting page %d offset %d (slice = %d; vectorsize = %d; v[0] = %e; previousvalue[%d] = %e)\n",
this, (
int)pageid, (
int)offset, (
int)SLICE, (
int)VECTORSIZE, ((TB*)&v)[0], (
int)SLICE,
get(pageid, offset));
368 bool islast = pageid ==
myPages.entries() - 1;
380 #ifdef VERBOSE_DATAARRAY_DEBUG_OUTPUT
381 printf(
" non-default value\n");
386 #ifdef VERBOSE_DATAARRAY_DEBUG_OUTPUT
395 #ifdef VERBOSE_DATAARRAY_DEBUG_OUTPUT
400 bool islast = pageid ==
myPages.entries() - 1;
406 #ifdef VERBOSE_DATAARRAY_DEBUG_OUTPUT
407 printf(
" newvalue[%d] = %e)\n", (
int)SLICE,
get(pageid, offset));
422 #ifdef VERBOSE_DATAARRAY_DEBUG_OUTPUT
423 printf(
"(table %p) Adding to page %d offset %d\n",
this, (
int)pageid, (
int)offset);
431 bool islast = pageid ==
myPages.entries() - 1;
444 bool islast = pageid ==
myPages.entries() - 1;
456 if (ga_IsNotZero(value))
458 for (
GA_Size i = 0; i < startdef; ++i)
463 memset(data, 0, startdef *
sizeof(
T));
465 if (startdef < capacity)
469 for (
GA_Size i = startdef; i < capacity; ++i)
474 memset(data + startdef, 0, (capacity - startdef) *
sizeof(
T));
488 bool islast = (pageid ==
myPages.entries() - 1);
492 #ifdef VERBOSE_DATAARRAY_DEBUG_OUTPUT
493 printf(
"(table %p) Hardening page %d, pages = %d, countInLast = %d\n",
this, (
int)pageid, (
int)
myPages.entries(), (
int)
countInLast());
498 #ifdef VERBOSE_DATAARRAY_DEBUG_OUTPUT
499 printf(
" beforevalue[0][%d] = %e)\n", (
int)SLICE,
get(pageid, 0));
504 #ifdef VERBOSE_DATAARRAY_DEBUG_OUTPUT
505 printf(
" aftervalue[0][%d] = %e)\n", (
int)SLICE,
get(pageid, 0));
516 #ifdef VERBOSE_DATAARRAY_DEBUG_OUTPUT
523 pageptr = oldpage->
copy(capacity);
526 if (oldcapacity < capacity)
530 for (
GA_Size i = oldcapacity; i < capacity; ++i)
535 memset(result + oldcapacity, 0, (capacity - oldcapacity) *
sizeof(
T));
594 bool islast = pageid ==
myPages.entries() - 1;
598 for (
GA_PageOff i = startoff; i < endstart; ++i)
607 bool islast = pageid ==
myPages.entries() - 1;
610 for (
GA_PageOff i = startoff; i < endstart; ++i)
617 for (
GA_PageNum pageid = startid; pageid < endid; ++pageid)
620 if (pageid != endid-1 || endoff == 0 || (pageid ==
myPages.entries() - 1 && endoff ==
countInLast()))
627 if (pageid ==
myPages.entries() - 1)
636 bool islast = pageid ==
myPages.entries() - 1;
649 bool islast = pageid ==
myPages.entries() - 1;
662 typedef ga_DataArrayPageTableImpl<UT_Vector3F,fpreal32,0,3>
673 template <
typename T>
687 result = pagetable->getVector(off);
693 template <
typename T>
707 pagetable->setVector(off,
val);
713 template <
typename T,
typename S>
731 pagetable->addVector(off,
val);
752 #endif // __GA_DATAARRAYPAGETABLEIMPL_H_INCLUDED__
SYS_FORCE_INLINE GA_PageOff countInLast() const
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
ga_DataArrayPageTableImpl< int16, int16, 0, 1 > ga_DataArrayPageTableImplI16
UT_Array< ga_DataArrayPagePtr > myPages
SYS_FORCE_INLINE GA_PageOff & countInLast()
SYS_FORCE_INLINE void addVector(GA_Offset offset, T v)
ga_DataArrayPageTableImpl< UT_Vector3F, fpreal32, 0, 3 > ga_DataArrayPageTableImplV3
ga_DataArrayPageTableImpl< int64, int64, 0, 1 > ga_DataArrayPageTableImplI64
SYS_SAFE_FORCE_INLINE bool ga_pageTableAdd< UT_Vector3F, UT_Vector3F >(GA_Private::ga_DataArrayPageTableImplV3 *pagetable, GA_Offset off, const UT_Vector3F &val)
constexpr SYS_FORCE_INLINE T & y() noexcept
auto printf(const S &fmt, const T &...args) -> int
GLsizei const GLfloat * value
constexpr SYS_FORCE_INLINE T & z() noexcept
SYS_SAFE_FORCE_INLINE bool ga_pageTableGet< UT_Vector3 >(GA_Private::ga_DataArrayPageTableImplV3 *pagetable, GA_Offset off, UT_Vector3 &result)
void setConstant(GA_Offset start_offset, GA_Offset end_offset, T value)
GLboolean GLboolean GLboolean GLboolean a
UT_Array< GA_PageOff > myCountInLast
**But if you need a result
#define SYS_SAFE_FORCE_INLINE
ga_DataArrayPageTableImpl< int32, int32, 0, 1 > ga_DataArrayPageTableImplI32
SYS_FORCE_INLINE bool GAisValid(GA_Size v)
exint GA_Size
Defines the bit width for index and offset types in GA.
SYS_FORCE_INLINE GA_PageOff GAgetPageOff(GA_Offset v)
constexpr SYS_FORCE_INLINE T & x() noexcept
SYS_FORCE_INLINE GA_PageOff & capacityInLast()
SYS_FORCE_INLINE void add(GA_PageNum pageid, GA_PageOff offset, TB v)
SYS_FORCE_INLINE T getVector(GA_Offset offset) const
void countMemory(UT_MemoryCounter &counter, bool inclusive) const
constexpr SYS_FORCE_INLINE T & z() noexcept
T * forceHardenToData(GA_PageNum pageid, GA_PageOff capacity=GA_PageOff(GA_PAGE_SIZE))
void countMemory(UT_MemoryCounter &counter, bool inclusive) const
SYS_FORCE_INLINE GA_PageNum GAgetPageNum(GA_Offset v)
SYS_FORCE_INLINE T * hardenToData(GA_PageNum pageid)
ga_DataArrayPage(GA_PageOff capacity)
SYS_FORCE_INLINE T * softenToData(GA_PageNum pageid)
ga_DataArrayPage< T > * ptr
SYS_FORCE_INLINE void addVector(GA_PageNum pageid, GA_PageOff offset, T v)
SYS_FORCE_INLINE void set(GA_PageNum pageid, GA_PageOff offset, TB v)
ga_DataArrayPage< T > * copy(GA_PageOff newcapacity=GA_PageOff(GA_PAGE_SIZE)) const
const T * castToData() const
SYS_SAFE_FORCE_INLINE bool ga_pageTableSet< UT_Vector3 >(GA_Private::ga_DataArrayPageTableImplV3 *pagetable, GA_Offset off, const UT_Vector3 &val)
int64 getMemoryUsage(bool inclusive) const
SYS_FORCE_INLINE GA_PageOff capacityInLast() const
UT_Vector3T< fpreal32 > UT_Vector3F
SYS_FORCE_INLINE T relaxedLoad() const
SYS_FORCE_INLINE void setVector(GA_Offset offset, const T &v)
ga_DataArrayPage< T > * createConstantPage(T value, GA_PageOff startdef=GA_PageOff(GA_PAGE_SIZE), GA_PageOff capacity=GA_PageOff(GA_PAGE_SIZE)) const
int64 getMemoryUsage(bool inclusive) const
Report memory usage (includes all shared memory)
union GA_Private::ga_DataArrayPageTableImpl::ga_DataArrayPagePtr::@27 myData
constexpr SYS_FORCE_INLINE T & w() noexcept
T add(T val)
Atomically adds val to myValue, returning the new value of myValue.
UT_Array< GA_PageOff > myCapacityInLast
SYS_SAFE_FORCE_INLINE bool ga_pageTableAdd< UT_Vector3F, UT_Vector3D >(GA_Private::ga_DataArrayPageTableImplV3 *pagetable, GA_Offset off, const UT_Vector3D &val)
ga_DataArrayPageTableImpl(T def)
constexpr SYS_FORCE_INLINE T & y() noexcept
SYS_FORCE_INLINE bool isShared() const
SYS_FORCE_INLINE void set(GA_Offset offset, TB v)
SYS_FORCE_INLINE T getVector(GA_PageNum pageid, GA_PageOff offset) const
SYS_FORCE_INLINE void setVector(GA_PageNum pageid, GA_PageOff offset, const T &v)
constexpr SYS_FORCE_INLINE T & x() noexcept