• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

tu_file.h

Go to the documentation of this file.
00001 // tu_file.h    -- Ignacio Castaņo, Thatcher Ulrich 2003
00002 
00003 // This source code has been donated to the Public Domain.  Do
00004 // whatever you want with it.
00005 
00006 // A very generic file class that can be customized with callbacks.
00007 
00008 
00009 #ifndef TU_FILE_H
00010 #define TU_FILE_H
00011 
00012 #include "dsodefs.h" // DSOEXPORT
00013 #include "utility.h"
00014 #include "IOChannel.h" // for inheritance
00015 
00016 
00017 namespace gnash {
00018 
00019 // a file abstraction that can be customized with callbacks.
00020 // Designed to be easy to hook up to FILE*, SDL_RWops*, or
00021 // whatever stream type(s) you might use in your game or
00022 // libraries.
00023 class DSOEXPORT tu_file : public gnash::IOChannel
00024 {
00025 public:
00026 
00027     // Make a file from an ordinary FILE*.
00028     tu_file(FILE* fp, bool autoclose);
00029     
00030     ~tu_file();
00031     
00034     //
00038     boost::uint32_t read_le32() 
00039     {
00040             // read_byte() is boost::uint8_t, so no masks with 0xff are required.
00041             boost::uint32_t result = static_cast<boost::uint32_t>(read_byte());
00042             result |= static_cast<boost::uint32_t>(read_byte()) << 8;
00043             result |= static_cast<boost::uint32_t>(read_byte()) << 16;
00044             result |= static_cast<boost::uint32_t>(read_byte()) << 24;
00045             return(result);
00046     }
00047         
00049     //
00053     boost::uint16_t read_le16()
00054     {
00055             boost::uint16_t result = static_cast<boost::uint16_t>(read_byte());
00056             result |= static_cast<boost::uint16_t>(read_byte()) << 8;
00057             return(result);
00058     }
00059     
00061     //
00065     boost::uint8_t read_byte() {
00066         boost::uint8_t u;
00067         read(&u, 1);
00068         return u;
00069     }
00070     
00072     //
00076     std::streamsize read(void* dst, std::streamsize num);
00077 
00079     //
00083     std::streamsize write(const void* src, std::streamsize num);
00084 
00086     //
00090     std::streampos tell() const;
00091 
00093     //
00100     bool seek(std::streampos p);
00101 
00103     //
00106     void go_to_end();
00107 
00109     //
00113     bool eof() const;
00114     
00116     //
00123     bool bad() const;
00124     
00126     size_t size() const;
00127     
00128 private:
00129     
00130     void close();
00131     
00132     void *      m_data;
00133 
00134     bool _autoclose;
00135 
00136 };
00137 
00138 
00139 } // namespace gnash
00140 #endif // TU_FILE_H
00141 
00142 
00143 // Local Variables:
00144 // mode: C++
00145 // indent-tabs-mode: t
00146 // End:

Generated on Fri Mar 16 2012 15:46:13 for Gnash by  doxygen 1.7.1