#pragma once #include #include #include #include #include "script/engine/Engine.hpp" /** * Represent a JavaScript file. * This is a wrapper around `QFile` */ class File { public: explicit File(const atlas::script::engine::Engine* engine, const std::filesystem::path& virtualPath); /** * Open the file to access its content. * @param mode the opening mode of the file, using "r", "w", "+", etc... */ void open(const std::string& mode = "r"); /** * Read the content of the file. * @param size the size of the content to read. * @return the content of the file */ std::vector read(size_t size = std::numeric_limits::max()); /** * Write data into the file * @param buffer the data to write into the file * @return the size of the data written */ void write(const std::vector& buffer); /** * Get the current cursor position * @return the current cursor position */ std::size_t tell(); /** * Set the cursor position * @param position the new cursor position */ void seek(std::size_t position); /** * Close the file. */ void close(); private: /** * Get the corresponding real file path * @return the real file path */ std::filesystem::path getRealPath() const; std::filesystem::path virtualPath; /// the Atlas engine const atlas::script::engine::Engine* engine; /// the internal file streamer std::fstream stream; };