HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PDGE_Resolutions.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  * COMMENTS:
7  */
8 
9 #ifndef __PDGE_RESOLUTIONS_H__
10 #define __PDGE_RESOLUTIONS_H__
11 
12 #include "PDGE_API.h"
13 
14 #include "PDGE_Dependency.h"
15 #include "PDGE_DependencyOwner.h"
16 
17 #include <UT/UT_Array.h>
18 #include <UT/UT_ArrayMap.h>
19 #include <UT/UT_NonCopyable.h>
20 #include <UT/UT_ParallelUtil.h>
21 #include <UT/UT_UniquePtr.h>
22 
23 class PDGE_Evaluator;
24 
25 /*
26  * An array of dependency resolutions, including both partial and full
27  * resolutions.
28  */
30 {
31 public:
32  PDGE_Resolutions(bool defer_heavy = true)
33  : myIsSerial(false)
34  , myIsDeferHeavy(defer_heavy) {}
35 
37  {
38  myResolutions =
39  std::move(array.myResolutions);
40  myPartials =
41  std::move(array.myPartials);
42  myIsSerial =
43  array.myIsSerial;
44  myIsDeferHeavy =
45  array.myIsDeferHeavy;
46  }
48  {
49  if (this == &other)
50  return *this;
51  myResolutions =
52  std::move(other.myResolutions);
53  myPartials =
54  std::move(other.myPartials);
55  myIsSerial = other.myIsSerial;
56  myIsDeferHeavy = other.myIsDeferHeavy;
57  return *this;
58  }
59 
60  /// Returns the memory usage of this object
61  int64 getMemoryUsage(bool inclusive) const;
62 
63  /// Clears all exisiting resolutions from the array, including both partial
64  /// and full resolves.
65  inline void clearAll()
66  {
67  myResolutions.clear();
68  myPartials.clear();
69  myIsSerial = false;
70  }
71 
72  /// Clears only partial resolutions from the array.
73  inline void clearPartials()
74  {
75  myPartials.clear();
76  myIsSerial = false;
77  }
78 
79  /// Concats the contents of the specificed resolutions with the ones in
80  /// this array. No deduplication is performed.
81  inline void concat(const PDGE_Resolutions& resolutions)
82  {
83  myResolutions.concat(
84  resolutions.myResolutions);
85  myPartials.concat(
86  resolutions.myPartials);
87  }
88 
89  /// Returns the number of full resolutions in the array
90  inline exint numResolves() const
91  { return myResolutions.size(); }
92 
93  /// Returns the number of partial resolutions in the array
94  inline exint numPartials() const
95  { return myPartials.size(); }
96 
97  /// Returns true if partial evaluation should be performed in serial
98  /// instead of in parallel
99  inline bool isSerial() const
100  { return myIsSerial; }
101 
102 
103  /// Adds a new dependency to the list of full resolutions
104  inline void addResolve(PDGE_Dependency* dependency)
105  { myResolutions.append(dependency); }
106 
107  /// Adds a new dependency to the list of partial resolutions, along with
108  /// the owner argument associated with the partial resolution.
109  bool addPartial(
110  PDGE_Dependency* dependency,
111  const PDGE_DependencyOwner::Array& owners,
112  bool ascending=true,
113  bool serial=false);
114 
115  /// Same as above, but with a single owner argument for convenience
116  bool addPartial(
117  PDGE_Dependency* dependency,
118  PDGE_DependencyOwner* owner,
119  bool ascending=true,
120  bool serial=false);
121 
122  /// Save as above, but with an arbitrarily typed array
123  template <typename T>
125  PDGE_Dependency* dependency,
126  const UT_Array<T>& owners,
127  bool ascending=true,
128  bool serial=false)
129  {
131  PDGE_DependencyOwner::cast<T>(
132  output, owners);
133 
134  return addPartial(dependency,
135  output,
136  ascending,
137  serial);
138  }
139 
140  /// Save as above, but with an arbitrarily typed array of unique pointers
141  template <typename T>
143  PDGE_Dependency* dependency,
144  const UT_Array<UT_UniquePtr<T>>& owners,
145  bool ascending=true,
146  bool serial=false)
147  {
149  PDGE_DependencyOwner::cast<T>(
150  output, owners);
151 
152  return addPartial(dependency,
153  output,
154  ascending,
155  serial);
156  }
157 
158  /// Evaluates all full resolutions in the array. This function should be
159  /// called from a UTparallelFor.
160  void evaluateResolves(
162  PDGE_Evaluator& evaluator,
163  PDGE_Resolutions& resolutions,
164  PDGE_Resolutions& deferred) const;
165 
166  /// Evaluates all partial resolutions and stores new resolutions into the
167  /// supplied array. This function should be called from a UTparalleReduce.
168  void evaluatePartials(
170  PDGE_Evaluator& evaluator,
171  PDGE_Resolutions& resolutions) const;
172 
173 private:
174  PDGE_Dependency::Array myResolutions;
175  PDGE_Dependency::Partial myPartials;
176  bool myIsSerial;
177  bool myIsDeferHeavy;
178 };
179 
180 #endif
GLenum GLint * range
Definition: glcorearb.h:1925
void clearPartials()
Clears only partial resolutions from the array.
int64 exint
Definition: SYS_Types.h:125
bool isSerial() const
bool addPartial(PDGE_Dependency *dependency, const UT_Array< T > &owners, bool ascending=true, bool serial=false)
Save as above, but with an arbitrarily typed array.
bool addPartial(PDGE_Dependency *dependency, const UT_Array< UT_UniquePtr< T >> &owners, bool ascending=true, bool serial=false)
Save as above, but with an arbitrarily typed array of unique pointers.
exint numPartials() const
Returns the number of partial resolutions in the array.
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
void concat(const PDGE_Resolutions &resolutions)
long long int64
Definition: SYS_Types.h:116
void addResolve(PDGE_Dependency *dependency)
Adds a new dependency to the list of full resolutions.
exint numResolves() const
Returns the number of full resolutions in the array.
PDGE_Resolutions(bool defer_heavy=true)
PDGE_Resolutions & operator=(PDGE_Resolutions &&other)
#define PDGE_API
Definition: PDGE_API.h:23
PDGE_Resolutions(PDGE_Resolutions &&array)
Declare prior to use.