• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

spl/io/File.h

00001 /*
00002  *   This file is part of the Standard Portable Library (SPL).
00003  *
00004  *   SPL is free software: you can redistribute it and/or modify
00005  *   it under the terms of the GNU General Public License as published by
00006  *   the Free Software Foundation, either version 3 of the License, or
00007  *   (at your option) any later version.
00008  *
00009  *   SPL is distributed in the hope that it will be useful,
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *   GNU General Public License for more details.
00013  *
00014  *   You should have received a copy of the GNU General Public License
00015  *   along with SPL.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 #ifndef _cfile_h
00018 #define _cfile_h
00019 
00020 #include <spl/types.h>
00021 #include <spl/Debug.h>
00022 
00023 #ifdef _WINDOWS
00024 #include <spl/configwin32.h>
00025 #else
00026 #include <spl/autoconf/config.h>
00027 #endif
00028 
00029 #include <spl/collection/Array.h>
00030 #include <spl/DateTime.h>
00031 #include <spl/Memory.h>
00032 #include <spl/io/IStream.h>
00033 #include <spl/io/Permissions.h>
00034 #include <spl/RefCountPtr.h>
00035 #include <spl/String.h>
00036 #include <spl/io/TextStream.h>
00037 
00046 class File
00047 {
00048 private:
00049         inline File() {}
00050         inline File& operator =(const File&) {}
00051 
00052 public:
00053         typedef enum _FileMode
00054         {
00055                 FILEMODE_Append = 6,
00056                 FILEMODE_Create = 2,
00057                 FILEMODE_CreateNew = 1,
00058                 FILEMODE_Open = 3,
00059                 FILEMODE_OpenOrCreate = 4,
00060                 FILEMODE_Truncate = 5
00061         } FileMode;
00062 
00063         typedef enum _FileAccess
00064         {
00065                 FILEACC_Read = 0x1,
00066                 FILEACC_Write = 0x2,
00067                 FILEACC_ReadWrite = FILEACC_Read | FILEACC_Write
00068         } FileAccess;
00069 
00070 protected:
00071 public:
00072         static void Delete( const String& filename );
00073         static void Rename(const String& oldname, const String& newname);
00074         static void Move(const String &oldFile, const String &newFile);
00075         
00076         static bool Exists( const String& filename );
00077         
00078         static void Copy( const String& sourcefile, const String& destfile );
00079         static void Copy( const String& sourcefile, const String& destfile, bool overwrite );
00080 
00081         static RefCountPtr<Array<byte> > LoadBinary( const String& filename );
00082         static StringPtr LoadText( const String& filename );
00083 
00084         static StringPtr ToOsFilePath( const String& filepathname );
00085         static StringPtr GetFileName( const String& filepathname );
00086 
00087         static TextWriterPtr AppendText( const String& filename );
00088         static spl::IStreamPtr Create( const String& filename );
00089         static TextWriterPtr CreateText( const String& filename );
00090         static TextReaderPtr ReadText( const String& filename );
00091         static spl::IStreamPtr Open( const String& filename, FileMode mode );
00092         static spl::IStreamPtr Open( const String& filename, FileMode mode, FileAccess access );
00093         static spl::IStreamPtr OpenRead( const String& filename );
00094         static spl::IStreamPtr OpenText( const String& filename );
00095         static spl::IStreamPtr OpenWrite( const String& filename );
00096 
00097         static long Size( const String& filename );
00098         static DateTime GetCreationTime( const String& filename );
00099         static DateTime GetLastAccessTime( const String& filename );
00100         static DateTime GetLastWriteTime( const String& filename );
00101 
00102         static bool IsFile(const String& filename);
00103 
00104         static Permissions GetPermissions(const String& filename);
00105         static void SetPermissions(const String& filename, const Permissions& perms);
00106 };
00107 
00108 REGISTER_TYPEOF(90, File);
00109 
00112 #endif