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  virtual ~VOP_CompositeTypeDefinition();
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  virtual bool load( const UT_JSONValue &json );
111  virtual bool save( UT_JSONValue &json ) const;
112  /// @}
113 
114  /// Obtains the source code that defines the type in the programming
115  /// (scripting) language.
116  virtual void getTypeDefinitionSourceCode( UT_String &code,
117  const VOP_Language *language ) const;
118 
119  /// @{ Getters and setters for member variable information.
120  /// The first three are the core functions, while the remaining ones
121  /// are convenience utility function to get at particular piece of info.
122  int getMemberVarCount() const;
123  const VOP_MemberVarInfo & getMemberVarInfo( int index ) const;
124  const VOP_MemberVarInfo * findMemberVarInfo( const char *member_name,
125  bool check_old_names = false) const;
126  int findMemberVarInfoIndex(
127  const char *member_name,
128  bool check_old_names = false) const;
129  void appendMemberVarInfo(
130  const VOP_MemberVarInfo &info );
131  /// @}
132 
133  /// @{ Getters and setter for member methods.
134  int getMethodCount() const;
135  const VOP_MemberMethodInfo & getMethodInfo( int index ) const;
136  const VOP_MemberMethodInfo * findMethodInfo(
137  const char *method_name ) const;
138  void appendMethodInfo(
139  const VOP_MemberMethodInfo &info);
140  /// @}
141 
142  /// @{ True if the type is ad-hoc (eg, defined by a Struct VOP node).
143  void setIsAdHoc( bool flag );
144  bool isAdHoc() const;
145  /// @}
146 
147  /// @{ Sets and gets the source code that should be used in
148  /// the shader definision source code.
149  /// If explicit code is NULL, then whenever an actual definition source
150  /// code is needed, this class will auto-generate the it from the info
151  /// about its members. This is the case for majority of vop structs/classes.
152  /// This override method is useful for struct definitions that are
153  /// outside of vops (eg, in a header file, in which case this override
154  /// would likely just specify #include directive).
155  void setExplicitDefinitionCode( const char *code );
156  const char * getExplicitDefinitionCode() const;
157  /// @}
158 
159 protected:
160  /// @{ Standard overrides from the base class
161  virtual bool isEqual( const VOP_TypeDefinition &other ) const;
162  /// @}
163 
164  /// Generates a type definition for the source code from the member info.
165  void generateTypeDefinition( UT_String &code,
166  const char *meta_type_keyword,
167  const VOP_Language *language ) const;
168 
169 private:
170  /// True if the type is ad-hoc (eg, defined by a Struct VOP node).
171  bool myIsAdHoc;
172 
173  /// Composite type member information (their types, names, and labels, etc).
174  UT_Array< VOP_MemberVarInfo > myMemberInfos;
175 
176  /// Composite type method information.
177  UT_Array< VOP_MemberMethodInfo > myMethodInfos;
178 
179  /// Code that should be used in the shader source code to define this type.
180  /// It can contain full type definition or an #include directive.
181  /// If it is NULL and the definition is required, the definition
182  /// is generated based on the member variable infos.
183  UT_StringHolder myExplicitDefinitionCode;
184  bool myUseExplicitDefinitionCode;
185 };
186 
187 // ============================================================================
188 /// Class that defines a struct vop type.
190 {
191 public:
192  /// @{ Standard overrides from the base class
194  virtual ~VOP_StructTypeDefinition();
195  /// @}
196 
197  /// @{ Override the meta-type string for structs
199  virtual UT_StringHolder getMetaType() const;
200  virtual UT_StringHolder getCodeTypeKeyword() const;
201  /// @}
202 };
203 
204 // ============================================================================
205 /// Class that defines a class vop type:
206 /// - in RSL it represents co-shader objects (ie, 'shader' type in source code).
208 {
209 public:
210  /// @{ Standard overrides from the base class
212  virtual ~VOP_ClassTypeDefinition();
213  /// @}
214 
215  /// @{ Override the meta-type string for classes.
217  virtual UT_StringHolder getMetaType() const;
218  virtual UT_StringHolder getCodeTypeKeyword() const;
219  /// @}
220 };
221 
222 #endif
223 
Reprsents a language for which VOPs can generate source code.
Definition: VOP_Language.h:27
A class abstracting definition of a VOP data type.
virtual UT_StringHolder getMetaType() const =0
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2544
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
virtual bool load(const UT_JSONValue &json)
virtual bool save(UT_JSONValue &json) const
GLuint const GLchar * name
Definition: glcorearb.h:785
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:785
virtual bool isEqual(const VOP_TypeDefinition &other) const =0
Class to store JSON objects as C++ objects.
Definition: UT_JSONValue.h:75
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.
png_infop png_uint_32 flag
Definition: png.h:2242
static const UT_StringHolder METATYPE_VALUE
Override the meta-type string for classes.