PCL
FileInfo.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.4.0
6 // ----------------------------------------------------------------------------
7 // pcl/FileInfo.h - Released 2020-07-31T19:33:04Z
8 // ----------------------------------------------------------------------------
9 // This file is part of the PixInsight Class Library (PCL).
10 // PCL is a multiplatform C++ framework for development of PixInsight modules.
11 //
12 // Copyright (c) 2003-2020 Pleiades Astrophoto S.L. All Rights Reserved.
13 //
14 // Redistribution and use in both source and binary forms, with or without
15 // modification, is permitted provided that the following conditions are met:
16 //
17 // 1. All redistributions of source code must retain the above copyright
18 // notice, this list of conditions and the following disclaimer.
19 //
20 // 2. All redistributions in binary form must reproduce the above copyright
21 // notice, this list of conditions and the following disclaimer in the
22 // documentation and/or other materials provided with the distribution.
23 //
24 // 3. Neither the names "PixInsight" and "Pleiades Astrophoto", nor the names
25 // of their contributors, may be used to endorse or promote products derived
26 // from this software without specific prior written permission. For written
27 // permission, please contact info@pixinsight.com.
28 //
29 // 4. All products derived from this software, in any form whatsoever, must
30 // reproduce the following acknowledgment in the end-user documentation
31 // and/or other materials provided with the product:
32 //
33 // "This product is based on software from the PixInsight project, developed
34 // by Pleiades Astrophoto and its contributors (http://pixinsight.com/)."
35 //
36 // Alternatively, if that is where third-party acknowledgments normally
37 // appear, this acknowledgment must be reproduced in the product itself.
38 //
39 // THIS SOFTWARE IS PROVIDED BY PLEIADES ASTROPHOTO AND ITS CONTRIBUTORS
40 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
41 // TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL PLEIADES ASTROPHOTO OR ITS
43 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
44 // EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, BUSINESS
45 // INTERRUPTION; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; AND LOSS OF USE,
46 // DATA OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49 // POSSIBILITY OF SUCH DAMAGE.
50 // ----------------------------------------------------------------------------
51 
52 #ifndef __PCL_FileInfo_h
53 #define __PCL_FileInfo_h
54 
56 
57 #include <pcl/Defs.h>
58 #include <pcl/Diagnostics.h>
59 
60 #include <pcl/File.h>
61 
62 namespace pcl
63 {
64 
65 // ----------------------------------------------------------------------------
66 
73 class PCL_CLASS FileInfo
74 {
75 public:
76 
82  {
83  Clear();
84  }
85 
90  FileInfo( const String& path )
91  {
92  Refresh( path );
93  }
94 
98  FileInfo( const FileInfo& ) = default;
99 
103  virtual ~FileInfo()
104  {
105  }
106 
110  FileInfo& operator =( const FileInfo& ) = default;
111 
115  const String& Path() const
116  {
117  return m_path;
118  }
119 
127  String Drive() const
128  {
129  return File::ExtractDrive( m_path );
130  }
131 
146  {
147  return File::ExtractDirectory( m_path );
148  }
149 
161  String Name() const
162  {
163  return File::ExtractName( m_path );
164  }
165 
178  {
179  return File::ExtractExtension( m_path );
180  }
181 
185  String Suffix() const
186  {
187  return Extension();
188  }
189 
201  {
202  return File::ExtractCompleteSuffix( m_path );
203  }
204 
210  {
211  return File::ExtractNameAndExtension( m_path );
212  }
213 
218  {
219  return NameAndExtension();
220  }
221 
225  bool Exists() const
226  {
227  return m_exists;
228  }
229 
234  const FileAttributes& Attributes() const
235  {
236  return m_attributes;
237  }
238 
242  bool IsDirectory() const
243  {
244  return m_attributes.IsFlagSet( FileAttribute::Directory );
245  }
246 
250  bool IsFile() const
251  {
252  return m_attributes.IsFlagSet( FileAttribute::Regular );
253  }
254 
261  bool IsSymbolicLink() const
262  {
263  return m_attributes.IsFlagSet( FileAttribute::SymbolicLink );
264  }
265 
273  String SymbolicLinkTarget() const;
274 
283  bool IsHidden() const
284  {
285  return m_attributes.IsFlagSet( FileAttribute::Hidden );
286  }
287 
292  bool IsReadable() const
293  {
294  return m_readable;
295  }
296 
301  bool IsWritable() const
302  {
303  return m_writable;
304  }
305 
318  bool IsExecutable() const
319  {
320  return m_executable;
321  }
322 
331  fsize_type Size() const
332  {
333  return m_size;
334  }
335 
343  int NumberOfHardLinks() const
344  {
345  return m_numberOfHardLinks;
346  }
347 
355  int UserId() const
356  {
357  return m_userId;
358  }
359 
367  int GroupId() const
368  {
369  return m_groupId;
370  }
371 
376  const FileTime& TimeCreated() const
377  {
378  return m_created;
379  }
380 
385  const FileTime& LastAccessed() const
386  {
387  return m_lastAccessed;
388  }
389 
394  const FileTime& LastModified() const
395  {
396  return m_lastModified;
397  }
398 
402  void Refresh();
403 
407  void Refresh( const String& path );
408 
413  void Clear();
414 
415 private:
416 
417  String m_path; // full file or directory path
418  FileAttributes m_attributes; // item attributes
419  fsize_type m_size; // file size in bytes
420  int m_numberOfHardLinks; // number of existing hard links to this file
421  int m_userId; // user id of the file owner
422  int m_groupId; // group id of the file owner
423  FileTime m_created; // creation time
424  FileTime m_lastAccessed; // time of last access
425  FileTime m_lastModified; // time of last change
426  bool m_exists; // item exists
427  bool m_readable; // caller has read permission
428  bool m_writable; // caller has write permission
429  bool m_executable; // caller has execute permission
430 
431  // Clears everything but *preserves* m_path
432  void ClearData();
433 };
434 
435 // ----------------------------------------------------------------------------
436 
437 } // pcl
438 
439 #endif // __PCL_FileInfo_h
440 
441 // ----------------------------------------------------------------------------
442 // EOF pcl/FileInfo.h - Released 2020-07-31T19:33:04Z
const String & Path() const
Definition: FileInfo.h:115
bool IsWritable() const
Definition: FileInfo.h:301
bool IsHidden() const
Definition: FileInfo.h:283
static String ExtractExtension(const String &path)
bool IsExecutable() const
Definition: FileInfo.h:318
static String ExtractNameAndExtension(const String &path)
virtual ~FileInfo()
Definition: FileInfo.h:103
const FileTime & LastAccessed() const
Definition: FileInfo.h:385
String Extension() const
Definition: FileInfo.h:177
String Suffix() const
Definition: FileInfo.h:185
PCL root namespace.
Definition: AbstractImage.h:76
String Name() const
Definition: FileInfo.h:161
int GroupId() const
Definition: FileInfo.h:367
String Drive() const
Definition: FileInfo.h:127
bool IsDirectory() const
Definition: FileInfo.h:242
FileInfo(const String &path)
Definition: FileInfo.h:90
const FileTime & TimeCreated() const
Definition: FileInfo.h:376
static String ExtractCompleteSuffix(const String &path)
Unicode (UTF-16) string.
Definition: String.h:7916
Platform-independent information on file and directory items.
Definition: FileInfo.h:73
A combination of file type, attribute and access mode flags.
int64 fsize_type
Definition: Defs.h:1119
bool IsReadable() const
Definition: FileInfo.h:292
String Directory() const
Definition: FileInfo.h:145
int UserId() const
Definition: FileInfo.h:355
String CompleteSuffix() const
Definition: FileInfo.h:200
fsize_type Size() const
Definition: FileInfo.h:331
static String ExtractName(const String &path)
String NameAndExtension() const
Definition: FileInfo.h:209
bool IsFile() const
Definition: FileInfo.h:250
const FileAttributes & Attributes() const
Definition: FileInfo.h:234
static String ExtractDirectory(const String &path)
bool IsSymbolicLink() const
Definition: FileInfo.h:261
bool Exists() const
Definition: FileInfo.h:225
File date and time.
Definition: File.h:288
int NumberOfHardLinks() const
Definition: FileInfo.h:343
String NameAndSuffix() const
Definition: FileInfo.h:217
static String ExtractDrive(const String &path)
const FileTime & LastModified() const
Definition: FileInfo.h:394