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