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