#pragma region CPL License /* Nuclex Native Framework Copyright (C) 2002-2021 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #pragma endregion // CPL License #ifndef NUCLEX_STORAGE_FILESYSTEM_FILE_H #define NUCLEX_STORAGE_FILESYSTEM_FILE_H #include "Nuclex/Storage/Config.h" #include "Nuclex/Storage/Blob.h" #include #include // Possible additions: // // - GetNativePath() // // Possibly useful if paths need to be passed to external tools and third-party // libraries, but problematic when .zip and other containers are involved. // // /// Returns the path the file is stored at in the native format // /// The file's absolute path in the native OS format // public: virtual const std::string &GetNativePath() const = 0; // // - CloseNativeHandle() // // It intuitively sounded like a good idea, but I can't think of a use for this. // // When renaming or deleting files, the FileManager knows to close the handle. // Running out of handles should not happen and even that could be dealt with // by the FileManager... // // /// Closes the operating system's file handle if this is a plain file // public: virtual void CloseNativeHandle() const = 0; // namespace Nuclex { namespace Storage { namespace FileSystem { // ------------------------------------------------------------------------------------------- // /// File storing binary data /// /// /// You may be used to the concept of opening files and receiving a handle. In this /// case, a file is simply something you can read from and write to at will. /// /// /// This may seem like a bold design choice, but in many cases (zip archives or memory /// files, for example) a file handle is just an artificial concept. In cases where /// it isn't (accessing files from the underlying operating system, for example), file /// handles can be transparently created and destroyed as needed. Leveraging incremental /// reads is also pretty easy by tracking the location of the file pointer. /// /// /// The interface presented is similar to a memory-mapped file: there is no file pointer /// and you can access the file at any location. Wrappers like the BinaryFileReader /// and BinaryFileWriter will maintain their own file pointers. This makes file reads /// completely insusceptible to threading issues as long as you consider the readers /// as lightweight objects each thread creates as required. /// /// /// If you wish to suppot reading from stdin / writing to stdout with this class, /// simply ensure your reads or writes are strictly sequential. The native filesystem /// implementations are required to not seek unless neccessary. /// /// class File : public Blob { /// Frees all resources owned by the instance public: NUCLEX_STORAGE_API virtual ~File() = default; /// Determines the size of the file /// The size of the file in bytes public: virtual std::uint64_t GetSize() const override = 0; /// Returns the name of the file /// The file's name public: virtual const std::string &GetName() const = 0; /// Returns the path the file is stored at in the native format /// The file's absolute path in the native OS format public: virtual const std::string &GetNativePath() const = 0; /// Changes the name of the file /// New name the file will be known under public: virtual void Rename(const std::string &name) = 0; /// Retrieves the time at which the file has been last modified /// The since since the last modification of the file took place public: virtual std::time_t GetLastModificationTime() const = 0; /// Reads raw data from the file /// Absolute file position data will be read from /// Buffer into which data will be read /// Number of bytes that will be read public: virtual void ReadAt( std::uint64_t location, void *buffer, std::size_t count ) const override = 0; /// Writes raw data into the file /// Absolute file position data will be written to /// Buffer from which data will be taken /// Number of bytes that will be written public: virtual void WriteAt( std::uint64_t location, const void *buffer, std::size_t count ) override = 0; /// Ensures changes to the file have been written to disk public: virtual void Flush() override = 0; }; // ------------------------------------------------------------------------------------------- // }}} // namespace Nuclex::Storage::FileSystem #endif // NUCLEX_STORAGE_FILESYSTEM_FILE_H