HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OP_OTLLibrary.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: OP_OTLLibrary.h ( OTL Library, C++)
7  *
8  * COMMENTS:
9  *
10  */
11 
12 #ifndef __OP_OTLLibrary__
13 #define __OP_OTLLibrary__
14 
15 #include "OP_API.h"
16 #include "OP_OTLDefinition.h"
17 #include "OP_OTLSectionNames.h"
18 #include <VEX/VEX_VexTypes.h>
19 #include <FS/FS_IndexFile.h>
20 #include <UT/UT_Defines.h>
21 #include <UT/UT_String.h>
22 #include <UT/UT_StringHolder.h>
23 #include <UT/UT_SymbolTable.h>
24 #include <UT/UT_TimeGate.h>
25 #include <time.h>
26 
27 
28 // Prefix "oplib:" for referencing OTL library files. Eg, "oplib:/Object/hda".
29 #define OTL_LIBRARY_PREFIX UT_OTL_LIBRARY_PREFIX
30 
31 // Prefix "opdef:" for referencing HDA definition index file ("opdef:/Sop/hda").
32 #define OTL_DEFINITION_PREFIX UT_HDA_DEFINITION_PREFIX
33 
34 #define OTL_INTERNAL "Embedded"
35 #define OTL_INTERNAL_SH "Embedded"_UTsh
36 #define OTL_INTERNAL_META "Current HIP File"
37 #define OTL_INTERNAL_META_SH "Current HIP File"_UTsh
38 #define OTL_FALLBACK_META "Fallback Libraries"
39 #define OTL_OTLSCAN_META "Scanned Asset Library Directories"
40 #define OTL_ROOTHDANAME "hdaroot"
41 
42 
43 
45 {
46 public:
47  OP_OTLLibrary();
48  OP_OTLLibrary(FS_Reader *reader);
49  OP_OTLLibrary(const char *source, const char *metasrc);
50  ~OP_OTLLibrary() override;
51 
52  const UT_StringHolder &getMetaSource() const;
53  const UT_StringHolder &getSource() const;
54 
56  {
57  MOD_TIME_OK, //modifiction time was obtained without errors
58  MOD_TIME_INTERNAL, //error; definition is internal (embedded)
59  MOD_TIME_SAVE_QUIT, //error; user chose save and quit
60  MOD_TIME_DISCARD_QUIT, //error; user chose discard and quit
61  MOD_TIME_EMBED, //error; user chose to embed dummy definition
62  MOD_TIME_REFRESH_ALL, // error: user chose to refresh otls and retry
63  MOD_TIME_LOAD_FILE // error: user chose to load alternative file
64  };
65 
66  /// Checks if filename has a .otl, if not, appends it.
67  /// Respects OTL_INTERNAL and other magic constants.
68  /// Returns true if filename was modified
69  static bool forceOTLExtension(UT_String &filename);
70 
71  /// Constructs a good vfl and vex code section names given the original
72  /// suggestion.
73  SYS_DEPRECATED(13.0)
74  static void getVexAndVflSectionNames( const char * suggestion,
75  UT_String & vexsect, UT_String & vflsect);
76 
77  /// Constructs a valid VEX code section, with an optional prefix.
78  static void getVexCodeSectionName(const char * prefix,
79  UT_String & vex_code_sect);
80 
81  // obtains the source's modification time. If source is not accessible,
82  // a pop-up dialog is displayed to prompt for an action:
83  // save & quit, discard & quit, retry, or embed)
84  // OUTPUTS:
85  // mod_time - a modification time of the source
86  // RETURNS:
87  // status of the attempt of getting modification time
88  OP_ModTimeStatus getSourceModTime(time_t &mod_time,
89  const char *type_name = NULL) const;
90 
91  bool addDefinition(const OP_OTLDefinition &definition,
92  time_t modtime = time_t(-1));
93  bool removeDefinition(int index);
94 
95  int getNumDefinitions() const
96  { return myDefinitions.entries(); }
97  const OP_OTLDefinition &
98  getDefinition(int index) const
99  { return *myDefinitions(index); }
100 
101  int getDefinitionIndex(const char *tablename,
102  const char *opname) const;
103  time_t getDefinitionModTime(int index) const;
104  const UT_StringHolder &getDefinitionName(int index) const;
105  const UT_StringHolder &getDefinitionOpTableName(int index) const;
106  bool getDefinitionIsDummy(int index) const;
107  bool getDefinition(int index,
108  OP_OTLDefinition &definition) const;
109 
110  // Get the FS_IndexFile for an asset definition in this library. Returns
111  // null if no such asset exists. Otherwise, it is up to the caller to
112  // delete the FS_IndexFile returned.
113  // NOTE: that this will NOT properly get the definition index file if the
114  // actual library has not been installed into the scene yet, even if
115  // all you want is an FS_IndexFile.
116  // WARNING: Caller gains ownership of the returned index file. You *MUST*
117  // delete the returned pointer when done to avoid memory leaks.
118  FS_IndexFileHandle getDefinitionIndexFile(
119  const char *tablename, const char *opname) const;
120 
121  // Remove a section from the given definition, if it is empty. This
122  // loads the index file that corresponds to the given section, modifies
123  // it, and then saves the modified section back to the otl. Returns
124  // true when modification occurred.
125  bool removeDefinitionSectionIfEmpty(
126  int index, const char *definition_section);
127 
128  void mergeLibrary(const OP_OTLLibrary &lib);
129 
130  bool expandToDirectory(const char *destdir) override;
131  bool collapseFromDirectory(const char *srcdir) override;
132  void writeFile(std::ostream &os) const override;
133 
134  void setIsBeingRefreshed(bool beingrefreshed);
135  bool getIsBeingRefreshed() const;
136 
137  // Use these methods to start and end source modfication time caching,
138  // preventing redundant stat() calls on the source file when we expect
139  // multiple successive calls to getSourceModTime().
140  void beginCachingSourceModTime();
141  void endCachingSourceModTime();
142 
143  bool getIsModTimeAccessOK() const;
144 
145  const UT_StringArray &getErrorMessages() const;
146 
147  static bool createBackupFile(const char *filename,
148  bool domove = false);
149  static bool isReservedSectionName(const UT_StringRef &sectname);
150  static const char *getEventName(int index);
151  static const UT_StringHolder &getEventSectionName(int index);
152 
153  static const UT_StringHolder &getVexCodeSectionName(VEX_ContextType type);
154  static const UT_StringHolder &getVflCodeSectionName(VEX_ContextType type);
155  static const UT_StringHolder &getEncapsulatedVexSectionName(VEX_ContextType type);
156  static UT_StringHolder getShaderPathWithSection(
157  const UT_StringRef &shader,
159  UT_String *opname = nullptr);
160 
161  // Returns a list of the files that are used in the OTL_Library 'libfile'.
162  // This will ignore extraneous files in the file system.
163  // NOTE: This is only currently implemented for expanded HDAs (OTLs).
164  static bool getFilenames(const UT_StringHolder &libfile,
165  UT_StringArray &filenames);
166 
167  // Get the default meta source to which a library should install. This
168  // will either be OTL_OTLSCAN_META or OTL_INTERNAL_META, depending on
169  // whether or not the library would be found in the scan path.
170  static const char *getDefaultInstallMetaSource(const char *lib_path);
171 
172 private:
173  void readDefinitions();
174  void saveDefinitionsToSection(bool binary);
175 
176  UT_StringHolder mySource;
177  UT_StringHolder myMetaSource;
178  OP_OTLDefinitionArray myDefinitions;
179  UT_SymbolMap<int> myDefinitionIndexMap;
180  UT_StringArray myErrorMessages;
181  int myUseCachedModTime;
182  mutable UT_TimeGate<1000> myModTimeGate;
183  mutable bool myIsModTimeAccessOK;
184  bool myIsBeingRefreshed;
185 };
186 
187 #endif
188 
Class for reading files.
Definition: FS_Reader.h:33
GT_API const UT_StringHolder filename
#define SYS_DEPRECATED(__V__)
const GLuint GLenum const void * binary
Definition: glcorearb.h:1924
const OP_OTLDefinition & getDefinition(int index) const
Definition: OP_OTLLibrary.h:98
int getSource() override
virtual bool collapseFromDirectory(const char *srcdir)
virtual bool expandToDirectory(const char *destdir)
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
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
GLuint shader
Definition: glcorearb.h:785
#define OP_API
Definition: OP_API.h:10
GLuint index
Definition: glcorearb.h:786
VEX_ContextType
Definition: VEX_VexTypes.h:60
type
Definition: core.h:1059
virtual void writeFile(std::ostream &os) const