forked from BigfootDev/flatbuffers
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user