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,2009 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 * $Id: FXMemoryStream.h,v 1.22 2009/01/06 13:07:25 fox Exp $                    *
00022 ********************************************************************************/
00023 #ifndef FXMEMORYSTREAM_H
00024 #define FXMEMORYSTREAM_H
00025 
00026 #ifndef FXSTREAM_H
00027 #include "FXStream.h"
00028 #endif
00029 
00030 namespace FX {
00031 
00032 
00033 /// Memory Store Definition
00034 class FXAPI FXMemoryStream : public FXStream {
00035 protected:
00036   virtual FXuval writeBuffer(FXuval count);
00037   virtual FXuval readBuffer(FXuval count);
00038 public:
00039 
00040   /// Create memory stream
00041   FXMemoryStream(const FXObject* cont=NULL);
00042 
00043   /// Create and open memory stream
00044   FXMemoryStream(FXStreamDirection save_or_load,FXuchar* data=NULL,FXuval size=~0UL,FXbool owned=false);
00045 
00046   /**
00047   * Open memory stream.
00048   * When reading from the data buffer, the size parameter is optional.  If not given,
00049   * the reader will need to know when to stop reading by some other means, like end-of-file
00050   * markers in the data.  When writing, the size parameter must be set to reflect the actual
00051   * buffer size, and should be at least 16.
00052   * If the owned flag is true, the stream becomes the owner of the data buffer; otherwise,
00053   * the stream will not delete the buffer.
00054   * Passing NULL for the data buffer will cause the stream to allocate a buffer of the
00055   * given size.
00056   */
00057   FXbool open(FXStreamDirection save_or_load,FXuchar* data=NULL,FXuval size=~0UL,FXbool owned=false);
00058 
00059   /// Take buffer away from stream
00060   void takeBuffer(FXuchar*& data,FXuval& size);
00061 
00062   /// Give buffer to stream, making it the owner of this buffer
00063   void giveBuffer(FXuchar *data,FXuval size);
00064 
00065   /// Get position
00066   FXlong position() const { return FXStream::position(); }
00067 
00068   /// Move to position
00069   virtual FXbool position(FXlong offset,FXWhence whence=FXFromStart);
00070 
00071   /// Save single items to stream
00072   FXMemoryStream& operator<<(const FXuchar& v){ FXStream::operator<<(v); return *this; }
00073   FXMemoryStream& operator<<(const FXchar& v){ FXStream::operator<<(v); return *this; }
00074   FXMemoryStream& operator<<(const FXbool& v){ FXStream::operator<<(v); return *this; }
00075   FXMemoryStream& operator<<(const FXushort& v){ FXStream::operator<<(v); return *this; }
00076   FXMemoryStream& operator<<(const FXshort& v){ FXStream::operator<<(v); return *this; }
00077   FXMemoryStream& operator<<(const FXuint& v){ FXStream::operator<<(v); return *this; }
00078   FXMemoryStream& operator<<(const FXint& v){ FXStream::operator<<(v); return *this; }
00079   FXMemoryStream& operator<<(const FXfloat& v){ FXStream::operator<<(v); return *this; }
00080   FXMemoryStream& operator<<(const FXdouble& v){ FXStream::operator<<(v); return *this; }
00081   FXMemoryStream& operator<<(const FXlong& v){ FXStream::operator<<(v); return *this; }
00082   FXMemoryStream& operator<<(const FXulong& v){ FXStream::operator<<(v); return *this; }
00083 
00084   /// Save arrays of items to stream
00085   FXMemoryStream& save(const FXuchar* p,FXuval n){ FXStream::save(p,n); return *this; }
00086   FXMemoryStream& save(const FXchar* p,FXuval n){ FXStream::save(p,n); return *this; }
00087   FXMemoryStream& save(const FXbool* p,FXuval n){ FXStream::save(p,n); return *this; }
00088   FXMemoryStream& save(const FXushort* p,FXuval n){ FXStream::save(p,n); return *this; }
00089   FXMemoryStream& save(const FXshort* p,FXuval n){ FXStream::save(p,n); return *this; }
00090   FXMemoryStream& save(const FXuint* p,FXuval n){ FXStream::save(p,n); return *this; }
00091   FXMemoryStream& save(const FXint* p,FXuval n){ FXStream::save(p,n); return *this; }
00092   FXMemoryStream& save(const FXfloat* p,FXuval n){ FXStream::save(p,n); return *this; }
00093   FXMemoryStream& save(const FXdouble* p,FXuval n){ FXStream::save(p,n); return *this; }
00094   FXMemoryStream& save(const FXlong* p,FXuval n){ FXStream::save(p,n); return *this; }
00095   FXMemoryStream& save(const FXulong* p,FXuval n){ FXStream::save(p,n); return *this; }
00096 
00097   /// Load single items from stream
00098   FXMemoryStream& operator>>(FXuchar& v){ FXStream::operator>>(v); return *this; }
00099   FXMemoryStream& operator>>(FXchar& v){ FXStream::operator>>(v); return *this; }
00100   FXMemoryStream& operator>>(FXbool& v){ FXStream::operator>>(v); return *this; }
00101   FXMemoryStream& operator>>(FXushort& v){ FXStream::operator>>(v); return *this; }
00102   FXMemoryStream& operator>>(FXshort& v){ FXStream::operator>>(v); return *this; }
00103   FXMemoryStream& operator>>(FXuint& v){ FXStream::operator>>(v); return *this; }
00104   FXMemoryStream& operator>>(FXint& v){ FXStream::operator>>(v); return *this; }
00105   FXMemoryStream& operator>>(FXfloat& v){ FXStream::operator>>(v); return *this; }
00106   FXMemoryStream& operator>>(FXdouble& v){ FXStream::operator>>(v); return *this; }
00107   FXMemoryStream& operator>>(FXlong& v){ FXStream::operator>>(v); return *this; }
00108   FXMemoryStream& operator>>(FXulong& v){ FXStream::operator>>(v); return *this; }
00109 
00110   /// Load arrays of items from stream
00111   FXMemoryStream& load(FXuchar* p,FXuval n){ FXStream::load(p,n); return *this; }
00112   FXMemoryStream& load(FXchar* p,FXuval n){ FXStream::load(p,n); return *this; }
00113   FXMemoryStream& load(FXbool* p,FXuval n){ FXStream::load(p,n); return *this; }
00114   FXMemoryStream& load(FXushort* p,FXuval n){ FXStream::load(p,n); return *this; }
00115   FXMemoryStream& load(FXshort* p,FXuval n){ FXStream::load(p,n); return *this; }
00116   FXMemoryStream& load(FXuint* p,FXuval n){ FXStream::load(p,n); return *this; }
00117   FXMemoryStream& load(FXint* p,FXuval n){ FXStream::load(p,n); return *this; }
00118   FXMemoryStream& load(FXfloat* p,FXuval n){ FXStream::load(p,n); return *this; }
00119   FXMemoryStream& load(FXdouble* p,FXuval n){ FXStream::load(p,n); return *this; }
00120   FXMemoryStream& load(FXlong* p,FXuval n){ FXStream::load(p,n); return *this; }
00121   FXMemoryStream& load(FXulong* p,FXuval n){ FXStream::load(p,n); return *this; }
00122 
00123   /// Save object
00124   FXMemoryStream& saveObject(const FXObject* v){ FXStream::saveObject(v); return *this; }
00125 
00126   /// Load object
00127   FXMemoryStream& loadObject(FXObject*& v){ FXStream::loadObject(v); return *this; }
00128 
00129   /// Destructor
00130   virtual ~FXMemoryStream();
00131   };
00132 
00133 }
00134 
00135 #endif

Copyright © 1997-2009 Jeroen van der Zijp