HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 
47  /// Returns language of a given type.
48  // TODO: return const language
49  VOP_Language * getLanguage( VOP_LanguageType type ) const;
50 
51  /// Gets the list of all available type definitions.
52  void getTypeDefinitionNames(
53  UT_StringArray &type_names ) const;
54 
55  /// Tests if the manager has a definition for the given name.
56  bool hasTypeDefinition( const char *type_name ) const;
57 
58  /// Gets the type definition based on the type name.
60  getTypeDefinitionHandle( const char *type_name ) const;
61 
62  /// Gets the source tha provides the full definition for the type.
64  getTypeDefinitionSource( const char *type_name ) const;
65 
66 
67 
68  /// Registers a new vop type whose full definition is provided by
69  /// the source upon request.
70  /// If 'type_name' already exists, the new source (and new definition)
71  /// is going to be used after this registration.
72  /// If 'old_type_name' is provided, the old type is renamed to the new name
73  /// whose full definition is provided by the given source; after
74  /// renaming, the old name is unregistered and becomes unavailable.
75  /// Issues an event about added or renamed type.
76  void registerTypeDefinition( const char *type_name,
78  const char * old_type_name = NULL );
79 
80  /// Removes the type from the manager. After unregistration,
81  /// this type definition will no longer be availble from manager.
82  /// Issues an event about removed type.
83  void unregisterTypeDefinition( const char *type_name );
84 
85  /// A convenience method that unregisters all the types associated
86  /// with the given source. Equivalent to calling unregisterTypeDefinition()
87  /// on all types registered with the given source (ie, whose definitions
88  /// are provided by this source).
89  /// Issues events about removed types.
90  void unregisterTypeDefinitionSource(
92 
93  /// Marks the given type definition as dirty.
94  /// The next time someone requests full definition handle, the manager will
95  /// ask the source for an update before returning the refreshed definition.
96  /// Issues an event about type definition change.
97  void dirtyTypeDefinition( const char *type_name );
98 
99 
100  /// Obtains a unique type name not used in the manager yet.
101  void generateUniqueTypeName( UT_String &type_name,
102  bool use_guid );
103 
104 
105  /// Returns an object that loads and saves the definitions to and from file.
106  VOP_TypeDefinitionFileLoader & getFileLoader();
107 
108 
109  /// For registering a GUI editor callback.
110  typedef void (*EditCallback)(const char *type_name);
111  static void setEditCallback( VOP_LanguageManager::EditCallback cb );
112 
113  /// Brings up a type editor GUI for editing the given type.
114  void editType( const char *type_name );
115 
116 
117 
118  /// Gets the notifier that sends events triggered by various changes
119  /// to the data structures overseen by the manager.
122  { return myEventNotifier; }
123 
124 private:
125  /// Sets the definition source for the info object, also registering
126  /// a deletion interest on the source (to avoid stale pointers).
127  void setDefinitionInfoSource(
128  vop_DefinitionInfo *info,
130 
131  /// @{
132  /// Helper methods to find, create, and remove the type definition info
133  /// from the table.
134  vop_DefinitionInfo* findDefinitionInfo( const char *type_name ) const;
135  vop_DefinitionInfo* findOrCreateDefinitionInfo( const char *type_name );
136  void removeDefinitionInfo( const char *type_name );
137  /// @}
138 
139 private:
140  /// All defined data types (aka, wire type or loosly variable type)
141  /// for all languages.
142  UT_StringMap< vop_DefinitionInfo* > myDefinitionInfos;
143 
144  /// Notifier object for manager's events.
146 
147  /// The default loader of definitions stored in files.
148  VOP_TypeDefinitionFileLoader * myFileLoader;
149 
150  // The callbak that can be invoked to edit a type in a GUI editor.
151  static VOP_LanguageManager::EditCallback theEditCallback;
152 };
153 
154 
155 // ============================================================================
156 /// A class describing notification events emitted by the language manager.
158 {
159 public:
160  /// Defines the type of the events that can manager can send out.
162  {
163  TYPE_ADDED, // a new vop type has been added
164  TYPE_CHANGED, // a vop type has been updated
165  TYPE_REMOVED, // a vop type has been removed
166  TYPE_RENAMED // a vop type has been renamed
167  };
168 
169  /// Constructor
171  const char *vop_type_name,
172  const char *new_vop_type_name = NULL );
173 
174  /// @{ Accessors.
175  /// Note, if the event type does not involve certain data,
176  /// the accessor for that data will return an empty string.
177  VOP_LanguageManagerEvent::EventType getEventType() const;
178  const UT_String & getVopTypeName() const;
179  const UT_String & getNewVopTypeName() const;
180  /// @}
181 
182 private:
183  /// The type of the event.
185 
186  /// The soure entity (such as a type name) the event is about.
187  UT_String myVopTypeName;
188  UT_String myNewVopTypeName;
189 };
190 
191 #endif
192 
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.
Wrapper around hboost::shared_ptr.
Definition: UT_SharedPtr.h:27
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
GLenum src
Definition: glcorearb.h:1792