aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/compiler/cpp/cpp_string_field.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/google/protobuf/compiler/cpp/cpp_string_field.cc')
-rw-r--r--src/google/protobuf/compiler/cpp/cpp_string_field.cc165
1 files changed, 117 insertions, 48 deletions
diff --git a/src/google/protobuf/compiler/cpp/cpp_string_field.cc b/src/google/protobuf/compiler/cpp/cpp_string_field.cc
index 6a710888..fec13b6d 100644
--- a/src/google/protobuf/compiler/cpp/cpp_string_field.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_string_field.cc
@@ -142,28 +142,47 @@ GenerateAccessorDeclarations(io::Printer* printer) const {
}
printer->Print(variables_,
- "$deprecated_attr$const ::std::string& $name$() const;\n"
- "$deprecated_attr$void set_$name$(const ::std::string& value);\n");
+ "$deprecated_attr$const ::std::string& $name$() const;\n");
+ printer->Annotate("name", descriptor_);
+ printer->Print(
+ variables_,
+ "$deprecated_attr$void ${$set_$name$$}$(const ::std::string& value);\n");
+ printer->Annotate("{", "}", descriptor_);
- if (!SupportsArenas(descriptor_)) {
- printer->Print(variables_,
- "#if LANG_CXX11\n"
- "$deprecated_attr$void set_$name$(::std::string&& value);\n"
- "#endif\n");
- }
+ printer->Print(variables_,
+ "#if LANG_CXX11\n"
+ "$deprecated_attr$void ${$set_$name$$}$(::std::string&& value);\n"
+ "#endif\n");
+ printer->Annotate("{", "}", descriptor_);
+ printer->Print(
+ variables_,
+ "$deprecated_attr$void ${$set_$name$$}$(const char* value);\n");
+ printer->Annotate("{", "}", descriptor_);
+ printer->Print(variables_,
+ "$deprecated_attr$void ${$set_$name$$}$(const $pointer_type$* "
+ "value, size_t size)"
+ ";\n");
+ printer->Annotate("{", "}", descriptor_);
printer->Print(variables_,
- "$deprecated_attr$void set_$name$(const char* value);\n"
- "$deprecated_attr$void set_$name$(const $pointer_type$* value, size_t size)"
- ";\n"
- "$deprecated_attr$::std::string* mutable_$name$();\n"
- "$deprecated_attr$::std::string* $release_name$();\n"
- "$deprecated_attr$void set_allocated_$name$(::std::string* $name$);\n");
+ "$deprecated_attr$::std::string* ${$mutable_$name$$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
+ printer->Print(variables_, "$deprecated_attr$::std::string* $release_name$();\n");
+ printer->Annotate("release_name", descriptor_);
+ printer->Print(
+ variables_,
+ "$deprecated_attr$void ${$set_allocated_$name$$}$(::std::string* $name$);\n");
+ printer->Annotate("{", "}", descriptor_);
if (SupportsArenas(descriptor_)) {
- printer->Print(variables_,
- "$deprecated_attr$::std::string* unsafe_arena_release_$name$();\n"
- "$deprecated_attr$void unsafe_arena_set_allocated_$name$(\n"
- " ::std::string* $name$);\n");
+ printer->Print(
+ variables_,
+ "$deprecated_attr$::std::string* ${$unsafe_arena_release_$name$$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
+ printer->Print(
+ variables_,
+ "$deprecated_attr$void ${$unsafe_arena_set_allocated_$name$$}$(\n"
+ " ::std::string* $name$);\n");
+ printer->Annotate("{", "}", descriptor_);
}
@@ -191,6 +210,14 @@ GenerateInlineAccessorDefinitions(io::Printer* printer,
" $name$_.Set($default_variable$, value, GetArenaNoVirtual());\n"
" // @@protoc_insertion_point(field_set:$full_name$)\n"
"}\n"
+ "#if LANG_CXX11\n"
+ "$inline$void $classname$::set_$name$(::std::string&& value) {\n"
+ " $set_hasbit$\n"
+ " $name$_.Set(\n"
+ " $default_variable$, ::std::move(value), GetArenaNoVirtual());\n"
+ " // @@protoc_insertion_point(field_set_rvalue:$full_name$)\n"
+ "}\n"
+ "#endif\n"
"$inline$void $classname$::set_$name$(const char* value) {\n"
" $null_check$"
" $set_hasbit$\n"
@@ -456,15 +483,10 @@ GenerateDefaultInstanceAllocator(io::Printer* printer) const {
printer->Print(variables_,
"$classname$::$default_variable_name$.DefaultConstruct();\n"
"*$classname$::$default_variable_name$.get_mutable() = "
- "::std::string($default$, $default_length$);\n");
- }
-}
-
-void StringFieldGenerator::
-GenerateShutdownCode(io::Printer* printer) const {
- if (!descriptor_->default_value_string().empty()) {
- printer->Print(variables_,
- "$classname$::$default_variable_name$.Shutdown();\n");
+ "::std::string($default$, $default_length$);\n"
+ "::google::protobuf::internal::OnShutdownDestroyString(\n"
+ " $classname$::$default_variable_name$.get_mutable());\n"
+ );
}
}
@@ -554,6 +576,19 @@ GenerateInlineAccessorDefinitions(io::Printer* printer,
" GetArenaNoVirtual());\n"
" // @@protoc_insertion_point(field_set:$full_name$)\n"
"}\n"
+ "#if LANG_CXX11\n"
+ "$inline$void $classname$::set_$name$(::std::string&& value) {\n"
+ " // @@protoc_insertion_point(field_set:$full_name$)\n"
+ " if (!has_$name$()) {\n"
+ " clear_$oneof_name$();\n"
+ " set_has_$name$();\n"
+ " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n"
+ " }\n"
+ " $oneof_prefix$$name$_.Set(\n"
+ " $default_variable$, ::std::move(value), GetArenaNoVirtual());\n"
+ " // @@protoc_insertion_point(field_set_rvalue:$full_name$)\n"
+ "}\n"
+ "#endif\n"
"$inline$void $classname$::set_$name$(const char* value) {\n"
" $null_check$"
" if (!has_$name$()) {\n"
@@ -837,28 +872,62 @@ GenerateAccessorDeclarations(io::Printer* printer) const {
}
printer->Print(variables_,
- "$deprecated_attr$const ::std::string& $name$(int index) const;\n"
- "$deprecated_attr$::std::string* mutable_$name$(int index);\n"
- "$deprecated_attr$void set_$name$(int index, const ::std::string& value);\n"
- "#if LANG_CXX11\n"
- "$deprecated_attr$void set_$name$(int index, ::std::string&& value);\n"
- "#endif\n"
- "$deprecated_attr$void set_$name$(int index, const char* value);\n"
- ""
- "$deprecated_attr$void set_$name$("
- "int index, const $pointer_type$* value, size_t size);\n"
- "$deprecated_attr$::std::string* add_$name$();\n"
- "$deprecated_attr$void add_$name$(const ::std::string& value);\n"
- "#if LANG_CXX11\n"
- "$deprecated_attr$void add_$name$(::std::string&& value);\n"
- "#endif\n"
- "$deprecated_attr$void add_$name$(const char* value);\n"
- "$deprecated_attr$void add_$name$(const $pointer_type$* value, size_t size)"
- ";\n"
- "$deprecated_attr$const ::google::protobuf::RepeatedPtrField< ::std::string>& $name$() "
- "const;\n"
- "$deprecated_attr$::google::protobuf::RepeatedPtrField< ::std::string>* mutable_$name$()"
+ "$deprecated_attr$const ::std::string& $name$(int index) const;\n");
+ printer->Annotate("name", descriptor_);
+ printer->Print(
+ variables_,
+ "$deprecated_attr$::std::string* ${$mutable_$name$$}$(int index);\n");
+ printer->Annotate("{", "}", descriptor_);
+ printer->Print(variables_,
+ "$deprecated_attr$void ${$set_$name$$}$(int index, const "
+ "::std::string& value);\n");
+ printer->Annotate("{", "}", descriptor_);
+ printer->Print(
+ variables_,
+ "#if LANG_CXX11\n"
+ "$deprecated_attr$void ${$set_$name$$}$(int index, ::std::string&& value);\n"
+ "#endif\n");
+ printer->Annotate("{", "}", descriptor_);
+ printer->Print(variables_,
+ "$deprecated_attr$void ${$set_$name$$}$(int index, const "
+ "char* value);\n");
+ printer->Annotate("{", "}", descriptor_);
+ printer->Print(variables_,
+ ""
+ "$deprecated_attr$void ${$set_$name$$}$("
+ "int index, const $pointer_type$* value, size_t size);\n");
+ printer->Annotate("{", "}", descriptor_);
+ printer->Print(variables_,
+ "$deprecated_attr$::std::string* ${$add_$name$$}$();\n");
+ printer->Annotate("{", "}", descriptor_);
+ printer->Print(
+ variables_,
+ "$deprecated_attr$void ${$add_$name$$}$(const ::std::string& value);\n");
+ printer->Annotate("{", "}", descriptor_);
+ printer->Print(variables_,
+ "#if LANG_CXX11\n"
+ "$deprecated_attr$void ${$add_$name$$}$(::std::string&& value);\n"
+ "#endif\n");
+ printer->Annotate("{", "}", descriptor_);
+ printer->Print(
+ variables_,
+ "$deprecated_attr$void ${$add_$name$$}$(const char* value);\n");
+ printer->Annotate("{", "}", descriptor_);
+ printer->Print(variables_,
+ "$deprecated_attr$void ${$add_$name$$}$(const $pointer_type$* "
+ "value, size_t size)"
+ ";\n");
+ printer->Annotate("{", "}", descriptor_);
+ printer->Print(
+ variables_,
+ "$deprecated_attr$const ::google::protobuf::RepeatedPtrField< ::std::string>& $name$() "
+ "const;\n");
+ printer->Annotate("name", descriptor_);
+ printer->Print(variables_,
+ "$deprecated_attr$::google::protobuf::RepeatedPtrField< ::std::string>* "
+ "${$mutable_$name$$}$()"
";\n");
+ printer->Annotate("{", "}", descriptor_);
if (unknown_ctype) {
printer->Outdent();