CASM  1.1.0
A Clusters Approach to Statistical Mechanics
FileData.hh
Go to the documentation of this file.
1 #include <ctime>
2 #include <string>
3 
4 #ifndef CASM_FileData_HH
5 #define CASM_FileData_HH
6 namespace CASM {
9 class FileData {
10  public:
12  FileData(std::string const &_path, std::time_t _timestamp)
13  : m_path(_path), m_timestamp(_timestamp) {}
14 
16  FileData(std::string const &_path) : m_path(_path), m_timestamp(0) {
17  this->refresh();
18  }
19 
21  FileData() : FileData("", 0) {}
22 
24  std::string const &path() const { return m_path; }
25 
28  std::time_t timestamp() const { return m_timestamp; }
29 
33  bool up_to_date() const { return (*this) == FileData(path()); }
34 
36  bool empty() const { return m_path.empty(); }
37 
39  bool exists() const;
40 
42  void refresh();
43 
45  bool operator==(FileData const &other) const {
46  return this->timestamp() == other.timestamp() &&
47  this->path() == other.path();
48  }
49 
50  private:
51  std::string m_path;
52  std::time_t m_timestamp;
53 };
54 } // namespace CASM
55 #endif
Interface class to check and/or store path and last_write_time of file on disk. Used to determine if ...
Definition: FileData.hh:9
bool exists() const
checks path for existing file. Does not alter stored timestamp
Definition: FileData.cc:9
FileData(std::string const &_path)
Construct with path, timestamp is set if file exists at path.
Definition: FileData.hh:16
FileData()
default constructor
Definition: FileData.hh:21
std::time_t timestamp() const
return stored timestamp. Timestamp corresponds to last_write_time of file timestamp defaults to 0 if ...
Definition: FileData.hh:28
std::string m_path
Definition: FileData.hh:51
bool empty() const
Returns true if path is empty.
Definition: FileData.hh:36
std::string const & path() const
return stored path
Definition: FileData.hh:24
bool up_to_date() const
checks timestamp of file at path. Returns true if last_write_time of file matches timestamp returns f...
Definition: FileData.hh:33
std::time_t m_timestamp
Definition: FileData.hh:52
void refresh()
Updates timestamp using stored path.
Definition: FileData.cc:11
bool operator==(FileData const &other) const
returns true if other FileData has same stored path and timestamp
Definition: FileData.hh:45
FileData(std::string const &_path, std::time_t _timestamp)
Construct with path and explicit timestamp.
Definition: FileData.hh:12
Main CASM namespace.
Definition: APICommand.hh:8