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 
129  GA_BreakpointGroup &operator =(const GA_BreakpointGroup &inputGroup);
130 
131 protected:
132  template<typename T>
134  public std::iterator<std::input_iterator_tag, T>
135  {
136  public:
137  typedef T &reference;
138 
139  /// Default constructor
141  myGroup(NULL),
142  myCurr(NULL),
143  myNext(NULL)
144  {
145  }
146  /// Copy constructor. Use a separate template type to allow copying
147  /// from a const_iterator to non-const iterator.
148  template<typename ET>
150  {
151  myGroup = src.myGroup;
152  myCurr = src.myCurr;
153  myNext = src.myNext;
154  }
155  bool operator==(const base_iterator &cmp) const
156  { return myCurr == cmp.myCurr; }
157 
158  bool operator!=(const base_iterator &cmp) const
159  { return myCurr != cmp.myCurr; }
160 
161  /// ++iterator
162  base_iterator &operator++() { advance(); return *this; }
163  // No post inc as it is harmful.
164 
165  bool atEnd() const { return !myCurr; }
166  void advance()
167  {
168  myCurr = myNext;
169  if (myNext)
170  myNext = static_cast<Entry *>(myNext->next());
171  }
172  void rewind()
173  {
174  myNext = static_cast<Entry *>(
175  myGroup->myBreakpointList.head());
176  advance();
177  }
178 
179  reference operator*() const { return myCurr->myBkpt; }
180  reference getBreakpoint() const { return myCurr->myBkpt; }
181  Entry *getEntry() { return myCurr; }
182  private:
184  : myGroup(group),
185  myCurr(static_cast<Entry *>(group->myBreakpointList.head()))
186  {
187  myNext = myCurr ? static_cast<Entry *>(myCurr->next()) : 0;
188  }
189  const GA_BreakpointGroup *myGroup;
190  Entry *myCurr, *myNext;
191 
192  friend class GA_BreakpointGroup;
193  };
194 public:
197 
198  iterator begin() { return iterator(this); }
199  iterator end() { return iterator(); }
200  const_iterator begin() const { return const_iterator(this); }
201  const_iterator end() const { return const_iterator(); }
202 
203 private:
204  bool addEntry(Entry *it);
205 
206  const GA_Detail &myDetail;
207  UT_LinkList myBreakpointList;
208  unsigned myNumSecondary; // number of secondary
209  // breakpoints
210 };
211 
212 
213 #endif
virtual int64 getMemoryUsage(bool inclusive) const =0
UT_LinkList & list()
bool isOrdered() const override
GLenum src
Definition: glew.h:2410
GLuint const GLchar * name
Definition: glew.h:1814
Used to pass options and map offset values during saving.
Definition: GA_SaveMap.h:48
GA_Size entriesMix() const
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:76
#define GA_API
Definition: GA_API.h:12
base_iterator< GA_Breakpoint > iterator
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:34
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:233
virtual void countMemory(UT_MemoryCounter &counter, bool inclusive) const =0
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:4246
GLubyte GLubyte GLubyte GLubyte w
Definition: glew.h:1890
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.
Entry(const GA_Breakpoint &b)
base_iterator & operator++()
++iterator
int cmp(T a, T b)
Definition: ImathFun.h:119
bool OIIO_API contains(string_view a, string_view b)
Does 'a' contain the string 'b' within it?
GLdouble GLdouble GLdouble b
Definition: glew.h:9122
GLuint counter
Definition: glew.h:2740
base_iterator(const base_iterator< ET > &src)
FMT_CONSTEXPR bool find(Ptr first, Ptr last, T value, Ptr &out)
Definition: format.h:2104
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:4269
bool operator!=(const base_iterator &cmp) const
Container class for all geometry.
Definition: GA_Detail.h:95
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 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
GLboolean GLuint group
Definition: glew.h:2745