00001
00002
00003
00004
00005
00006
00007
00008 #ifndef _SK_IO_FILE_
00009 #define _SK_IO_FILE_
00010
00011 #include <sk/util/Object.h>
00012 #include <sk/util/Holder.hxx>
00013 #include <sk/util/String.h>
00014 #include <sk/io/FileDescriptor.h>
00015
00016 struct stat;
00017
00018 namespace sk {
00019 namespace io {
00020 class File
00021 : public virtual sk::util::Object
00022 {
00023 public:
00024 File(const sk::util::String& name);
00025 File(const sk::util::String& name, const sk::util::String& mode);
00026 File(const sk::util::String& name, const sk::util::String& mode, int permissions);
00027 File(const sk::util::String& name, int mode);
00028 File(const sk::util::String& name, int mode, int permissions);
00029 File(const File& other);
00030 virtual ~File();
00031
00032 const sk::util::String getName() const;
00033 virtual sk::io::FileDescriptor& getFileDescriptor() const;
00034 virtual void close();
00035 long long size() const;
00036 long long position() const;
00037
00038
00039 const sk::util::Class getClass() const;
00040
00041 private:
00042 File& operator = (const File& other);
00043
00044 void open(const sk::util::String& mode, int permissions);
00045 void open(int mode, int permissions);
00046 int numericMode(const sk::util::String& mode);
00047 struct ::stat& stat() const;
00048
00049 sk::util::String _name;
00050 sk::util::Holder<sk::io::FileDescriptor> _descriptorHolder;
00051 mutable sk::util::Holder<struct ::stat> _statHolder;
00052 };
00053 }
00054 }
00055
00056 #if 0
00057 Mode | Meaning
00058 -----+--------------------------------------------------------
00059 "r" | Read-only, starts at beginning of file (default mode).
00060 -----+--------------------------------------------------------
00061 "r+" | Read-write, starts at beginning of file.
00062 -----+--------------------------------------------------------
00063 "w" | Write-only, truncates existing file
00064 | to zero length or creates a new file for writing.
00065 -----+--------------------------------------------------------
00066 "w+" | Read-write, truncates existing file to zero length
00067 | or creates a new file for reading and writing.
00068 -----+--------------------------------------------------------
00069 "a" | Write-only, starts at end of file if file exists,
00070 | otherwise creates a new file for writing.
00071 -----+--------------------------------------------------------
00072 "a+" | Read-write, starts at end of file if file exists,
00073 | otherwise creates a new file for reading and
00074 | writing.
00075 -----+--------------------------------------------------------
00076 "b" | (DOS/Windows only) Binary file mode (may appear with
00077 | any of the key letters listed above).
00078 #endif
00079
00080 #endif