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
25 class Datagram;
26
27/**
28 * A wrapper around an istream used for reading an IFF file.
29 */
30 class IffInputFile : public TypedObject {
31 public:
32 IffInputFile();
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
66 protected:
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
76 public:
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() {
85 TypedObject::init_type();
86 register_type(_type_handle, "IffInputFile",
87 TypedObject::get_class_type());
88 }
89
90 private:
91 static TypeHandle _type_handle;
92
93 friend class IffChunk;
94};
95
96#include "iffInputFile.I"
97
98#endif
Datagram
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition datagram.h:38
Filename
The name of a file, such as a texture file or an Egg file.
Definition filename.h:44
IffId
A four-byte chunk ID appearing in an "IFF" file.
Definition iffId.h:26
IffInputFile::open_read
bool open_read(Filename filename)
Attempts to open the indicated filename for reading.
Definition iffInputFile.cxx:50
IffInputFile::get_be_float32
PN_stdfloat get_be_float32()
Extracts a 32-bit big-endian single-precision floating-point number.
Definition iffInputFile.cxx:165
IffInputFile::read_bytes
bool read_bytes(Datagram &datagram, int length)
Reads a series of bytes, and stores them in the indicated Datagram.
Definition iffInputFile.cxx:325
IffInputFile::set_input
void set_input(std::istream *input, bool owns_istream)
Sets up the input to use an arbitrary istream.
Definition iffInputFile.cxx:71
IffInputFile::get_be_uint16
uint16_t get_be_uint16()
Extracts an unsigned 16-bit big-endian integer.
Definition iffInputFile.cxx:139
IffInputFile::get_id
IffId get_id()
Extracts a 4-character IFF ID.
Definition iffInputFile.cxx:196
IffInputFile::get_bytes_read
size_t get_bytes_read() const
Returns the number of bytes read so far from the input file.
Definition iffInputFile.I:44
IffInputFile::get_be_uint32
uint32_t get_be_uint32()
Extracts an unsigned 32-bit big-endian integer.
Definition iffInputFile.cxx:152
IffInputFile::get_be_int32
int32_t get_be_int32()
Extracts a signed 32-bit big-endian integer.
Definition iffInputFile.cxx:126
IffInputFile::get_int8
int8_t get_int8()
Extracts a signed 8-bit integer.
Definition iffInputFile.cxx:87
IffInputFile::skip_bytes
bool skip_bytes(int length)
Reads a series of bytes, but does not store them.
Definition iffInputFile.cxx:348
IffInputFile::read_byte
bool read_byte(char &byte)
Reads a single byte.
Definition iffInputFile.cxx:309
IffInputFile::get_be_int16
int16_t get_be_int16()
Extracts a signed 16-bit big-endian integer.
Definition iffInputFile.cxx:113
IffInputFile::get_filename
const Filename & get_filename() const
Returns the filename that the InputFile is currently opened on, if available.
Definition iffInputFile.I:27
IffInputFile::get_uint8
uint8_t get_uint8()
Extracts an unsigned 8-bit integer.
Definition iffInputFile.cxx:100
IffInputFile::align
void align()
If the current file pointer is not positioned on an even-byte boundary, reads and discards one byte s...
Definition iffInputFile.I:53
IffInputFile::get_string
std::string get_string()
Extracts a null-terminated string.
Definition iffInputFile.cxx:178
IffInputFile::is_eof
bool is_eof() const
Returns true if the last read operation failed because of reaching EOF, false otherwise.
Definition iffInputFile.I:36
IffInputFile::set_filename
void set_filename(const Filename &filename)
Indicates the filename that the InputFile is currently opened on.
Definition iffInputFile.I:18
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
TypedObject::init_type
static void init_type()
This function is declared non-inline to work around a compiler bug in g++ 2.96.
Definition typedObject.cxx:44
iffChunk.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
iffId.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
iffInputFile.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pandatoolbase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pointerTo.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
register_type
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition register_type.I:22
typedObject.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.