HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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  const UT_StringHolder & getName() const
45  { return getTypeName(); }
46  /// @}
47  //
48  /// @{ Sets and gets the type definition unique name identifier.
49  const UT_StringHolder & getTypeLabel() const;
50  void setTypeLabel( const char *label );
51  /// @}
52 
53  /// @{ Methods for the color of the connector of this type.
54  const UT_Color * getConnectorColor() const;
55  void setSpecificConnectorColor(const UT_Color &clr);
56  void setDefaultConnectorColor();
57  /// @}
58 
59  /// @{ Sets and gets the type name used in the generated code.
60  void setCodeTypeName( const char *code_type_name );
61  const UT_StringHolder & getCodeTypeName() const;
62  const UT_StringHolder & getCodeTypeNameRaw() const;
63  /// @}
64 
65  /// The key in the JSONValue map dictionary that denotes the metatype
66  /// of the type definition (e.g., "struct" or "custom").
68 
69  /// Loads a type definition from a JSON value.
70  /// The JSON value parameter is a map (of type JSON_MAP) containing
71  /// entries relevant to the type.
72  /// Returns true on success, and false on failure.
73  virtual bool load( const UT_JSONValue &json );
74 
75  /// Saves a type definition to a JSON value.
76  /// The JSON value should be a map (of type JSON_MAP).
77  /// Returns true on success, and false on failure.
78  virtual bool save( UT_JSONValue &json ) const;
79 
80 
81  /// @{ Standard comparison operators.
82  bool operator==( const VOP_TypeDefinition &other ) const;
83  bool operator!=( const VOP_TypeDefinition &other ) const;
84  /// @}
85 
86  /// Obtains the source code that defines the type in the programming
87  /// (scripting) language.
88  // TODO: this method should be moved to the language class (or language
89  // manager) because vop type definition should be language agnostic.
90  // Any custom vop types should provide mapping between vop type
91  // and its definition in a specific language.
92  virtual void getTypeDefinitionSourceCode( UT_String &code,
93  const VOP_Language *language ) const;
94 
95 protected:
96  /// Returns true if the types are the same, even though their identifier
97  /// name may be different.
98  virtual bool isEqual( const VOP_TypeDefinition &other ) const = 0;
99 
100 private:
101  /// Name identifying the vop type definition.
102  /// It can be an arbitrary name and does not have to be the same as the
103  /// keyword that declares variables of that type.
104  /// The name should be unique within a given language.
105  UT_StringHolder myTypeName;
106 
107  // Label used for human-readable interfaces. If empty, the name is used.
108  UT_StringHolder myTypeLabel;
109 
110  /// Connector color. If NULL, use the default color for this type.
111  UT_SharedPtr<UT_Color> myConnectorColor;
112 
113  /// The type name used in the generated code.
114  UT_StringHolder myCodeTypeName;
115 };
116 
117 // ============================================================================
118 /// Define a handle for the type definition objects.
120 
121 // ============================================================================
122 /// The simplest form of a custom type implementation.
124 {
125 public:
126  /// Constructor and destructor.
128  ~VOP_CustomTypeDefinition() override;
129 
130  /// @{ Saves to or loades from a JSON value associated with given key.
132  UT_StringHolder getMetaType() const override;
133  /// @}
134 
135 protected:
136  /// @{ Standard overrides from the base class
137  bool isEqual(
138  const VOP_TypeDefinition &other
139  ) const override;
140  /// @}
141 };
142 
143 #endif
144 
Reprsents a language for which VOPs can generate source code.
Definition: VOP_Language.h:29
A class abstracting definition of a VOP data type.
const UT_StringHolder & getName() const
Sets and gets the type definition unique name identifier.
virtual UT_StringHolder getMetaType() const =0
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2545
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
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:36
static const UT_StringHolder METATYPE_KEY
GLuint const GLchar * name
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
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.