HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
VOP_TypeDefinition.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 describes a generic vop type definition for complex types.
9  * A vop type corresponds to the (wire) connector types on nodes.
10  * Simple types don't need a definition, but custom and complex
11  * types like structs need a way to describe their members, etc.
12  */
13 
14 #ifndef __VOP_TypeDefinition__
15 #define __VOP_TypeDefinition__
16 
17 #include "VOP_API.h"
18 #include <UT/UT_SharedPtr.h>
19 #include <UT/UT_StringHolder.h>
20 
21 class VOP_Language;
22 class UT_String;
23 class UT_Color;
24 class UT_JSONValue;
25 
26 
27 // ============================================================================
28 /// A class abstracting definition of a VOP data type.
30 {
31 public:
32  /// Constructor and destructor.
34  virtual ~VOP_TypeDefinition();
35 
36  /// Returns what sort of type this is. (eg, "struct", "class", "custom").
37  /// It is used in JSON files to identify the type definition implementation
38  /// factory and to tell in general the kind of a type.
39  virtual UT_StringHolder getMetaType() const = 0;
40 
41  /// @{ Sets and gets the type definition unique name identifier.
42  const UT_StringHolder & getTypeName() const;
43  void setTypeName( const char *name );
44  /// @}
45  //
46  /// @{ Sets and gets the type definition unique name identifier.
47  const UT_StringHolder & getTypeLabel() const;
48  void setTypeLabel( const char *label );
49  /// @}
50 
51  /// @{ Methods for the color of the connector of this type.
52  const UT_Color * getConnectorColor() const;
53  void setSpecificConnectorColor(const UT_Color &clr);
54  void setDefaultConnectorColor();
55  /// @}
56 
57  /// @{ Sets and gets the type name used in the generated code.
58  void setCodeTypeName( const char *code_type_name );
59  const UT_StringHolder & getCodeTypeName() const;
60  const UT_StringHolder & getCodeTypeNameRaw() const;
61  /// @}
62 
63  /// The key in the JSONValue map dictionary that denotes the metatype
64  /// of the type definition (e.g., "struct" or "custom").
66 
67  /// Loads a type definition from a JSON value.
68  /// The JSON value parameter is a map (of type JSON_MAP) containing
69  /// entries relevant to the type.
70  /// Returns true on success, and false on failure.
71  virtual bool load( const UT_JSONValue &json );
72 
73  /// Saves a type definition to a JSON value.
74  /// The JSON value should be a map (of type JSON_MAP).
75  /// Returns true on success, and false on failure.
76  virtual bool save( UT_JSONValue &json ) const;
77 
78 
79  /// @{ Standard comparison operators.
80  bool operator==( const VOP_TypeDefinition &other ) const;
81  bool operator!=( const VOP_TypeDefinition &other ) const;
82  /// @}
83 
84  /// Obtains the source code that defines the type in the programming
85  /// (scripting) language.
86  // TODO: this method should be moved to the language class (or language
87  // manager) because vop type definition should be language agnostic.
88  // Any custom vop types should provide mapping between vop type
89  // and its definition in a specific language.
90  virtual void getTypeDefinitionSourceCode( UT_String &code,
91  const VOP_Language *language ) const;
92 
93 protected:
94  /// Returns true if the types are the same, even though their identifier
95  /// name may be different.
96  virtual bool isEqual( const VOP_TypeDefinition &other ) const = 0;
97 
98 private:
99  /// Name identifying the vop type definition.
100  /// It can be an arbitrary name and does not have to be the same as the
101  /// keyword that declares variables of that type.
102  /// The name should be unique within a given language.
103  UT_StringHolder myTypeName;
104 
105  // Label used for human-readable interfaces. If empty, the name is used.
106  UT_StringHolder myTypeLabel;
107 
108  /// Connector color. If NULL, use the default color for this type.
109  UT_SharedPtr<UT_Color> myConnectorColor;
110 
111  /// The type name used in the generated code.
112  UT_StringHolder myCodeTypeName;
113 };
114 
115 // ============================================================================
116 /// Define a handle for the type definition objects.
118 
119 // ============================================================================
120 /// The simplest form of a custom type implementation.
122 {
123 public:
124  /// Constructor and destructor.
126  virtual ~VOP_CustomTypeDefinition();
127 
128  /// @{ Saves to or loades from a JSON value associated with given key.
130  virtual UT_StringHolder getMetaType() const;
131  /// @}
132 
133 protected:
134  /// @{ Standard overrides from the base class
135  virtual bool isEqual( const VOP_TypeDefinition &other ) const;
136  /// @}
137 };
138 
139 #endif
140 
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
static const UT_StringHolder METATYPE_VALUE
Saves to or loades from a JSON value associated with given key.
The simplest form of a custom type implementation.
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
#define VOP_API
Definition: VOP_API.h:10
static const UT_StringHolder METATYPE_KEY
GLuint const GLchar * name
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
bool operator!=(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:165
UT_SharedPtr< const VOP_TypeDefinition > VOP_TypeDefinitionHandle
Define a handle for the type definition objects.