Implement --file-names-only (#8788)

* flatc builds and seems to work, some of the extra targets are having linker errors

* fix build system

* pipeline failures

* un-rename files

* refactor to use unique_ptr

* typo

* rm make_unique, add comments

* fix cmake

---------

Co-authored-by: Wouter van Oortmerssen <aardappel@gmail.com>
This commit is contained in:
Justin Davis
2025-12-02 23:37:06 -05:00
committed by GitHub
parent 0b60686e3d
commit a1e125af11
34 changed files with 207 additions and 210 deletions

View File

@@ -17,30 +17,52 @@
#ifndef FLATBUFFERS_FILE_MANAGER_H_
#define FLATBUFFERS_FILE_MANAGER_H_
#include <cstddef>
#include <set>
#include <string>
#include "flatbuffers/util.h"
namespace flatbuffers {
// A File interface to write data to file by default or
// save only file names
class FileManager {
class FileSaver {
public:
FileManager() = default;
virtual ~FileManager() = default;
FileSaver() = default;
virtual ~FileSaver() = default;
virtual bool SaveFile(const std::string& absolute_file_name,
const std::string& content) = 0;
virtual bool SaveFile(const char* name, const char* buf, size_t len,
bool binary) = 0;
virtual bool LoadFile(const std::string& absolute_file_name,
std::string* buf) = 0;
bool SaveFile(const char* name, const std::string& buf, bool binary) {
return SaveFile(name, buf.c_str(), buf.size(), binary);
}
virtual void Finish() {}
private:
// Copying is not supported.
FileManager(const FileManager&) = delete;
FileManager& operator=(const FileManager&) = delete;
FileSaver(const FileSaver&) = delete;
FileSaver& operator=(const FileSaver&) = delete;
// Rule of 5
FileSaver(FileSaver&&) = default;
FileSaver& operator=(FileSaver&&) = default;
};
class RealFileSaver final : public FileSaver {
public:
bool SaveFile(const char* name, const char* buf, size_t len,
bool binary) final;
};
class FileNameSaver final : public FileSaver {
public:
bool SaveFile(const char* name, const char* buf, size_t len,
bool binary) final;
void Finish() final;
private:
std::set<std::string> file_names_{};
};
} // namespace flatbuffers