HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VOP_LanguageManager.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_LanguageManager.h ( VOP Library, C++)
7  *
8  * COMMENTS: Class for managing vop languages, their properties and types.
9  */
10 
11 #ifndef __VOP_LanguageManager__
12 #define __VOP_LanguageManager__
13 
14 #include "VOP_API.h"
15 #include "VOP_Types.h"
16 #include "VOP_TypeDefinition.h"
17 #include <UT/UT_Notifier.h>
18 #include <UT/UT_StringMap.h>
24 class vop_DefinitionInfo;
25 
26 
27 // ============================================================================
28 /// Obtains the manager for vop languages and their types.
30 
31 
32 // ============================================================================
33 /// A class for managing the languages and custom data types in VOPs.
35 {
36 public:
37  /// @{
38  /// Default constructor and destructor
41  /// @}
42 
43 
44  /// Returns language type guessed from shader's render mask.
45  VOP_LanguageType getLanguageTypeFromRenderMask( const char *mask ) const;
46  bool isMantraVexFromRenderMask( const char *mask ) const;
47 
48  /// Returns language of a given type.
49  // TODO: return const language
50  VOP_Language * getLanguage( VOP_LanguageType type ) const;
51 
52  /// Gets the list of all available type definitions.
53  void getTypeDefinitionNames(
54  UT_StringArray &type_names ) const;
55 
56  /// Tests if the manager has a definition for the given name.
57  bool hasTypeDefinition( const char *type_name ) const;
58 
59  /// Gets the type definition based on the type name.
61  getTypeDefinitionHandle( const char *type_name ) const;
62 
63  /// Gets the source tha provides the full definition for the type.
65  getTypeDefinitionSource( const char *type_name ) const;
66 
67 
68 
69  /// Registers a new vop type whose full definition is provided by
70  /// the source upon request.
71  /// If 'type_name' already exists, the new source (and new definition)
72  /// is going to be used after this registration.
73  /// If 'old_type_name' is provided, the old type is renamed to the new name
74  /// whose full definition is provided by the given source; after
75  /// renaming, the old name is unregistered and becomes unavailable.
76  /// Issues an event about added or renamed type.
77  void registerTypeDefinition( const char *type_name,
79  const char * old_type_name = NULL );
80 
81  /// Removes the type from the manager. After unregistration,
82  /// this type definition will no longer be availble from manager.
83  /// Issues an event about removed type.
84  void unregisterTypeDefinition( const char *type_name );
85 
86  /// A convenience method that unregisters all the types associated
87  /// with the given source. Equivalent to calling unregisterTypeDefinition()
88  /// on all types registered with the given source (ie, whose definitions
89  /// are provided by this source).
90  /// Issues events about removed types.
91  void unregisterTypeDefinitionSource(
93 
94  /// Marks the given type definition as dirty.
95  /// The next time someone requests full definition handle, the manager will
96  /// ask the source for an update before returning the refreshed definition.
97  /// Issues an event about type definition change.
98  void dirtyTypeDefinition( const char *type_name );
99 
100 
101  /// Obtains a unique type name not used in the manager yet.
102  void generateUniqueTypeName( UT_String &type_name,
103  bool use_guid );
104 
105 
106  /// Returns an object that loads and saves the definitions to and from file.
107  VOP_TypeDefinitionFileLoader & getFileLoader();
108 
109 
110  /// For registering a GUI editor callback.
111  typedef void (*EditCallback)(const char *type_name);
112  static void setEditCallback( VOP_LanguageManager::EditCallback cb );
113 
114  /// Brings up a type editor GUI for editing the given type.
115  void editType( const char *type_name );
116 
117 
118 
119  /// Gets the notifier that sends events triggered by various changes
120  /// to the data structures overseen by the manager.
123  { return myEventNotifier; }
124 
125 private:
126  /// Sets the definition source for the info object, also registering
127  /// a deletion interest on the source (to avoid stale pointers).
128  void setDefinitionInfoSource(
129  vop_DefinitionInfo *info,
131 
132  /// @{
133  /// Helper methods to find, create, and remove the type definition info
134  /// from the table.
135  vop_DefinitionInfo* findDefinitionInfo( const char *type_name ) const;
136  vop_DefinitionInfo* findOrCreateDefinitionInfo( const char *type_name );
137  void removeDefinitionInfo( const char *type_name );
138  /// @}
139 
140 private:
141  /// All defined data types (aka, wire type or loosly variable type)
142  /// for all languages.
143  UT_StringMap< vop_DefinitionInfo* > myDefinitionInfos;
144 
145  /// Notifier object for manager's events.
147 
148  /// The default loader of definitions stored in files.
149  VOP_TypeDefinitionFileLoader * myFileLoader;
150 
151  // The callbak that can be invoked to edit a type in a GUI editor.
152  static VOP_LanguageManager::EditCallback theEditCallback;
153 };
154 
155 
156 // ============================================================================
157 /// A class describing notification events emitted by the language manager.
159 {
160 public:
161  /// Defines the type of the events that can manager can send out.
163  {
164  TYPE_ADDED, // a new vop type has been added
165  TYPE_CHANGED, // a vop type has been updated
166  TYPE_REMOVED, // a vop type has been removed
167  TYPE_RENAMED // a vop type has been renamed
168  };
169 
170  /// Constructor
172  const char *vop_type_name,
173  const char *new_vop_type_name = NULL );
174 
175  /// @{ Accessors.
176  /// Note, if the event type does not involve certain data,
177  /// the accessor for that data will return an empty string.
178  VOP_LanguageManagerEvent::EventType getEventType() const;
179  const UT_String & getVopTypeName() const;
180  const UT_String & getNewVopTypeName() const;
181  /// @}
182 
183 private:
184  /// The type of the event.
186 
187  /// The soure entity (such as a type name) the event is about.
188  UT_String myVopTypeName;
189  UT_String myNewVopTypeName;
190 };
191 
192 #endif
193 
Reprsents a language for which VOPs can generate source code.
Definition: VOP_Language.h:27
A class describing notification events emitted by the language manager.
UT_NotifierImpl< const VOP_LanguageManagerEvent & > & getEventNotifier()
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLint GLuint mask
Definition: glcorearb.h:123
EventType
Defines the type of the events that can manager can send out.
A class for managing the languages and custom data types in VOPs.
A generic source of the vop (connector wire) type definitions.
VOP_API VOP_LanguageManager & VOPgetLanguageManager()
Obtains the manager for vop languages and their types.
void(* EditCallback)(const char *type_name)
For registering a GUI editor callback.
#define VOP_API
Definition: VOP_API.h:10
A class for handling files and HDAs as sources of vop type definitions.
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
Represents a source of vop type definitions saved in files or inside HDAs.
VOP_LanguageType
Definition: VOP_Types.h:158
UT_SharedPtr< const VOP_TypeDefinition > VOP_TypeDefinitionHandle
Define a handle for the type definition objects.
GLenum src
Definition: glcorearb.h:1792