HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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  virtual ~GA_BreakpointGroup();
35 
36  /// Return the owning detail
37  virtual const GA_Detail &getDetail() const { return myDetail; }
38 
39  /// Report memory usage
40  virtual int64 getMemoryUsage(bool inclusive) const;
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  virtual void countMemory(UT_MemoryCounter &counter, bool inclusive) const;
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  virtual GA_Size entries() const
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  /// Query the total number of breakpoints (from both primary and secondary
83  /// primitives) in the group.
84  GA_Size entriesMix() const {return myBreakpointList.length();}
85  /// Query whether the group does not contain any breakpoints.
86  virtual bool isEmptyMix() const { return myBreakpointList.isEmpty(); }
87 
88  /// Query if we contain any breakpoints from secondary primitives.
89  virtual bool isMixed() const { return myNumSecondary > 0; }
90 
91  virtual bool isOrdered() const { return false; }
92 
93  virtual void clear();
94  virtual void addAll();
95 
96  /// Save data to a JSON stream.
97  /// @section JSON-GA_BreakpointGroup JSON Schema: GA_BreakpointGroup
98  /// @code
99  /// {
100  /// "name" : "GA_BreakpointGroup",
101  /// "description" : "A list of breakpoints",
102  /// "type" : "orderedmap",
103  /// "properties": {
104  /// "breakpoints": {
105  /// "type" : "array",
106  /// "items" : { "$ref", "GA_Breakpoint" },
107  /// "description" : "Array of breakpoints in the group",
108  /// }
109  /// },
110  /// }
111  /// @endcode
112  /// @see @ref JSON_FileFormat, GA_Group
113  virtual bool jsonSaveData(UT_JSONWriter &w,
114  const GA_SaveMap &map) const;
115 
116  /// Load breakpoint group from a JSON stream.
117  virtual bool jsonLoadData(UT_JSONParser &w, const GA_LoadMap &map);
118 
119  /// Iterator to iterate over all breakpoints in the group. It is safe to
120  /// call advance() after deleting the current entry.
121 
122  GA_BreakpointGroup &operator|=(const GA_BreakpointGroup &inputGroup);
123  GA_BreakpointGroup &operator&=(const GA_BreakpointGroup &inputGroup);
124  GA_BreakpointGroup &operator-=(const GA_BreakpointGroup &inputGroup);
125  GA_BreakpointGroup &operator+=(const GA_BreakpointGroup &inputGroup);
126  GA_BreakpointGroup &operator^=(const GA_BreakpointGroup &inputGroup);
127  GA_BreakpointGroup &operator =(const GA_BreakpointGroup &inputGroup);
128 
129 protected:
130  template<typename T>
132  public std::iterator<std::input_iterator_tag, T>
133  {
134  public:
135  typedef T &reference;
136 
137  /// Default constructor
139  myGroup(NULL),
140  myCurr(NULL),
141  myNext(NULL)
142  {
143  }
144  /// Copy constructor. Use a separate template type to allow copying
145  /// from a const_iterator to non-const iterator.
146  template<typename ET>
148  {
149  myGroup = src.myGroup;
150  myCurr = src.myCurr;
151  myNext = src.myNext;
152  }
153  /// Assignment operator
155  {
156  myGroup = src.myGroup;
157  myCurr = src.myCurr;
158  myNext = src.myNext;
159  return *this;
160  }
161  bool operator==(const base_iterator &cmp) const
162  { return myCurr == cmp.myCurr; }
163 
164  bool operator!=(const base_iterator &cmp) const
165  { return myCurr != cmp.myCurr; }
166 
167  /// ++iterator
168  base_iterator &operator++() { advance(); return *this; }
169  // No post inc as it is harmful.
170 
171  bool atEnd() const { return !myCurr; }
172  void advance()
173  {
174  myCurr = myNext;
175  if (myNext)
176  myNext = static_cast<Entry *>(myNext->next());
177  }
178  void rewind()
179  {
180  myNext = static_cast<Entry *>(
181  myGroup->myBreakpointList.head());
182  advance();
183  }
184 
185  reference operator*() const { return myCurr->myBkpt; }
186  reference getBreakpoint() const { return myCurr->myBkpt; }
187  Entry *getEntry() { return myCurr; }
188  private:
189  base_iterator(const GA_BreakpointGroup *group)
190  : myGroup(group),
191  myCurr(static_cast<Entry *>(group->myBreakpointList.head()))
192  {
193  myNext = myCurr ? static_cast<Entry *>(myCurr->next()) : 0;
194  }
195  const GA_BreakpointGroup *myGroup;
196  Entry *myCurr, *myNext;
197 
198  friend class GA_BreakpointGroup;
199  };
200 public:
203 
204  iterator begin() { return iterator(this); }
205  iterator end() { return iterator(); }
206  const_iterator begin() const { return const_iterator(this); }
207  const_iterator end() const { return const_iterator(); }
208 
209 private:
210  bool addEntry(Entry *it);
211 
212  const GA_Detail &myDetail;
213  UT_LinkList myBreakpointList;
214  unsigned myNumSecondary; // number of secondary
215  // breakpoints
216 };
217 
218 
219 #endif
virtual int64 getMemoryUsage(bool inclusive) const =0
UT_LinkList & list()
const base_iterator & operator=(const base_iterator &src)
Assignment operator.
Used to pass options and map offset values during saving.
Definition: GA_SaveMap.h:48
GA_Size entriesMix() const
virtual GA_Size entries() const
Query the number of breakpoints from primary primitives in the group.
virtual bool isOrdered() const
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:72
#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:32
base_iterator< const GA_Breakpoint > const_iterator
GA_Breakpoint myBkpt
base_iterator()
Default constructor.
virtual bool isMixed() const
Query if we contain any breakpoints from secondary primitives.
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:211
virtual void countMemory(UT_MemoryCounter &counter, bool inclusive) const =0
long long int64
Definition: SYS_Types.h:106
virtual bool isEmptyMix() const
Query whether the group does not contain any breakpoints.
virtual const GA_Detail & getDetail() const
Return the owning detail.
const_iterator end() const
const_iterator begin() const
const UT_LinkList & list() const
Options during loading.
Definition: GA_LoadMap.h:42
GLuint const GLchar * name
Definition: glcorearb.h:785
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
Entry(const GA_Breakpoint &b)
base_iterator & operator++()
++iterator
int cmp(T a, T b)
Definition: ImathFun.h:119
base_iterator(const base_iterator< ET > &src)
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:856
bool operator==(const base_iterator &cmp) const
GLenum src
Definition: glcorearb.h:1792