home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / wv2 / olestream.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-06-12  |  5.0 KB  |  227 lines

  1. /* This file is part of the wvWare 2 project
  2.    Copyright (C) 2001-2003 Werner Trobin <trobin@kde.org>
  3.  
  4.    This library is free software; you can redistribute it and/or
  5.    modify it under the terms of the GNU Library General Public
  6.    License version 2 as published by the Free Software Foundation.
  7.  
  8.    This library is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  11.    Library General Public License for more details.
  12.  
  13.    You should have received a copy of the GNU Library General Public License
  14.    along with this library; see the file COPYING.LIB.  If not, write to
  15.    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  16.    Boston, MA 02111-1307, USA.
  17. */
  18.  
  19. #ifndef OLESTREAM_H
  20. #define OLESTREAM_H
  21.  
  22. #include "olestorage.h"
  23. #include "global.h"  // U8,... typedefs
  24. #include <stack>
  25.  
  26. #include <glib/giochannel.h> // GSeekType
  27.  
  28. namespace wvWare {
  29.  
  30. class OLEStream
  31. {
  32. public:
  33.     /**
  34.      * Create an OLE stream
  35.      */
  36.     OLEStream( OLEStorage* storage );
  37.     virtual ~OLEStream();
  38.  
  39.     /**
  40.      * Is this still a valid stream?
  41.      */
  42.     virtual bool isValid() const = 0;
  43.  
  44.     /**
  45.      * works like plain fseek
  46.      */
  47.     virtual bool seek( int offset, GSeekType whence = G_SEEK_SET ) = 0;
  48.     /**
  49.      * works like plain ftell
  50.      */
  51.     virtual int tell() const = 0;
  52.     /**
  53.      * The size of the stream
  54.      */
  55.     virtual size_t size() const = 0;
  56.  
  57.     /**
  58.      * Push the current offset on the stack
  59.      */
  60.     void push();
  61.     /**
  62.      * Pop the topmost position (false if the stack was empty)
  63.      */
  64.     bool pop();
  65.  
  66. private:
  67.     /**
  68.      * we don't want to allow copying and assigning streams
  69.      */
  70.     OLEStream( const OLEStream& rhs );
  71.     /**
  72.      * we don't want to allow copying and assigning streams
  73.      */
  74.     OLEStream& operator=( const OLEStream& rhs );
  75.  
  76.     std::stack<int> m_positions;
  77.     /**
  78.      *  for bookkeeping :}
  79.      */
  80.     OLEStorage *m_storage;
  81. };
  82.  
  83.  
  84. class OLEStreamReader : public OLEStream
  85. {
  86. public:
  87.     OLEStreamReader( GsfInput* stream, OLEStorage* storage );
  88.     virtual ~OLEStreamReader();
  89.  
  90.     /**
  91.      * Is this still a valid stream?
  92.      */
  93.     virtual bool isValid() const;
  94.  
  95.     /**
  96.      * works like plain fseek
  97.      */
  98.     virtual bool seek( int offset, GSeekType whence = G_SEEK_SET );
  99.     /**
  100.      * works like plain ftell
  101.      */
  102.     virtual int tell() const;
  103.     /**
  104.      * The size of the stream
  105.      */
  106.     virtual size_t size() const;
  107.  
  108.     /**
  109.      * Reading from the current position
  110.      * Note: Modifies the current position!
  111.      * All the read methods are endian-aware and convert
  112.      * the contents from the file if necessary
  113.      */
  114.     U8 readU8();
  115.     /**
  116.      * @see readU8()
  117.      */
  118.     S8 readS8();
  119.     /**
  120.      * @see readU8()
  121.      */
  122.     U16 readU16();
  123.     /**
  124.      * @see readU8()
  125.      */
  126.     S16 readS16();
  127.     /**
  128.      * @see readU8()
  129.      */
  130.     U32 readU32();
  131.     /**
  132.      * @see readU8()
  133.      */
  134.     S32 readS32();
  135.  
  136.     /**
  137.      * Reads a bunch of bytes w/o endian conversion to the
  138.      * given buffer, at most length bytes.
  139.      * Returns true on success
  140.      */
  141.     bool read( U8 *buffer, size_t length );
  142.  
  143.     /**
  144.      * For debugging
  145.      */
  146.     void dumpStream( const std::string& fileName );
  147.  
  148. private:
  149.     // we don't want to allow copying and assigning streams
  150.     OLEStreamReader( const OLEStreamReader& rhs );
  151.     OLEStreamReader& operator=( const OLEStreamReader& rhs );
  152.  
  153.     GsfInput* m_stream;
  154. };
  155.  
  156.  
  157. class OLEStreamWriter : public OLEStream
  158. {
  159. public:
  160.     OLEStreamWriter( GsfOutput* stream, OLEStorage* storage );
  161.     virtual ~OLEStreamWriter();
  162.  
  163.     /**
  164.      * Is this still a valid stream?
  165.      */
  166.     virtual bool isValid() const;
  167.  
  168.     /**
  169.      * works like plain fseek
  170.      */
  171.     virtual bool seek( int offset, GSeekType whence = G_SEEK_SET );
  172.     /**
  173.      * works like plain ftell
  174.      */
  175.     virtual int tell() const;
  176.     /**
  177.      * The size of the stream
  178.      */
  179.     virtual size_t size() const;
  180.  
  181.     /**
  182.      * Writing to the current position
  183.      * Note: Modifies the current position!
  184.      * These write methods are endian-aware
  185.      * and convert the contents to be LE in the file
  186.      */
  187.     void write( U8 data );
  188.     /**
  189.      * @see write(U8 data)
  190.      */
  191.     void write( S8 data );
  192.     /**
  193.      * @see write(U8 data)
  194.      */
  195.     void write( U16 data );
  196.     /**
  197.      * @see write(U8 data)
  198.      */
  199.     void write( S16 data );
  200.     /**
  201.      * @see write(U8 data)
  202.      */
  203.     void write( U32 data );
  204.     /**
  205.      * @see write(U8 data)
  206.      */
  207.     void write( S32 data );
  208.  
  209.     /**
  210.      * Attention: This write method just writes out the
  211.      * contents of the memory directly (w/o converting
  212.      * to little-endian first!)
  213.      */
  214.     void write( U8* data, size_t length );
  215.  
  216. private:
  217.     // we don't want to allow copying and assigning streams
  218.     OLEStreamWriter( const OLEStreamWriter& rhs );
  219.     OLEStreamWriter& operator=( const OLEStreamWriter& rhs );
  220.  
  221.     GsfOutput* m_stream;
  222. };
  223.  
  224. } // namespace wvWare
  225.  
  226. #endif // OLESTREAM_H
  227.