PCL
File.h
Go to the documentation of this file.
1 // ____ ______ __
2 // / __ \ / ____// /
3 // / /_/ // / / /
4 // / ____// /___ / /___ PixInsight Class Library
5 // /_/ \____//_____/ PCL 2.1.19
6 // ----------------------------------------------------------------------------
7 // pcl/File.h - Released 2019-11-07T10:59:34Z
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-2019 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_File_h
53 #define __PCL_File_h
54 
56 
57 #include <pcl/Defs.h>
58 #include <pcl/Diagnostics.h>
59 
60 #include <pcl/ByteArray.h>
61 #include <pcl/Exception.h>
62 #include <pcl/Flags.h>
63 #include <pcl/StringList.h>
64 
65 #ifndef __PCL_FILE_DONT_REMOVE_PREVIOUS_DECLARATION
66 
67 /*
68  * Remove conflicting identifiers from Win32 SDK headers.
69  */
70 
71 #ifdef CreateFile
72 #undef CreateFile
73 #endif
74 
75 #ifdef CopyFile
76 #undef CopyFile
77 #endif
78 
79 #ifdef MoveFile
80 #undef MoveFile
81 #endif
82 
83 #ifdef CreateDirectory
84 #undef CreateDirectory
85 #endif
86 
87 #ifdef RemoveDirectory
88 #undef RemoveDirectory
89 #endif
90 
91 #endif // !__PCL_FILE_DONT_REMOVE_PREVIOUS_DECLARATION
92 
93 namespace pcl
94 {
95 
96 // ----------------------------------------------------------------------------
97 
102 // ----------------------------------------------------------------------------
103 
122 namespace FileMode
123 {
124  enum mask_type
125  {
126  Zero = 0x00000000,
127 
128  /*
129  * Access mode
130  */
131  Read = 0x00000001,
132  Write = 0x00000002,
133  AccessMode = 0x0000000F,
134 
135  /*
136  * Share mode (Windows only)
137  */
138  ShareRead = 0x00000010,
139  ShareWrite = 0x00000020,
140  ShareMode = 0x000000F0,
141 
142  /*
143  * Open/create mode
144  */
145  Open = 0x00000100,
146  Create = 0x00000200,
147  OpenMode = 0x00000F00
148  };
149 }
150 
156 typedef Flags<FileMode::mask_type> FileModes;
157 
158 // ----------------------------------------------------------------------------
159 
172 namespace SeekMode
173 {
174  enum value_type
175  {
176  FromBegin, // Move relative to the beginning of the file
177  FromCurrent, // Move from current position
178  FromEnd, // Move relative to the end of the file
179  NumberOfSeekModes
180  };
181 }
182 
183 // ----------------------------------------------------------------------------
184 
224 namespace FileAttribute
225 {
226  enum mask_type
227  {
228  /*
229  * File type.
230  */
231  Block = 0x00000001, // Block special
232  Character = 0x00000002, // Character special
233  FIFO = 0x00000004, // FIFO special
234  Regular = 0x00000008, // Regular file
235  Directory = 0x00000010, // Directory
236  SymbolicLink = 0x00000020, // Symbolic link
237  Socket = 0x00000040, // Socket
238  FileType = 0x000000FF,
239 
240  /*
241  * File attributes.
242  * These are Windows-exclusive, except ReadOnly and Hidden, which we
243  * emulate on UNIX and Linux.
244  */
245  Archive = 0x00001000, // File is archived
246  Compressed = 0x00002000, // File is compressed
247  Encrypted = 0x00004000, // File is encrypted
248  Hidden = 0x00008000, // File is hidden
249  ReadOnly = 0x00010000, // File is read-only
250  System = 0x00020000, // File is a system file
251  Temporary = 0x00040000, // File is a temporary file
252  FileAttributes = 0x000FF000,
253 
254  /*
255  * File permissions.
256  */
257  Read = 0x00100000, // Owner can read
258  Write = 0x00200000, // Owner can write
259  Execute = 0x00400000, // Owner can execute/search
260  ReadGroup = 0x01000000, // Group can read
261  WriteGroup = 0x02000000, // Group can write
262  ExecuteGroup = 0x04000000, // Group can execute/search
263  ReadOthers = 0x10000000, // Others can read
264  WriteOthers = 0x20000000, // Others can write
265  ExecuteOthers = 0x40000000, // Others can execute/search
266  FilePermissions= 0xFFF00000
267  };
268 }
269 
275 typedef Flags<FileAttribute::mask_type> FileAttributes;
276 
277 // ----------------------------------------------------------------------------
278 
288 struct FileTime
289 {
290  uint16 year : 16;
291  uint8 month : 4;
292  uint8 day : 5;
293  uint8 hour : 5;
294  int : 2;
295  uint8 minute : 6;
296  uint8 second : 6;
297  int : 4;
299  int : 6;
300 
304  bool operator ==( const FileTime& t ) const
305  {
306  return second == t.second && minute == t.minute && hour == t.hour &&
307  day == t.day && month == t.month && year == t.year &&
308  milliseconds == t.milliseconds;
309  }
310 
314  bool operator <( const FileTime& t ) const
315  {
316  if ( year != t.year ) return year < t.year;
317  if ( month != t.month ) return month < t.month;
318  if ( day != t.day ) return day < t.day;
319  if ( hour != t.hour ) return hour < t.hour;
320  if ( minute != t.minute ) return minute < t.minute;
321  if ( second != t.second ) return second < t.second;
322  if ( milliseconds != t.milliseconds ) return milliseconds < t.milliseconds;
323  return false;
324  }
325 
330  double ToJD() const;
331 
336  double DaysSinceEpoch() const
337  {
338  return ToJD() - 2440587.5;
339  }
340 
345  double SecondsSinceEpoch() const
346  {
347  return 86400*DaysSinceEpoch();
348  }
349 };
350 
351 // ----------------------------------------------------------------------------
352 
360 {
362  FileAttributes attributes;
365  int userId;
366  int groupId;
370 
374  bool IsDirectory() const
375  {
376  return attributes.IsFlagSet( FileAttribute::Directory );
377  }
378 
383  bool IsArchive() const
384  {
385  return attributes.IsFlagSet( FileAttribute::Archive );
386  }
387 
392  bool IsCompressed() const
393  {
394  return attributes.IsFlagSet( FileAttribute::Compressed );
395  }
396 
401  bool IsEncrypted() const
402  {
403  return attributes.IsFlagSet( FileAttribute::Encrypted );
404  }
405 
410  bool IsHidden() const
411  {
412  return attributes.IsFlagSet( FileAttribute::Hidden );
413  }
414 
419  bool IsReadOnly() const
420  {
421  return attributes.IsFlagSet( FileAttribute::ReadOnly );
422  }
423 
428  bool IsSystem() const
429  {
430  return attributes.IsFlagSet( FileAttribute::System );
431  }
432 
437  bool IsTemporary() const
438  {
439  return attributes.IsFlagSet( FileAttribute::Temporary );
440  }
441 
445  bool IsEmpty() const
446  {
447  return size == 0;
448  }
449 };
450 
451 // ----------------------------------------------------------------------------
452 
467 namespace ReadTextOption
468 {
469  enum mask_type
470  {
471  RemoveEmptyLines = 0x0001,
472  TrimTrailingSpaces = 0x0002,
473  TrimLeadingSpaces = 0x0004,
474  TrimSpaces = TrimTrailingSpaces | TrimLeadingSpaces
475  };
476 }
477 
485 
486 // ----------------------------------------------------------------------------
487 
496 class PCL_CLASS File
497 {
498 public:
499 
503  typedef void* handle;
504 
508  typedef SeekMode::value_type seek_mode;
509 
515  class PCL_CLASS Error : public pcl::Error
516  {
517  public:
518 
523  Error( const String& filePath, const String& message ) :
524  pcl::Error( message ),
525  m_filePath( filePath )
526  {
527  }
528 
532  Error( const Error& ) = default;
533 
536  String ExceptionClass() const override
537  {
538  return "File I/O Error";
539  }
540 
544  virtual String FilePath() const
545  {
546  return m_filePath;
547  }
548 
551  virtual String ErrorMessage() const
552  {
553  return m_message;
554  }
555 
558  String Message() const override
559  {
560  String filePath = FilePath();
561  String message = m_message;
562  if ( !filePath.IsEmpty() )
563  {
564  message += ": ";
565  message += filePath;
566  }
567  return message;
568  }
569 
570  private:
571 
572  String m_filePath;
573  };
574 
611  class PCL_CLASS Find
612  {
613  public:
614 
618  Find() = default;
619 
627  Find( const String& path )
628  {
629  Begin( path );
630  }
631 
637  {
638  End();
639  }
640 
645  Find( const Find& ) = delete;
646 
651  Find& operator =( const Find& ) = delete;
652 
659  void Begin( const String& path );
660 
672  bool NextItem( FindFileInfo& info );
673 
678  void End();
679 
684  {
685  return m_searchPath;
686  }
687 
688  private:
689 
690  FindFileInfo m_info;
691  String m_searchPath;
692 #ifndef __PCL_WINDOWS
693  String m_searchDir;
694  String m_searchName;
695 #endif
696  void* m_handle = nullptr;
697  };
698 
712  class PCL_CLASS Progress
713  {
714  public:
715 
729  Progress( fsize_type total, const String& initialText = String(), fsize_type initialValue = 0 ) :
730  m_total( Max( fsize_type( 0 ), total ) ),
731  m_current( Range( initialValue, fsize_type( 0 ), m_total ) ),
732  m_text( initialText ),
733  m_abort( false )
734  {
735  }
736 
740  virtual ~Progress()
741  {
742  }
743 
748  {
749  return m_total;
750  }
751 
756  {
757  return m_current;
758  }
759 
763  const String& Text() const
764  {
765  return m_text;
766  }
767 
775  void SetValue( fsize_type current )
776  {
777  if ( current >= m_current )
778  {
779  m_current = current;
780 
781  if ( !ValueChanged() )
782  {
783  m_abort = true;
784  throw ProcessAborted();
785  }
786  }
787  }
788 
796  void Add( fsize_type delta )
797  {
798  if ( delta >= 0 )
799  {
800  m_current += delta;
801 
802  if ( !ValueChanged() )
803  {
804  m_abort = true;
805  throw ProcessAborted();
806  }
807  }
808  }
809 
817  void SetText( const String& text )
818  {
819  m_text = text;
820 
821  if ( !TextChanged() )
822  {
823  m_abort = true;
824  throw ProcessAborted();
825  }
826  }
827 
831  bool IsAborted() const
832  {
833  return m_abort;
834  }
835 
836  protected:
837 
838  fsize_type m_total;
839  fsize_type m_current;
840  String m_text;
841  bool m_abort : 1;
842 
850  virtual bool ValueChanged() = 0;
851 
859  virtual bool TextChanged() = 0;
860  };
861 
862  // -------------------------------------------------------------------------
863 
868  {
869  Initialize();
870  }
871 
876  File( const String& path, FileModes mode )
877  {
878  PCL_PRECONDITION( !path.IsEmpty() )
879  Initialize();
880  Open( path, mode );
881  }
882 
886  File( File&& x ) :
887  m_fileHandle( x.m_fileHandle ),
888  m_filePath( std::move( x.m_filePath ) ),
889  m_fileMode( x.m_fileMode )
890  {
891  x.m_fileHandle = s_invalidHandle;
892  x.m_fileMode = FileMode::Zero;
893  }
894 
898  File& operator =( File&& x )
899  {
900  if ( &x != this )
901  {
902  if ( IsOpen() )
903  Close();
904  m_fileHandle = x.m_fileHandle;
905  m_filePath = std::move( x.m_filePath );
906  m_fileMode = x.m_fileMode;
907  x.m_fileHandle = s_invalidHandle;
908  x.m_fileMode = FileMode::Zero;
909  }
910  return *this;
911  }
912 
917  virtual ~File()
918  {
919  if ( IsOpen() )
920  Close();
921  }
922 
927  File( const File& ) = delete;
928 
933  File& operator =( const File& ) = delete;
934 
938  bool IsOpen() const
939  {
940  return IsValidHandle( m_fileHandle );
941  }
942 
947  const String& FilePath() const
948  {
949  return m_filePath;
950  }
951 
958  const String& FileName() const
959  {
960  return FilePath();
961  }
962 
966  FileModes Mode() const
967  {
968  return m_fileMode;
969  }
970 
974  virtual bool CanRead() const
975  {
976  return m_fileMode.IsFlagSet( FileMode::Read );
977  }
978 
982  virtual bool CanWrite() const
983  {
984  return m_fileMode.IsFlagSet( FileMode::Write );
985  }
986 
991  virtual fpos_type Position() const;
992 
996  virtual void SetPosition( fpos_type pos );
997 
1005  fpos_type Seek( fpos_type dist, seek_mode mode = SeekMode::FromCurrent );
1006 
1016  {
1017  return Seek( 0, SeekMode::FromEnd );
1018  }
1019 
1025  void Rewind()
1026  {
1027  SetPosition( 0 );
1028  }
1029 
1034  bool IsEOF() const
1035  {
1036  return Position() >= Size();
1037  }
1038 
1042  virtual fsize_type Size() const;
1043 
1047  virtual void Resize( fsize_type length );
1048 
1052  virtual void Read( void* buffer, fsize_type len );
1053 
1057  template <typename T>
1058  void Read( T& x )
1059  {
1060  Read( (void*)&x, sizeof( T ) );
1061  }
1062 
1070  template <typename T>
1071  void ReadArray( T* a, size_type n )
1072  {
1073  Read( (void*)a, n*sizeof( T ) );
1074  }
1075 
1079  template <typename T>
1080  void ReadI32( T& x )
1081  {
1082  int32 i; Read( i ); x = T( i );
1083  }
1084 
1088  template <typename T>
1089  void ReadUI32( T& x )
1090  {
1091  uint32 i; Read( i ); x = T( i );
1092  }
1093 
1097  template <typename T>
1098  void ReadI64( T& x )
1099  {
1100  int64 i; Read( i ); x = T( i );
1101  }
1102 
1106  template <typename T>
1107  void ReadUI64( T& x )
1108  {
1109  uint64 i; Read( i ); x = T( i );
1110  }
1111 
1115  virtual void Write( const void* buffer, fsize_type len );
1116 
1120  template <typename T>
1121  void Write( const T& x )
1122  {
1123  Write( (const void*)&x, sizeof( T ) );
1124  }
1125 
1133  template <typename T>
1134  void WriteArray( const T* a, size_type n )
1135  {
1136  Write( (const void*)a, n*sizeof( T ) );
1137  }
1138 
1142  template <typename T>
1143  void WriteI32( const T& x )
1144  {
1145  Write( int32( x ) );
1146  }
1147 
1151  template <typename T>
1152  void WriteUI32( const T& x )
1153  {
1154  Write( uint32( x ) );
1155  }
1156 
1160  template <typename T>
1161  void WriteI64( const T& x )
1162  {
1163  Write( int64( x ) );
1164  }
1165 
1169  template <typename T>
1170  void WriteUI64( const T& x )
1171  {
1172  Write( uint64( x ) );
1173  }
1174 
1181  void Read( bool& b )
1182  {
1183  unsigned i; ReadUI32( i ); b = i != 0;
1184  }
1185 
1192  void Write( const bool& b )
1193  {
1194  WriteUI32( b ? 1 : 0 );
1195  }
1196 
1202  void Read( IsoString& s );
1203 
1209  void Read( String& s );
1210 
1215  void Write( const char* i, const char* j );
1216 
1220  void Write( const char* s )
1221  {
1222  Write( s, s + IsoCharTraits::Length( s ) );
1223  }
1224 
1228  void Write( const IsoString& s )
1229  {
1230  Write( s.Begin(), s.End() );
1231  }
1232 
1237  void Write( const char16_type* i, const char16_type* j );
1238 
1242  void Write( const char16_type* s )
1243  {
1244  Write( s, s + CharTraits::Length( s ) );
1245  }
1246 
1250  void Write( const String& s )
1251  {
1252  Write( s.Begin(), s.End() );
1253  }
1254 
1255 #ifndef __PCL_NO_FLAGS_FILE_IO
1256 
1260  template <typename E>
1261  static void Read( Flags<E>& f )
1262  {
1263  Read( f.m_flags );
1264  }
1265 
1269  template <typename E>
1270  static void ReadUI32( Flags<E>& f )
1271  {
1272  ReadUI32( f.m_flags );
1273  }
1274 
1278  template <typename E>
1279  static void Write( Flags<E> f )
1280  {
1281  Write( f.m_flags );
1282  }
1283 
1287  template <typename E>
1288  static void WriteUI32( Flags<E> f )
1289  {
1290  WriteUI32( f.m_flags );
1291  }
1292 
1293 #endif
1294 
1299  void OutText( const char* i, const char* j )
1300  {
1301  if ( i < j )
1302  Write( (const void*)i, fsize_type( j - i ) );
1303  }
1304 
1308  void OutText( const char* s )
1309  {
1310  OutText( s, s + IsoCharTraits::Length( s ) );
1311  }
1312 
1316  void OutText( const IsoString& s )
1317  {
1318  OutText( s.Begin(), s.End() );
1319  }
1320 
1325  void OutText( const char16_type* i, const char16_type* j )
1326  {
1327  if ( i < j )
1328  Write( (const void*)i, fsize_type( j - i ) << 1 );
1329  }
1330 
1334  void OutText( const char16_type* s )
1335  {
1336  OutText( s, s + CharTraits::Length( s ) );
1337  }
1338 
1342  void OutText( const String& s )
1343  {
1344  OutText( s.Begin(), s.End() );
1345  }
1346 
1351  void OutTextLn( const char* i, const char* j )
1352  {
1353  OutText( i, j ); Write( '\n' );
1354  }
1355 
1360  void OutTextLn( const char* s )
1361  {
1362  OutText( s ); Write( '\n' );
1363  }
1364 
1376  void OutTextLn()
1377  {
1378  Write( '\n' );
1379  }
1380 
1385  void OutTextLn( const IsoString& s )
1386  {
1387  OutText( s ); Write( '\n' );
1388  }
1389 
1394  void OutTextLn( const char16_type* i, const char16_type* j )
1395  {
1396  OutText( i, j ); Write( char16_type( '\n' ) );
1397  }
1398 
1403  void OutTextLn( const char16_type* s )
1404  {
1405  OutText( s ); Write( char16_type( '\n' ) );
1406  }
1407 
1412  void OutTextLn( const String& s )
1413  {
1414  OutText( s ); Write( char16_type( '\n' ) );
1415  }
1416 
1420  void Flush();
1421 
1431  virtual void Open( const String& path, FileModes mode = FileMode::Read|FileMode::Open );
1432 
1438  virtual void OpenForReading( const String& path )
1439  {
1440  Open( path, FileMode::Read|FileMode::Open|FileMode::ShareRead );
1441  }
1442 
1449  static File OpenFileForReading( const String& path )
1450  {
1451  File f;
1452  f.OpenForReading( path );
1453  return f;
1454  }
1455 
1459  virtual void OpenForReadWrite( const String& path )
1460  {
1461  Open( path, FileMode::Read|FileMode::Write|FileMode::Open );
1462  }
1463 
1468  static File OpenFileForReadWrite( const String& path )
1469  {
1470  File f;
1471  f.OpenForReadWrite( path );
1472  return f;
1473  }
1474 
1480  virtual void Create( const String& path )
1481  {
1482  Open( path, FileMode::Read|FileMode::Write|FileMode::Create );
1483  }
1484 
1490  static File CreateFile( const String& path )
1491  {
1492  File f;
1493  f.Create( path );
1494  return f;
1495  }
1496 
1502  virtual void CreateForWriting( const String& path )
1503  {
1504  Open( path, FileMode::Write|FileMode::Create );
1505  }
1506 
1512  static File CreateFileForWriting( const String& path )
1513  {
1514  File f;
1515  f.CreateForWriting( path );
1516  return f;
1517  }
1518 
1523  void OpenOrCreate( const String& path )
1524  {
1525  Open( path, FileMode::Read|FileMode::Write|FileMode::Open|FileMode::Create );
1526  }
1527 
1532  static File OpenOrCreateFile( const String& path )
1533  {
1534  File f;
1535  f.OpenOrCreate( path );
1536  return f;
1537  }
1538 
1543  virtual void Close();
1544 
1548  static void Remove( const String& filePath );
1549 
1557  static void CreateDirectory( const String& dirPath, bool createIntermediateDirectories = true );
1558 
1564  static void RemoveDirectory( const String& dirPath );
1565 
1580  static void Move( const String& filePath, const String& newFilePath );
1581 
1585  static bool Exists( const String& filePath );
1586 
1590  static bool DirectoryExists( const String& dirPath );
1591 
1596  static bool IsReadOnly( const String& filePath );
1597 
1602  static void SetReadOnly( const String& filePath, bool rdOnly = true );
1603 
1611  static void SetReadWrite( const String& filePath )
1612  {
1613  SetReadOnly( filePath, false );
1614  }
1615 
1620  static ByteArray ReadFile( const String& filePath );
1621 
1643  static void WriteFile( const String& filePath, const ByteArray& contents );
1644 
1660  static void WriteFile( const String& filePath, const ByteArray& contents, size_type start, size_type size );
1661 
1676  static void WriteFile( const String& filePath, const void* data, size_type size );
1677 
1685  static IsoString ReadTextFile( const String& filePath );
1686 
1701  static void WriteTextFile( const String& filePath, const IsoString& text );
1702 
1718  static void SetPermissions( const String& targetPath, FileAttributes permissions );
1719 
1730  static void CopyTimesAndPermissions( const String& targetPath, const String& sourcePath );
1731 
1732 #ifndef __PCL_WINDOWS
1733 
1750  static void CopyLink( const String& targetLinkPath, const String& sourceLinkPath );
1751 #endif // !__PCL_WINDOWS
1752 
1786  static void CopyFile( const String& targetFilePath, const String& sourceFilePath, File::Progress* progress = nullptr );
1787 
1826  static void MoveFile( const String& targetFilePath, const String& sourceFilePath, File::Progress* progress = nullptr );
1827 
1841  static bool SameDevice( const String& path1, const String& path2 );
1842 
1861  static bool SameFile( const String& path1, const String& path2 );
1862 
1882  static IsoStringList ReadLines( const String& filePath,
1883  ReadTextOptions options = ReadTextOptions() );
1884 
1922  static size_type ScanLines( const String& filePath,
1923  bool (*callback)( char*, void* ), void* data = nullptr,
1924  ReadTextOptions options = ReadTextOptions() );
1925 
1929  static String FullPath( const String& path );
1930 
1960  static IsoString FileURI( const String& path );
1961 
1977  static String SystemTempDirectory();
1978 
1989  static String SystemCacheDirectory();
1990 
2005  static String HomeDirectory();
2006 
2011  static String WindowsPathToUnix( const String& path );
2012 
2017  static String UnixPathToWindows( const String& path );
2018 
2049  static String UniqueFileName( const String& directory = String(), int n = 12,
2050  const String& prefix = String(), const String& postfix = String() );
2051 
2074  static uint64 GetAvailableSpace( const String& dirPath, uint64* totalBytes = nullptr, uint64* freeBytes = nullptr );
2075 
2085  static size_type FindDrive( const String& path );
2086 
2095  static size_type FindName( const String& path );
2096 
2109  static size_type FindExtension( const String& path );
2110 
2114  static size_type FindSuffix( const String& path )
2115  {
2116  return FindExtension( path );
2117  }
2118 
2131  static size_type FindCompleteSuffix( const String& path );
2132 
2142  static String ExtractDrive( const String& path ); // always empty string on X
2143 
2158  static String ExtractDirectory( const String& path );
2159 
2171  static String ExtractName( const String& path );
2172 
2186  static String ExtractExtension( const String& path );
2187 
2191  static String ExtractSuffix( const String& path )
2192  {
2193  return ExtractExtension( path );
2194  }
2195 
2209  static String ExtractCompleteSuffix( const String& path );
2210 
2217  static String ExtractNameAndExtension( const String& path );
2218 
2222  static String ExtractNameAndSuffix( const String& path )
2223  {
2224  return ExtractNameAndExtension( path );
2225  }
2226 
2238  static String ChangeExtension( const String& filePath, const String& ext );
2239 
2244  static String AppendToName( const String& filePath, const String& postfix );
2245 
2250  static String PrependToName( const String& filePath, const String& prefix );
2251 
2276  static String SizeAsString( fsize_type sizeInBytes, int precision = 3, bool alsoShowBytes = false );
2277 
2278 protected:
2279 
2280  handle m_fileHandle;
2281  String m_filePath;
2282  FileModes m_fileMode;
2283 
2284  static const handle s_invalidHandle;
2285 
2286  void Initialize();
2287  virtual bool IsValidHandle( handle h ) const;
2288 };
2289 
2290 // ----------------------------------------------------------------------------
2291 
2292 } // pcl
2293 
2294 #endif // __PCL_File_h
2295 
2296 // ----------------------------------------------------------------------------
2297 // EOF pcl/File.h - Released 2019-11-07T10:59:34Z
bool IsSystem() const
Definition: File.h:428
virtual bool CanRead() const
Definition: File.h:974
Reduction of planetary and stellar positions.
Definition: Position.h:318
void WriteI32(const T &x)
Definition: File.h:1143
static File CreateFile(const String &path)
Definition: File.h:1490
An exception class signaling the interruption of a process.
void OutTextLn()
Definition: File.h:1376
double SecondsSinceEpoch() const
Definition: File.h:345
bool IsEncrypted() const
Definition: File.h:401
Progress(fsize_type total, const String &initialText=String(), fsize_type initialValue=0)
Definition: File.h:729
void WriteUI32(const T &x)
Definition: File.h:1152
FileTime lastModified
Time of last change.
Definition: File.h:369
Find(const String &path)
Definition: File.h:627
void ReadI32(T &x)
Definition: File.h:1080
unsigned char uint8
Definition: Defs.h:576
virtual void OpenForReading(const String &path)
Definition: File.h:1438
fsize_type Value() const
Definition: File.h:755
FileModes Mode() const
Definition: File.h:966
Dynamic list of 8-bit strings.
void OutTextLn(const IsoString &s)
Definition: File.h:1385
bool IsReadOnly() const
Definition: File.h:419
String SearchPath() const
Definition: File.h:683
int64 fpos_type
Definition: Defs.h:1113
PCL root namespace.
Definition: AbstractImage.h:76
void OpenOrCreate(const String &path)
Definition: File.h:1523
uint16 char16_type
Definition: Defs.h:1075
String name
File or directory name, including the file name extension.
Definition: File.h:361
void OutTextLn(const char16_type *i, const char16_type *j)
Definition: File.h:1394
void Write(const char16_type *s)
Definition: File.h:1242
virtual String FilePath() const
Definition: File.h:544
Dynamic array of 8-bit unsigned integers.
bool IsHidden() const
Definition: File.h:410
iterator End()
Definition: String.h:973
A type-safe collection of enumerated flags.
Definition: Flags.h:84
bool IsEmpty() const
Definition: String.h:785
void OutText(const char *s)
Definition: File.h:1308
static void WriteUI32(Flags< E > f)
Definition: File.h:1288
virtual void OpenForReadWrite(const String &path)
Definition: File.h:1459
static void Read(Flags< E > &f)
Definition: File.h:1261
fsize_type Total() const
Definition: File.h:747
static File OpenFileForReadWrite(const String &path)
Definition: File.h:1468
virtual ~Progress()
Definition: File.h:740
int groupId
Group id of the file owner.
Definition: File.h:366
int numberOfLinks
Number of existing hard links to this file.
Definition: File.h:364
const String & FilePath() const
Definition: File.h:947
void * handle
Definition: File.h:503
void Add(fsize_type delta)
Definition: File.h:796
void WriteArray(const T *a, size_type n)
Definition: File.h:1134
static constexpr size_type Length(const char_type *s)
Definition: CharTraits.h:879
File(File &&x)
Definition: File.h:886
int userId
User id of the file owner.
Definition: File.h:365
static size_type FindSuffix(const String &path)
Definition: File.h:2114
Abstract base class of file progress objects.
Definition: File.h:712
bool IsOpen() const
Definition: File.h:938
void Write(const String &s)
Definition: File.h:1250
bool IsEmpty() const
Definition: File.h:445
void Read(T &x)
Definition: File.h:1058
virtual void Create(const String &path)
Definition: File.h:1480
void Read(bool &b)
Definition: File.h:1181
constexpr const T & Range(const T &x, const T &a, const T &b)
Definition: Utility.h:190
bool IsArchive() const
Definition: File.h:383
void Write(const char *s)
Definition: File.h:1220
size_t size_type
Definition: Defs.h:543
void ReadArray(T *a, size_type n)
Definition: File.h:1071
bool IsAborted() const
Definition: File.h:831
File information structure used by File::Find
Definition: File.h:359
const String & Text() const
Definition: File.h:763
static File CreateFileForWriting(const String &path)
Definition: File.h:1512
void Rewind()
Definition: File.h:1025
void Write(const T &x)
Definition: File.h:1121
Error(const String &filePath, const String &message)
Definition: File.h:523
Unicode (UTF-16) string.
Definition: String.h:7911
File I/O exception.
Definition: File.h:515
unsigned long long uint64
Definition: Defs.h:616
virtual void CreateForWriting(const String &path)
Definition: File.h:1502
String Message() const override
Definition: File.h:558
static void ReadUI32(Flags< E > &f)
Definition: File.h:1270
constexpr const T & Max(const T &a, const T &b)
Definition: Utility.h:119
void OutTextLn(const char *s)
Definition: File.h:1360
unsigned short uint16
Definition: Defs.h:588
static void SetReadWrite(const String &filePath)
Definition: File.h:1611
void WriteI64(const T &x)
Definition: File.h:1161
int64 fsize_type
Definition: Defs.h:1119
bool IsCompressed() const
Definition: File.h:392
uint8 minute
Minute [0,59].
Definition: File.h:295
signed int int32
Definition: Defs.h:594
virtual bool CanWrite() const
Definition: File.h:982
bool IsDirectory() const
Definition: File.h:374
fsize_type size
File size in bytes.
Definition: File.h:363
void OutText(const String &s)
Definition: File.h:1342
fpos_type SeekEnd()
Definition: File.h:1015
static File OpenOrCreateFile(const String &path)
Definition: File.h:1532
bool operator<(const Array< T, A > &x1, const Array< T, A > &x2)
Definition: Array.h:2086
const String & FileName() const
Definition: File.h:958
static size_type Length(const char_type *s)
Definition: CharTraits.h:1139
void ReadI64(T &x)
Definition: File.h:1098
uint16 year
Year.
Definition: File.h:290
static String ExtractNameAndSuffix(const String &path)
Definition: File.h:2222
A simple exception with an associated error message.
Definition: Exception.h:213
void OutText(const char16_type *i, const char16_type *j)
Definition: File.h:1325
void OutText(const char16_type *s)
Definition: File.h:1334
uint8 day
Day [1,31].
Definition: File.h:292
FileTime lastAccessed
Time of last access.
Definition: File.h:368
static void Write(Flags< E > f)
Definition: File.h:1279
File()
Definition: File.h:867
static File OpenFileForReading(const String &path)
Definition: File.h:1449
Directory search operation.
Definition: File.h:611
void SetText(const String &text)
Definition: File.h:817
A combination of file text reading mode flags.
FileTime created
Creation time.
Definition: File.h:367
String ExceptionClass() const override
Definition: File.h:536
void OutTextLn(const char16_type *s)
Definition: File.h:1403
void Write(const bool &b)
Definition: File.h:1192
void OutTextLn(const String &s)
Definition: File.h:1412
void OutTextLn(const char *i, const char *j)
Definition: File.h:1351
File(const String &path, FileModes mode)
Definition: File.h:876
static String ExtractSuffix(const String &path)
Definition: File.h:2191
void ReadUI64(T &x)
Definition: File.h:1107
bool operator==(const Array< T, A > &x1, const Array< T, A > &x2)
Definition: Array.h:2075
double DaysSinceEpoch() const
Definition: File.h:336
uint16 milliseconds
Milliseconds [0,999].
Definition: File.h:298
virtual ~File()
Definition: File.h:917
uint8 hour
Hour [0,23].
Definition: File.h:293
uint8 second
Second [0,59].
Definition: File.h:296
void OutText(const char *i, const char *j)
Definition: File.h:1299
FileAttributes attributes
Item attributes.
Definition: File.h:362
File date and time.
Definition: File.h:288
void OutText(const IsoString &s)
Definition: File.h:1316
uint8 month
Month [1,12].
Definition: File.h:291
void WriteUI64(const T &x)
Definition: File.h:1170
unsigned int uint32
Definition: Defs.h:600
signed long long int64
Definition: Defs.h:610
iterator Begin()
Definition: String.h:943
void Write(const IsoString &s)
Definition: File.h:1228
bool IsEOF() const
Definition: File.h:1034
void ReadUI32(T &x)
Definition: File.h:1089
SeekMode::value_type seek_mode
Definition: File.h:508
bool IsTemporary() const
Definition: File.h:437
void SetValue(fsize_type current)
Definition: File.h:775
A platform-independent interface to the local file system.
Definition: File.h:496
Eight-bit string (ISO/IEC-8859-1 or UTF-8 string)
Definition: String.h:5387