HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VOP_AutoConvert.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: VOP Library (C++)
7  *
8  * Note: This is more of an internal class, not an actual node. It needs to inherit
9  * from VOP_Node to generate code properly, though. What happens is during code
10  * generation, copies of it are inserted into the flattened node list, and (before
11  * they are inserted) are told which two nodes and which input/output they go between.
12  * Thus, these are essentially virtual nodes that get created only at code generation
13  * time and destroyed immediately afterwards.
14  *
15  * During code generation, they pretend they really are connected between the two nodes,
16  * and generate proper auto-conversion code. Auto convert also contains severa static
17  * functions that determine whether two types can be auto-converted between.
18  *
19  */
20 
21 #ifndef __VOP_AutoConvert_h__
22 #define __VOP_AutoConvert_h__
23 
24 #include "VOP_API.h"
25 #include "VOP_AutoNode.h"
26 #include <string>
27 
28 // #define DEBUG_DISABLE_AUTOCONVERT
29 
31 {
32 public:
34  ~VOP_AutoConvert() override;
35 
36  /// Returns true if intype can be converted to outtype.
37  static bool canAutoconvert(VOP_Type intype, VOP_Type outtype,
38  const VOP_Language *language);
39  static bool canAutoconvert(const VOP_TypeInfo &intype,
40  const VOP_TypeInfo &outtype,
41  const VOP_Language *language);
42 
43  // Since this "node" is meant to be used on its own, we override this
44  // to let VEX code be generated properly.
45  void getPathWithSubnet(UT_String &str) const override;
46  void getOuterCode(
47  UT_String &codestr,
48  const VOP_CodeGenContext &context) override;
49  void getCode(UT_String &codestr,
50  const VOP_CodeGenContext &context) override;
51 
52  OP_Network *getParentNetwork() const override;
53 
54  OP_Input *getInputReference(unsigned idx, bool grow) override;
55  OP_Input *getInputReferenceConst(unsigned idx) const override;
56 
57  void hookupBetween(VOP_Node* input_node,
58  VOP_Node* output_node,
59  int input_idx, bool tell_nodes);
60 
61  bool isConnected(int inputidx, bool recursive) override;
62  unsigned getNumVisibleInputs() const override;
63  unsigned getNumVisibleOutputs() const override;
64  const char *inputLabel(unsigned idx) const override;
65  const char *outputLabel(unsigned idx) const override;
66 
67  static void initConversions();
68 
69  static const char* getAutoConvertOpName(const VOP_TypeInfo &from_type,
70  const VOP_TypeInfo &to_type);
71  static const char* getAutoConvertOpName(VOP_Type from_type, VOP_Type to_type);
72  static VOP_Type generateCodeFor(VOP_Node *input_node,
73  VOP_Node *output_node,
74  int input_idx, UT_String &codestr,
75  bool current_types_only);
76 
77  bool isAutoConvertNode() const override
78  { return true; }
79 
80 protected:
81 
83  UT_String &in,
84  int idx) const override;
86  const UT_String &in) const override;
88  VOP_TypeInfo &type_info,
89  int idx) override;
90 
92  UT_String &out,
93  int idx) const override;
95  VOP_TypeInfo &type_info,
96  int idx) override;
97 
98  static void getConversionBetween(VOP_Type intype, VOP_Type outtype,
99  std::string& out, const VOP_Language *language);
100 
101 private:
102 
103 
104  // Since autoconversion nodes are only created when generating
105  // code, we can just keep the pointers. Also, we can't use setInput(), etc.
106  // because that will modify the actual node graph, and disconnect previous nodes.
107  // We don't want to do that.
108  VOP_Node *myInput, *myOutput;
109  int myInputIdx; // input index on the node we output to
110 
111  // From-to-type.
112  static std::string theConversionTable[VOP_MAX_TYPES][VOP_MAX_TYPES];
113  static bool theDidInitConversions;
114  static std::string theConversionNodeNameTable[VOP_MAX_TYPES][VOP_MAX_TYPES];
115 
116  VOP_TypeInfo myConvertedOutputTypeInfo;
117 };
118 
119 #endif
virtual int getInputFromNameSubclass(const UT_String &in) const
Reprsents a language for which VOPs can generate source code.
Definition: VOP_Language.h:29
virtual void getOuterCode(UT_String &codestr, const VOP_CodeGenContext &context)
bool isAutoConvertNode() const override
Retruns true if the node is an internal auto-convert node.
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
virtual unsigned getNumVisibleInputs() const
virtual OP_Input * getInputReferenceConst(unsigned idx) const
virtual const char * inputLabel(unsigned idx) const
virtual unsigned getNumVisibleOutputs() const
virtual void getInputTypeInfoSubclass(VOP_TypeInfo &type_info, int idx)
virtual bool isConnected(int inputidx, bool recursive)
#define VOP_API
Definition: VOP_API.h:10
virtual void getCode(UT_String &codestr, const VOP_CodeGenContext &context)
Get the code fragment to be included in the shader code.
virtual const char * outputLabel(unsigned idx) const
virtual void getOutputTypeInfoSubclass(VOP_TypeInfo &type_info, int idx)
virtual void getOutputNameSubclass(UT_String &out, int idx) const
void getPathWithSubnet(UT_String &str) const override
Returns the path of this node relative to its getCreator()
virtual OP_Input * getInputReference(unsigned idx, bool grow)
VOP_Type
Enumeration of the built-in (basic) VOP data types.
Definition: VOP_Types.h:25
virtual void getInputNameSubclass(UT_String &in, int idx) const
OP_Network * getParentNetwork() const override
Returns the network that is our parent.