Jpp  pmt_effective_area_update_2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JStat.hh
Go to the documentation of this file.
1 #ifndef __JSYSTEM__JSTAT__
2 #define __JSYSTEM__JSTAT__
3 
4 #include <sys/stat.h>
5 #include <string>
6 
7 #include "JSystem/JDate.hh"
9 
10 
11 /**
12  * \file
13  * File status.
14  * \author mdejong
15  */
16 namespace JSYSTEM {}
17 namespace JPP { using namespace JSYSTEM; }
18 
19 namespace JSYSTEM {
20 
22 
23 
24  /**
25  * Auxiliary class for file status.
26  * This class encapsulates the <tt>stat</tt> data structure.
27  */
28  struct JStat :
29  public stat,
31  {
32  /**
33  * Default constructor.
34  */
36  {}
37 
38 
39  /**
40  * Constructor.
41  *
42  * \param file_name file name
43  */
44  JStat(const char* file_name)
45  {
46  get(file_name);
47  }
48 
49 
50  /**
51  * Get status of object.
52  *
53  * \return status of this object
54  */
55  virtual bool getStatus() const override
56  {
57  return this->error == 0;
58  }
59 
60 
61  /**
62  * Get status of file.
63  *
64  * \param file_name file name
65  * \return file status
66  */
67  const JStat& get(const char* file_name)
68  {
69  if (::stat(file_name, static_cast<stat*>(this)) != 0)
70  this->error = errno;
71  else
72  this->error = 0;
73 
74  return *this;
75  }
76 
77 
78  /**
79  * Get status of file.
80  *
81  * \param file_name file name
82  * \return file status
83  */
84  const JStat& operator()(const char* file_name)
85  {
86  return get(file_name);
87  }
88 
89 
90  /**
91  * Get UID of file.
92  *
93  * \return UID
94  */
95  uid_t getUID() const
96  {
97  return this->st_uid;
98  }
99 
100 
101  /**
102  * Get GID of file.
103  *
104  * \return GID
105  */
106  uid_t getGID() const
107  {
108  return this->st_gid;
109  }
110 
111 
112  /**
113  * Get size of file.
114  *
115  * \return size [B]
116  */
117  off_t getSize() const
118  {
119  return this->st_size;
120  }
121 
122 
123  /**
124  * Get time of last access.
125  *
126  * \return date and time
127  */
129  {
130  return JDateAndTime(this->st_atime);
131  }
132 
133 
134  /**
135  * Get time of last modification.
136  *
137  * \return date and time
138  */
140  {
141  return JDateAndTime(this->st_mtime);
142  }
143 
144 
145  /**
146  * Get time of last change.
147  *
148  * \return date and time
149  */
151  {
152  return JDateAndTime(this->st_ctime);
153  }
154 
155 
156  /**
157  * Get error of last call.
158  *
159  * \return error
160  */
161  int getError() const
162  {
163  return this->error;
164  }
165 
166  int error; //!< error code from last call
167  };
168 
169 
170  /**
171  * Function object for file status.
172  */
174 }
175 
176 #endif
177 
uid_t getUID() const
Get UID of file.
Definition: JStat.hh:95
uid_t getGID() const
Get GID of file.
Definition: JStat.hh:106
JStat(const char *file_name)
Constructor.
Definition: JStat.hh:44
JDateAndTime getTimeOfLastAccess() const
Get time of last access.
Definition: JStat.hh:128
Date and time functions.
JDateAndTime getTimeOfLastModification() const
Get time of last modification.
Definition: JStat.hh:139
int getError() const
Get error of last call.
Definition: JStat.hh:161
int error
error code from last call
Definition: JStat.hh:166
JDateAndTime getTimeOfLastChange() const
Get time of last change.
Definition: JStat.hh:150
static JStat getFileStatus
Function object for file status.
Definition: JStat.hh:173
JStat()
Default constructor.
Definition: JStat.hh:35
Auxililary class to get date and time.
Auxiliary class for file status.
Definition: JStat.hh:28
Interface for status of object.
virtual bool getStatus() const override
Get status of object.
Definition: JStat.hh:55
off_t getSize() const
Get size of file.
Definition: JStat.hh:117
const JStat & operator()(const char *file_name)
Get status of file.
Definition: JStat.hh:84