- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

gfile.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2013 Graeme Walker <graeme_walker@users.sourceforge.net>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 // ===
20
21 #ifndef G_FILE_H
22 #define G_FILE_H
23
24 #include "gdef.h"
25 #include "gpath.h"
26 #include "gexception.h"
27 #include "gdatetime.h"
28 #include <cstdio> // std::remove()
29
31 namespace G
32 {
33 class File ;
34 class DirectoryIteratorImp ;
35 }
36
41 class G::File
42 {
43 public:
44 G_EXCEPTION( StatError , "cannot stat() file" ) ;
45 G_EXCEPTION( CannotRemove , "cannot delete file" ) ;
46 G_EXCEPTION( CannotRename , "cannot rename file" ) ;
47 G_EXCEPTION( CannotCopy , "cannot copy file" ) ;
48 G_EXCEPTION( CannotMkdir , "cannot mkdir" ) ;
49 G_EXCEPTION( CannotChmod , "cannot chmod file" ) ;
50 G_EXCEPTION( CannotLink , "cannot create symlink" ) ;
51 G_EXCEPTION( CannotCreate , "cannot create empty file" ) ;
52 G_EXCEPTION( SizeOverflow , "file size overflow" ) ;
53 G_EXCEPTION( TimeError , "cannot get file modification time" ) ;
54 typedef DateTime::EpochTime time_type ;
56 class NoThrow
57 {} ;
58
59 static bool remove( const Path & path , const NoThrow & ) ;
61
62 static void remove( const Path & path ) ;
64
65 static bool rename( const Path & from , const Path & to , const NoThrow & ) ;
67
68 static void rename( const Path & from , const Path & to ) ;
70
71 static bool copy( const Path & from , const Path & to , const NoThrow & ) ;
73
74 static void copy( const Path & from , const Path & to ) ;
76
77 static void copy( std::istream & from , std::ostream & to ,
78 std::streamsize limit = 0U , std::string::size_type block = 0U ) ;
80
81 static bool mkdirs( const Path & dir , const NoThrow & , int = 100 ) ;
84
85 static void mkdirs( const Path & dir , int = 100 ) ;
88
89 static bool mkdir( const Path & dir , const NoThrow & ) ;
91
92 static void mkdir( const Path & dir ) ;
94
95 static std::string sizeString( const Path & file ) ;
98
99 static bool exists( const Path & file ) ;
103
104 static bool exists( const Path & file , const NoThrow & ) ;
107
108 static time_type time( const Path & file ) ;
110
111 static time_type time( const Path & file , const NoThrow & ) ;
114
115 static void chmodx( const Path & file ) ;
117
118 static bool chmodx( const Path & file , const NoThrow & ) ;
120
121 static void link( const Path & target , const Path & new_link ) ;
123
124 static bool link( const Path & target , const Path & new_link , const NoThrow & ) ;
126
127 static bool executable( const Path & ) ;
132
133 static void create( const Path & ) ;
135
136 private:
137 friend class G::DirectoryIteratorImp ;
138 static std::string copy( const Path & , const Path & , int ) ;
139 static std::string sizeString( g_uint32_t hi , g_uint32_t lo ) ; // win32
140 static bool exists( const Path & , bool , bool ) ;
141 static bool exists( const char * , bool & ) ; // o/s-specific
142 static bool chmodx( const Path & file , bool ) ;
143 } ;
144
145 #endif
G::DateTime::EpochTime
std::time_t EpochTime
Definition: gdatetime.h:41
G::File::copy
static bool copy(const Path &from, const Path &to, const NoThrow &)
Copies a file. Returns false on error.
Definition: gfile.cpp:70
G::File::time_type
DateTime::EpochTime time_type
Definition: gfile.h:44
G::File::create
static void create(const Path &)
Creates an empty file. Throws on error.
Definition: gfile.cpp:188
md5::size_type
std::string::size_type size_type
A std::size_t type.
Definition: md5.h:43
G::File
A simple static class for dealing with files.
Definition: gfile.h:41
G::File::rename
static bool rename(const Path &from, const Path &to, const NoThrow &)
Renames the file. Returns false on error.
Definition: gfile.cpp:46
G::File::mkdirs
static bool mkdirs(const Path &dir, const NoThrow &, int=100)
Creates a directory and all necessary parents.
Definition: gfile.cpp:169
G::File::executable
static bool executable(const Path &)
Returns true if the path is probably executable.
Definition: gfile_unix.cpp:50
G
Low-level classes.
G::File::exists
static bool exists(const Path &file)
Returns true if the file (directory, link, device etc.) exists.
Definition: gfile.cpp:130
G::File::mkdir
static bool mkdir(const Path &dir, const NoThrow &)
Creates a directory. Returns false on error.
Definition: gfile_unix.cpp:30
G::File::NoThrow
An overload discriminator class for File methods.
Definition: gfile.h:56
gdatetime.h
gexception.h
G_EXCEPTION
#define G_EXCEPTION(class_name, description)
define as a function rather than a type if optimising for size
Definition: gexception.h:93
G::File::chmodx
static void chmodx(const Path &file)
Makes the file executable.
Definition: gfile.cpp:164
gpath.h
G::File::link
static void link(const Path &target, const Path &new_link)
Creates a symlink.
Definition: gfile_unix.cpp:111
G::File::sizeString
static std::string sizeString(const Path &file)
Returns the file's size in string format.
Definition: gfile_unix.cpp:67
G::DirectoryIteratorImp
A pimple-pattern implementation class for DirectoryIterator.
Definition: gdirectory_unix_glob.cpp:42
G::Path
A Path object represents a file system path.
Definition: gpath.h:44
G::File::time
static time_type time(const Path &file)
Returns the file's timestamp.
Definition: gfile_unix.cpp:78