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
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;
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;
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;
786 return IsValidHandle( m_fileHandle );
822 return m_fileMode.IsFlagSet( FileMode::Read );
830 return m_fileMode.IsFlagSet( FileMode::Write );
863 return Seek( 0, SeekMode::FromEnd );
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 );
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' );
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 );
1563 SetReadOnly( filePath,
false );
1682 #ifndef __PCL_WINDOWS
1873 bool (*callback)(
char*,
void* ),
void* data =
nullptr,
2066 return FindExtension( path );
2143 return ExtractExtension( path );
2174 return ExtractNameAndExtension( path );
2234 static const handle s_invalidHandle;
2237 virtual bool IsValidHandle(
handle h )
const;
static size_type Length(const char_type *__restrict__ s) noexcept
A simple exception with an associated error message.
A combination of file access, share and opening/creation mode flags.
Error(const String &filePath, const String &message)
String Message() const override
Error(const Error &)=default
String ExceptionClass() const override
virtual String FilePath() const
Directory search operation.
bool NextItem(FindFileInfo &info)
String SearchPath() const
void Begin(const String &path)
Find(const Find &)=delete
Abstract base class of file progress objects.
Progress(fsize_type total, const String &initialText=String(), fsize_type initialValue=0)
const String & Text() const
virtual bool TextChanged()=0
virtual bool ValueChanged()=0
void SetValue(fsize_type current)
void Add(fsize_type delta)
void SetText(const String &text)
A platform-independent interface to the local file system.
virtual void OpenForReading(const String &path)
static String ExtractDrive(const String &path)
static File CreateFileForWriting(const String &path)
virtual void Write(const void *buffer, fsize_type len)
virtual void Resize(fsize_type length)
static bool IsReadOnly(const String &filePath)
static String ExtractDirectory(const String &path)
static void CopyFile(const String &targetFilePath, const String &sourceFilePath, File::Progress *progress=nullptr)
static String ChangeExtension(const String &filePath, const String &ext)
void OutTextLn(const char16_type *i, const char16_type *j)
static String WindowsPathToUnix(const String &path)
static String ExtractSuffix(const String &path)
static bool Exists(const String &filePath)
void WriteUI32(const T &x)
static IsoString ReadTextFile(const String &filePath)
const String & FilePath() const
static void RemoveDirectory(const String &dirPath)
void OutText(const char *i, const char *j)
static void Read(Flags< E > &f)
static bool DirectoryExists(const String &dirPath)
static File OpenFileForReadWrite(const String &path)
static IsoString FileURI(const String &path)
static UniqueFileChecks EnsureNewUniqueDirectory(String &dirPath)
static void Move(const String &filePath, const String &newFilePath)
static String ExtractNameAndSuffix(const String &path)
static void ReadUI32(Flags< E > &f)
virtual bool CanRead() const
static String HomeDirectory()
static void SetReadOnly(const String &filePath, bool rdOnly=true)
void OutText(const char *s)
static File OpenFileForReading(const String &path)
virtual void Read(void *buffer, fsize_type len)
static File OpenOrCreateFile(const String &path)
static size_type FindName(const String &path)
static String ExtractNameAndExtension(const String &path)
static void Remove(const String &filePath)
static String FullPath(const String &path)
void WriteI64(const T &x)
static void WriteUI32(Flags< E > f)
void OutText(const String &s)
void OutTextLn(const IsoString &s)
static void WriteFile(const String &filePath, const ByteArray &contents)
static File CreateFile(const String &path)
static String ExtractCompleteSuffix(const String &path)
virtual fsize_type Size() const
static void WriteFile(const String &filePath, const ByteArray &contents, size_type start, size_type size)
virtual fpos_type Position() const
virtual void CreateForWriting(const String &path)
static void SetReadWrite(const String &filePath)
virtual void Open(const String &path, FileModes mode=FileMode::Read|FileMode::Open)
static String SizeAsString(fsize_type sizeInBytes, int precision=3, bool alsoShowBytes=false)
void WriteI32(const T &x)
static String ExtractName(const String &path)
static String SystemTempDirectory()
void Write(const bool &b)
void Write(const char *s)
File(const String &path, FileModes mode)
static String AppendToName(const String &filePath, const String &postfix)
void OutText(const char16_type *s)
static void MoveFile(const String &targetFilePath, const String &sourceFilePath, File::Progress *progress=nullptr)
void Write(const IsoString &s)
static void SetPermissions(const String &targetPath, FileAttributes permissions)
static bool SameFile(const String &path1, const String &path2)
static void CopyTimesAndPermissions(const String &targetPath, const String &sourcePath)
void WriteUI64(const T &x)
static void WriteTextFile(const String &filePath, const IsoString &text)
static size_type FindDrive(const String &path)
static String UniqueFileName(const String &directory=String(), int n=12, const String &prefix=String(), const String &postfix=String())
static String PrependToName(const String &filePath, const String &prefix)
static String UnixPathToWindows(const String &path)
void Write(const char *i, const char *j)
void ReadArray(T *a, size_type n)
virtual bool CanWrite() const
fpos_type Seek(fpos_type dist, seek_mode mode=SeekMode::FromCurrent)
virtual void SetPosition(fpos_type pos)
static size_type ScanLines(const String &filePath, bool(*callback)(char *, void *), void *data=nullptr, ReadTextOptions options=ReadTextOptions())
File(const File &)=delete
static String SystemCacheDirectory()
static UniqueFileChecks EnsureNewUniqueFile(String &filePath, bool canOverwrite=false)
void OutTextLn(const char *s)
static size_type FindCompleteSuffix(const String &path)
static void CopyLink(const String &targetLinkPath, const String &sourceLinkPath)
static size_type FindSuffix(const String &path)
void Write(const String &s)
void OutTextLn(const String &s)
static IsoStringList ReadLines(const String &filePath, ReadTextOptions options=ReadTextOptions())
void WriteArray(const T *a, size_type n)
static void CreateDirectory(const String &dirPath, bool createIntermediateDirectories=true)
void OpenOrCreate(const String &path)
void OutTextLn(const char16_type *s)
void Write(const char16_type *s)
void OutTextLn(const char *i, const char *j)
static uint64 GetAvailableSpace(const String &dirPath, uint64 *totalBytes=nullptr, uint64 *freeBytes=nullptr)
void OutText(const char16_type *i, const char16_type *j)
static String ExtractExtension(const String &path)
void Write(const char16_type *i, const char16_type *j)
virtual void Create(const String &path)
static size_type FindExtension(const String &path)
static void Write(Flags< E > f)
static ByteArray ReadFile(const String &filePath)
virtual void OpenForReadWrite(const String &path)
const String & FileName() const
static void WriteFile(const String &filePath, const void *data, size_type size)
static bool SameDevice(const String &path1, const String &path2)
void OutText(const IsoString &s)
constexpr bool IsFlagSet(enum_type e) const
bool IsEmpty() const noexcept
static constexpr size_type Length(const char_type *__restrict__ s) noexcept
Eight-bit string (ISO/IEC-8859-1 or UTF-8 string)
Reduction of planetary and stellar positions.
An exception class signaling the interruption of a process.
A combination of file text reading mode flags.
unsigned long long uint64
constexpr const T & Range(const T &x, const T &a, const T &b) noexcept
constexpr const T & Max(const T &a, const T &b) noexcept
File information structure used by File::Find
String name
File or directory name, including the file name extension.
FileTime lastModified
Time of last change.
bool IsCompressed() const
fsize_type size
File size in bytes.
FileTime created
Creation time.
int numberOfLinks
Number of existing hard links to this file.
FileAttributes attributes
Item attributes.
int userId
User id of the file owner.
int groupId
Group id of the file owner.
FileTime lastAccessed
Time of last access.
A simple POD structure to hold file uniqueness and overwrite verification results.