Panda3D
iffInputFile.h
1 // Filename: iffInputFile.h
2 // Created by: drose (24Apr01)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef IFFINPUTFILE_H
16 #define IFFINPUTFILE_H
17 
18 #include "pandatoolbase.h"
19 
20 #include "iffId.h"
21 #include "iffChunk.h"
22 
23 #include "typedObject.h"
24 #include "pointerTo.h"
25 
26 class Datagram;
27 
28 ////////////////////////////////////////////////////////////////////
29 // Class : IffInputFile
30 // Description : A wrapper around an istream used for reading an IFF
31 // file.
32 ////////////////////////////////////////////////////////////////////
33 class IffInputFile : public TypedObject {
34 public:
35  IffInputFile();
36  virtual ~IffInputFile();
37 
38  bool open_read(Filename filename);
39  void set_input(istream *input, bool owns_istream);
40 
41  INLINE void set_filename(const Filename &filename);
42  INLINE const Filename &get_filename() const;
43 
44  INLINE bool is_eof() const;
45  INLINE size_t get_bytes_read() const;
46 
47  INLINE void align();
48 
49  PN_int8 get_int8();
50  PN_uint8 get_uint8();
51 
52  PN_int16 get_be_int16();
53  PN_int32 get_be_int32();
54  PN_uint16 get_be_uint16();
55  PN_uint32 get_be_uint32();
56  PN_stdfloat get_be_float32();
57 
58  string get_string();
59 
60  IffId get_id();
61 
62  PT(IffChunk) get_chunk();
63  PT(IffChunk) get_subchunk(IffChunk *context);
64 
65  bool read_byte(char &byte);
66  bool read_bytes(Datagram &datagram, int length);
67  bool skip_bytes(int length);
68 
69 protected:
70  virtual IffChunk *make_new_chunk(IffId id);
71 
72  istream *_input;
73  Filename _filename;
74  bool _owns_istream;
75  bool _eof;
76  bool _unexpected_eof;
77  size_t _bytes_read;
78 
79 public:
80  virtual TypeHandle get_type() const {
81  return get_class_type();
82  }
83  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
84  static TypeHandle get_class_type() {
85  return _type_handle;
86  }
87  static void init_type() {
89  register_type(_type_handle, "IffInputFile",
90  TypedObject::get_class_type());
91  }
92 
93 private:
94  static TypeHandle _type_handle;
95 
96  friend class IffChunk;
97 };
98 
99 #include "iffInputFile.I"
100 
101 #endif
102 
103 
bool skip_bytes(int length)
Reads a series of bytes, but does not store them.
void align()
If the current file pointer is not positioned on an even-byte boundary, reads and discards one byte s...
Definition: iffInputFile.I:68
static void init_type()
This function is declared non-inline to work around a compiler bug in g++ 2.96.
Definition: typedObject.cxx:52
void set_filename(const Filename &filename)
Indicates the filename that the InputFile is currently opened on.
Definition: iffInputFile.I:23
bool read_bytes(Datagram &datagram, int length)
Reads a series of bytes, and stores them in the indicated Datagram.
string get_string()
Extracts a null-terminated string.
size_t get_bytes_read() const
Returns the number of bytes read so far from the input file.
Definition: iffInputFile.I:56
PN_uint16 get_be_uint16()
Extracts an unsigned 16-bit big-endian integer.
This is an abstract class that all classes which use TypeHandle, and also provide virtual functions t...
Definition: typedObject.h:98
PN_int16 get_be_int16()
Extracts a signed 16-bit big-endian integer.
PN_int32 get_be_int32()
Extracts a signed 32-bit big-endian integer.
bool open_read(Filename filename)
Attempts to open the indicated filename for reading.
bool read_byte(char &byte)
Reads a single byte.
const Filename & get_filename() const
Returns the filename that the InputFile is currently opened on, if available.
Definition: iffInputFile.I:34
The basic kind of record in an EA "IFF" file, which the LightWave object file is based on...
Definition: iffChunk.h:32
void set_input(istream *input, bool owns_istream)
Sets up the input to use an arbitrary istream.
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
A wrapper around an istream used for reading an IFF file.
Definition: iffInputFile.h:33
PN_uint32 get_be_uint32()
Extracts an unsigned 32-bit big-endian integer.
PN_stdfloat get_be_float32()
Extracts a 32-bit big-endian single-precision floating-point number.
PN_int8 get_int8()
Extracts a signed 8-bit integer.
PN_uint8 get_uint8()
Extracts an unsigned 8-bit integer.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
A four-byte chunk ID appearing in an "IFF" file.
Definition: iffId.h:29
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
bool is_eof() const
Returns true if the last read operation failed because of reaching EOF, false otherwise.
Definition: iffInputFile.I:45
IffId get_id()
Extracts a 4-character IFF ID.