HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PDGE_DependencyOwner.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_DEPENDENCY_OWNER_H__
10 #define __PDGE_DEPENDENCY_OWNER_H__
11 
12 #include "PDGE_API.h"
13 #include "PDGE_Dependency.h"
14 
15 #include <UT/UT_Array.h>
16 #include <UT/UT_Assert.h>
17 #include <UT/UT_NonCopyable.h>
18 #include <UT/UT_StringHolder.h>
19 #include <UT/UT_UniquePtr.h>
20 
21 class PDGE_Evaluator;
22 class PDGE_Resolutions;
23 
24 /**
25  * Base class for objects that own dependencies
26  */
28 {
29 public:
32 
33 public:
34  /// Constructs a new dependency owner, which must have a string name
36  virtual ~PDGE_DependencyOwner() {}
37 
39 
40  /// Returns the memory usage of this owner instance
41  virtual int64 getMemoryUsage(bool inclusive) const
42  {
43  int64 mem = inclusive ? sizeof(*this) : 0;
44  mem += myPropagateSet.getMemoryUsage(false);
45  return mem;
46  }
47 
48  /// Resets the owner
49  virtual void resetOwner()
50  { myPropagateSet.clear(); }
51 
52  /// Debug name for this dependency owner object, used when various debug
53  /// utilities are enabled
54  virtual UT_StringHolder debugName() const = 0;
55 
56  /// Debug name for the dependency group this owner is in, used for DOT
57  /// graph output when enabled.
58  virtual UT_StringHolder debugGroup() const
59  { return debugName(); }
60 
61  /// Converts an owner array to an array of the specified type
62  template <typename T>
63  static inline void cast(UT_Array<T>& out, const Array& in)
64  {
65  out.setCapacity(in.size());
66  for (auto&& input : in)
67  out.append((T)(input));
68  }
69 
70  /// Converts an array of the specified type to an owner array
71  template <typename T>
72  static inline void cast(Array& out, const UT_Array<T>& in)
73  {
74  out.setCapacity(in.size());
75  for (auto&& input : in)
76  out.append(input);
77  }
78 
79  template <typename T>
80  static inline void cast(
81  Array& out,
82  const UT_Array<UT_UniquePtr<T>>& in)
83  {
84  out.setCapacity(in.size());
85  for (auto&& input : in)
86  out.append(input.get());
87  }
88 protected:
89  friend class PDGE_Dependency;
90  friend class PDGE_PropagateGroup;
91 
92  /// Called when a dependency owned by this object is resolved
94  const PDGE_Evaluator&,
96  {
97  UT_ASSERT(false);
99  }
100 
101  /// Called when a dependency owned by this object is unresolved
102  /// during an evaluation. This method is not called for normal
103  /// reset calls between evaluations, or when a dependency object
104  /// is destroyed. It also cannot be used to add new dependencies or
105  /// trigger evaluation of existing ones, however it can return back
106  /// additional dependencies that should be unresolved.
109  {
110  return 0;
111  }
112 
113  /// Called when a dependency owned by this object receives a partial
114  /// resolve notification.
116  const PDGE_Evaluator&,
118  const Array&)
119  {
120  UT_ASSERT(false);
122  }
123 
124  /// Returns the propagate set for this owner
125  inline const PDGE_Dependency::Set&
127  { return myPropagateSet; }
128 
129  /// Adds an entry to the propagate set
130  inline void addPropagate(PDGE_Dependency* dependency)
131  { myPropagateSet.insert(dependency); }
132 
133 private:
134  /// Propagate set, used by PDGE_PropgateGroup
135  PDGE_Dependency::Set myPropagateSet;
136 };
137 
138 #endif
static void cast(Array &out, const UT_Array< UT_UniquePtr< T >> &in)
virtual PDGE_Dependency::State evalPartial(PDGE_Resolutions &, const PDGE_Evaluator &, PDGE_Dependency *, const Array &)
static void cast(Array &out, const UT_Array< T > &in)
Converts an array of the specified type to an owner array.
void setCapacity(exint new_capacity)
exint size() const
Definition: UT_Array.h:667
constexpr auto in(type t, int set) -> bool
Definition: core.h:611
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
void addPropagate(PDGE_Dependency *dependency)
Adds an entry to the propagate set.
The dependency was successfully resolved.
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
long long int64
Definition: SYS_Types.h:116
PDGE_DependencyOwner()
Constructs a new dependency owner, which must have a string name.
exint append()
Definition: UT_Array.h:142
static void cast(UT_Array< T > &out, const Array &in)
Converts an owner array to an array of the specified type.
#define PDGE_API
Definition: PDGE_API.h:23
virtual PDGE_Dependency::State evalResolve(PDGE_Resolutions &, const PDGE_Evaluator &, PDGE_Dependency *)
Called when a dependency owned by this object is resolved.
virtual UT_StringHolder debugGroup() const
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:165
virtual int evalUnresolve(PDGE_Dependency::Array &, PDGE_Dependency *)
virtual void resetOwner()
Resets the owner.
const PDGE_Dependency::Set & propagateSet()
Returns the propagate set for this owner.