HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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  // Note that the extension starts with ".".
35  bool canReadFileType(const char *extension);
36  bool canWriteFileType(const char *extension);
37 
38  // These methods return information about which file extensions are
39  // supported for reading and writing.
41  { return myClipReaders.entries(); }
42  const char *getReadableExtension(int index) const
43  { return myClipReaders[index]->getKey().getName(); }
44 
46  { return myClipWriters.entries(); }
47  const char *getWritableExtension(int index) const
48  { return myClipWriters[index]->getKey().getName(); }
49 
50  // Clip readers and writers register themselves by calling these methods.
51  // This class assumes that readers and writers are never deleted. Note
52  // that the extension begins with a dot, like it does in UT_IOTable.
53  void registerClipReader(const char *extension,
54  CL_ClipReader &clip_reader);
55  void registerClipWriter(const char *extension,
56  CL_ClipWriter &clip_writer);
57 
58 protected:
59 
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 private:
72  CL_ClipIO();
73  void registerClipHandlers();
74 
75  // Find a CL_ClipReader for the path, searching through compound extensions
76  // (e.g. .clip.gz) from longest to shortest.
77  CL_ClipReader *findReaderForPath(const char *path) const;
78 
79  class MapKey
80  {
81  public:
82  MapKey(const char *name)
83  {
84  init(name, NULL, NULL);
85  }
86  MapKey(const char *name, CL_ClipReader &reader)
87  {
88  init(name, &reader, NULL);
89  }
90  MapKey(const char *name, CL_ClipWriter &writer)
91  {
92  init(name, NULL, &writer);
93  }
94  MapKey(const MapKey &k)
95  {
96  init(k.myName, k.myReader, k.myWriter);
97  myName.harden(); // Hard copy
98  }
99 
100  void init(const char *name, CL_ClipReader *r, CL_ClipWriter *w)
101  {
102  myName = name; // Shallow copy
103  myReader = r;
104  myWriter = w;
105  }
106 
107  const char *getName() const { return myName; }
108  CL_ClipReader *getReader() const { return myReader; }
109  CL_ClipWriter *getWriter() const { return myWriter; }
110 
111  uint hash() const { return myName.hash(); }
112  bool isEqual(const MapKey &key) const
113  { return myName == key.myName; }
114  bool operator<(const MapKey &key) const
115  { return strcmp(myName, key.myName) < 0; }
116 
117  private:
118  UT_String myName;
119  CL_ClipReader *myReader;
120  CL_ClipWriter *myWriter;
121  };
124 
127 };
128 
129 // These functions are called from shared objects/dll's to register readers
130 // and writers.
131 extern "C" {
132  SYS_VISIBILITY_EXPORT extern void CLregisterClipReader(void *);
133  SYS_VISIBILITY_EXPORT extern void CLregisterClipWriter(void *);
134 }
135 
136 #endif
#define SYS_VISIBILITY_EXPORT
GLsizei const GLchar *const * path
Definition: glcorearb.h:3340
const char * getReadableExtension(int index) const
Definition: CL_ClipIO.h:42
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:40
int getNumWritableExtensions() const
Definition: CL_ClipIO.h:45
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:39
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:47
GLboolean r
Definition: glcorearb.h:1221
CL_ClipReader * findReader(const char *name) const
Definition: CL_ClipIO.h:60
CL_ClipWriter * findWriter(const char *name) const
Definition: CL_ClipIO.h:65