Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXMemoryStream.h

Go to the documentation of this file.
00001 /********************************************************************************
00002 *                                                                               *
00003 *                   M e m o r y   S t r e a m   C l a s s e s                   *
00004 *                                                                               *
00005 *********************************************************************************
00006 * Copyright (C) 1997,2010 by Jeroen van der Zijp.   All Rights Reserved.        *
00007 *********************************************************************************
00008 * This library is free software; you can redistribute it and/or modify          *
00009 * it under the terms of the GNU Lesser General Public License as published by   *
00010 * the Free Software Foundation; either version 3 of the License, or             *
00011 * (at your option) any later version.                                           *
00012 *                                                                               *
00013 * This library is distributed in the hope that it will be useful,               *
00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                 *
00016 * GNU Lesser General Public License for more details.                           *
00017 *                                                                               *
00018 * You should have received a copy of the GNU Lesser General Public License      *
00019 * along with this program.  If not, see <http://www.gnu.org/licenses/>          *
00020 ********************************************************************************/
00021 #ifndef FXMEMORYSTREAM_H
00022 #define FXMEMORYSTREAM_H
00023 
00024 #ifndef FXSTREAM_H
00025 #include "FXStream.h"
00026 #endif
00027 
00028 namespace FX {
00029 
00030 
00031 /// Memory Store Definition
00032 class FXAPI FXMemoryStream : public FXStream {
00033 protected:
00034   virtual FXuval writeBuffer(FXuval count);
00035   virtual FXuval readBuffer(FXuval count);
00036 public:
00037 
00038   /// Create memory stream
00039   FXMemoryStream(const FXObject* cont=NULL);
00040 
00041   /// Create and open memory stream
00042   FXMemoryStream(FXStreamDirection save_or_load,FXuchar* data=NULL,FXuval size=~0UL,FXbool owned=false);
00043 
00044   /**
00045   * Open memory stream.
00046   * When reading from the data buffer, the size parameter is optional.  If not given,
00047   * the reader will need to know when to stop reading by some other means, like end-of-file
00048   * markers in the data.  When writing, the size parameter must be set to reflect the actual
00049   * buffer size, and should be at least 16.
00050   * If the owned flag is true, the stream becomes the owner of the data buffer; otherwise,
00051   * the stream will not delete the buffer.
00052   * Passing NULL for the data buffer will cause the stream to allocate a buffer of the
00053   * given size.
00054   */
00055   FXbool open(FXStreamDirection save_or_load,FXuchar* data=NULL,FXuval size=~0UL,FXbool owned=false);
00056 
00057   /// Take buffer away from stream
00058   void takeBuffer(FXuchar*& data,FXuval& size);
00059 
00060   /// Give buffer to stream, making it the owner of this buffer
00061   void giveBuffer(FXuchar *data,FXuval size);
00062 
00063   /// Get position
00064   FXlong position() const { return FXStream::position(); }
00065 
00066   /// Move to position
00067   virtual FXbool position(FXlong offset,FXWhence whence=FXFromStart);
00068 
00069   /// Save single items to stream
00070   FXMemoryStream& operator<<(const FXuchar& v){ FXStream::operator<<(v); return *this; }
00071   FXMemoryStream& operator<<(const FXchar& v){ FXStream::operator<<(v); return *this; }
00072   FXMemoryStream& operator<<(const FXbool& v){ FXStream::operator<<(v); return *this; }
00073   FXMemoryStream& operator<<(const FXushort& v){ FXStream::operator<<(v); return *this; }
00074   FXMemoryStream& operator<<(const FXshort& v){ FXStream::operator<<(v); return *this; }
00075   FXMemoryStream& operator<<(const FXuint& v){ FXStream::operator<<(v); return *this; }
00076   FXMemoryStream& operator<<(const FXint& v){ FXStream::operator<<(v); return *this; }
00077   FXMemoryStream& operator<<(const FXfloat& v){ FXStream::operator<<(v); return *this; }
00078   FXMemoryStream& operator<<(const FXdouble& v){ FXStream::operator<<(v); return *this; }
00079   FXMemoryStream& operator<<(const FXlong& v){ FXStream::operator<<(v); return *this; }
00080   FXMemoryStream& operator<<(const FXulong& v){ FXStream::operator<<(v); return *this; }
00081 
00082   /// Save arrays of items to stream
00083   FXMemoryStream& save(const FXuchar* p,FXuval n){ FXStream::save(p,n); return *this; }
00084   FXMemoryStream& save(const FXchar* p,FXuval n){ FXStream::save(p,n); return *this; }
00085   FXMemoryStream& save(const FXbool* p,FXuval n){ FXStream::save(p,n); return *this; }
00086   FXMemoryStream& save(const FXushort* p,FXuval n){ FXStream::save(p,n); return *this; }
00087   FXMemoryStream& save(const FXshort* p,FXuval n){ FXStream::save(p,n); return *this; }
00088   FXMemoryStream& save(const FXuint* p,FXuval n){ FXStream::save(p,n); return *this; }
00089   FXMemoryStream& save(const FXint* p,FXuval n){ FXStream::save(p,n); return *this; }
00090   FXMemoryStream& save(const FXfloat* p,FXuval n){ FXStream::save(p,n); return *this; }
00091   FXMemoryStream& save(const FXdouble* p,FXuval n){ FXStream::save(p,n); return *this; }
00092   FXMemoryStream& save(const FXlong* p,FXuval n){ FXStream::save(p,n); return *this; }
00093   FXMemoryStream& save(const FXulong* p,FXuval n){ FXStream::save(p,n); return *this; }
00094 
00095   /// Load single items from stream
00096   FXMemoryStream& operator>>(FXuchar& v){ FXStream::operator>>(v); return *this; }
00097   FXMemoryStream& operator>>(FXchar& v){ FXStream::operator>>(v); return *this; }
00098   FXMemoryStream& operator>>(FXbool& v){ FXStream::operator>>(v); return *this; }
00099   FXMemoryStream& operator>>(FXushort& v){ FXStream::operator>>(v); return *this; }
00100   FXMemoryStream& operator>>(FXshort& v){ FXStream::operator>>(v); return *this; }
00101   FXMemoryStream& operator>>(FXuint& v){ FXStream::operator>>(v); return *this; }
00102   FXMemoryStream& operator>>(FXint& v){ FXStream::operator>>(v); return *this; }
00103   FXMemoryStream& operator>>(FXfloat& v){ FXStream::operator>>(v); return *this; }
00104   FXMemoryStream& operator>>(FXdouble& v){ FXStream::operator>>(v); return *this; }
00105   FXMemoryStream& operator>>(FXlong& v){ FXStream::operator>>(v); return *this; }
00106   FXMemoryStream& operator>>(FXulong& v){ FXStream::operator>>(v); return *this; }
00107 
00108   /// Load arrays of items from stream
00109   FXMemoryStream& load(FXuchar* p,FXuval n){ FXStream::load(p,n); return *this; }
00110   FXMemoryStream& load(FXchar* p,FXuval n){ FXStream::load(p,n); return *this; }
00111   FXMemoryStream& load(FXbool* p,FXuval n){ FXStream::load(p,n); return *this; }
00112   FXMemoryStream& load(FXushort* p,FXuval n){ FXStream::load(p,n); return *this; }
00113   FXMemoryStream& load(FXshort* p,FXuval n){ FXStream::load(p,n); return *this; }
00114   FXMemoryStream& load(FXuint* p,FXuval n){ FXStream::load(p,n); return *this; }
00115   FXMemoryStream& load(FXint* p,FXuval n){ FXStream::load(p,n); return *this; }
00116   FXMemoryStream& load(FXfloat* p,FXuval n){ FXStream::load(p,n); return *this; }
00117   FXMemoryStream& load(FXdouble* p,FXuval n){ FXStream::load(p,n); return *this; }
00118   FXMemoryStream& load(FXlong* p,FXuval n){ FXStream::load(p,n); return *this; }
00119   FXMemoryStream& load(FXulong* p,FXuval n){ FXStream::load(p,n); return *this; }
00120 
00121   /// Save object
00122   FXMemoryStream& saveObject(const FXObject* v){ FXStream::saveObject(v); return *this; }
00123 
00124   /// Load object
00125   FXMemoryStream& loadObject(FXObject*& v){ FXStream::loadObject(v); return *this; }
00126 
00127   /// Destructor
00128   virtual ~FXMemoryStream();
00129   };
00130 
00131 }
00132 
00133 #endif

Copyright © 1997-2010 Jeroen van der Zijp