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 protected:
60 
61  CL_ClipReader *findReader(const char *name) const
62  {
63  MapItem *item=myClipReaders.find(MapKey(name));
64  return item ? item->getKey().getReader() : NULL;
65  }
66  CL_ClipWriter *findWriter(const char *name) const
67  {
68  MapItem *item=myClipWriters.find(MapKey(name));
69  return item ? item->getKey().getWriter() : NULL;
70  }
71 
72 private:
73  CL_ClipIO();
74  void registerClipHandlers();
75 
76  // Find a CL_ClipReader for the path, searching through compound extensions
77  // (e.g. .clip.gz) from longest to shortest.
78  CL_ClipReader *findReaderForPath(const char *path) const;
79 
80  CL_ClipWriter *findWriterForPath(const char *path) const;
81 
82  class MapKey
83  {
84  public:
85  MapKey(const char *name)
86  {
87  init(name, NULL, NULL);
88  }
89  MapKey(const char *name, CL_ClipReader &reader)
90  {
91  init(name, &reader, NULL);
92  }
93  MapKey(const char *name, CL_ClipWriter &writer)
94  {
95  init(name, NULL, &writer);
96  }
97  MapKey(const MapKey &k)
98  {
99  init(k.myName, k.myReader, k.myWriter);
100  myName.harden(); // Hard copy
101  }
102 
103  void init(const char *name, CL_ClipReader *r, CL_ClipWriter *w)
104  {
105  myName = name; // Shallow copy
106  myReader = r;
107  myWriter = w;
108  }
109 
110  const char *getName() const { return myName; }
111  CL_ClipReader *getReader() const { return myReader; }
112  CL_ClipWriter *getWriter() const { return myWriter; }
113 
114  uint hash() const { return myName.hash(); }
115  bool isEqual(const MapKey &key) const
116  { return myName == key.myName; }
117  bool operator<(const MapKey &key) const
118  { return strcmp(myName, key.myName) < 0; }
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:3340
const char * getReadableExtension(int index) const
Definition: CL_ClipIO.h:43
SYS_VISIBILITY_EXPORT void CLregisterClipWriter(void *)
A thread-safe hash map which stores indexed shared items.
SYS_VISIBILITY_EXPORT void CLregisterClipReader(void *)
#define CL_API
Definition: CL_API.h:10
int getNumReadableExtensions() const
Definition: CL_ClipIO.h:41
int getNumWritableExtensions() const
Definition: CL_ClipIO.h:46
bool operator<(const GU_TetrahedronFacet &a, const GU_TetrahedronFacet &b)
GLuint const GLchar * name
Definition: glcorearb.h:785
unsigned int uint
Definition: SYS_Types.h:40
IMATH_INTERNAL_NAMESPACE_HEADER_ENTER T clip(const T &p, const Box< T > &box)
Definition: ImathBoxAlgo.h:89
GLuint index
Definition: glcorearb.h:785
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
const char * getWritableExtension(int index) const
Definition: CL_ClipIO.h:48
GLboolean r
Definition: glcorearb.h:1221
CL_ClipReader * findReader(const char *name) const
Definition: CL_ClipIO.h:61
CL_ClipWriter * findWriter(const char *name) const
Definition: CL_ClipIO.h:66