Cortex  10.0.0-a4
IndexedIO.h
1 //
3 // Copyright (c) 2007-2013, Image Engine Design Inc. All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // * Redistributions in binary form must reproduce the above copyright
13 // notice, this list of conditions and the following disclaimer in the
14 // documentation and/or other materials provided with the distribution.
15 //
16 // * Neither the name of Image Engine Design nor the names of any
17 // other contributors to this software may be used to endorse or
18 // promote products derived from this software without specific prior
19 // written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22 // IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 //
34 
35 #ifndef IE_CORE_INDEXEDIO_H
36 #define IE_CORE_INDEXEDIO_H
37 
38 #include <string>
39 #include <vector>
40 #include <map>
41 #include <stdint.h>
42 
43 #include "OpenEXR/half.h"
44 
45 #include "IECore/Export.h"
46 #include "IECore/RunTimeTyped.h"
47 #include "IECore/InternedString.h"
48 
49 namespace IECore
50 {
51 
52 IE_CORE_FORWARDDECLARE( IndexedIO );
53 
57 class IECORE_API IndexedIO : public RunTimeTyped
58 {
59  public:
60 
61  IE_CORE_DECLARERUNTIMETYPED( IndexedIO, RunTimeTyped );
62 
65  {
66  Read = 1L << 0,
67  Write = 1L << 1,
68  Append = 1L << 2,
69 
70  Shared = 1L << 3,
71  Exclusive = 1L << 4,
72  } ;
73 
74  typedef unsigned OpenMode;
75 
76  typedef enum
77  {
78  Directory=0,
79  File
80  } EntryType;
81 
82 
83  typedef enum
84  {
85  Invalid=0,
86  Float,
87  FloatArray,
88  Double,
89  DoubleArray,
90  Int,
91  IntArray,
92  Long,
95  StringArray,
96  UInt,
97  UIntArray,
98  Char,
99  CharArray,
100  UChar,
101  UCharArray,
102  Half,
103  HalfArray,
104  Short,
105  ShortArray,
106  UShort,
107  UShortArray,
108  Int64,
109  Int64Array,
110  UInt64,
111  UInt64Array,
112  InternedStringArray
113  } DataType;
114 
116  typedef enum {
117  ThrowIfMissing = 0,
118  NullIfMissing,
119  CreateIfMissing
120  } MissingBehaviour;
121 
122  typedef InternedString EntryID;
123  typedef std::vector< EntryID > EntryIDList;
124  class Entry;
125  // singleton representing the root name
126  static const EntryID rootName;
127  // singleton representing the root location (to be passed in the factory function)
128  static const EntryIDList rootPath;
129 
130  typedef IndexedIOPtr (*CreatorFn)(const std::string &, const EntryIDList &, IndexedIO::OpenMode );
131 
140  static IndexedIOPtr create( const std::string &path, const EntryIDList &root, IndexedIO::OpenMode mode);
141 
144  static void supportedExtensions( std::vector<std::string> &extensions );
145 
149  template<class T>
150  struct Description
151  {
152  Description(const std::string &extension) { IndexedIO::registerCreator( extension, &T::create ); }
153  };
154 
155  ~IndexedIO() override;
156 
158  virtual IndexedIO::OpenMode openMode() const = 0;
159 
161  virtual void path( IndexedIO::EntryIDList & ) const = 0;
162 
164  virtual bool hasEntry( const IndexedIO::EntryID &name ) const = 0;
165 
167  virtual const IndexedIO::EntryID &currentEntryId() const = 0;
168 
170  virtual void entryIds( IndexedIO::EntryIDList &names ) const = 0;
171 
172  // Stores in the given array all the ids for the given entry type
173  virtual void entryIds( IndexedIO::EntryIDList &names, IndexedIO::EntryType type ) const = 0;
174 
176  //returns Null pointer if NullIfMissing or creates the child directory if CreateIfMissing.
177  virtual IndexedIOPtr subdirectory( const IndexedIO::EntryID &name, MissingBehaviour missingBehaviour = ThrowIfMissing ) = 0;
178 
180  // ThrowIfMissing or CreateIfMissing, returns Null pointer if NullIfMissing.
181  virtual ConstIndexedIOPtr subdirectory( const IndexedIO::EntryID &name, MissingBehaviour missingBehaviour = ThrowIfMissing ) const = 0;
182 
184  virtual IndexedIO::Entry entry( const IndexedIO::EntryID &name ) const = 0;
185 
187  virtual IndexedIOPtr createSubdirectory( const IndexedIO::EntryID &name ) = 0;
188 
191  virtual void remove( const IndexedIO::EntryID &name ) = 0;
192 
195  virtual void removeAll() = 0;
196 
201  virtual void commit() = 0;
202 
204  virtual IndexedIOPtr parentDirectory() = 0;
205 
207  virtual ConstIndexedIOPtr parentDirectory() const = 0;
208 
210  virtual IndexedIOPtr directory( const IndexedIO::EntryIDList &path, MissingBehaviour missingBehaviour = ThrowIfMissing ) = 0;
211 
213  virtual ConstIndexedIOPtr directory( const IndexedIO::EntryIDList &path, MissingBehaviour missingBehaviour = ThrowIfMissing ) const = 0;
214 
219  virtual void write(const IndexedIO::EntryID &name, const float *x, unsigned long arrayLength) = 0;
220 
225  virtual void write(const IndexedIO::EntryID &name, const double *x, unsigned long arrayLength) = 0;
226 
231  virtual void write(const IndexedIO::EntryID &name, const half *x, unsigned long arrayLength) = 0;
232 
237  virtual void write(const IndexedIO::EntryID &name, const int *x, unsigned long arrayLength) = 0;
238 
243  virtual void write(const IndexedIO::EntryID &name, const int64_t *x, unsigned long arrayLength) = 0;
244 
249  virtual void write(const IndexedIO::EntryID &name, const uint64_t *x, unsigned long arrayLength) = 0;
250 
255  virtual void write(const IndexedIO::EntryID &name, const unsigned int *x, unsigned long arrayLength) = 0;
256 
261  virtual void write(const IndexedIO::EntryID &name, const char *x, unsigned long arrayLength) = 0;
262 
267  virtual void write(const IndexedIO::EntryID &name, const unsigned char *x, unsigned long arrayLength) = 0;
268 
273  virtual void write(const IndexedIO::EntryID &name, const short *x, unsigned long arrayLength) = 0;
274 
279  virtual void write(const IndexedIO::EntryID &name, const unsigned short *x, unsigned long arrayLength) = 0;
280 
285  virtual void write(const IndexedIO::EntryID &name, const std::string *x, unsigned long arrayLength) = 0;
286 
291  virtual void write(const IndexedIO::EntryID &name, const InternedString *x, unsigned long arrayLength) = 0;
292 
296  virtual void write(const IndexedIO::EntryID &name, const float &x) = 0;
297 
301  virtual void write(const IndexedIO::EntryID &name, const double &x) = 0;
302 
306  virtual void write(const IndexedIO::EntryID &name, const half &x) = 0;
307 
311  virtual void write(const IndexedIO::EntryID &name, const int &x) = 0;
312 
316  virtual void write(const IndexedIO::EntryID &name, const int64_t &x) = 0;
317 
321  virtual void write(const IndexedIO::EntryID &name, const uint64_t &x) = 0;
322 
326  virtual void write(const IndexedIO::EntryID &name, const std::string &x) = 0;
327 
331  virtual void write(const IndexedIO::EntryID &name, const unsigned int &x) = 0;
332 
336  virtual void write(const IndexedIO::EntryID &name, const char &x) = 0;
337 
341  virtual void write(const IndexedIO::EntryID &name, const unsigned char &x) = 0;
342 
346  virtual void write(const IndexedIO::EntryID &name, const short &x) = 0;
347 
351  virtual void write(const IndexedIO::EntryID &name, const unsigned short &x) = 0;
352 
357  virtual void read(const IndexedIO::EntryID &name, float *&x, unsigned long arrayLength) const = 0;
358 
363  virtual void read(const IndexedIO::EntryID &name, double *&x, unsigned long arrayLength) const = 0;
364 
369  virtual void read(const IndexedIO::EntryID &name, half *&x, unsigned long arrayLength) const = 0;
370 
375  virtual void read(const IndexedIO::EntryID &name, int *&x, unsigned long arrayLength) const = 0;
376 
381  virtual void read(const IndexedIO::EntryID &name, int64_t *&x, unsigned long arrayLength) const = 0;
382 
387  virtual void read(const IndexedIO::EntryID &name, uint64_t *&x, unsigned long arrayLength) const = 0;
388 
393  virtual void read(const IndexedIO::EntryID &name, unsigned int *&x, unsigned long arrayLength) const = 0;
394 
399  virtual void read(const IndexedIO::EntryID &name, char *&x, unsigned long arrayLength) const = 0;
400 
405  virtual void read(const IndexedIO::EntryID &name, unsigned char *&x, unsigned long arrayLength) const = 0;
406 
411  virtual void read(const IndexedIO::EntryID &name, short *&x, unsigned long arrayLength) const = 0;
412 
417  virtual void read(const IndexedIO::EntryID &name, unsigned short *&x, unsigned long arrayLength) const = 0;
418 
423  virtual void read(const IndexedIO::EntryID &name, std::string *&x, unsigned long arrayLength) const = 0;
424 
429  virtual void read(const IndexedIO::EntryID &name, InternedString *&x, unsigned long arrayLength) const = 0;
430 
434  virtual void read(const IndexedIO::EntryID &name, float &x) const = 0;
435 
439  virtual void read(const IndexedIO::EntryID &name, double &x) const = 0;
440 
444  virtual void read(const IndexedIO::EntryID &name, half &x) const = 0;
445 
449  virtual void read(const IndexedIO::EntryID &name, int &x) const = 0;
450 
454  virtual void read(const IndexedIO::EntryID &name, int64_t &x) const = 0;
455 
459  virtual void read(const IndexedIO::EntryID &name, uint64_t &x) const = 0;
460 
464  virtual void read(const IndexedIO::EntryID &name, std::string &x) const = 0;
465 
469  virtual void read(const IndexedIO::EntryID &name, unsigned int &x) const = 0;
470 
474  virtual void read(const IndexedIO::EntryID &name, char &x) const = 0;
475 
479  virtual void read(const IndexedIO::EntryID &name, unsigned char &x) const = 0;
480 
484  virtual void read(const IndexedIO::EntryID &name, short &x) const = 0;
485 
489  virtual void read(const IndexedIO::EntryID &name, unsigned short &x) const = 0;
490 
492  class IECORE_API Entry
493  {
494  public:
495  Entry();
496 
497  Entry( const EntryID &id, EntryType eType, DataType dType, unsigned long arrayLength);
498 
500  const EntryID &id() const;
501 
503  EntryType entryType() const;
504 
507  DataType dataType() const;
508 
510  bool isArray() const;
511 
513  unsigned long arrayLength() const;
514 
516  static bool isArray( DataType dType );
517 
518  protected:
519 
520  EntryID m_ID;
521  EntryType m_entryType;
522  DataType m_dataType;
523  unsigned long m_arrayLength;
524  };
525 
526  // Method for establishing flattened size of a data object
527  template<typename T>
528  struct DataSizeTraits;
529 
530  // Method for flatting/unflattening data objects
531  template<typename T>
532  struct DataFlattenTraits;
533 
534  template<typename T>
535  struct DataTypeTraits;
536 
537  protected:
538 
539  // Throw an exception if the entry is not readable
540  virtual void readable(const IndexedIO::EntryID &name) const;
541 
542  // Throw an exception if the entry is not writable
543  virtual void writable(const IndexedIO::EntryID &name) const;
544 
545  static void validateOpenMode(IndexedIO::OpenMode &mode);
546 
547  private:
549  static void registerCreator( const std::string &extension, CreatorFn f );
550 
551  typedef std::map<std::string, CreatorFn> CreatorMap;
552  static CreatorMap &getCreateFns() { static CreatorMap *g_createFns = new CreatorMap(); return *g_createFns; }
553 
554 };
555 
556 } // namespace IECore
557 
558 #include "IndexedIO.inl"
559 
560 #endif // IE_CORE_INDEXEDIO_H
OpenModeFlags
General enums and low level structures.
Definition: IndexedIO.h:64
Obsolete.
Definition: IndexedIO.h:94
Definition: IndexedIO.h:57
DataType
Definition: IndexedIO.h:83
Definition: IndexedIO.h:150
Obsolete.
Definition: IndexedIO.h:93
MissingBehaviour
Enum used to specify behavior when querying child directories.
Definition: IndexedIO.h:116
Definition: InternedString.h:55
A representation of a single file/directory.
Definition: IndexedIO.h:492
Definition: RunTimeTyped.h:211
This namespace contains all components of the core library.
Definition: AddSmoothSkinningInfluencesOp.h:43