" --gen-includes Generate include statements for included schemas the\n"
" generated file depends on (C++).\n"
" --gen-mutable Generate accessors that can mutate buffers in-place.\n"
+ " --gen-onefile Generate single output file for C#\n"
" --raw-binary Allow binaries without file_indentifier to be read.\n"
" This may crash flatc given a mismatched schema.\n"
" --proto Input is a .proto, translate to .fbs.\n"
opts.mutable_buffer = true;
} else if(arg == "--gen-includes") {
opts.include_dependence_headers = true;
- } else if(arg == "--raw-binary") {
+ }else if (arg == "--gen-onefile") {
+ opts.one_file = true;
+ }else if (arg == "--raw-binary") {
raw_binary = true;
} else if(arg == "--") { // Separator between text and binary inputs.
binary_files_from = filenames.size();
// Save out the generated code for a single class while adding
// declaration boilerplate.
static bool SaveClass(const LanguageParameters &lang, const Parser &parser,
- const Definition &def, const std::string &classcode,
- const std::string &path, bool needs_includes) {
+ const std::string &defname, const std::string &classcode,
+ const std::string &path, bool needs_includes, bool onefile) {
if (!classcode.length()) return true;
std::string namespace_general;
namespace_general += ".";
}
namespace_general += *it;
- namespace_dir += *it + kPathSeparator;
+ if (!onefile) {
+ namespace_dir += *it + kPathSeparator;
+ }
+
}
EnsureDirExists(namespace_dir);
if (needs_includes) code += lang.includes;
code += classcode;
code += lang.namespace_end;
- auto filename = namespace_dir + def.name + lang.file_extension;
+ auto filename = namespace_dir + defname + lang.file_extension;
return SaveFile(filename.c_str(), code, false);
}
bool GenerateGeneral(const Parser &parser,
const std::string &path,
- const std::string & /*file_name*/,
+ const std::string & file_name,
const GeneratorOptions &opts) {
assert(opts.lang <= GeneratorOptions::kMAX);
auto lang = language_parameters[opts.lang];
+ std::string one_file_code;
for (auto it = parser.enums_.vec.begin();
it != parser.enums_.vec.end(); ++it) {
std::string enumcode;
GenEnum(lang, **it, &enumcode);
- if (!SaveClass(lang, parser, **it, enumcode, path, false))
- return false;
+ if (opts.one_file) {
+ one_file_code = enumcode;
+ }
+ else {
+ if (!SaveClass(lang, parser, (**it).name, enumcode, path, false, false))
+ return false;
+ }
}
for (auto it = parser.structs_.vec.begin();
it != parser.structs_.vec.end(); ++it) {
std::string declcode;
GenStruct(lang, parser, **it, &declcode);
- if (!SaveClass(lang, parser, **it, declcode, path, true))
- return false;
+ if (opts.one_file) {
+ one_file_code += declcode;
+ }
+ else {
+ if (!SaveClass(lang, parser, (**it).name, declcode, path, true, false))
+ return false;
+ }
}
+ if (opts.one_file) {
+ return SaveClass(lang, parser, file_name, one_file_code,path, true, true);
+ }
return true;
}