HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GA_PrimitiveP.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: GA_PrimitiveP.h (GA Library, C++)
7  *
8  * COMMENTS: Wrapper for GA_Primitive to emulate a pointer,
9  * avoiding hardening the primitive list in a few cases.
10  */
11 
12 #pragma once
13 
14 #include "GA_Detail.h"
15 #include "GA_PrimCompat.h"
16 #include "GA_Primitive.h"
17 #include "GA_Types.h"
18 #include <UT/UT_Assert.h>
19 #include <SYS/SYS_Compiler.h>
20 #include <SYS/SYS_Inline.h>
21 #include <type_traits>
22 
23 template<typename PrimT,typename DetailT>
25 {
26 public:
29  : myDetail(nullptr)
30  , myOffset(GA_INVALID_OFFSET)
31  {
34  }
37  : myDetail(detail)
38  , myOffset(offset)
39  {
40  }
41  template<typename OtherPrimT,typename OtherDetailT>
44  : myDetail(that.myDetail)
45  , myOffset(that.myOffset)
46  {
47  // Can't assign (GA_Primitive*) = (const GA_Primitive*)
48  // All 3 other combinations are fine.
51  }
53  GA_PrimitiveP_T(PrimT *that)
54  : myDetail(that ? (DetailT*)&that->getDetail() : nullptr)
55  , myOffset(that ? that->getMapOffset() : GA_INVALID_OFFSET)
56  {}
57  template<typename OtherPrimT,typename OtherDetailT>
60  {
61  // Can't assign (GA_Primitive*) = (const GA_Primitive*)
62  // All 3 other combinations are fine.
65  myDetail = that.myDetail;
66  myOffset = that.myOffset;
67  }
69  GA_PrimitiveP_T &operator=(PrimT *that)
70  {
71  if (that == nullptr)
72  {
73  myDetail = nullptr;
74  myOffset = GA_INVALID_OFFSET;
75  }
76  else
77  {
78  myDetail = (DetailT*)&that->getDetail();
79  myOffset = that->getMapOffset();
80  }
81  return *this;
82  }
83  template<typename OtherPrimT,typename OtherDetailT>
86  {
87  return myDetail == that.myDetail && myOffset == that.myOffset;
88  }
89  template<typename OtherPrimT,typename OtherDetailT>
92  {
93  return !((*this) == that);
94  }
96  bool operator==(const PrimT *that) const
97  {
98  if (that == nullptr)
99  return !(*this);
100  return myDetail == &that->getDetail() && myOffset == that->getMapOffset();
101  }
103  bool operator!=(const PrimT *that) const
104  {
105  return !((*this) == that);
106  }
108  SYS_SAFE_BOOL operator bool() const
109  {
110  return myDetail && GAisValid(myOffset);
111  }
113  bool operator!() const
114  {
115  return !myDetail || !GAisValid(myOffset);
116  }
118  PrimT &operator*() const
119  {
120  UT_ASSERT_P(myDetail && GAisValid(myOffset));
121  return *(PrimT *)myDetail->getPrimitive(myOffset);
122  }
124  PrimT *operator->() const
125  {
126  UT_ASSERT_P(myDetail && GAisValid(myOffset));
127  return (PrimT *)myDetail->getPrimitive(myOffset);
128  }
130  operator PrimT*() const
131  {
132  if (!myDetail || !GAisValid(myOffset))
133  return nullptr;
134  return (PrimT *)myDetail->getPrimitive(myOffset);
135  }
136  template <typename OtherPrimT>
138  OtherPrimT castPtr() const
139  {
140  if (!myDetail || !GAisValid(myOffset))
141  return nullptr;
142  return UTverify_cast<OtherPrimT>(myDetail->getPrimitive(myOffset));
143  }
145  DetailT *detail() const
146  {
147  return myDetail;
148  }
150  DetailT &detailRef() const
151  {
152  UT_ASSERT_P(myDetail);
153  return *myDetail;
154  }
157  {
158  return myOffset;
159  }
160  void set(DetailT *detail, GA_Offset offset)
161  {
162  myDetail = detail;
163  myOffset = offset;
164  }
166  int getTypeId() const
167  {
168  return myDetail->getPrimitiveTypeId(myOffset);
169  }
172  {
174  }
176  bool isClosed() const
177  {
178  return myDetail->getPrimitiveClosedFlag(myOffset);
179  }
180 
181 private:
182  DetailT *myDetail;
183  GA_Offset myOffset;
184 };
185 
SYS_FORCE_INLINE GA_PrimitiveP_T & operator=(PrimT *that)
Definition: GA_PrimitiveP.h:69
SYS_FORCE_INLINE GA_PrimitiveP_T(PrimT *that)
Definition: GA_PrimitiveP.h:53
SYS_FORCE_INLINE bool operator!=(const PrimT *that) const
UT_ASSERT_COMPILETIME(BRAY_EVENT_MAXFLAGS<=32)
SYS_FORCE_INLINE GA_PrimitiveP_T()
Definition: GA_PrimitiveP.h:28
SYS_FORCE_INLINE PrimT * operator->() const
GLsizei const GLfloat * value
Definition: glcorearb.h:824
bool GAisValid(GA_Size v)
Definition: GA_Types.h:649
void set(DetailT *detail, GA_Offset offset)
SYS_FORCE_INLINE GA_PrimCompat::TypeMask getPrimitiveId() const
SYS_FORCE_INLINE TO_T UTverify_cast(FROM_T from)
Definition: UT_Assert.h:229
SYS_FORCE_INLINE bool operator==(const GA_PrimitiveP_T< OtherPrimT, OtherDetailT > &that) const
Definition: GA_PrimitiveP.h:85
SYS_FORCE_INLINE bool operator!() const
#define GA_INVALID_OFFSET
Definition: GA_Types.h:678
SYS_FORCE_INLINE bool operator==(const PrimT *that) const
Definition: GA_PrimitiveP.h:96
SYS_FORCE_INLINE DetailT & detailRef() const
GA_Size GA_Offset
Definition: GA_Types.h:641
GLintptr offset
Definition: glcorearb.h:665
SYS_FORCE_INLINE OtherPrimT castPtr() const
SYS_FORCE_INLINE bool operator!=(const GA_PrimitiveP_T< OtherPrimT, OtherDetailT > &that) const
Definition: GA_PrimitiveP.h:91
#define SYS_SAFE_BOOL
Definition: SYS_Compiler.h:55
#define UT_ASSERT_P(ZZ)
Definition: UT_Assert.h:155
SYS_FORCE_INLINE GA_PrimitiveP_T(const GA_PrimitiveP_T< OtherPrimT, OtherDetailT > &that)
Definition: GA_PrimitiveP.h:43
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
SYS_FORCE_INLINE GA_PrimitiveP_T & operator=(const GA_PrimitiveP_T< OtherPrimT, OtherDetailT > &that)
Definition: GA_PrimitiveP.h:59
SYS_FORCE_INLINE DetailT * detail() const
SYS_FORCE_INLINE GA_Offset offset() const
SYS_FORCE_INLINE PrimT & operator*() const
SYS_FORCE_INLINE bool isClosed() const
SYS_FORCE_INLINE int getTypeId() const
static SYS_FORCE_INLINE GA_PrimCompat::TypeMask primCompatMaskFromTypeId(int type_id)
Definition: GA_Primitive.h:818
SYS_FORCE_INLINE GA_PrimitiveP_T(DetailT *detail, GA_Offset offset)
Definition: GA_PrimitiveP.h:36