/** * @brief The file guard class to manage the FILE pointer automatically. * file_guard object can close the FILE pointer automatically when his scope is exit. */ classfile_guard { public: /** * @brief Construct a new file guard object * * @param file the pointer of the FILE object */ explicitfile_guard(FILE *file);
/** * @brief Get the FILE pointer. * * @return FILE* */ FILE *getfd()const;
private: FILE *file_; };
/** * @brief Read the text content of a file. * * @param path the filepath of the file to be read * @param max_read_size the maximum size to be read, default is 4096 bytes. * * If the file size is larger than max_read_size, only the first max_read_size bytes will be read. otherwise, the whole file will be read. * * @return text content of the file */ std::string readtext(const filepath &path, uint64_t max_read_size = 4096);
/** * @brief Write the text content to a file. * * @param path the filepath of the file to be written * @param content text content to be written to the file * @return true if the content is written successfully, false otherwise. */ boolwritetext(const filepath &path, const std::string &content);