00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __GU_AttribCache_H__
00024 #define __GU_AttribCache_H__
00025
00026 #include "GU_API.h"
00027 #include <UT/UT_Assert.h>
00028 #include <UT/UT_RefArray.h>
00029 #include <GB/GB_Attribute.h>
00030
00031 class GU_API GU_AttribCache
00032 {
00033 public:
00034 explicit GU_AttribCache(unsigned int sz = 0)
00035 : myRefArray(sz)
00036 {
00037 myRefArray.entries(sz);
00038 myEntries = 0;
00039 }
00040
00041 ~GU_AttribCache()
00042 {
00043 UT_ASSERT(myRefArray.capacity() == myRefArray.entries());
00044 }
00045 void resize(unsigned int sz, unsigned short copyFlag=1)
00046 {
00047 myRefArray.resize(sz, copyFlag);
00048 myRefArray.entries(sz);
00049 if (sz < myEntries)
00050 myEntries = sz;
00051 }
00052
00053 unsigned int capacity(void) const
00054 { return myRefArray.capacity(); }
00055 unsigned int entries(void) const { return myEntries; }
00056
00057 bool isEmpty(void) const { return myEntries == 0; }
00058
00059 void entries(unsigned int ne)
00060 {
00061 UT_ASSERT(ne <= myRefArray.entries());
00062 myEntries = ne;
00063 }
00064
00065 GB_AttributeData &operator()(unsigned i)
00066 { return myRefArray(i); }
00067 const GB_AttributeData &operator()(unsigned i) const
00068 { return myRefArray(i); }
00069 private:
00070 UT_RefArray<GB_AttributeData> myRefArray;
00071 unsigned int myEntries;
00072 };
00073
00074 #endif