Added accessor for file_extension in generated code.
authorWouter van Oortmerssen <wvo@google.com>
Mon, 4 May 2015 17:52:40 +0000 (10:52 -0700)
committerWouter van Oortmerssen <wvo@google.com>
Mon, 4 May 2015 20:38:20 +0000 (13:38 -0700)
Change-Id: I2de7d14dbb1f7b8f81022dd2c9da65060ae49300
Tested: on Linux.

src/idl_gen_cpp.cpp
tests/monster_test_generated.h
tests/test.cpp

index aab5729..37d968e 100644 (file)
@@ -717,6 +717,13 @@ std::string GenerateCPP(const Parser &parser,
         code += name + "Identifier()); }\n\n";
       }
 
+      if (parser.file_extension_.length()) {
+        // Return the extension
+        code += "inline const char *" + name;
+        code += "Extension() { return \"" + parser.file_extension_;
+        code += "\"; }\n\n";
+      }
+
       // Finish a buffer with a given root object:
       code += "inline void Finish" + name;
       code += "Buffer(flatbuffers::FlatBufferBuilder &fbb, flatbuffers::Offset<";
index f729fa0..5de3da0 100755 (executable)
@@ -332,6 +332,8 @@ inline const char *MonsterIdentifier() { return "MONS"; }
 
 inline bool MonsterBufferHasIdentifier(const void *buf) { return flatbuffers::BufferHasIdentifier(buf, MonsterIdentifier()); }
 
+inline const char *MonsterExtension() { return "mon"; }
+
 inline void FinishMonsterBuffer(flatbuffers::FlatBufferBuilder &fbb, flatbuffers::Offset<Monster> root) { fbb.Finish(root, MonsterIdentifier()); }
 
 }  // namespace Example
index 766b325..b0cace9 100644 (file)
@@ -135,6 +135,7 @@ void AccessFlatBufferTest(const uint8_t *flatbuf, size_t length) {
 
   TEST_EQ(strcmp(MonsterIdentifier(), "MONS"), 0);
   TEST_EQ(MonsterBufferHasIdentifier(flatbuf), true);
+  TEST_EQ(strcmp(MonsterExtension(), "mon"), 0);
 
   // Access the buffer from the root.
   auto monster = GetMonster(flatbuf);