Jpp 19.3.0-rc.3
the software that should make you happy
Loading...
Searching...
No Matches
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
9
10
11/**
12 * \file
13 * File status.
14 * \author mdejong
15 */
16namespace JSYSTEM {}
17namespace JPP { using namespace JSYSTEM; }
18
19namespace 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
Date and time functions.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary classes and methods for operating system calls.
static JStat getFileStatus
Function object for file status.
Definition JStat.hh:173
Interface for status of object.
Auxiliary class for date and time.
Auxiliary class for file status.
Definition JStat.hh:31
JStat(const char *file_name)
Constructor.
Definition JStat.hh:44
const JStat & get(const char *file_name)
Get status of file.
Definition JStat.hh:67
off_t getSize() const
Get size of file.
Definition JStat.hh:117
JStat()
Default constructor.
Definition JStat.hh:35
JDateAndTime getTimeOfLastChange() const
Get time of last change.
Definition JStat.hh:150
uid_t getUID() const
Get UID of file.
Definition JStat.hh:95
JDateAndTime getTimeOfLastModification() const
Get time of last modification.
Definition JStat.hh:139
virtual bool getStatus() const override
Get status of object.
Definition JStat.hh:55
const JStat & operator()(const char *file_name)
Get status of file.
Definition JStat.hh:84
uid_t getGID() const
Get GID of file.
Definition JStat.hh:106
int getError() const
Get error of last call.
Definition JStat.hh:161
JDateAndTime getTimeOfLastAccess() const
Get time of last access.
Definition JStat.hh:128
int error
error code from last call
Definition JStat.hh:166