FileInfo.h
1 /*
2  * Copyright (C) 2006-2013 Marc Boris Duerner
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * As a special exception, you may use this file as part of a free
10  * software library without restriction. Specifically, if other files
11  * instantiate templates or use macros or inline functions from this
12  * file, or you compile this file and link it with other files to
13  * produce an executable, this file does not by itself cause the
14  * resulting executable to be covered by the GNU General Public
15  * License. This exception does not however invalidate any other
16  * reasons why the executable file might be covered by the GNU Library
17  * General Public License.
18  *
19  * This library is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  * Lesser General Public License for more details.
23  *
24  * You should have received a copy of the GNU Lesser General Public
25  * License along with this library; if not, write to the Free Software
26  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27  */
28 
29 #ifndef Pt_System_FileInfo_h
30 #define Pt_System_FileInfo_h
31 
32 #include <Pt/System/Api.h>
33 #include <Pt/System/Path.h>
34 #include <Pt/DateTime.h>
35 #include <Pt/String.h>
36 #include <Pt/Types.h>
37 #include <string>
38 
39 namespace Pt {
40 
41 namespace System {
42 
103 class PT_SYSTEM_API FileInfo
104 {
105  public:
107  enum Type
108  {
109  Invalid = 0,
110  Directory = 1,
111  File = 2
112  };
113 
114  public:
117  {}
118 
121  explicit FileInfo(const Path& path);
122 
125  explicit FileInfo(const Pt::String& path);
126 
129  explicit FileInfo(const char* path);
130 
133  {}
134 
136  void clear();
137 
143  const Path& path() const
144  { return _path; }
145 
148  { return FileInfo::size(_path); }
149 
151  Type type() const
152  { return FileInfo::type(_path); }
153 
154  public:
156  static Type type(const Path& path);
157 
159  static Pt::uint64_t size(const Path& path);
160 
162  static DateTime lastModified(const Path& path);
163 
165  static bool exists(const Path& path)
166  { return type(path) != Invalid; }
167 
169  static void createFile(const Path& path);
170 
172  static void createDirectory(const Path& path);
173 
175  static void createDirectories(const Path& path);
176 
178  static void resize(const Path& path, Pt::uint64_t n);
179 
181  static void remove(const Path& path);
182 
184  static void removeAll(const Pt::System::Path& path);
185 
187  static void move(const Path& path, const Path& to);
188 
189  public:
191  Path& path()
192  { return _path; }
193 
194  private:
195  Path _path;
196 };
197 
198 
203 inline bool operator<(const FileInfo& a, const FileInfo& b)
204 {
205  return a.path() < b.path();
206 }
207 
212 inline bool operator==(const FileInfo& a, const FileInfo& b)
213 {
214  return a.path() == b.path();
215 }
216 
221 inline bool operator!=(const FileInfo& a, const FileInfo& b)
222 {
223  return !(a == b);
224 }
225 
226 } // namespace System
227 
228 } // namespace Pt
229 
230 #endif // Pt_System_FileInfo_h
~FileInfo()
Destructor.
Definition: FileInfo.h:132
Provides information about a node in the file-system.
Definition: FileInfo.h:103
Type type() const
Returns the file type.
Definition: FileInfo.h:151
FileInfo()
Default constructor.
Definition: FileInfo.h:116
Represents a path in the file-system.
Definition: Path.h:47
Pt::uint64_t size() const
Returns the file size.
Definition: FileInfo.h:147
Combined Date and Time value.
Definition: DateTime.h:59
static bool exists(const Path &path)
Returns true if a file or directory exists at the path.
Definition: FileInfo.h:165
Type
File-node type.
Definition: FileInfo.h:107
uint_type uint64_t
Unsigned 64-bit integer type.
Definition: Types.h:54
Unicode capable basic_string.
Definition: String.h:42
bool operator==(const FileInfo &a, const FileInfo &b)
Compare two FileInfo objects.
Definition: FileInfo.h:212
bool operator<(const FileInfo &a, const FileInfo &b)
Compare two FileInfo objects.
Definition: FileInfo.h:203
bool operator!=(const FileInfo &a, const FileInfo &b)
Compare two FileInfo objects.
Definition: FileInfo.h:221
const Path & path() const
Returns the full path of node in the file-system.
Definition: FileInfo.h:143