diff options
author | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2017-06-23 14:24:51 -0400 |
---|---|---|
committer | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2017-06-23 14:24:51 -0400 |
commit | 517cfce6ce0c242545ef647c4e83cb837fdefecd (patch) | |
tree | 95c00b8db672e26604002faadce87735751e2c79 | |
parent | a7f353bd83f20fcc8370a07f12bb557aac75e951 (diff) | |
download | mongo-517cfce6ce0c242545ef647c4e83cb837fdefecd.tar.gz |
SERVER-29778 Add a string constant for the command name to generated classes
-rw-r--r-- | buildscripts/idl/idl/generator.py | 12 | ||||
-rw-r--r-- | src/mongo/idl/idl_test.cpp | 11 |
2 files changed, 17 insertions, 6 deletions
diff --git a/buildscripts/idl/idl/generator.py b/buildscripts/idl/idl/generator.py index 46467dd7560..851c7a4da41 100644 --- a/buildscripts/idl/idl/generator.py +++ b/buildscripts/idl/idl/generator.py @@ -436,6 +436,12 @@ class _CppHeaderFileWriter(_CppFileWriterBase): constant_name=_get_field_constant_name(field), field_name=field.name)) + if isinstance(struct, ast.Command): + self._writer.write_line( + common.template_args( + 'static constexpr auto kCommandName = "${struct_name}"_sd;', + struct_name=struct.name)) + def gen_enum_functions(self, idl_enum): # type: (ast.Enum) -> None """Generate the declaration for an enum's supporting functions.""" @@ -971,6 +977,12 @@ class _CppSourceFileWriter(_CppFileWriterBase): class_name=common.title_case(struct.name), constant_name=_get_field_constant_name(field))) + if isinstance(struct, ast.Command): + self._writer.write_line( + common.template_args( + 'constexpr StringData ${class_name}::kCommandName;', + class_name=common.title_case(struct.name))) + def gen_enum_definition(self, idl_enum): # type: (ast.Enum) -> None """Generate the definitions for an enum's supporting functions.""" diff --git a/src/mongo/idl/idl_test.cpp b/src/mongo/idl/idl_test.cpp index f97fddd6577..24af110112d 100644 --- a/src/mongo/idl/idl_test.cpp +++ b/src/mongo/idl/idl_test.cpp @@ -1438,12 +1438,11 @@ TEST(IDLEnum, TestStringEnumNegative) { TEST(IDLCommand, TestConcatentateWithDb) { IDLParserErrorContext ctxt("root"); - auto testDoc = BSON("BasicConcatenateWithDbCommand" - << "coll1" - << "field1" - << 3 - << "field2" - << "five"); + auto testDoc = BSON(BasicConcatenateWithDbCommand::kCommandName << "coll1" + << "field1" + << 3 + << "field2" + << "five"); auto testStruct = BasicConcatenateWithDbCommand::parse(ctxt, "db", testDoc); ASSERT_EQUALS(testStruct.getField1(), 3); |