HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GA_BreakpointGroup.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_BreakpointGroup.h (GA Library, C++)
7  *
8  * COMMENTS: GA_BreakpointGroup is a group container for GA_Breakpoint
9  * entities.
10  */
11 
12 #pragma once
13 
14 #ifndef __GA_BreakpointGroup_h__
15 #define __GA_BreakpointGroup_h__
16 
17 #include "GA_API.h"
18 #include <UT/UT_LinkList.h>
19 
20 #include "GA_Breakpoint.h"
21 #include "GA_Group.h"
22 
23 #include <iterator>
24 
25 class GA_Detail;
26 class GA_Primitive;
27 class UT_MemoryCounter;
28 
30 {
31 public:
32  GA_BreakpointGroup(const GA_Detail &gdp,
33  const char *name="");
34  ~GA_BreakpointGroup() override;
35 
36  /// Return the owning detail
37  const GA_Detail &getDetail() const override { return myDetail; }
38 
39  /// Report memory usage
40  int64 getMemoryUsage(bool inclusive) const override;
41 
42  /// Count memory usage using a UT_MemoryCounter in order to count
43  /// shared memory correctly.
44  /// If inclusive is true, the size of this object is counted,
45  /// else only memory owned by this object is counted.
46  /// If this is pointed to by the calling object, inclusive should be true.
47  /// If this is contained in the calling object, inclusive should be false.
48  /// (Its memory was already counted in the size of the calling object.)
49  void countMemory(UT_MemoryCounter &counter, bool inclusive) const override;
50 
51  class GA_API Entry : public UT_LinkNode
52  {
53  public:
54  explicit Entry(const GA_Breakpoint &b)
55  : myBkpt(b) {}
56 
58  };
59 
60  Entry *find(const GA_Breakpoint &it) const;
61  bool contains(const GA_Breakpoint &it) const;
62 
63 
64  // Adds return 1 if successful and 0 otherwise
65  bool add(const GA_Breakpoint &it);
66 
67  bool toggle(const GA_Breakpoint &it);
68 
69  bool removeEntry(Entry *it);
70  bool remove(const GA_Breakpoint &it);
71 
72  UT_LinkList &list() { return myBreakpointList; }
73  const UT_LinkList &list() const { return myBreakpointList; }
74 
75  /// Query the number of breakpoints from primary primitives in the group.
76  GA_Size entries() const override
77  { return myBreakpointList.length() - myNumSecondary; }
78  /// Query whether the group does not contain any breakpoints from primary
79  /// primitives.
80  bool isEmpty() const
81  { return myBreakpointList.length() <= myNumSecondary; }
82 
83  /// Query the total number of breakpoints (from both primary and secondary
84  /// primitives) in the group.
85  GA_Size entriesMix() const {return myBreakpointList.length();}
86  /// Query whether the group does not contain any breakpoints.
87  virtual bool isEmptyMix() const { return myBreakpointList.isEmpty(); }
88 
89  /// Query if we contain any breakpoints from secondary primitives.
90  bool isMixed() const override { return myNumSecondary > 0; }
91 
92  bool isOrdered() const override { return false; }
93 
94  void clear() override;
95  void addAll() override;
96 
97  /// Save data to a JSON stream.
98  /// @section JSON-GA_BreakpointGroup JSON Schema: GA_BreakpointGroup
99  /// @code
100  /// {
101  /// "name" : "GA_BreakpointGroup",
102  /// "description" : "A list of breakpoints",
103  /// "type" : "orderedmap",
104  /// "properties": {
105  /// "breakpoints": {
106  /// "type" : "array",
107  /// "items" : { "$ref", "GA_Breakpoint" },
108  /// "description" : "Array of breakpoints in the group",
109  /// }
110  /// },
111  /// }
112  /// @endcode
113  /// @see @ref JSON_FileFormat, GA_Group
114  bool jsonSaveData(UT_JSONWriter &w,
115  const GA_SaveMap &map) const override;
116 
117  /// Load breakpoint group from a JSON stream.
118  bool jsonLoadData(UT_JSONParser &w,
119  const GA_LoadMap &map) override;
120 
121  /// Iterator to iterate over all breakpoints in the group. It is safe to
122  /// call advance() after deleting the current entry.
123 
124  GA_BreakpointGroup &operator|=(const GA_BreakpointGroup &input_group);
125  GA_BreakpointGroup &operator&=(const GA_BreakpointGroup &input_group);
126  GA_BreakpointGroup &operator-=(const GA_BreakpointGroup &input_group);
127  GA_BreakpointGroup &operator+=(const GA_BreakpointGroup &input_group);
128  GA_BreakpointGroup &operator^=(const GA_BreakpointGroup &input_group);
129  GA_BreakpointGroup &operator =(const GA_BreakpointGroup &input_group);
130 
131 protected:
132  template<typename T>
134  {
135  public:
136  using iterator_category = std::input_iterator_tag;
137  using value_type = T;
138  using difference_type = std::ptrdiff_t;
139  using pointer = T*;
140  using reference = T&;
141 
142  /// Default constructor
144  myGroup(NULL),
145  myCurr(NULL),
146  myNext(NULL)
147  {
148  }
149  /// Copy constructor. Use a separate template type to allow copying
150  /// from a const_iterator to non-const iterator.
151  template<typename ET>
153  {
154  myGroup = src.myGroup;
155  myCurr = src.myCurr;
156  myNext = src.myNext;
157  }
158  bool operator==(const base_iterator &cmp) const
159  { return myCurr == cmp.myCurr; }
160 
161  bool operator!=(const base_iterator &cmp) const
162  { return myCurr != cmp.myCurr; }
163 
164  /// ++iterator
165  base_iterator &operator++() { advance(); return *this; }
166  // No post inc as it is harmful.
167 
168  bool atEnd() const { return !myCurr; }
169  void advance()
170  {
171  myCurr = myNext;
172  if (myNext)
173  myNext = static_cast<Entry *>(myNext->next());
174  }
175  void rewind()
176  {
177  myNext = static_cast<Entry *>(
178  myGroup->myBreakpointList.head());
179  advance();
180  }
181 
182  reference operator*() const { return myCurr->myBkpt; }
183  reference getBreakpoint() const { return myCurr->myBkpt; }
184  Entry *getEntry() { return myCurr; }
185  private:
186  base_iterator(const GA_BreakpointGroup *group)
187  : myGroup(group),
188  myCurr(static_cast<Entry *>(group->myBreakpointList.head()))
189  {
190  myNext = myCurr ? static_cast<Entry *>(myCurr->next()) : 0;
191  }
192  const GA_BreakpointGroup *myGroup;
193  Entry *myCurr, *myNext;
194 
195  friend class GA_BreakpointGroup;
196  };
197 public:
200 
201  iterator begin() { return iterator(this); }
202  iterator end() { return iterator(); }
203  const_iterator begin() const { return const_iterator(this); }
204  const_iterator end() const { return const_iterator(); }
205 
206 private:
207  bool addEntry(Entry *it);
208 
209  const GA_Detail &myDetail;
210  UT_LinkList myBreakpointList;
211  unsigned myNumSecondary; // number of secondary
212  // breakpoints
213 };
214 
215 
216 #endif
virtual int64 getMemoryUsage(bool inclusive) const =0
UT_LinkList & list()
bool isOrdered() const override
Used to pass options and map offset values during saving.
Definition: GA_SaveMap.h:48
GA_Size entriesMix() const
UT_StringArray JOINTS head
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:87
#define GA_API
Definition: GA_API.h:14
base_iterator< GA_Breakpoint > iterator
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:37
base_iterator< const GA_Breakpoint > const_iterator
GA_Breakpoint myBkpt
std::enable_if< UT_EnableBitMask< T >::enable, T & >::type operator&=(T &lhs, T rhs)
Definition: UT_EnumHelper.h:57
base_iterator()
Default constructor.
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:235
virtual void countMemory(UT_MemoryCounter &counter, bool inclusive) const =0
IMATH_HOSTDEVICE constexpr int cmp(T a, T b) IMATH_NOEXCEPT
Definition: ImathFun.h:84
auto base_iterator(std::back_insert_iterator< Container > &it, checked_ptr< typename Container::value_type >) -> std::back_insert_iterator< Container >
Definition: format.h:394
virtual bool isEmptyMix() const
Query whether the group does not contain any breakpoints.
OIIO_FORCEINLINE const vint4 & operator+=(vint4 &a, const vint4 &b)
Definition: simd.h:4369
std::input_iterator_tag iterator_category
const_iterator end() const
const_iterator begin() const
long long int64
Definition: SYS_Types.h:116
const UT_LinkList & list() const
Options during loading.
Definition: GA_LoadMap.h:42
GA_Size entries() const override
Query the number of breakpoints from primary primitives in the group.
GLuint const GLchar * name
Definition: glcorearb.h:786
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
Entry(const GA_Breakpoint &b)
base_iterator & operator++()
++iterator
base_iterator(const base_iterator< ET > &src)
std::enable_if< UT_EnableBitMask< T >::enable, T & >::type operator^=(T &lhs, T rhs)
Definition: UT_EnumHelper.h:76
OIIO_FORCEINLINE const vint4 & operator-=(vint4 &a, const vint4 &b)
Definition: simd.h:4392
bool operator!=(const base_iterator &cmp) const
Container class for all geometry.
Definition: GA_Detail.h:96
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
ImageBuf OIIO_API add(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
bool isMixed() const override
Query if we contain any breakpoints from secondary primitives.
bool OIIO_UTIL_API contains(string_view a, string_view b)
Does 'a' contain the string 'b' within it?
bool operator==(const base_iterator &cmp) const
const GA_Detail & getDetail() const override
Return the owning detail.
std::enable_if< UT_EnableBitMask< T >::enable, T & >::type operator|=(T &lhs, T rhs)
Definition: UT_EnumHelper.h:37
FMT_CONSTEXPR auto find(Ptr first, Ptr last, T value, Ptr &out) -> bool
Definition: core.h:2089
GLenum src
Definition: glcorearb.h:1793