Main Page   Class Hierarchy   Compound List   File List   Compound Members   Related Pages  

FileDescriptorDevice.h

00001 /*****************************************************************************
00002  * Author:   Valient Gough <vgough@pobox.com>
00003  *
00004  *****************************************************************************
00005  * Copyright (c) 2001, Valient Gough
00006  *
00007  * This library is free software; you can distribute it and/or modify it under
00008  * the terms of the GNU Lesser General Public License (LGPL), as published by
00009  * the Free Software Foundation; either version 2.1 of the License, or (at your
00010  * option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful, but WITHOUT
00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014  * FITNESS FOR A PARTICULAR PURPOSE.  See the LGPL in the file COPYING for more
00015  * details.
00016  *
00017  */
00018 
00019 #ifndef _FileDescriptorDevice_incl_
00020 #define _FileDescriptorDevice_incl_
00021 
00022 #include <rel/IODevice.h>
00023 #include <rel/SmartPtr.h>
00024 
00025 #include <stdio.h> // for FILE
00026 
00027 namespace rel
00028 {
00029 
00030     class FileDescriptorDevice : public IODevice
00031     {
00032     public:
00033         // The file descriptors are kept as smart pointers so that the caller
00034         // can decide wether they should be destroyed or not when this class is
00035         // destroyed.
00036         FileDescriptorDevice(const SmartPtr<int> &inputFD, 
00037                 const SmartPtr<int> &outputFD);
00038         virtual ~FileDescriptorDevice();
00039 
00040         // for use in case both input and output are not known at construction
00041         // time.  This allows setting the input or output descriptor later.
00042         // Should be used only when descriptor was given as null in
00043         // constructor.
00044         virtual bool setInputDescriptor(const SmartPtr<int> &inputFD);
00045         virtual bool setOutputDescriptor(const SmartPtr<int> &outputFD);
00046 
00047 
00048         virtual int getReadDescriptor() const;
00049 
00050         virtual bool isDirectAccess() const;
00051         virtual size_type at() const;
00052         virtual bool at(size_type offset);
00053 
00054         virtual bool atEnd() const;
00055 
00056         virtual size_type writeBytes(const char *data, size_type len);
00057         virtual void flush();
00058 
00059         virtual size_type readBytes(char *data, size_type maxLen) const;
00060 
00061         //virtual std::string print();
00062 
00063     private:
00064         FileDescriptorDevice(const FileDescriptorDevice &);
00065         FileDescriptorDevice &operator=(const FileDescriptorDevice &);
00066 
00067         FILE *in;
00068         FILE *out;
00069 
00070         SmartPtr<int> inputFD;
00071         SmartPtr<int> outputFD;
00072 
00073         unsigned long inputSize;
00074     };
00075 
00081     void fileCloseDestructor(int descriptor);
00082     void fileCloseDestructor(int *descriptor);
00083 
00084 } // namespace rel
00085 
00086 #endif
00087 

Generated at Sat Sep 22 02:20:00 2001 for librel by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001