HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CL_ClipIO.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: CL_ClipIO.h
7  *
8  * COMMENTS:
9  * This singleton object stores a set of clip reader and clip writer
10  * objects. When told to read or write a clip file, it choses which
11  * reader or writer to use based on the file extension.
12  */
13 
14 #ifndef __CL_ClipIO_h__
15 #define __CL_ClipIO_h__
16 
17 #include "CL_API.h"
18 #include <UT/UT_IndexedHashMapT.h>
19 class CL_Clip;
20 class CL_ClipReader;
21 class CL_ClipWriter;
22 
24 {
25 public:
26  // Use this static method to access the clipIO singleton object.
27  static CL_ClipIO &inst();
28 
29  // These methods read a clip from a file or write a clip to a file.
30  // If the clip could not be read/written, false will be returned.
31  bool readClip(const char *file_name, CL_Clip &clip);
32  bool writeClip(const char *file_name, const CL_Clip &clip);
33 
34  /// Returns true if the file extension is supported. The input can be the
35  /// full file path.
36  bool canReadFileType(const char *file_name);
37  bool canWriteFileType(const char *file_name);
38 
39  // These methods return information about which file extensions are
40  // supported for reading and writing.
42  { return myClipReaders.entries(); }
43  const char *getReadableExtension(int index) const
44  { return myClipReaders[index]->getKey().getName(); }
45 
47  { return myClipWriters.entries(); }
48  const char *getWritableExtension(int index) const
49  { return myClipWriters[index]->getKey().getName(); }
50 
51  // Clip readers and writers register themselves by calling these methods.
52  // This class assumes that readers and writers are never deleted. Note
53  // that the extension begins with a dot, like it does in UT_IOTable.
54  void registerClipReader(const char *extension,
55  CL_ClipReader &clip_reader);
56  void registerClipWriter(const char *extension,
57  CL_ClipWriter &clip_writer);
58 
59 private:
60  CL_ClipReader *findReader(const char *name) const
61  {
62  MapItem *item=myClipReaders.find(MapKey(name));
63  return item ? item->getKey().getReader() : NULL;
64  }
65  CL_ClipWriter *findWriter(const char *name) const
66  {
67  MapItem *item=myClipWriters.find(MapKey(name));
68  return item ? item->getKey().getWriter() : NULL;
69  }
70 
71  CL_ClipIO();
72  void registerClipHandlers();
73 
74  // Find a CL_ClipReader for the path, searching through compound extensions
75  // (e.g. .clip.gz) from longest to shortest.
76  CL_ClipReader *findReaderForPath(const char *path) const;
77 
78  CL_ClipWriter *findWriterForPath(const char *path) const;
79 
80  class MapKey
81  {
82  public:
83  MapKey(const char *name)
84  {
85  init(name, NULL, NULL);
86  }
87  MapKey(const char *name, CL_ClipReader &reader)
88  {
89  init(name, &reader, NULL);
90  }
91  MapKey(const char *name, CL_ClipWriter &writer)
92  {
93  init(name, NULL, &writer);
94  }
95  MapKey(const MapKey &k)
96  {
97  init(k.myName, k.myReader, k.myWriter);
98  myName.harden(); // Hard copy
99  }
100 
101  void init(const char *name, CL_ClipReader *r, CL_ClipWriter *w)
102  {
103  myName = name; // Shallow copy
104  myReader = r;
105  myWriter = w;
106  }
107 
108  const char *getName() const { return myName; }
109  CL_ClipReader *getReader() const { return myReader; }
110  CL_ClipWriter *getWriter() const { return myWriter; }
111 
112  uint hash() const { return myName.hash(); }
113  bool isEqual(const MapKey &key) const
114  { return myName == key.myName; }
115  bool operator<(const MapKey &key) const
116  { return strcmp(myName, key.myName) < 0; }
117  bool operator==(const MapKey &key) const
118  { return isEqual(key); }
119 
120  private:
121  UT_String myName;
122  CL_ClipReader *myReader;
123  CL_ClipWriter *myWriter;
124  };
127 
130 };
131 
132 // These functions are called from shared objects/dll's to register readers
133 // and writers.
134 extern "C" {
135  SYS_VISIBILITY_EXPORT extern void CLregisterClipReader(void *);
136  SYS_VISIBILITY_EXPORT extern void CLregisterClipWriter(void *);
137 }
138 
139 #endif
#define SYS_VISIBILITY_EXPORT
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
const char * getReadableExtension(int index) const
Definition: CL_ClipIO.h:43
SYS_VISIBILITY_EXPORT void CLregisterClipWriter(void *)
SYS_VISIBILITY_EXPORT void CLregisterClipReader(void *)
#define CL_API
Definition: CL_API.h:10
int getNumReadableExtensions() const
Definition: CL_ClipIO.h:41
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
int getNumWritableExtensions() const
Definition: CL_ClipIO.h:46
PXL_API const char * getName(const ColorSpace *space)
Return the name of the color space.
bool operator<(const GU_TetrahedronFacet &a, const GU_TetrahedronFacet &b)
GLuint const GLchar * name
Definition: glcorearb.h:786
GLuint index
Definition: glcorearb.h:786
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
const char * getWritableExtension(int index) const
Definition: CL_ClipIO.h:48
GLboolean r
Definition: glcorearb.h:1222
IMATH_INTERNAL_NAMESPACE_HEADER_ENTER IMATH_HOSTDEVICE IMATH_CONSTEXPR14 T clip(const T &p, const Box< T > &box) IMATH_NOEXCEPT
Definition: ImathBoxAlgo.h:29
unsigned int uint
Definition: SYS_Types.h:45
OIIO_UTIL_API std::string extension(string_view filepath, bool include_dot=true) noexcept