QMemMap.h

Go to the documentation of this file.
00001 /********************************************************************************
00002 *                                                                               *
00003 *                           Mapped memory i/o device                            *
00004 *                                                                               *
00005 *********************************************************************************
00006 *        Copyright (C) 2003-2006 by Niall Douglas.   All Rights Reserved.       *
00007 *       NOTE THAT I DO NOT PERMIT ANY OF MY CODE TO BE PROMOTED TO THE GPL      *
00008 *********************************************************************************
00009 * This code is free software; you can redistribute it and/or modify it under    *
00010 * the terms of the GNU Library General Public License v2.1 as published by the  *
00011 * Free Software Foundation EXCEPT that clause 3 does not apply ie; you may not  *
00012 * "upgrade" this code to the GPL without my prior written permission.           *
00013 * Please consult the file "License_Addendum2.txt" accompanying this file.       *
00014 *                                                                               *
00015 * This code is distributed in the hope that it will be useful,                  *
00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                          *
00018 *********************************************************************************
00019 * $Id:                                                                          *
00020 ********************************************************************************/
00021 
00022 
00023 #ifndef QMEMMAP_H
00024 #define QMEMMAP_H
00025 #include "QIODevice.h"
00026 
00027 namespace FX {
00028 
00033 class FXString;
00034 class QFile;
00035 
00164 struct QMemMapPrivate;
00165 class FXAPIR QMemMap : public QIODevice
00166 {
00167     QMemMapPrivate *p;
00168     QMemMap(const QMemMap &);
00169     QMemMap &operator=(const QMemMap &);
00170     void winopen(int mode);
00171     inline void setIoIndex(FXfval offset);
00172 public:
00174     enum Type
00175     {
00176         File=0,         
00177         Memory          
00178     };
00180     struct MappedRegion
00181     {
00182         FXfval offset;  
00183         FXfval length;  
00184         FXfval end;     
00185         void *addr;     
00186         MappedRegion() { }
00187         MappedRegion(FXfval _offset, FXfval _length, void *_addr) : offset(_offset), length(_length), end(_offset+_length), addr(_addr) { }
00189         bool operator!() const throw() { return !offset && !length && !addr; }
00190     };
00191     QMemMap();
00193     QMemMap(const FXString &filename);
00195     QMemMap(QFile &file);
00197     QMemMap(const FXString &name, FXuval len);
00198     ~QMemMap();
00199 
00201     const FXString &name() const;
00203     void setName(const FXString &name);
00205     bool isUnique() const;
00207     void setUnique(bool v);
00209     Type type() const;
00211     void setType(Type type);
00213     bool exists() const;
00215     bool remove();
00217     FXfval reloadSize();
00219     FXfval mappableSize() const;
00221     void maximiseMappableSize();
00222 
00236     void *mapIn(FXfval offset=0, FXfval amount=(FXfval) -1, bool copyOnWrite=false);
00240     void mapOut(FXfval offset=0, FXfval amount=(FXfval) -1);
00244     void mapOut(void *area);
00249     bool mappedRegion(MappedRegion *current, MappedRegion *next=0, FXfval offset=(FXfval) -1) const;
00254     void *mapOffset(FXfval offset=(FXfval) -1) const;
00255 
00256     virtual bool open(FXuint mode);
00257     virtual void close();
00259     virtual void flush();
00260     virtual FXfval size() const;
00265     virtual void truncate(FXfval size);
00266     virtual FXfval at() const;
00267     virtual bool at(FXfval newpos);
00268     virtual bool atEnd() const;
00269     virtual const FXACL &permissions() const;
00270     virtual void setPermissions(const FXACL &perms);
00272     static FXACL permissions(const FXString &name);
00274     static void setPermissions(const FXString &name, const FXACL &perms);
00275     virtual FXuval readBlock(char *data, FXuval maxlen);
00276     virtual FXuval writeBlock(const char *data, FXuval maxlen);
00277     virtual FXuval readBlockFrom(char *data, FXuval maxlen, FXfval pos);
00278     virtual FXuval writeBlockTo(FXfval pos, const char *data, FXuval maxlen);
00279     virtual int getch();
00280     virtual int putch(int c);
00281     virtual int ungetch(int c);
00282 };
00283 
00284 } // namespace
00285 
00286 #endif

(C) 2002-2009 Niall Douglas. Some parts (C) to assorted authors.
Generated on Fri Nov 20 18:31:26 2009 for TnFOX by doxygen v1.4.7