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_LanguageInfo.h"
16 #include "VOP_Types.h"
17 #include "VOP_TypeDefinition.h"
18 #include <UT/UT_Notifier.h>
19 #include <UT/UT_UniquePtr.h>
20 #include <UT/UT_StringMap.h>
26 class vop_TypeDefInfo;
27 class vop_LangDefInfo;
28 
29 
30 // ============================================================================
31 /// Obtains the manager for vop languages and their types.
33 
34 
35 // ============================================================================
36 /// A class for managing the languages and custom data types in VOPs.
38 {
39 public:
40  /// @{
41  /// Default constructor and destructor
44  /// @}
45 
46 
47  /// @{ Returns language type guessed from shader's render mask.
48  /// Prefer to use language info rather than type, because
49  /// it can handle user-defined languages.
50  VOP_LanguageInfo getLanguageInfoFromRenderMask(
51  const UT_StringRef &mask ) const;
53  const UT_StringRef &mask ) const
54  { return getLanguageInfoFromRenderMask(
55  mask ).getType(); }
56  bool isMantraVexFromRenderMask(
57  const UT_StringRef &mask ) const;
58  /// @}
59 
60  /// @{ Returns language of a given type.
61  /// NOTE: returned language is often held by VOP_Node, so can't be deleted.
62  const VOP_Language *getLanguage( const VOP_LanguageInfo &lang_info ) const;
63  const VOP_Language *getLanguage( const UT_StringRef &lang_name ) const;
65  { return getLanguage( VOP_LanguageInfo( type )); }
66  /// @}
67 
68  /// Gets the list of all available languages.
69  void getLanguageNames( UT_StringArray &lang_names ) const;
70 
71  /// Tests if the manager has a definition for the given name.
72  bool hasLanguage( const UT_StringRef &lang_name ) const;
73 
74  /// Gets the source that provides the full definition for the language.
75  VOP_TypeDefinitionSource * getLanguageSource(
76  const UT_StringRef &lang_name ) const;
77 
78  /// Registers a new vop language whose full definition is provided by
79  /// the source upon request.
80  /// If 'lang_name' already exists, the new source (and new definition)
81  /// is going to be used after this registration.
82  void registerLanguage( const UT_StringRef &lang_name,
84 
85  /// Removes the language from the manager. After unregistration,
86  /// this language definition will no longer be availble from manager.
87  /// Issues an event about removed language.
88  void unregisterLanguage( const UT_StringRef &lang_name );
89 
90 
91 
92 
93  /// Gets the list of all available type definitions.
94  void getTypeDefinitionNames(
95  UT_StringArray &type_names ) const;
96 
97  /// Tests if the manager has a definition for the given name.
98  bool hasTypeDefinition( const UT_StringRef &type_name) const;
99 
100  /// Gets the type definition based on the type name.
101  VOP_TypeDefinitionHandle getTypeDefinitionHandle(
102  const UT_StringRef &type_name) const;
103 
104  /// Gets the source tha provides the full definition for the type.
105  VOP_TypeDefinitionSource * getTypeDefinitionSource(
106  const UT_StringRef &type_name ) const;
107 
108 
109 
110  /// Registers a new vop type whose full definition is provided by
111  /// the source upon request.
112  /// If 'type_name' already exists, the new source (and new definition)
113  /// is going to be used after this registration.
114  /// If 'old_type_name' is provided, the old type is renamed to the new name
115  /// whose full definition is provided by the given source; after
116  /// renaming, the old name is unregistered and becomes unavailable.
117  /// Issues an event about added or renamed type.
118  void registerTypeDefinition( const UT_StringRef &type_name,
120  const UT_StringRef & old_type_name =
121  UT_StringRef() );
122 
123  /// Removes the type from the manager. After unregistration,
124  /// this type definition will no longer be availble from manager.
125  /// Issues an event about removed type.
126  void unregisterTypeDefinition(const UT_StringRef &type_name);
127 
128  /// Marks the given type definition as dirty.
129  /// The next time someone requests full definition handle, the manager will
130  /// ask the source for an update before returning the refreshed definition.
131  /// Issues an event about type definition change.
132  void dirtyTypeDefinition( const UT_StringRef &type_name );
133 
134  /// Obtains a unique type name not used in the manager yet.
135  void generateUniqueTypeName( UT_String &type_name,
136  bool use_guid );
137 
138  /// For registering a GUI editor callback.
139  typedef void (*EditCallback)(const UT_StringRef &type_name);
140  static void setEditCallback( VOP_LanguageManager::EditCallback cb );
141 
142  /// Brings up a type editor GUI for editing the given type.
143  void editType( const UT_StringRef &type_name );
144 
145 
146  /// Returns an object that loads and saves the definitions to and from file.
147  VOP_TypeDefinitionFileLoader & getFileLoader();
148 
149 
150 
151  /// A convenience method that unregisters all the types and languages
152  /// associated with the given source.
153  /// Issues events about removed types.
154  void unregisterTypeDefinitionSource(
156 
157 
158  /// Gets the notifier that sends events triggered by various changes
159  /// to the data structures overseen by the manager.
162  { return myEventNotifier; }
163 
164 
165 private:
166  /// All defined data types (aka, wire type or loosly variable type)
167  /// for all languages.
169 
170  /// All defined data types (aka, wire type or loosly variable type)
171  /// for all languages.
173 
174  /// Notifier object for manager's events.
176 
177  /// The default loader of definitions stored in files.
179 
180  // The callbak that can be invoked to edit a type in a GUI editor.
181  static VOP_LanguageManager::EditCallback theEditCallback;
182 };
183 
184 
185 // ============================================================================
186 /// A class describing notification events emitted by the language manager.
188 {
189 public:
190  /// Defines the type of the events that can manager can send out.
192  {
193  LANGUAGE_ADDED, // a new language has been added
194  LANGUAGE_REMOVED, // a language has been removed
195 
196  TYPE_ADDED, // a new vop type has been added
197  TYPE_CHANGED, // a vop type has been updated
198  TYPE_REMOVED, // a vop type has been removed
199  TYPE_RENAMED // a vop type has been renamed
200  };
201 
202  /// Constructor
204  const UT_StringRef &name,
205  const UT_StringRef &new_name = UT_StringRef() );
206 
207  /// @{ Accessors.
208  /// Note, if the event type does not involve certain data,
209  /// the accessor for that data will return an empty string.
210  VOP_LanguageManagerEvent::EventType getEventType() const;
211  const UT_StringHolder & getVopTypeName() const;
212  const UT_StringHolder & getNewVopTypeName() const;
213  /// @}
214 
215 private:
216  /// The type of the event.
218 
219  /// The soure entity (such as a type name) the event is about.
220  UT_StringHolder myName;
221  UT_StringHolder myNewName;
222 };
223 
224 #endif
225 
Reprsents a language for which VOPs can generate source code.
Definition: VOP_Language.h:29
A class describing notification events emitted by the language manager.
void
Definition: png.h:1083
UT_NotifierImpl< const VOP_LanguageManagerEvent & > & getEventNotifier()
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.
VOP_API VOP_LanguageManager & VOPgetLanguageManager()
Obtains the manager for vop languages and their types.
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
VOP_LanguageType getLanguageTypeFromRenderMask(const UT_StringRef &mask) const
#define VOP_API
Definition: VOP_API.h:10
const VOP_Language * getLanguage(VOP_LanguageType type) const
VOP_LanguageType getType() const
Returns the type enumeration value of the language.
constexpr std::enable_if< I< type_count_base< T >::value, int >::type tuple_type_size(){return subtype_count< typename std::tuple_element< I, T >::type >::value+tuple_type_size< T, I+1 >);}template< typename T > struct type_count< T, typename std::enable_if< is_tuple_like< T >::value >::type >{static constexpr int value{tuple_type_size< T, 0 >)};};template< typename T > struct subtype_count{static constexpr int value{is_mutable_container< T >::value?expected_max_vector_size:type_count< T >::value};};template< typename T, typename Enable=void > struct type_count_min{static const int value{0};};template< typename T >struct type_count_min< T, typename std::enable_if<!is_mutable_container< T >::value &&!is_tuple_like< T >::value &&!is_wrapper< T >::value &&!is_complex< T >::value &&!std::is_void< T >::value >::type >{static constexpr int value{type_count< T >::value};};template< typename T > struct type_count_min< T, typename std::enable_if< is_complex< T >::value >::type >{static constexpr int value{1};};template< typename T >struct type_count_min< T, typename std::enable_if< is_wrapper< T >::value &&!is_complex< T >::value &&!is_tuple_like< T >::value >::type >{static constexpr int value{subtype_count_min< typename T::value_type >::value};};template< typename T, std::size_t I >constexpr typename std::enable_if< I==type_count_base< T >::value, int >::type tuple_type_size_min(){return 0;}template< typename T, std::size_t I > constexpr typename std::enable_if< I< type_count_base< T >::value, int >::type tuple_type_size_min(){return subtype_count_min< typename std::tuple_element< I, T >::type >::value+tuple_type_size_min< T, I+1 >);}template< typename T > struct type_count_min< T, typename std::enable_if< is_tuple_like< T >::value >::type >{static constexpr int value{tuple_type_size_min< T, 0 >)};};template< typename T > struct subtype_count_min{static constexpr int value{is_mutable_container< T >::value?((type_count< T >::value< expected_max_vector_size)?type_count< T >::value:0):type_count_min< T >::value};};template< typename T, typename Enable=void > struct expected_count{static const int value{0};};template< typename T >struct expected_count< T, typename std::enable_if<!is_mutable_container< T >::value &&!is_wrapper< T >::value &&!std::is_void< T >::value >::type >{static constexpr int value{1};};template< typename T > struct expected_count< T, typename std::enable_if< is_mutable_container< T >::value >::type >{static constexpr int value{expected_max_vector_size};};template< typename T >struct expected_count< T, typename std::enable_if<!is_mutable_container< T >::value &&is_wrapper< T >::value >::type >{static constexpr int value{expected_count< typename T::value_type >::value};};enum class object_category:int{char_value=1, integral_value=2, unsigned_integral=4, enumeration=6, boolean_value=8, floating_point=10, number_constructible=12, double_constructible=14, integer_constructible=16, string_assignable=23, string_constructible=24, other=45, wrapper_value=50, complex_number=60, tuple_value=70, container_value=80,};template< typename T, typename Enable=void > struct classify_object{static constexpr object_category value{object_category::other};};template< typename T >struct classify_object< T, typename std::enable_if< std::is_integral< T >::value &&!std::is_same< T, char >::value &&std::is_signed< T >::value &&!is_bool< T >::value &&!std::is_enum< T >::value >::type >{static constexpr object_category value{object_category::integral_value};};template< typename T >struct classify_object< T, typename std::enable_if< std::is_integral< T >::value &&std::is_unsigned< T >::value &&!std::is_same< T, char >::value &&!is_bool< T >::value >::type >{static constexpr object_category value{object_category::unsigned_integral};};template< typename T >struct classify_object< T, typename std::enable_if< std::is_same< T, char >::value &&!std::is_enum< T >::value >::type >{static constexpr object_category value{object_category::char_value};};template< typename T > struct classify_object< T, typename std::enable_if< is_bool< T >::value >::type >{static constexpr object_category value{object_category::boolean_value};};template< typename T > struct classify_object< T, typename std::enable_if< std::is_floating_point< T >::value >::type >{static constexpr object_category value{object_category::floating_point};};template< typename T >struct classify_object< T, typename std::enable_if<!std::is_floating_point< T >::value &&!std::is_integral< T >::value &&std::is_assignable< T &, std::string >::value >::type >{static constexpr object_category value{object_category::string_assignable};};template< typename T >struct classify_object< T, typename std::enable_if<!std::is_floating_point< T >::value &&!std::is_integral< T >::value &&!std::is_assignable< T &, std::string >::value &&(type_count< T >::value==1)&&std::is_constructible< T, std::string >::value >::type >{static constexpr object_category value{object_category::string_constructible};};template< typename T > struct classify_object< T, typename std::enable_if< std::is_enum< T >::value >::type >{static constexpr object_category value{object_category::enumeration};};template< typename T > struct classify_object< T, typename std::enable_if< is_complex< T >::value >::type >{static constexpr object_category value{object_category::complex_number};};template< typename T > struct uncommon_type{using type=typename std::conditional<!std::is_floating_point< T >::value &&!std::is_integral< T >::value &&!std::is_assignable< T &, std::string >::value &&!std::is_constructible< T, std::string >::value &&!is_complex< T >::value &&!is_mutable_container< T >::value &&!std::is_enum< T >::value, std::true_type, std::false_type >::type;static constexpr bool value=type::value;};template< typename T >struct classify_object< T, typename std::enable_if<(!is_mutable_container< T >::value &&is_wrapper< T >::value &&!is_tuple_like< T >::value &&uncommon_type< T >::value)>::type >{static constexpr object_category value{object_category::wrapper_value};};template< typename T >struct classify_object< T, typename std::enable_if< uncommon_type< T >::value &&type_count< T >::value==1 &&!is_wrapper< T >::value &&is_direct_constructible< T, double >::value &&is_direct_constructible< T, int >::value >::type >{static constexpr object_category value{object_category::number_constructible};};template< typename T >struct classify_object< T, typename std::enable_if< uncommon_type< T >::value &&type_count< T >::value==1 &&!is_wrapper< T >::value &&!is_direct_constructible< T, double >::value &&is_direct_constructible< T, int >::value >::type >{static constexpr object_category value{object_category::integer_constructible};};template< typename T >struct classify_object< T, typename std::enable_if< uncommon_type< T >::value &&type_count< T >::value==1 &&!is_wrapper< T >::value &&is_direct_constructible< T, double >::value &&!is_direct_constructible< T, int >::value >::type >{static constexpr object_category value{object_category::double_constructible};};template< typename T >struct classify_object< T, typename std::enable_if< is_tuple_like< T >::value &&((type_count< T >::value >=2 &&!is_wrapper< T >::value)||(uncommon_type< T >::value &&!is_direct_constructible< T, double >::value &&!is_direct_constructible< T, int >::value)||(uncommon_type< T >::value &&type_count< T >::value >=2))>::type >{static constexpr object_category value{object_category::tuple_value};};template< typename T > struct classify_object< T, typename std::enable_if< is_mutable_container< T >::value >::type >{static constexpr object_category value{object_category::container_value};};template< typename T, enable_if_t< classify_object< T >::value==object_category::char_value, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"CHAR";}template< typename T, enable_if_t< classify_object< T >::value==object_category::integral_value||classify_object< T >::value==object_category::integer_constructible, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"INT";}template< typename T, enable_if_t< classify_object< T >::value==object_category::unsigned_integral, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"UINT";}template< typename T, enable_if_t< classify_object< T >::value==object_category::floating_point||classify_object< T >::value==object_category::number_constructible||classify_object< T >::value==object_category::double_constructible, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"FLOAT";}template< typename T, enable_if_t< classify_object< T >::value==object_category::enumeration, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"ENUM";}template< typename T, enable_if_t< classify_object< T >::value==object_category::boolean_value, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"BOOLEAN";}template< typename T, enable_if_t< classify_object< T >::value==object_category::complex_number, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"COMPLEX";}template< typename T, enable_if_t< classify_object< T >::value >=object_category::string_assignable &&classify_object< T >::value<=object_category::other, detail::enabler >=detail::dummy >constexpr const char *type_name(){return"TEXT";}template< typename T, enable_if_t< classify_object< T >::value==object_category::tuple_value &&type_count_base< T >::value >=2, detail::enabler >=detail::dummy >std::string type_name();template< typename T, enable_if_t< classify_object< T >::value==object_category::container_value||classify_object< T >::value==object_category::wrapper_value, detail::enabler >=detail::dummy >std::string type_name();template< typename T, enable_if_t< classify_object< T >::value==object_category::tuple_value &&type_count_base< T >::value==1, detail::enabler >=detail::dummy >inline std::string type_name(){return type_name< typename std::decay< typename std::tuple_element< 0, T >::type >::type >);}template< typename T, std::size_t I >inline typename std::enable_if< I==type_count_base< T >::value, std::string >::type tuple_name(){return std::string{};}template< typename T, std::size_t I >inline typename std::enable_if<(I< type_count_base< T >::value), std::string >::type tuple_name(){auto str=std::string{type_name< typename std::decay< typename std::tuple_element< I, T >::type >::type >)}+ ','+tuple_name< T, I+1 >);if(str.back()== ',') str.pop_back();return str;}template< typename T, enable_if_t< classify_object< T >::value==object_category::tuple_value &&type_count_base< T >::value >=2, detail::enabler > > std::string type_name()
Recursively generate the tuple type name.
Definition: CLI11.h:1729
GLint GLuint mask
Definition: glcorearb.h:124
void(* EditCallback)(const UT_StringRef &type_name)
For registering a GUI editor callback.
GLuint const GLchar * name
Definition: glcorearb.h:786
A class for handling files and HDAs as sources of vop type definitions.
Represents a source of vop type definitions saved in files or inside HDAs.
type
Definition: core.h:1059
VOP_LanguageType
Definition: VOP_Types.h:186
UT_SharedPtr< const VOP_TypeDefinition > VOP_TypeDefinitionHandle
Define a handle for the type definition objects.
GLenum src
Definition: glcorearb.h:1793