AnCH Framework  0.1
Another C++ Hack Framework
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
file.hpp
1 /*
2  ANCH Framework: ANother C++ Hack is a C++ framework based on C++11 standard
3  Copyright (C) 2012 Vincent Lachenal
4 
5  This file is part of ANCH Framework.
6 
7  ANCH Framework is free software: you can redistribute it and/or modify
8  it under the terms of the GNU Lesser General Public License as published by
9  the Free Software Foundation, either version 3 of the License, or
10  (at your option) any later version.
11 
12  ANCH Framework is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public License
18  along with ANCH Framework. If not, see <http://www.gnu.org/licenses/>.
19 */
20 #ifndef _ANCH_FILE_FILE_H_
21 #define _ANCH_FILE_FILE_H_
22 
23 #include <iostream>
24 #include <vector>
25 #include <fstream>
26 #include <memory>
27 
28 #include "file/fileException.hpp"
29 #include "date/date.hpp"
30 
31 
32 namespace anch {
33  namespace file {
34 
40  class File {
41  // Attributes +
42  public:
44  static const char SEP;
45 
46  private:
48  std::string _path;
49 
51  std::shared_ptr<File> _parent;
52 
54  bool _exists = false;
55 
57  bool _directory = false;
58 
60  bool _readable = false;
61 
63  bool _writable = false;
64 
66  bool _executable = false;
67 
69  uint64_t _size;
70 
72  anch::date::Date _lastAccess;
73 
75  anch::date::Date _lastModification;
76 
78  anch::date::Date _lastStatusChange;
79  // Attributes -
80 
81  // Constructors +
82  public:
89  File(const std::string& path, bool init = true);
90 
97  File(const std::string& parent, const std::string& name);
98 
105  File(const File& parent, const std::string& name);
106 
113  File(std::shared_ptr<File> parent, const std::string& name);
114 
120  File(const File& file);
121  // Constructors -
122 
123  // Destructor +
124  public:
128  virtual ~File();
129  // Destructor -
130 
131  // Methods +
132  public:
138  void createFile() throw(anch::file::FileException);
139 
147  void createFile(std::ofstream& out) throw(anch::file::FileException);
148 
156  void createDirectory(bool parents = false) throw(anch::file::FileException);
157 
163  void deleteFile() throw(anch::file::FileException);
164 
172  void list(std::vector<std::string>& files) throw(anch::file::FileException);
173 
181  void list(std::vector<File>& files) throw(anch::file::FileException);
182 
183  private:
187  void initialize();
188  // Methods -
189 
190  // Accessors +
191  public:
197  inline const std::string& getPath() const {
198  return _path;
199  }
200 
206  inline std::shared_ptr<File> getParent() const {
207  return _parent;
208  }
209 
215  inline bool exists() const {
216  return _exists;
217  }
218 
224  inline bool isDirectory() const {
225  return _directory;
226  }
227 
233  inline bool isFile() const {
234  return !_directory;
235  }
236 
242  inline bool canRead() const {
243  return _readable;
244  }
245 
251  inline bool canWrite() const {
252  return _writable;
253  }
254 
260  inline bool canExecute() const {
261  return _executable;
262  }
263 
269  inline uint64_t getSize() const {
270  return _size;
271  }
272 
278  inline const anch::date::Date& getLastAccess() const {
279  return _lastAccess;
280  }
281 
287  inline const anch::date::Date& getLastModification() const {
288  return _lastModification;
289  }
290 
296  inline const anch::date::Date& getLastStatusChange() const {
297  return _lastStatusChange;
298  }
299  // Accessors -
300 
301  };
302 
303  }
304 }
305 
306 #endif // _ANCH_FILE_FILE_H_
bool exists() const
Definition: file.hpp:215
const std::string & getPath() const
Definition: file.hpp:197
void deleteFile()
Definition: file.cpp:208
bool canWrite() const
Definition: file.hpp:251
STL namespace.
virtual ~File()
Definition: file.cpp:140
const anch::date::Date & getLastModification() const
Definition: file.hpp:287
const anch::date::Date & getLastAccess() const
Definition: file.hpp:278
AnCH framework base namespace.
Definition: base64.hpp:28
Definition: fileException.hpp:34
bool canRead() const
Definition: file.hpp:242
std::shared_ptr< File > getParent() const
Definition: file.hpp:206
bool isDirectory() const
Definition: file.hpp:224
bool canExecute() const
Definition: file.hpp:260
void createFile()
Definition: file.cpp:153
File(const std::string &path, bool init=true)
Definition: file.cpp:56
const anch::date::Date & getLastStatusChange() const
Definition: file.hpp:296
bool isFile() const
Definition: file.hpp:233
void list(std::vector< std::string > &files)
Definition: file.cpp:228
Definition: file.hpp:40
static const char SEP
Definition: file.hpp:44
Definition: date.hpp:47
uint64_t getSize() const
Definition: file.hpp:269
void createDirectory(bool parents=false)
Definition: file.cpp:190