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.cc28
1 files changed, 19 insertions, 9 deletions
diff --git a/src/google/protobuf/compiler/cpp/cpp_string_field.cc b/src/google/protobuf/compiler/cpp/cpp_string_field.cc
index 66a0496c..3e694ab7 100644
--- a/src/google/protobuf/compiler/cpp/cpp_string_field.cc
+++ b/src/google/protobuf/compiler/cpp/cpp_string_field.cc
@@ -163,12 +163,12 @@ GenerateInlineAccessorDefinitions(io::Printer* printer) const {
"inline ::std::string* $classname$::mutable_$name$() {\n"
" _set_bit($index$);\n"
" if ($name$_ == &_default_$name$_) {\n");
- if (descriptor_->has_default_value()) {
+ if (descriptor_->default_value_string().empty()) {
printer->Print(variables_,
- " $name$_ = new ::std::string(_default_$name$_);\n");
+ " $name$_ = new ::std::string;\n");
} else {
printer->Print(variables_,
- " $name$_ = new ::std::string;\n");
+ " $name$_ = new ::std::string(_default_$name$_);\n");
}
printer->Print(variables_,
" }\n"
@@ -178,26 +178,26 @@ GenerateInlineAccessorDefinitions(io::Printer* printer) const {
void StringFieldGenerator::
GenerateNonInlineAccessorDefinitions(io::Printer* printer) const {
- if (descriptor_->has_default_value()) {
+ if (descriptor_->default_value_string().empty()) {
printer->Print(variables_,
- "const ::std::string $classname$::_default_$name$_($default$);");
+ "const ::std::string $classname$::_default_$name$_;");
} else {
printer->Print(variables_,
- "const ::std::string $classname$::_default_$name$_;");
+ "const ::std::string $classname$::_default_$name$_($default$);");
}
}
void StringFieldGenerator::
GenerateClearingCode(io::Printer* printer) const {
- if (descriptor_->has_default_value()) {
+ if (descriptor_->default_value_string().empty()) {
printer->Print(variables_,
"if ($name$_ != &_default_$name$_) {\n"
- " $name$_->assign(_default_$name$_);\n"
+ " $name$_->clear();\n"
"}\n");
} else {
printer->Print(variables_,
"if ($name$_ != &_default_$name$_) {\n"
- " $name$_->clear();\n"
+ " $name$_->assign(_default_$name$_);\n"
"}\n");
}
}
@@ -208,6 +208,11 @@ GenerateMergingCode(io::Printer* printer) const {
}
void StringFieldGenerator::
+GenerateSwappingCode(io::Printer* printer) const {
+ printer->Print(variables_, "std::swap($name$_, other->$name$_);\n");
+}
+
+void StringFieldGenerator::
GenerateInitializer(io::Printer* printer) const {
printer->Print(variables_,
",\n$name$_(const_cast< ::std::string*>(&_default_$name$_))");
@@ -350,6 +355,11 @@ GenerateMergingCode(io::Printer* printer) const {
}
void RepeatedStringFieldGenerator::
+GenerateSwappingCode(io::Printer* printer) const {
+ printer->Print(variables_, "$name$_.Swap(&other->$name$_);\n");
+}
+
+void RepeatedStringFieldGenerator::
GenerateInitializer(io::Printer* printer) const {
// Not needed for repeated fields.
}