Go to the documentation of this file.
58 #include <pcl/Diagnostics.h>
65 #ifndef __PCL_FILE_DONT_REMOVE_PREVIOUS_DECLARATION
83 #ifdef CreateDirectory
84 #undef CreateDirectory
87 #ifdef RemoveDirectory
88 #undef RemoveDirectory
91 #endif // !__PCL_FILE_DONT_REMOVE_PREVIOUS_DECLARATION
133 AccessMode = 0x0000000F,
138 ShareRead = 0x00000010,
139 ShareWrite = 0x00000020,
140 ShareMode = 0x000000F0,
147 OpenMode = 0x00000F00
156 using FileModes = Flags<FileMode::mask_type>;
299 namespace ReadTextOption
303 RemoveEmptyLines = 0x0001,
304 TrimTrailingSpaces = 0x0002,
305 TrimLeadingSpaces = 0x0004,
306 TrimSpaces = TrimTrailingSpaces | TrimLeadingSpaces
330 bool overwrite =
false;
355 using seek_mode = SeekMode::value_type;
372 , m_filePath( filePath )
385 return "File I/O Error";
398 virtual String ErrorMessage()
const
407 String filePath = FilePath();
408 String message = m_message;
498 Find& operator =(
const Find& ) =
delete;
506 void Begin(
const String& path );
539 #ifndef __PCL_WINDOWS
543 void* m_handle =
nullptr;
579 , m_text( initialText )
623 if ( current >= m_current )
627 if ( !ValueChanged() )
648 if ( !ValueChanged() )
667 if ( !TextChanged() )
687 bool m_abort =
false;
696 virtual bool ValueChanged() = 0;
705 virtual bool TextChanged() = 0;
724 PCL_PRECONDITION( !path.
IsEmpty() )
733 : m_fileHandle( x.m_fileHandle )
734 , m_filePath( std::move( x.m_filePath ) )
735 , m_fileMode( x.m_fileMode )
737 x.m_fileHandle = s_invalidHandle;
738 x.m_fileMode = FileMode::Zero;
750 m_fileHandle = x.m_fileHandle;
751 m_filePath = std::move( x.m_filePath );
752 m_fileMode = x.m_fileMode;
753 x.m_fileHandle = s_invalidHandle;
754 x.m_fileMode = FileMode::Zero;
779 File& operator =(
const File& ) =
delete;
786 return IsValidHandle( m_fileHandle );
822 return m_fileMode.IsFlagSet( FileMode::Read );
830 return m_fileMode.IsFlagSet( FileMode::Write );
842 virtual void SetPosition(
fpos_type pos );
863 return Seek( 0, SeekMode::FromEnd );
898 virtual void Read(
void* buffer,
fsize_type len );
903 template <
typename T>
906 Read( (
void*)&x,
sizeof( T ) );
916 template <
typename T>
919 Read( (
void*)a, n*
sizeof( T ) );
925 template <
typename T>
928 int32 i; Read( i ); x = T( i );
934 template <
typename T>
937 uint32 i; Read( i ); x = T( i );
943 template <
typename T>
946 int64 i; Read( i ); x = T( i );
952 template <
typename T>
955 uint64 i; Read( i ); x = T( i );
961 virtual void Write(
const void* buffer,
fsize_type len );
966 template <
typename T>
969 Write( (
const void*)&x,
sizeof( T ) );
979 template <
typename T>
982 Write( (
const void*)a, n*
sizeof( T ) );
988 template <
typename T>
997 template <
typename T>
1006 template <
typename T>
1009 Write(
int64( x ) );
1015 template <
typename T>
1029 unsigned i; ReadUI32( i ); b = i != 0;
1040 WriteUI32( b ? 1 : 0 );
1061 void Write(
const char* i,
const char* j );
1101 #ifndef __PCL_NO_FLAGS_FILE_IO
1106 template <
typename E>
1115 template <
typename E>
1118 ReadUI32( f.m_flags );
1124 template <
typename E>
1133 template <
typename E>
1136 WriteUI32( f.m_flags );
1148 Write( (
const void*)i,
fsize_type( j - i ) );
1174 Write( (
const void*)i,
fsize_type( j - i ) << 1 );
1199 OutText( i, j ); Write(
'\n' );
1208 OutText( s ); Write(
'\n' );
1233 OutText( s ); Write(
'\n' );
1277 virtual void Open(
const String& path,
FileModes mode = FileMode::Read|FileMode::Open );
1286 Open( path, FileMode::Read|FileMode::Open|FileMode::ShareRead );
1307 Open( path, FileMode::Read|FileMode::Write|FileMode::Open );
1328 Open( path, FileMode::Read|FileMode::Write|FileMode::Create );
1350 Open( path, FileMode::Write|FileMode::Create );
1371 Open( path, FileMode::Read|FileMode::Write|FileMode::Open|FileMode::Create );
1389 virtual void Close();
1394 static void Remove(
const String& filePath );
1403 static void CreateDirectory(
const String& dirPath,
bool createIntermediateDirectories =
true );
1410 static void RemoveDirectory(
const String& dirPath );
1426 static void Move(
const String& filePath,
const String& newFilePath );
1431 static bool Exists(
const String& filePath );
1436 static bool DirectoryExists(
const String& dirPath );
1546 static bool IsReadOnly(
const String& filePath );
1552 static void SetReadOnly(
const String& filePath,
bool rdOnly =
true );
1563 SetReadOnly( filePath,
false );
1593 static void WriteFile(
const String& filePath,
const ByteArray& contents );
1626 static void WriteFile(
const String& filePath,
const void* data,
size_type size );
1651 static void WriteTextFile(
const String& filePath,
const IsoString& text );
1680 static void CopyTimesAndPermissions(
const String& targetPath,
const String& sourcePath );
1682 #ifndef __PCL_WINDOWS
1700 static void CopyLink(
const String& targetLinkPath,
const String& sourceLinkPath );
1701 #endif // !__PCL_WINDOWS
1791 static bool SameDevice(
const String& path1,
const String& path2 );
1811 static bool SameFile(
const String& path1,
const String& path2 );
1873 bool (*callback)(
char*,
void* ),
void* data =
nullptr,
1927 static String SystemTempDirectory();
1939 static String SystemCacheDirectory();
1955 static String HomeDirectory();
2024 static uint64 GetAvailableSpace(
const String& dirPath,
uint64* totalBytes =
nullptr,
uint64* freeBytes =
nullptr );
2066 return FindExtension( path );
2143 return ExtractExtension( path );
2159 static String ExtractCompleteSuffix(
const String& path );
2167 static String ExtractNameAndExtension(
const String& path );
2174 return ExtractNameAndExtension( path );
2226 static String SizeAsString(
fsize_type sizeInBytes,
int precision = 3,
bool alsoShowBytes =
false );
2230 handle m_fileHandle;
2234 static const handle s_invalidHandle;
2237 virtual bool IsValidHandle( handle h )
const;
2244 #endif // __PCL_File_h
bool IsCompressed() const
Progress(fsize_type total, const String &initialText=String(), fsize_type initialValue=0)
void WriteUI32(const T &x)
virtual String FilePath() const
void Write(const char16_type *s)
FileAttributes attributes
Item attributes.
constexpr const T & Range(const T &x, const T &a, const T &b) noexcept
static File CreateFile(const String &path)
virtual void OpenForReading(const String &path)
void OutText(const char *s)
void WriteUI64(const T &x)
void Write(const IsoString &s)
Directory search operation.
void OutTextLn(const IsoString &s)
void OpenOrCreate(const String &path)
static constexpr size_type Length(const char_type *__restrict__ s) noexcept
void SetValue(fsize_type current)
void OutTextLn(const char16_type *i, const char16_type *j)
void Add(fsize_type delta)
Reduction of planetary and stellar positions.
constexpr const T & Max(const T &a, const T &b) noexcept
static size_type FindSuffix(const String &path)
virtual void OpenForReadWrite(const String &path)
static void Read(Flags< E > &f)
Abstract base class of file progress objects.
void ReadArray(T *a, size_type n)
Eight-bit string (ISO/IEC-8859-1 or UTF-8 string)
File information structure used by File::Find
A platform-independent interface to the local file system.
Error(const String &filePath, const String &message)
virtual void CreateForWriting(const String &path)
void Write(const char *s)
static void SetReadWrite(const String &filePath)
void WriteI64(const T &x)
A combination of file text reading mode flags.
const String & Text() const
static void WriteUI32(Flags< E > f)
constexpr bool IsFlagSet(enum_type e) const
static File OpenFileForReadWrite(const String &path)
virtual bool CanWrite() const
void Write(const String &s)
const String & FilePath() const
bool IsEmpty() const noexcept
static File OpenOrCreateFile(const String &path)
String Message() const override
void WriteArray(const T *a, size_type n)
A simple exception with an associated error message.
unsigned long long uint64
static File CreateFileForWriting(const String &path)
A combination of file access, share and opening/creation mode flags.
void OutText(const char16_type *s)
virtual void Create(const String &path)
void OutTextLn(const char *s)
A simple POD structure to hold file uniqueness and overwrite verification results.
static File OpenFileForReading(const String &path)
static String ExtractNameAndSuffix(const String &path)
String SearchPath() const
static void ReadUI32(Flags< E > &f)
int userId
User id of the file owner.
String name
File or directory name, including the file name extension.
void OutTextLn(const String &s)
void OutTextLn(const char *i, const char *j)
File(const String &path, FileModes mode)
void OutText(const String &s)
FileTime lastModified
Time of last change.
int numberOfLinks
Number of existing hard links to this file.
const String & FileName() const
String ExceptionClass() const override
void SetText(const String &text)
int groupId
Group id of the file owner.
static size_type Length(const char_type *__restrict__ s) noexcept
void OutTextLn(const char16_type *s)
void OutText(const char16_type *i, const char16_type *j)
fsize_type size
File size in bytes.
virtual bool CanRead() const
static void Write(Flags< E > f)
void OutText(const IsoString &s)
void WriteI32(const T &x)
An exception class signaling the interruption of a process.
void OutText(const char *i, const char *j)
FileTime created
Creation time.
void Write(const bool &b)
static String ExtractSuffix(const String &path)
FileTime lastAccessed
Time of last access.