00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __GB_AttributeDict_h__
00021 #define __GB_AttributeDict_h__
00022
00023 #include "GB_API.h"
00024 #include <UT/UT_LinkList.h>
00025
00026 #include "GB_AttributeRef.h"
00027 #include "GB_AttributeDefines.h"
00028
00029 class UT_IStream;
00030 class GB_Attribute;
00031 class GB_AttributeData;
00032 class GB_AttributeElem;
00033 class GB_FloatOffsets;
00034 class GB_VectorOffsets;
00035
00036
00037
00038
00039
00040 class GB_API GB_AttributeDict : public UT_LinkList
00041 {
00042 public:
00043
00044 GB_AttributeDict() : UT_LinkList() { myUsedSize = myAllocSize = 0; }
00045 ~GB_AttributeDict();
00046
00047 GB_Attribute *find(const char *name, int s, GB_AttribType t) const;
00048
00049
00050 GB_Attribute *find(const char *name, GB_AttribType t) const;
00051
00052
00053 GB_Attribute *find(const char *name) const;
00054
00055
00056 GB_Attribute *findClone(const GB_Attribute *src) const;
00057
00058
00059 GB_Attribute *findByOffset(const GB_AttributeRef &offset) const;
00060
00061 GB_Attribute *getHead(void) const {return (GB_Attribute*)head();}
00062 int getSize(void) const { return myUsedSize; }
00063 int getAlloc(void) const { return myAllocSize; }
00064 GB_AttributeRef getOffset(const char *name, int size,
00065 GB_AttribType type) const;
00066
00067
00068 GB_AttributeRef getOffset(const char *name, GB_AttribType type) const;
00069
00070
00071 GB_AttributeRef getOffset(const GB_Attribute *src) const;
00072
00073 GB_Attribute *grow(const char* name, int oldsize,
00074 unsigned int addedsize, GB_AttribType type,
00075 GB_AttributeRef &offset);
00076
00077 GB_Attribute *shrink( const char* name, int oldsize,
00078 unsigned int removedsize, GB_AttribType type,
00079 GB_AttributeRef &offset );
00080
00081 void clearAndDestroy()
00082 {
00083 clear();
00084 myUsedSize = myAllocSize = 0;
00085 }
00086
00087
00088
00089 void useDefaults(GB_AttributeData &d, int alloc=1) const;
00090
00091
00092
00093
00094 int getFloatOffsets(GB_FloatOffsets &offsets) const;
00095
00096 int getVectorOffsets(GB_VectorOffsets &offsets) const;
00097
00098
00099
00100 int getPersistentCount(void) const;
00101
00102
00103
00104
00105
00106 virtual void sortAs(const GB_AttributeDict &) = 0;
00107
00108
00109
00110 virtual int isEqual(const GB_AttributeDict &table) const;
00111
00112
00113
00114
00115
00116
00117
00118 int save(ostream &os, const GB_AttributeElem &obj, int binary,
00119 char attribDelim='(') const;
00120 bool load(UT_IStream &is, GB_AttributeElem &obj);
00121
00122
00123
00124
00125 int save(ostream &os, const char *label) const;
00126 GB_Attribute *load(UT_IStream &is, int tblSize);
00127
00128
00129
00130 class GB_API AttribXlate {
00131 public:
00132 GB_AttributeRef srcOff;
00133 int size;
00134 int idxType;
00135 int idxOffset;
00136 GB_Attribute *atr;
00137 AttribXlate *next;
00138 };
00139 void translateData(const AttribXlate *table,
00140 void *input,
00141 void *tmp) const;
00142
00143 protected:
00144
00145
00146
00147
00148 GB_Attribute *append(const char *n, int s,
00149 GB_AttribType type, GB_AttribTypeInfo type_info,
00150 const void *defValue, GB_AttributeRef *offset);
00151 GB_Attribute *insertBefore(const char *n, int s, GB_AttribType type,
00152 GB_AttribTypeInfo type_info,
00153 const void *defValue, int dup_check,
00154 GB_Attribute *before, GB_AttributeRef *offset);
00155
00156
00157
00158
00159 GB_Attribute *destroy(const char *name, int size,
00160 GB_AttribType type, int *offset);
00161
00162
00163
00164 GB_Attribute *destroy(const char *name,
00165 GB_AttribType type, int *offset);
00166
00167
00168 void setAlloc(int a) { myAllocSize = a; }
00169
00170
00171
00172
00173 AttribXlate *preSort(const GB_AttributeDict &table, int *totSize);
00174
00175 private:
00176
00177
00178
00179 GB_Attribute *headFloatOffset(int &o) const;
00180 GB_Attribute *nextFloatOffset(int &o, const GB_Attribute *a) const;
00181
00182
00183
00184
00185 bool load(UT_IStream &is, GB_AttributeData &data);
00186 int save(ostream &os, const GB_AttributeData &data, int binary,
00187 char attribDelim='(') const;
00188
00189
00190
00191 int saveData(ostream &os, const void *d, int size, int type,
00192 int binary, char leadChar = ' ') const;
00193 int loadData(UT_IStream &is, void *d, int size, int type);
00194
00195
00196 int myUsedSize;
00197 int myAllocSize;
00198
00199 friend class GB_AttributeTable;
00200 };
00201
00202 #endif