00001 /* 00002 * FileAccessor.h 00003 * 00004 * Smalltalk like class library for C++ 00005 * Accessor to file stored on disc. Header. 00006 * 00007 * Copyright (c) 2003 Milan Cermak 00008 */ 00009 /* 00010 * This library is free software; you can redistribute it and/or 00011 * modify it under the terms of the GNU Lesser General Public 00012 * License as published by the Free Software Foundation; either 00013 * version 2.1 of the License, or (at your option) any later version. 00014 * 00015 * This library 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. See the GNU 00018 * Lesser General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU Lesser General Public 00021 * License along with this library; if not, write to the Free Software 00022 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00023 */ 00024 #ifndef __FILEACCESSOR_H 00025 #define __FILEACCESSOR_H 00026 00027 #include <stlib/IOAccessor.h> 00028 #include <stlib/LineEndConvention.h> 00029 00030 namespace Core { 00031 00032 class ByteArray; 00033 class String; 00034 00035 class FileAccessor : public IOAccessor 00036 { 00037 protected: 00039 String *name; 00041 int descriptor; 00042 00043 public: 00051 FileAccessor(int fd); 00052 00058 FileAccessor(String *pathname, int rwMode, int creationRule); 00059 00060 FileAccessor(const char *pathname, int rwMode, int creationRule); 00061 00062 /* Class-accessing protocol */ 00063 virtual String *className(void) const; 00064 00065 /* Instance creation protocol */ 00066 static FileAccessor *openFileReadOnly(String *pathname); 00067 static FileAccessor *openFileWriteOnly(String *pathname); 00068 00069 /* Initialize-release protocol */ 00070 virtual void close(void); 00071 00072 /* Accessing protocol */ 00073 virtual void commit(void); 00074 virtual long dataSize(void); 00075 virtual LineEndConvention lineEndConvention(void); 00076 00077 /* Data transfer protocol */ 00078 virtual int readInto(ByteArray *buffer) 00079 { return IOAccessor::readInto(buffer); } 00080 virtual int readInto(ByteArray *buffer, long startIndex, long count); 00081 00082 virtual int writeFrom(ByteArray *buffer) 00083 { return IOAccessor::writeFrom(buffer); } 00084 virtual int writeFrom(ByteArray *buffer, long startIndex, long count); 00085 00086 /* Positioning protocol */ 00087 virtual void seekTo(long position); 00088 00089 /* Stream redirection protocol */ 00094 virtual void changeDescriptorTo(int fd); 00095 00096 /* Testing protocol */ 00097 virtual bool isSeekable(void); 00098 }; 00099 00100 }; 00101 00102 #endif /* __FILEACCESSOR_H */