HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GA_RTIFiltered.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_RTIFiltered.h ( GA Library, C++)
7  *
8  */
9 
10 #ifndef __GA_RTIFiltered__
11 #define __GA_RTIFiltered__
12 
13 #include "GA_API.h"
14 #include "GA_Range.h"
15 #include "GA_RangeTypeInterface.h"
16 #include "GA_Types.h"
17 
18 #include <UT/UT_IntrusivePtr.h>
19 
20 #include <SYS/SYS_AtomicInt.h>
21 
22 
23 class GA_IndexMap;
24 class GA_IteratorState;
25 
26 
27 /// @brief Filter to test whether an offset is valid for a GA_RTIFiltered range
28 ///
29 /// This class defines a simple interface to test whether offsets are valid for
30 /// a given range. The objects should be processed through the intrusive
31 /// pointer typedef. For example @code
32 /// class MyFilter : public GA_RTIFilterObject { ... }
33 /// ...
34 /// const GA_Range &source_range;
35 /// GA_RTIFiltered range(source_range, GA_RTIFilterHandle(new MyFilter));
36 /// @endcode
38 {
39 public:
41  virtual ~GA_RTIFilterObject();
42 
43  virtual bool filter(const GA_IndexMap &map, GA_Offset offset) const = 0;
44  virtual bool isEqual(const GA_RTIFilterObject *src) const = 0;
45 
46  void incref() { myRefCount.add(1); }
47  void decref()
48  {
49  if (!myRefCount.add(-1))
50  delete this;
51  }
52 private:
53  SYS_AtomicInt32 myRefCount;
54 };
55 
56 /// @{
57 /// Intrusive pointer typdef
58 static inline void intrusive_ptr_add_ref(GA_RTIFilterObject *o) { o->incref(); }
59 static inline void intrusive_ptr_release(GA_RTIFilterObject *o) { o->decref(); }
60 
62 /// @}
63 
64 /// @brief An implementation of a range which "filters" the range
65 ///
66 /// The GA_RTIFiltered class takes a source range and a filter. The filter is
67 /// applied to the source range to determine whether elements of the source
68 /// range belong to the filtered range. A example might be: @code
69 /// class FilterOdd : GA_RTIFilterObject
70 /// {
71 /// FilterOdd() {}
72 /// virtual ~FilterOdd() {}
73 ///
74 /// virtual bool filter(const GA_IndexMap &, GA_Offset offset) const
75 /// { return (offset & 1) != 0; }
76 /// virtual bool isEqual(const GA_RTIFilterObject *src) const
77 /// { return dynamic_cast<const FilterOdd *>(src) != NULL; }
78 /// };
79 ///
80 /// ...
81 /// GA_Range all_points(new GA_RTIOffset(geo.getPointMap()));
82 /// GA_Range odd_points(all_points, GA_RTIFilterHandle(new FilterOdd));
83 /// ...
84 /// @endcode
85 ///
87 {
88 public:
89  // Range which filters the source range given the filter specified
90  GA_RTIFiltered(const GA_Range &base, const GA_RTIFilterHandle &filter);
91 
92  // Copy c-tor
94 
95  ~GA_RTIFiltered() override;
96 
97  /// @{
98  /// RangeTypeInterface implementation
99  GA_RangeTypeInterface *copy() const override;
100  bool isSplittable() const override { return false; }
101  bool isEmpty() const override;
102  GA_Size getMaxEntries() const override;
103  GA_Size getEntries() const override;
104  bool isEqual(const GA_RangeTypeInterface &src) const override;
105  bool split(GA_RangeTypeInterface *list[2]) const override;
106  void iterateCreate(GA_IteratorState &state) const override;
107  void iterateDestroy(GA_IteratorState &state) const override;
108  void iterateCopy(GA_IteratorState &dest,
109  const GA_IteratorState &src) const override;
110  void iterateRewind(GA_IteratorState &state,
111  GA_Offset &start, GA_Offset &end) const override;
112  void iterateNext(GA_IteratorState &state,
113  GA_Offset &start, GA_Offset &end) const override;
114  bool areTraversalDeletionsSafe() const override;
115  GA_Size getPageCount() const override { return -1; }
116  bool getPageElementRange(GA_Range &, GA_Size, GA_Size) const override
120  /// @}
121 
122 private:
123  void init();
124 
125  GA_Range myRange;
126  const GA_RangeTypeInterface *myBase; // Convenience ptr
127  GA_RTIFilterHandle myFilter;
128  GA_Size myComputedSize;
129 };
130 
131 #endif
A class to manage an ordered array which has fixed offset handles.
Definition: GA_IndexMap.h:63
virtual bool isEmpty() const =0
Check whether the range is empty.
virtual GA_RangeTypeInterface * copy() const =0
Method to create a copy of this selection.
virtual void iterateCopy(GA_IteratorState &dest, const GA_IteratorState &src) const =0
Copy iterator state. The dest state will not have been constructed.
virtual bool split(GA_RangeTypeInterface *list[2]) const =0
GLuint start
Definition: glcorearb.h:475
UT_IntrusivePtr< GA_RTIFilterObject > GA_RTIFilterHandle
Filter to test whether an offset is valid for a GA_RTIFiltered range.
virtual void iterateDestroy(GA_IteratorState &state) const
#define GA_API
Definition: GA_API.h:14
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:235
A range of elements in an index-map.
Definition: GA_Range.h:42
virtual void iterateCreate(GA_IteratorState &state) const
bool getPageElementRangeNonSplittable() const
Method which can be called for getPageElementRange()
GA_Size GA_Offset
Definition: GA_Types.h:641
GLintptr offset
Definition: glcorearb.h:665
GA_Offset getFirstOffsetInPageNonSplittable() const
Method which can be called for getFirstOffsetInPage()
GLuint GLuint end
Definition: glcorearb.h:475
virtual void iterateRewind(GA_IteratorState &state, GA_Offset &start, GA_Offset &end) const =0
bool isSplittable() const override
Abstract implementation of a range.
An implementation of a range which "filters" the range.
virtual GA_Size getMaxEntries() const =0
Get an upper bound on the size of the range.
bool getPageElementRange(GA_Range &, GA_Size, GA_Size) const override
GA_Size getPageCount() const override
GA_Offset getFirstOffsetInPage(GA_Size) const override
virtual GA_Size getEntries() const =0
virtual bool areTraversalDeletionsSafe() const
virtual void iterateNext(GA_IteratorState &state, GA_Offset &start, GA_Offset &end) const =0
virtual bool isEqual(const GA_RangeTypeInterface &src) const =0
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
Definition: glcorearb.h:1297
GLenum src
Definition: glcorearb.h:1793