HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VOP_CompositeTypeDefinition.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_TypeDefinition.h (VOP Library, C++)
7  *
8  * COMMENTS: Class implementing a composite vop connector types,
9  * like a struct or a class.
10  */
11 
12 #ifndef __VOP_CompositeTypeDefinition__
13 #define __VOP_CompositeTypeDefinition__
14 
15 #include "VOP_API.h"
16 #include "VOP_TypeDefinition.h"
17 #include "VOP_TypeInfo.h"
18 #include <UT/UT_StringArray.h>
19 
20 
21 // ============================================================================
22 /// Class that contains information about a struct/class member variable.
24 {
25 public:
26  /// Constructor and destructor.
28  VOP_MemberVarInfo( const VOP_TypeInfo &type_info,
29  const char *name,
30  const char *label = NULL,
31  const char *old_name = NULL );
33 
34  /// Comparison operator.
35  bool operator==(const VOP_MemberVarInfo &other) const;
36 
37  /// @{ Member getters and setters.
38  const VOP_TypeInfo & getTypeInfo() const;
39  void setTypeInfo( const VOP_TypeInfo &type_info );
40  const UT_StringHolder & getName() const;
41  void setName( const char *name );
42  const UT_StringHolder & getLabel() const;
43  void setLabel( const char *label );
44  void setOldName( const char *old_name );
45  const UT_StringHolder & getOldName() const;
46  /// @}
47 
48 private:
49  VOP_TypeInfo myTypeInfo; // member type
50  UT_StringHolder myName; // member name
51  UT_StringHolder myLabel; // member label
52 
53  // The name by which this member was known in the past, in case
54  // some node still refers to it like that.
55  UT_StringHolder myOldName;
56 };
57 
58 // ============================================================================
59 /// Class that contains information about a struct/class method.
61 {
62 public:
63  /// Constructor and destructor.
66 
67  /// Comparison operator.
68  bool operator==(const VOP_MemberMethodInfo &other) const;
69 
70  /// @{ Method getters and setters.
71  const UT_StringHolder & getName() const;
72  void setName( const char *name );
73  const VOP_TypeInfo & getReturnTypeInfo() const;
74  void setReturnTypeInfo( const VOP_TypeInfo &type_info );
75  bool isVariadic() const;
76  void setIsVariadic( bool flag );
77 
78  int getArgCount() const;
79  const UT_StringHolder & getArgName( int idx ) const;
80  const VOP_TypeInfo & getArgTypeInfo( int idx ) const;
81  bool isArgOut( int idx ) const;
82  void appendArg( const char *name,
83  const VOP_TypeInfo &type_info,
84  bool is_out );
85  /// @}
86 
87 private:
88  VOP_TypeInfo myReturnTypeInfo; // method return type
89  UT_StringHolder myName; // method name
90  UT_StringArray myArgNames; // method argument names
91  UT_Array<VOP_TypeInfo> myArgTypes; // method argument types
92  UT_Array<bool> myArgOut; // is output argument
93  bool myIsVariadic; // accepts arbitrary extra args
94 };
95 
96 // ============================================================================
97 /// Class that defines a type composed by assembling other types as members.
99 {
100 public:
101  /// Constructor and destructor.
103  ~VOP_CompositeTypeDefinition() override;
104 
105  /// Returns a keyword to be used in the source code for defining
106  /// this composite type (eg, "struct", "class", etc).
107  virtual UT_StringHolder getCodeTypeKeyword() const = 0;
108 
109  /// @{ Saves to or loades from a JSON value.
110  bool load( const UT_JSONValue &json ) override;
111  bool save( UT_JSONValue &json ) const override;
112  /// @}
113 
114  /// Obtains the source code that defines the type in the programming
115  /// (scripting) language.
117  UT_String &code,
118  const VOP_Language *language
119  ) const override;
120 
121  /// @{ Getters and setters for member variable information.
122  /// The first three are the core functions, while the remaining ones
123  /// are convenience utility function to get at particular piece of info.
124  int getMemberVarCount() const;
125  const VOP_MemberVarInfo & getMemberVarInfo( int index ) const;
126  const VOP_MemberVarInfo * findMemberVarInfo( const char *member_name,
127  bool check_old_names = false) const;
128  int findMemberVarInfoIndex(
129  const char *member_name,
130  bool check_old_names = false) const;
131  void appendMemberVarInfo(
132  const VOP_MemberVarInfo &info );
133  /// @}
134 
135  /// @{ Getters and setter for member methods.
136  int getMethodCount() const;
137  const VOP_MemberMethodInfo & getMethodInfo( int index ) const;
138  const VOP_MemberMethodInfo * findMethodInfo(
139  const char *method_name ) const;
140  void appendMethodInfo(
141  const VOP_MemberMethodInfo &info);
142  /// @}
143 
144  /// @{ True if the type is ad-hoc (eg, defined by a Struct VOP node).
145  void setIsAdHoc( bool flag );
146  bool isAdHoc() const;
147  /// @}
148 
149  /// @{ Sets and gets the source code that should be used in
150  /// the shader definision source code.
151  /// If explicit code is NULL, then whenever an actual definition source
152  /// code is needed, this class will auto-generate the it from the info
153  /// about its members. This is the case for majority of vop structs/classes.
154  /// This override method is useful for struct definitions that are
155  /// outside of vops (eg, in a header file, in which case this override
156  /// would likely just specify #include directive).
157  void setExplicitDefinitionCode( const char *code );
158  const char * getExplicitDefinitionCode() const;
159  /// @}
160 
161 protected:
162  /// @{ Standard overrides from the base class
163  bool isEqual(const VOP_TypeDefinition &other) const override;
164  /// @}
165 
166  /// Generates a type definition for the source code from the member info.
167  void generateTypeDefinition( UT_String &code,
168  const char *meta_type_keyword,
169  const VOP_Language *language ) const;
170 
171 private:
172  /// True if the type is ad-hoc (eg, defined by a Struct VOP node).
173  bool myIsAdHoc;
174 
175  /// Composite type member information (their types, names, and labels, etc).
176  UT_Array< VOP_MemberVarInfo > myMemberInfos;
177 
178  /// Composite type method information.
179  UT_Array< VOP_MemberMethodInfo > myMethodInfos;
180 
181  /// Code that should be used in the shader source code to define this type.
182  /// It can contain full type definition or an #include directive.
183  /// If it is NULL and the definition is required, the definition
184  /// is generated based on the member variable infos.
185  UT_StringHolder myExplicitDefinitionCode;
186  bool myUseExplicitDefinitionCode;
187 };
188 
189 // ============================================================================
190 /// Class that defines a struct vop type.
192 {
193 public:
194  /// @{ Standard overrides from the base class
196  ~VOP_StructTypeDefinition() override;
197  /// @}
198 
199  /// @{ Override the meta-type string for structs
201  UT_StringHolder getMetaType() const override;
202  UT_StringHolder getCodeTypeKeyword() const override;
203  /// @}
204 };
205 
206 // ============================================================================
207 /// Class that defines a class vop type:
208 /// - in RSL it represents co-shader objects (ie, 'shader' type in source code).
210 {
211 public:
212  /// @{ Standard overrides from the base class
214  ~VOP_ClassTypeDefinition() override;
215  /// @}
216 
217  /// @{ Override the meta-type string for classes.
219  UT_StringHolder getMetaType() const override;
220  UT_StringHolder getCodeTypeKeyword() const override;
221  /// @}
222 };
223 
224 #endif
225 
Reprsents a language for which VOPs can generate source code.
Definition: VOP_Language.h:29
A class abstracting definition of a VOP data type.
virtual UT_StringHolder getMetaType() const =0
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2545
virtual UT_StringHolder getCodeTypeKeyword() const =0
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
#define VOP_API
Definition: VOP_API.h:10
PXL_API const char * getName(const ColorSpace *space)
Return the name of the color space.
virtual bool load(const UT_JSONValue &json)
virtual bool save(UT_JSONValue &json) const
GLuint const GLchar * name
Definition: glcorearb.h:786
Class that defines a struct vop type.
Class that contains information about a struct/class method.
Class that contains information about a struct/class member variable.
GLuint index
Definition: glcorearb.h:786
virtual bool isEqual(const VOP_TypeDefinition &other) const =0
Class to store JSON objects as C++ objects.
Definition: UT_JSONValue.h:99
static const UT_StringHolder METATYPE_VALUE
Override the meta-type string for structs.
virtual void getTypeDefinitionSourceCode(UT_String &code, const VOP_Language *language) const
Class that defines a type composed by assembling other types as members.
static const UT_StringHolder METATYPE_VALUE
Override the meta-type string for classes.