Cortex  10.0.0-a4
IFFFile.h
1 //
3 // Copyright (c) 2009-2011, 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_IFFFILE_H
36 #define IE_CORE_IFFFILE_H
37 
38 #include <vector>
39 #include <fstream>
40 
41 #include "OpenEXR/ImathVec.h"
42 
43 #include "IECore/Export.h"
44 #include "IECore/RefCounted.h"
45 
46 namespace IECore
47 {
48 
49 IE_CORE_FORWARDDECLARE( IFFFile );
50 
53 class IECORE_API IFFFile : public RefCounted
54 {
55  public :
56 
57  IFFFile( const std::string &fileName );
58  ~IFFFile() override;
59 
60  class Tag;
61  class Chunk;
62 
63  Chunk *root();
64 
68  class Tag
69  {
70  public :
71 
72  Tag( );
73  Tag( const char *buffer );
74  Tag( std::string str );
75  std::string name();
76  int id();
77  char alignmentByte();
78  bool isGroup();
79 
80  // FORM is currently the only accepted group type.
81  // CAT, LIST, and PROP have not been implemented.
82  enum GroupTagID
83  {
84  kFORM = 1179603533,
85  kFOR4 = 1179603508,
86  kFOR8 = 1179603512,
87  };
88 
89  static const int TagSize = 4;
90 
91  private :
92 
93  char m_a;
94  char m_b;
95  char m_c;
96  char m_d;
97  int m_id;
98  };
99 
105  class Chunk
106  {
107  public :
108 
109  friend class IFFFile;
110 
111  Tag type();
112  unsigned int dataSize();
113 
114  bool isGroup();
115  Tag groupName();
116 
117  typedef std::vector<Chunk>::iterator ChunkIterator;
118  ChunkIterator childrenBegin();
119  ChunkIterator childrenEnd();
120 
122  template<typename T>
123  void read( T &data );
124 
126  void read( std::string &data );
127 
129  template<typename T>
130  size_t read( std::vector<T> &data );
131 
133  template<typename T>
134  size_t read( std::vector<Imath::Vec3<T> > &data );
135 
136  private :
137 
138  Chunk( );
139  Chunk( std::string type, unsigned int dataSize, IFFFilePtr file, std::streampos filePosition, int alignmentQuota );
140 
141  Tag m_type;
142  unsigned int m_dataSize;
143 
144  IFFFilePtr m_file;
145  std::streampos m_filePosition;
146 
147  Tag m_groupName;
148  int m_alignmentQuota;
149  std::vector<Chunk> m_children;
150 
151  // fills m_children
152  void ls();
153 
154  // reads most member variables from m_file, starting at pos
155  void readHeader( std::streampos *pos );
156 
157  // reads the data from m_file, storing it in dataBuffer
158  template<typename T>
159  void readData( T *dataBuffer, unsigned long n );
160 
161  // returns the proper byte alignment value for m_type
162  int alignmentQuota();
163 
164  // returns the number of bytes that can be skipped to fill the group's alignment quota
165  int skippableBytes();
166  };
167 
168  private :
169 
170  bool open();
171  std::ifstream *m_iStream;
172  std::string m_streamFileName;
173 
174  Chunk *m_root;
175 
176  // reads data from the char buffer into a more specific buffer, accounting for byte order
177  template<typename T>
178  static void readData( const char *dataBuffer, T *attrBuffer, unsigned long n );
179 };
180 
181 } // namespace IECore
182 
183 #include "IFFFile.inl"
184 
185 #endif // IE_CORE_IFFFILE_H
Definition: IFFFile.h:105
Definition: IFFFile.h:68
Definition: IFFFile.h:53
IECORE_API void ls(const std::string &path, std::vector< FileSequencePtr > &sequences, size_t minSequenceSize=2)
Generates all sequences with at least minSequenceSize elements residing in given directory in the for...
Definition: RefCounted.h:124
This namespace contains all components of the core library.
Definition: AddSmoothSkinningInfluencesOp.h:43