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