19 #include <string_view>
26 #include "lfilesystem/lfilesystem_Export.h"
67 File& operator= (
const File&) =
default;
82 [[nodiscard]] std::string
getFilename (
bool includeExtension =
false)
const;
104 [[nodiscard]]
bool isFile() const noexcept final;
105 [[nodiscard]]
bool isDirectory() const noexcept final;
106 [[nodiscard]]
bool isSymLink() const noexcept final;
128 bool replaceFileExtension (const std::string_view& newFileExtension,
129 bool renameOnDisk = true);
139 File& operator= (const std::string_view& newPath);
149 [[nodiscard]] std::
string loadAsString() const noexcept;
155 [[nodiscard]] std::vector<std::
string> loadAsLines() const;
161 [[nodiscard]] std::unique_ptr<std::ifstream> getInputStream() const;
170 bool overwrite (const
char* const data, std::
size_t numBytes) const noexcept;
171 bool overwrite (const std::string_view& text) const noexcept;
177 [[nodiscard]] std::unique_ptr<std::ofstream> getOutputStream() const;
191 bool append (const
char* const data, std::
size_t numBytes) const noexcept;
192 bool append (const std::string_view& text) const noexcept;
200 bool prepend (const
char* const data, std::
size_t numBytes) const noexcept;
201 bool prepend (const std::string_view& text) const noexcept;
218 bool resize (std::uintmax_t newSizeInBytes,
bool allowTruncation = true,
bool allowIncreasing = true) const noexcept;
235 std::optional<
File> createHardLink (const
Path& path) const;
243 [[nodiscard]] std::uintmax_t getHardLinkCount() const noexcept;
278 std::optional<
File> duplicate() const noexcept;
297 using iterator_category = std::forward_iterator_tag;
298 using value_type = std::string;
299 using difference_type = std::ptrdiff_t;
300 using pointer = std::string*;
301 using reference = std::string&;
304 [[nodiscard]]
Iterator operator++ (
int);
308 reference operator*()
const;
309 pointer operator->()
const;
320 using VectorType = std::vector<std::string>;
324 std::shared_ptr<VectorType> lines {
nullptr };
326 VectorType::size_type idx { 0UL };
359 [[nodiscard]]
bool write_data (
const char*
const data, std::size_t numBytes,
bool overwrite)
const noexcept;
364 #pragma mark TempFile
366 #pragma region TempFile
397 bool destroyOnDelete =
true);
423 bool shouldDelete {
true };
431 std::ostream& operator<< (std::ostream& os,
const File& file);
438 std::istream& operator>> (std::istream& is,
const File& file);
451 struct LFILE_EXPORT hash<limes::files::File> final
This class is a wrapper around a C-style FILE* that takes care of freeing the file when the object is...
This class represents a file on the filesystem.
bool hasFileExtension(const std::string_view &extension) const
Returns true if this file has the specified file extension.
std::string getFileExtension() const
Returns this file's file extension, if any.
bool hasFileExtension() const
Returns true if this file has a file extension.
static File getCurrentExecutable()
Returns a file representing the location of the executable file that launched the current process.
std::string getFilename(bool includeExtension=false) const
Returns this file's filename.
Iterator begin() const
Returns an iterator to the first line in this file.
Iterator end() const
Returns an iterator to the last line in this file.
bool isMacOSBundle() const noexcept
Returns true if this file is a MacOS bundle.
static File getCurrentModule()
Returns a file representing the location of the current code module.
The base class for any kind of object on the filesystem.
FilesystemEntry()=default
Creates a FilesystemEntry with an empty path.
Represents a temporary file.
TempFile(const Path &filepath, bool destroyOnDelete=true)
Creates a temporary file with the specified path.
~TempFile() final
The temporary file will be deleted from the filesystem when this object is destroyed,...
std::filesystem::path Path
Convenience typedef for filesystem paths.
This file defines the CFile class.
This file defines the FilesystemEntry class.
An iterator class that allows iterating a file like a standard C++ container.