HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PDGT_TypeInstance.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 __PDGT_ENUM_TYPE_INSTANCE_H__
10 #define __PDGT_ENUM_TYPE_INSTANCE_H__
11 
12 #include "PDGT_API.h"
13 
14 #include "PDGT_BaseType.h"
15 #include "PDGT_ValueArgs.h"
16 
17 #include <UT/UT_NonCopyable.h>
18 
19 /**
20  * The base class for all instances created using a PDGT_RegisteredType. The
21  * Class argument to the registered type should derive from this class.
22  *
23  * This class provides basic functionality common to all instances, such as:
24  *
25  * Providing the ability to look up a back reference to the type object
26  * Tracking whether or not the instance is currently being reloaded.
27  *
28  * This class also defines the `reloadInstance` virtual method, which is called
29  * when the instance should reload itself. Typically, the instance will need
30  * to implement a custom method that calls `type()->reloadInstance(...)` with
31  * itself as an argument, and the various other construction arguments needed
32  * in order to properly re-initialize the underyling object.
33  *
34  * For example, nodes based on Python classes needed to reconstruct their
35  * underyling Python instance, which requires passing in the PDG_Node as a
36  * construction argument. PDG_NodeCallback, which is a subclass of this class,
37  * defines a custom `reloadInstance` method that makes the correct call into
38  * its PDG_NodeCallbackType::reloadInstance method with the PDG_Node as an
39  * argument.
40  */
41 template <typename EnumType>
43 {
44 public:
46 
47 public:
49  : myBaseType(nullptr)
50  , myReloading(false) {}
51 
53  const PDGT_ValueArgs& extra_args)
54  : myBaseType(base_type)
55  , myExtraArgs(extra_args)
56  , myReloading(false)
57  {
58  if (myBaseType)
59  myBaseType->instanceCreated();
60  }
61 
63  {
64  if (myBaseType)
65  myBaseType->instanceDestroyed();
66  }
67 
68  virtual int64 getMemoryUsage(bool inclusive) const
69  {
70  int64 mem = inclusive ? sizeof(*this) : 0;
71  mem += myExtraArgs.getMemoryUsage(false);
72  return mem;
73  }
74 
75  virtual bool reloadInstance(UT_WorkBuffer& errors)
76  { return false; }
77 
78  const BaseType* type() const
79  { return myBaseType; }
80  const UT_StringHolder& typeName() const
81  { return myBaseType->typeName(); }
82  const PDGT_ValueArgs& extraArgs() const
83  { return myExtraArgs; }
84 
85  bool compareType(const BaseType* other_type,
86  bool deep=true) const
87  {
88  return myBaseType->compareType(other_type,
89  deep);
90  }
91 
92  void setReloading(bool is_reloading)
93  { myReloading = is_reloading; }
94  bool isReloading() const
95  { return myReloading; }
96 
97 protected:
101 };
102 
103 #endif
bool compareType(const BaseType *other_type, bool deep=true) const
const PDGT_ValueArgs & extraArgs() const
void setReloading(bool is_reloading)
virtual bool reloadInstance(UT_WorkBuffer &errors)
PDGT_TypeInstance(const PDGT_BaseType< EnumType > *base_type, const PDGT_ValueArgs &extra_args)
virtual int64 getMemoryUsage(bool inclusive) const
#define PDGT_API_TMPL
Definition: PDGT_API.h:24
long long int64
Definition: SYS_Types.h:116
const BaseType * type() const
bool isReloading() const
virtual ~PDGT_TypeInstance()
const UT_StringHolder & typeName() const
PDGT_ValueArgs myExtraArgs
const BaseType * myBaseType