HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GA_PrimitiveTypeMask.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_PrimitiveTypeMask.h (GA Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GA_PrimitiveTypeMask_h__
12 #define __GA_PrimitiveTypeMask_h__
13 
14 #include "GA_API.h"
15 
16 #include "GA_PrimitiveTypeId.h"
17 
18 #include <SYS/SYS_Types.h>
19 #include <iterator>
20 
21 class UT_BitArray;
23 
25 {
26 public:
28  {
29  explicit FamilyBitMask(unsigned m) : myMask(m) {}
30  unsigned getMask() const { return myMask; }
31  private:
32  unsigned myMask;
33  };
34 
36  {
37  explicit FactoryTypeBitMask(unsigned m) : myMask(m) {}
38  unsigned getMask() const { return myMask; }
39  private:
40  unsigned myMask;
41  };
42 
44  : myBaseMask(0), myExtendedMask(NULL)
45  {
46  }
48  const FamilyBitMask &mask)
49  : myBaseMask(0), myExtendedMask(NULL)
50  {
51  init(factory, mask);
52  }
54  : myBaseMask(mask.getMask()), myExtendedMask(NULL)
55  {
56  }
57 
60 
62 
65 
66  bool includes(GA_PrimitiveTypeId type_id) const;
67  bool excludes(GA_PrimitiveTypeId type_id) const
68  { return !includes(type_id); }
69 
70  void add(GA_PrimitiveTypeId type_id);
71  void remove(GA_PrimitiveTypeId type_id);
72 
73  void operator|=(const GA_PrimitiveTypeMask &m);
74  void operator&=(const GA_PrimitiveTypeMask &m);
75  void operator-=(const GA_PrimitiveTypeMask &m);
76  bool operator==(const GA_PrimitiveTypeMask &m);
77  bool operator!=(const GA_PrimitiveTypeMask &m);
78 
80  {
81  public:
82  using iterator_category = std::forward_iterator_tag;
84  using difference_type = std::ptrdiff_t;
85  using pointer = value_type*;
87 
88  const GA_PrimitiveTypeId &operator*() const { return myId; }
89 
90  bool operator==(const const_iterator &other) const
91  { return myId == other.myId; }
92  bool operator!=(const const_iterator &other) const
93  { return myId != other.myId; }
94 
96  {
97  myId = myMask.getNextType(myId);
98  return *this;
99  }
100 
101  // Delete the post-increment operator.
102  const_iterator &operator++(int) = delete;
103 
104  protected:
105  friend class GA_PrimitiveTypeMask;
107  const GA_PrimitiveTypeId &id) : myMask(mask), myId(id) {}
108  private:
109  const GA_PrimitiveTypeMask &myMask;
110  GA_PrimitiveTypeId myId;
111  };
112 
113  /// Returns an iterator representing the beginning of the range for the
114  /// type ids contained with this mask.
116  { return const_iterator(*this, getFirstType()); }
117 
118  /// Returns an iterator representing the end of the range for the
119  /// type ids contained with this mask.
121  { return const_iterator(*this, GA_PrimitiveTypeId()); }
122 
123  SYS_SAFE_BOOL operator bool() const;
124 
125 private:
127 
128  /// Initialize primitive mask using a family mask.
129  void init(const GA_PrimitiveFactory &factory,
130  const FamilyBitMask &mask);
131 
132  GA_PrimitiveTypeId getFirstType() const;
133  GA_PrimitiveTypeId getNextType(GA_PrimitiveTypeId c) const;
134 
135  friend const GA_PrimitiveTypeMask operator|
136  (const GA_PrimitiveTypeMask &m1, const GA_PrimitiveTypeMask &m2);
137  friend const GA_PrimitiveTypeMask operator&
138  (const GA_PrimitiveTypeMask &m1, const GA_PrimitiveTypeMask &m2);
139 #if 0
140  friend const GA_PrimitiveTypeMask operator~
141  (const GA_PrimitiveTypeMask &m1);
142 #endif
143 
144  uint64 myBaseMask;
145  UT_BitArray *myExtendedMask;
146 };
147 
148 // Binary Operations on GA_TypeMask
149 inline const GA_PrimitiveTypeMask
151 {
152  GA_PrimitiveTypeMask m(m1);
153  m |= m2;
154  return m;
155 }
156 inline const GA_PrimitiveTypeMask
158 {
159  GA_PrimitiveTypeMask m(m1);
160  m &= m2;
161  return m;
162 }
163 
164 // TODO: Cannot invert without a GA_PrimitiveFactory reference...
165 #if 0
166 inline const GA_PrimitiveTypeMask
168 {
169  GA_PrimitiveTypeMask m(m1);
170  m.invert();
171  return m;
172 }
173 #endif
174 
175 #endif
const GA_PrimitiveTypeId & operator*() const
const_iterator begin() const
GA_PrimitiveTypeMask(const GA_PrimitiveFactory &factory, const FamilyBitMask &mask)
const TypeMask operator~(const TypeMask &m1)
Definition: GA_PrimCompat.h:95
const_iterator(const GA_PrimitiveTypeMask &mask, const GA_PrimitiveTypeId &id)
const GA_PrimitiveTypeMask operator&(const GA_PrimitiveTypeMask &m1, const GA_PrimitiveTypeMask &m2)
bool operator==(const const_iterator &other) const
#define GA_API
Definition: GA_API.h:14
bool operator!=(const const_iterator &other) const
unsigned long long uint64
Definition: SYS_Types.h:117
std::enable_if< UT_EnableBitMask< T >::enable, T & >::type operator&=(T &lhs, T rhs)
Definition: UT_EnumHelper.h:57
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
#define SYS_SAFE_BOOL
Definition: SYS_Compiler.h:55
std::forward_iterator_tag iterator_category
GLint GLuint mask
Definition: glcorearb.h:124
const_iterator end() const
OIIO_FORCEINLINE const vint4 & operator-=(vint4 &a, const vint4 &b)
Definition: simd.h:4392
GA_PrimitiveTypeMask(const FactoryTypeBitMask &mask)
ImageBuf OIIO_API add(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
bool operator!=(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:165
#define const
Definition: zconf.h:214
const GA_PrimitiveTypeMask operator|(const GA_PrimitiveTypeMask &m1, const GA_PrimitiveTypeMask &m2)
std::enable_if< UT_EnableBitMask< T >::enable, T & >::type operator|=(T &lhs, T rhs)
Definition: UT_EnumHelper.h:37