summaryrefslogtreecommitdiff
path: root/src/idl_gen_general.cpp
diff options
context:
space:
mode:
authorWouter van Oortmerssen <wvo@google.com>2016-04-27 13:59:16 -0700
committerWouter van Oortmerssen <wvo@google.com>2016-04-27 13:59:16 -0700
commit933c195e51412078cbafad7dc127a96d19a9f1c7 (patch)
treeccd01cf9d6ae88c9e744f56628c7738a8128cc70 /src/idl_gen_general.cpp
parentd0898fd0c8770fbe78d9083634a687cef862bec0 (diff)
parent6765c19d45509fdcffd5ee62cac5cacea32bd397 (diff)
downloadflatbuffers-933c195e51412078cbafad7dc127a96d19a9f1c7.tar.gz
flatbuffers-933c195e51412078cbafad7dc127a96d19a9f1c7.tar.bz2
flatbuffers-933c195e51412078cbafad7dc127a96d19a9f1c7.zip
Merge pull request #3843 from Lakedaemon/refactoring
Transition 1 (nice diffs) Go, C++ and General generators with class
Diffstat (limited to 'src/idl_gen_general.cpp')
-rw-r--r--src/idl_gen_general.cpp77
1 files changed, 45 insertions, 32 deletions
diff --git a/src/idl_gen_general.cpp b/src/idl_gen_general.cpp
index 91f1aeb6..4a4e54dc 100644
--- a/src/idl_gen_general.cpp
+++ b/src/idl_gen_general.cpp
@@ -19,6 +19,7 @@
#include "flatbuffers/flatbuffers.h"
#include "flatbuffers/idl.h"
#include "flatbuffers/util.h"
+#include "flatbuffers/code_generators.h"
#include <algorithm>
namespace flatbuffers {
@@ -1148,44 +1149,56 @@ static bool SaveClass(const LanguageParameters &lang, const Parser &parser,
return SaveFile(filename.c_str(), code, false);
}
-bool GenerateGeneral(const Parser &parser,
- const std::string &path,
- const std::string & file_name) {
-
- assert(parser.opts.lang <= IDLOptions::kMAX);
- auto lang = language_parameters[parser.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, parser, **it, &enumcode);
- if (parser.opts.one_file) {
- one_file_code += enumcode;
- }
- else {
- if (!SaveClass(lang, parser, (**it).name, enumcode, path, false, false))
- return false;
+namespace general {
+class GeneralGenerator : public BaseGenerator {
+ public:
+ GeneralGenerator(const Parser &parser, const std::string &path,
+ const std::string &file_name)
+ : BaseGenerator(parser, path, file_name){};
+ bool generate() {
+ assert(parser_.opts.lang <= IDLOptions::kMAX);
+ auto lang = language_parameters[parser_.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, parser_, **it, &enumcode);
+ if (parser_.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 (parser.opts.one_file) {
- one_file_code += declcode;
+ for (auto it = parser_.structs_.vec.begin();
+ it != parser_.structs_.vec.end(); ++it) {
+ std::string declcode;
+ GenStruct(lang, parser_, **it, &declcode);
+ if (parser_.opts.one_file) {
+ one_file_code += declcode;
+ } else {
+ if (!SaveClass(lang, parser_, (**it).name, declcode, path_, true,
+ false))
+ return false;
+ }
}
- else {
- if (!SaveClass(lang, parser, (**it).name, declcode, path, true, false))
- return false;
+
+ if (parser_.opts.one_file) {
+ return SaveClass(lang, parser_, file_name_, one_file_code, path_, true,
+ true);
}
+ return true;
}
+};
+} // namespace general
- if (parser.opts.one_file) {
- return SaveClass(lang, parser, file_name, one_file_code,path, true, true);
- }
- return true;
+bool GenerateGeneral(const Parser &parser, const std::string &path,
+ const std::string &file_name) {
+ general::GeneralGenerator generator(parser, path, file_name);
+ return generator.generate();
}
static std::string ClassFileName(const LanguageParameters &lang,