HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
VOP_TypeInfo.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_TypeInfo.h ( Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __VOP_TypeInfo__
12 #define __VOP_TypeInfo__
13 
14 #include "VOP_API.h"
15 #include <UT/UT_StringHolder.h>
16 #include "VOP_Types.h"
17 
18 class VOP_Language;
19 class VOP_TypeDefinition;
20 template<typename T> class UT_SharedPtr;
22 
23 
24 // ============================================================================
25 // In general, this is a type meta-name that accepts any struct name.
26 // An empty string does not collide with custom struct type names and
27 // also works well with printf() which is used for connector type name tokens.
28 // The exact meaning is imposed by the use of it:
29 // - auto-detect and adhoc-unpack (etc) vops specify it as input types,
30 // indicating that any struct type is accepted
31 // - some vops test the incoming wire type, and interpret it as a struct type
32 // yet-unresolved to anything concrete
33 #define VOP_STRUCT_TYPE_NAME_ANY ""
34 
35 // ============================================================================
36 /// Class abstracting VOP variable and connector types.
37 /// Unlike the basic VOP_Type enum, this class can represent and refer to any
38 /// type, including structs and custom types.
40 {
41 public:
42  /// @{
43  /// A constructor and a destructor.
44  // NB: explicit keyword is useful during sweeps to convert code from
45  // VOP_Type to VOP_TypeInfo; after that we can remove the keyword
47  const char * type_name = NULL );
48  ~VOP_TypeInfo();
49  /// @}
50 
51  /// Utility function that converts VOP_Type into a VOP_TypeInfo.
52  /// It is used during transition from VOP_Type to VOP_TypeInfo to mark
53  /// the places that should abandon VOP_Type in favour of VOP_TypeInfo,
54  /// but whose conversion is quite involved and likely requires lengthy
55  /// sweeps, and thus is postponed untill later phases.
56  // TODO: convert all places that call this function to use VOP_TypeInfo
57  // directly, instead of going through VOP_Type.
59  { setType( type ); }
60 
61  /// @{
62  /// Sets a new type and additional data for the type info.
63  void setType( VOP_Type type,
64  VOP_Type raw_type = VOP_TYPE_UNDEF,
65  const char *type_name = NULL );
66  void setType( VOP_Type type,
67  const char *type_name );
68  /// @}
69 
70  /// @{ Returns the type enumeration value.
71  VOP_Type getType() const
72  { return myType; }
74  { return myRawType; }
76  { return VOP_BASE_TYPE( myType ); }
77  /// @}
78 
79  /// Returns the official type name.
81  { return myTypeName; }
82 
83  /// Returns the actual type definition for the type represented by object.
84  VOP_TypeDefinitionHandle getTypeDefinitionHandle() const;
85 
86  /// @{ Sets and gets the array length.
87  enum { UNKNOWN_ARRAY_LENGTH = -1 };
89  { myArrayLength = length; }
90  int getArrayLength() const
91  { return myArrayLength; }
92  bool isFixedArrayLength() const
93  { return myArrayLength != UNKNOWN_ARRAY_LENGTH; }
94  /// @}
95 
96  /// Returns a type info that represents an undefined type.
97  static const VOP_TypeInfo & getUndefinedTypeInfo();
98 
99 
100  /// @{ Comparison operators.
101  bool operator==( const VOP_TypeInfo &other ) const;
102  bool operator!=( const VOP_TypeInfo &other ) const;
103  /// @}
104 
105  /// Language will condition the type to an equivalent base type,
106  /// which is useful for comparing types to test assignment compatibility
107  /// (eg, color and vector). Makes the type and raw type equal to the
108  /// type conditioned by the language.
109  void conditionType( const VOP_Language &language );
110 
111  /// Returns true if a variable of this type can be directly assigned
112  /// a value of the src_type type, without any explicit conversion.
113  bool canDirectlyAssign( const VOP_TypeInfo &src_type,
114  const VOP_Language *language = nullptr) const;
115 
116  /// Returns true if the type is valid.
117  bool isValid() const;
118 
119  /// Returns true if the type is an array.
120  bool isArray() const;
121 
122  /// Returns the type of the array element, if this type is an array.
123  VOP_TypeInfo getArrayElementTypeInfo() const;
124 
125  /// Returns true for sturct and class custom type.
126  bool isStructLike() const;
127 
128  /// Returns a type description used for labeling node inputs, outputs,
129  /// and other places with a legible name. Eg, "int", "uniform float",
130  /// "vector array", and "mystruct" (for 'struct mystruct' type).
131  void getDescriptionString( UT_String &description ) const;
132 
133  /// Returns a string that encodes the type information into a single-worded
134  /// string. Eg, "int", "ufloat", "vectora", "struct_mystruct" (for 'struct
135  /// mystruct' type).
136  void getTokenString( UT_String &token ) const;
137 
138  /// Sets the type info from the string representation of that type.
139  /// The string representation should be compatible with the strings
140  /// returned from getDescriptionString() or getTokenString() above.
141  /// Note, the struct types can be only deduced from strings compatible
142  /// with getTokenString(), or if str is "struct" (unnamed struct).
143  void setFromTokenString( const char *token_or_description );
144 
145 private:
146  /// The basic type of a variable or a connector.
147  VOP_Type myType;
148 
149  // The raw (unconditioned) type of the variable or connector. The
150  // raw type is not used for VOP_TypeInfo comparison, but is simply a way of
151  // doing an exact equivalence check when selecting the most appropriate
152  // signature of a scripted VOP.
153  VOP_Type myRawType;
154 
155  /// The name of the type.
156  /// For simple types it is an empty string (tough it could contain the
157  /// official vop type name for simple types too).
158  /// For structs and custom types, it contains the official type name
159  /// recognized by the language & type manager, VOP_LanguageManager.
160  UT_StringHolder myTypeName;
161 
162  /// The length of the array.
163  /// Some languages like OSL require statically determined lengths.
164  int myArrayLength;
165 };
166 
167 #endif
168 
Reprsents a language for which VOPs can generate source code.
Definition: VOP_Language.h:27
A class abstracting definition of a VOP data type.
bool isFixedArrayLength() const
Sets and gets the array length.
Definition: VOP_TypeInfo.h:92
void setArrayLength(int length)
Sets and gets the array length.
Definition: VOP_TypeInfo.h:88
VOP_Type getType() const
Returns the type enumeration value.
Definition: VOP_TypeInfo.h:71
Wrapper around hboost::shared_ptr.
Definition: UT_SharedPtr.h:27
VOP_Type getBaseType() const
Returns the type enumeration value.
Definition: VOP_TypeInfo.h:75
UT_SharedPtr< const VOP_TypeDefinition > VOP_TypeDefinitionHandle
Definition: VOP_TypeInfo.h:20
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
#define VOP_API
Definition: VOP_API.h:10
const UT_StringHolder & getTypeName() const
Returns the official type name.
Definition: VOP_TypeInfo.h:80
#define VOP_BASE_TYPE(type)
Definition: VOP_Types.h:118
int getArrayLength() const
Sets and gets the array length.
Definition: VOP_TypeInfo.h:90
VOP_Type getRawType() const
Returns the type enumeration value.
Definition: VOP_TypeInfo.h:73
void setTypeInfoFromType(VOP_Type type)
Definition: VOP_TypeInfo.h:58
VOP_Type
Definition: VOP_Types.h:24
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
bool operator!=(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:165
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:794