00001 // Filename: iffInputFile.h 00002 // Created by: drose (24Apr01) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 #ifndef IFFINPUTFILE_H 00020 #define IFFINPUTFILE_H 00021 00022 #include <pandatoolbase.h> 00023 00024 #include "iffId.h" 00025 #include "iffChunk.h" 00026 00027 #include <typedObject.h> 00028 #include <pointerTo.h> 00029 00030 class Datagram; 00031 00032 //////////////////////////////////////////////////////////////////// 00033 // Class : IffInputFile 00034 // Description : A wrapper around an istream used for reading an IFF 00035 // file. 00036 //////////////////////////////////////////////////////////////////// 00037 class IffInputFile : public TypedObject { 00038 public: 00039 IffInputFile(); 00040 virtual ~IffInputFile(); 00041 00042 bool open_read(Filename filename); 00043 void set_input(istream *input, bool owns_istream); 00044 00045 INLINE void set_filename(const Filename &filename); 00046 INLINE const Filename &get_filename() const; 00047 00048 INLINE bool is_eof() const; 00049 INLINE size_t get_bytes_read() const; 00050 00051 INLINE void align(); 00052 00053 PN_int8 get_int8(); 00054 PN_uint8 get_uint8(); 00055 00056 PN_int16 get_be_int16(); 00057 PN_int32 get_be_int32(); 00058 PN_uint16 get_be_uint16(); 00059 PN_uint32 get_be_uint32(); 00060 float get_be_float32(); 00061 00062 string get_string(); 00063 00064 IffId get_id(); 00065 00066 PT(IffChunk) get_chunk(); 00067 PT(IffChunk) get_subchunk(IffChunk *context); 00068 00069 bool read_byte(char &byte); 00070 bool read_bytes(Datagram &datagram, int length); 00071 bool skip_bytes(int length); 00072 00073 protected: 00074 virtual IffChunk *make_new_chunk(IffId id); 00075 00076 istream *_input; 00077 Filename _filename; 00078 bool _owns_istream; 00079 bool _eof; 00080 bool _unexpected_eof; 00081 size_t _bytes_read; 00082 00083 public: 00084 virtual TypeHandle get_type() const { 00085 return get_class_type(); 00086 } 00087 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00088 static TypeHandle get_class_type() { 00089 return _type_handle; 00090 } 00091 static void init_type() { 00092 TypedObject::init_type(); 00093 register_type(_type_handle, "IffInputFile", 00094 TypedObject::get_class_type()); 00095 } 00096 00097 private: 00098 static TypeHandle _type_handle; 00099 00100 friend class IffChunk; 00101 }; 00102 00103 #include "iffInputFile.I" 00104 00105 #endif 00106 00107