00001 /* 00002 * PROPRIETARY INFORMATION. This software is proprietary to 00003 * Side Effects Software Inc., and is not to be reproduced, 00004 * transmitted, or disclosed in any way without written permission. 00005 * 00006 * Produced by: 00007 * Side Effects Software Inc 00008 * 123 Front Street West, Suite 1401 00009 * Toronto, Ontario 00010 * Canada M5J 2M2 00011 * 416-504-9876 00012 * 00013 * NAME: GB_AttributeRef.h ( GB Library, C++) 00014 * 00015 * COMMENTS: 00016 */ 00017 00018 #ifndef __GB_AttributeRef__ 00019 #define __GB_AttributeRef__ 00020 00021 #include "GB_API.h" 00022 #include <UT/UT_RefArray.h> 00023 00024 00025 /// @brief This class provides a way to lookup attribute data for an element 00026 /// 00027 /// Each GB_AttributeElem stores attribute data. The GB_AttributeRef class 00028 /// stores the information needed to extract the data from the attribute 00029 /// element. 00030 /// 00031 /// This class provides an opaque interface to how the element stores the data. 00032 /// @code 00033 /// GB_AttributeRef Nref; 00034 /// UT_Vector3 *N; 00035 /// Nref = gdp.findNormalAttribute(GEO_POINT_DICT); 00036 /// if (Nref.isValid()) 00037 /// { 00038 /// FOR_ALL_GPOINTS(gdp, ppt) 00039 /// { 00040 /// N = ppt->castAttribData<UT_Vector3>(Nref); 00041 /// N->normalize(); 00042 /// } 00043 /// } 00044 /// 00045 /// @endcode 00046 /// @see GEO_Detail::findPointAttrib() 00047 class GB_API GB_AttributeRef { 00048 public: 00049 /// Default constructor 00050 GB_AttributeRef(); 00051 /// Copy constructor 00052 GB_AttributeRef(const GB_AttributeRef &); 00053 /// Destructor 00054 ~GB_AttributeRef(); 00055 00056 /// Assignment operator 00057 GB_AttributeRef &operator=(const GB_AttributeRef &src); 00058 00059 /// Comparison operator 00060 bool operator==(const GB_AttributeRef &src) const 00061 { return myHandle == src.myHandle; } 00062 /// Comparison operator 00063 bool operator!=(const GB_AttributeRef &src) const 00064 { return myHandle != src.myHandle; } 00065 00066 /// Test to see if the attribute reference refers to a valid attribute 00067 bool isValid() const { return myHandle >= 0; } 00068 00069 /// Test to see if the attribute reference refers to a valid attribute 00070 bool isInvalid() const { return myHandle < 0; } 00071 00072 /// Method to clear the handle (so that it is no longer valid) 00073 void clear() { myHandle = -1; } 00074 00075 #if !defined(HDK_RELAXED_GB) 00076 private: 00077 #endif 00078 /// Constructor which allows creation of a valid reference (private) 00079 /// 00080 /// If you get an error that the constructor is private, that means 00081 /// that you are trying to assign an integer value to the offset. If you 00082 /// need an invalid offset (i.e. -1), this is set in the default 00083 /// constructor. 00084 /// 00085 /// @warning If you are an HDK user, you might want to define 00086 /// HDK_RELAXED_GB 00087 /// When compiling your code. Be cautioned, however, that you will need to 00088 /// change your code sooner or later. 00089 #if defined(HDK_RELAXED_GB) 00090 GB_AttributeRef(int offset); 00091 #else 00092 explicit GB_AttributeRef(int offset); 00093 #endif 00094 00095 #if defined(HDK_RELAXED_GB) 00096 operator int() const { return myHandle; } 00097 operator int&() { return myHandle; } 00098 private: 00099 #endif 00100 00101 friend class GB_AttributeData; 00102 friend class GB_AttributeElem; 00103 friend class GB_AttributeDict; 00104 friend class GB_AttributeDictOffsetIterator; 00105 friend class GB_ConstAttributeDictOffsetIterator; 00106 friend class GB_AttributeTable; 00107 00108 friend class GEO_AttribDict; 00109 friend class GEO_AttributeHandleList; 00110 friend class GEO_PointAttribDict; 00111 friend class GEO_PrimAttribDict; 00112 friend class GEO_VertexAttribDict; 00113 00114 // For float offsets 00115 friend class GU_CurveCache; 00116 friend class GU_PrimTriBezierCache; 00117 friend class GU_TPSurfCache; 00118 friend class POP_AttribMap; 00119 00120 int myHandle; 00121 }; 00122 00123 /// @{ 00124 /// In previous versions of the HDK, the GB_AttributeRef was represented by an 00125 /// integer. Thus, the methods @c isValid() and @c isInvalid() were not 00126 /// available. If you need to compile code for earlier baselines with minimal 00127 /// changes, you can use these functions to perform validity checks seamlessly. 00128 static inline bool GBisAttributeRefValid(const GB_AttributeRef &a) 00129 { return a.isValid(); } 00130 00131 static inline bool GBisAttributeRefInvalid(const GB_AttributeRef &a) 00132 { return a.isInvalid(); } 00133 00134 static inline GB_AttributeRef GBmakeInvalidAttributeRef() 00135 { return GB_AttributeRef(); } 00136 00137 static inline void GBclearAttributeRef(GB_AttributeRef &a) { a.clear(); } 00138 00139 /// @} 00140 00141 // Explicitly instantiate templated classes using GB_AttributeRef so that 00142 // the generated template code will only be created once in libGB. 00143 #ifndef EXPORT_GB 00144 extern template class GB_API UT_RefArray<GB_AttributeRef>; 00145 #endif 00146 00147 #endif
1.5.9