| OLD | NEW |
| 1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
| 2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
| 3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
| 4 // | 4 // |
| 5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
| 6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
| 7 // met: | 7 // met: |
| 8 // | 8 // |
| 9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
| 10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 descriptor, "release_"); | 69 descriptor, "release_"); |
| 70 (*variables)["full_name"] = descriptor->full_name(); | 70 (*variables)["full_name"] = descriptor->full_name(); |
| 71 | 71 |
| 72 (*variables)["string_piece"] = "::std::string"; | 72 (*variables)["string_piece"] = "::std::string"; |
| 73 } | 73 } |
| 74 | 74 |
| 75 } // namespace | 75 } // namespace |
| 76 | 76 |
| 77 // =================================================================== | 77 // =================================================================== |
| 78 | 78 |
| 79 StringFieldGenerator:: | 79 StringFieldGenerator::StringFieldGenerator(const FieldDescriptor* descriptor, |
| 80 StringFieldGenerator(const FieldDescriptor* descriptor, | 80 const Options& options) |
| 81 const Options& options) | 81 : FieldGenerator(options), descriptor_(descriptor) { |
| 82 : descriptor_(descriptor) { | |
| 83 SetStringVariables(descriptor, &variables_, options); | 82 SetStringVariables(descriptor, &variables_, options); |
| 84 } | 83 } |
| 85 | 84 |
| 86 StringFieldGenerator::~StringFieldGenerator() {} | 85 StringFieldGenerator::~StringFieldGenerator() {} |
| 87 | 86 |
| 88 void StringFieldGenerator:: | 87 void StringFieldGenerator:: |
| 89 GeneratePrivateMembers(io::Printer* printer) const { | 88 GeneratePrivateMembers(io::Printer* printer) const { |
| 90 // N.B. that we continue to use |ArenaStringPtr| instead of |string*| for | 89 // N.B. that we continue to use |ArenaStringPtr| instead of |string*| for |
| 91 // string fields, even when SupportArenas(descriptor_) == false. Why? | 90 // string fields, even when SupportArenas(descriptor_) == false. Why? |
| 92 // The simple answer is to avoid unmaintainable complexity. The reflection | 91 // The simple answer is to avoid unmaintainable complexity. The reflection |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 | 132 |
| 134 if (unknown_ctype) { | 133 if (unknown_ctype) { |
| 135 printer->Outdent(); | 134 printer->Outdent(); |
| 136 printer->Print( | 135 printer->Print( |
| 137 " private:\n" | 136 " private:\n" |
| 138 " // Hidden due to unknown ctype option.\n"); | 137 " // Hidden due to unknown ctype option.\n"); |
| 139 printer->Indent(); | 138 printer->Indent(); |
| 140 } | 139 } |
| 141 | 140 |
| 142 printer->Print(variables_, | 141 printer->Print(variables_, |
| 143 "const ::std::string& $name$() const$deprecation$;\n" | 142 "$deprecated_attr$const ::std::string& $name$() const;\n" |
| 144 "void set_$name$(const ::std::string& value)$deprecation$;\n" | 143 "$deprecated_attr$void set_$name$(const ::std::string& value);\n" |
| 145 "void set_$name$(const char* value)$deprecation$;\n" | 144 "$deprecated_attr$void set_$name$(const char* value);\n" |
| 146 "void set_$name$(const $pointer_type$* value, size_t size)" | 145 "$deprecated_attr$void set_$name$(const $pointer_type$* value, size_t size)" |
| 147 "$deprecation$;\n" | 146 ";\n" |
| 148 "::std::string* mutable_$name$()$deprecation$;\n" | 147 "$deprecated_attr$::std::string* mutable_$name$();\n" |
| 149 "::std::string* $release_name$()$deprecation$;\n" | 148 "$deprecated_attr$::std::string* $release_name$();\n" |
| 150 "void set_allocated_$name$(::std::string* $name$)$deprecation$;\n"); | 149 "$deprecated_attr$void set_allocated_$name$(::std::string* $name$);\n"); |
| 151 if (SupportsArenas(descriptor_)) { | 150 if (SupportsArenas(descriptor_)) { |
| 152 printer->Print(variables_, | 151 printer->Print(variables_, |
| 153 "::std::string* unsafe_arena_release_$name$()$deprecation$;\n" | 152 "$deprecated_attr$::std::string* unsafe_arena_release_$name$();\n" |
| 154 "void unsafe_arena_set_allocated_$name$(\n" | 153 "$deprecated_attr$void unsafe_arena_set_allocated_$name$(\n" |
| 155 " ::std::string* $name$)$deprecation$;\n"); | 154 " ::std::string* $name$);\n"); |
| 156 } | 155 } |
| 157 | 156 |
| 158 | 157 |
| 159 if (unknown_ctype) { | 158 if (unknown_ctype) { |
| 160 printer->Outdent(); | 159 printer->Outdent(); |
| 161 printer->Print(" public:\n"); | 160 printer->Print(" public:\n"); |
| 162 printer->Indent(); | 161 printer->Indent(); |
| 163 } | 162 } |
| 164 } | 163 } |
| 165 | 164 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 192 " $name$_.Set($default_variable$, $string_piece$(\n" | 191 " $name$_.Set($default_variable$, $string_piece$(\n" |
| 193 " reinterpret_cast<const char*>(value), size), GetArenaNoVirtual());\
n" | 192 " reinterpret_cast<const char*>(value), size), GetArenaNoVirtual());\
n" |
| 194 " // @@protoc_insertion_point(field_set_pointer:$full_name$)\n" | 193 " // @@protoc_insertion_point(field_set_pointer:$full_name$)\n" |
| 195 "}\n" | 194 "}\n" |
| 196 "$inline$ ::std::string* $classname$::mutable_$name$() {\n" | 195 "$inline$ ::std::string* $classname$::mutable_$name$() {\n" |
| 197 " $set_hasbit$\n" | 196 " $set_hasbit$\n" |
| 198 " // @@protoc_insertion_point(field_mutable:$full_name$)\n" | 197 " // @@protoc_insertion_point(field_mutable:$full_name$)\n" |
| 199 " return $name$_.Mutable($default_variable$, GetArenaNoVirtual());\n" | 198 " return $name$_.Mutable($default_variable$, GetArenaNoVirtual());\n" |
| 200 "}\n" | 199 "}\n" |
| 201 "$inline$ ::std::string* $classname$::$release_name$() {\n" | 200 "$inline$ ::std::string* $classname$::$release_name$() {\n" |
| 201 " // @@protoc_insertion_point(field_release:$full_name$)\n" |
| 202 " $clear_hasbit$\n" | 202 " $clear_hasbit$\n" |
| 203 " return $name$_.Release($default_variable$, GetArenaNoVirtual());\n" | 203 " return $name$_.Release($default_variable$, GetArenaNoVirtual());\n" |
| 204 "}\n" | 204 "}\n" |
| 205 "$inline$ ::std::string* $classname$::unsafe_arena_release_$name$() {\n" | 205 "$inline$ ::std::string* $classname$::unsafe_arena_release_$name$() {\n" |
| 206 " // @@protoc_insertion_point(field_unsafe_arena_release:$full_name$)\n" |
| 206 " GOOGLE_DCHECK(GetArenaNoVirtual() != NULL);\n" | 207 " GOOGLE_DCHECK(GetArenaNoVirtual() != NULL);\n" |
| 207 " $clear_hasbit$\n" | 208 " $clear_hasbit$\n" |
| 208 " return $name$_.UnsafeArenaRelease($default_variable$,\n" | 209 " return $name$_.UnsafeArenaRelease($default_variable$,\n" |
| 209 " GetArenaNoVirtual());\n" | 210 " GetArenaNoVirtual());\n" |
| 210 "}\n" | 211 "}\n" |
| 211 "$inline$ void $classname$::set_allocated_$name$(::std::string* $name$) {\
n" | 212 "$inline$ void $classname$::set_allocated_$name$(::std::string* $name$) {\
n" |
| 212 " if ($name$ != NULL) {\n" | 213 " if ($name$ != NULL) {\n" |
| 213 " $set_hasbit$\n" | 214 " $set_hasbit$\n" |
| 214 " } else {\n" | 215 " } else {\n" |
| 215 " $clear_hasbit$\n" | 216 " $clear_hasbit$\n" |
| 216 " }\n" | 217 " }\n" |
| 217 " $name$_.SetAllocated($default_variable$, $name$,\n" | 218 " $name$_.SetAllocated($default_variable$, $name$,\n" |
| 218 " GetArenaNoVirtual());\n" | 219 " GetArenaNoVirtual());\n" |
| 219 " // @@protoc_insertion_point(field_set_allocated:$full_name$)\n" | 220 " // @@protoc_insertion_point(field_set_allocated:$full_name$)\n" |
| 220 "}\n" | 221 "}\n" |
| 221 "$inline$ void $classname$::unsafe_arena_set_allocated_$name$(\n" | 222 "$inline$ void $classname$::unsafe_arena_set_allocated_$name$(\n" |
| 222 " ::std::string* $name$) {\n" | 223 " ::std::string* $name$) {\n" |
| 223 " GOOGLE_DCHECK(GetArenaNoVirtual() != NULL);\n" | 224 " GOOGLE_DCHECK(GetArenaNoVirtual() != NULL);\n" |
| 224 " if ($name$ != NULL) {\n" | 225 " if ($name$ != NULL) {\n" |
| 225 " $set_hasbit$\n" | 226 " $set_hasbit$\n" |
| 226 " } else {\n" | 227 " } else {\n" |
| 227 " $clear_hasbit$\n" | 228 " $clear_hasbit$\n" |
| 228 " }\n" | 229 " }\n" |
| 229 " $name$_.UnsafeArenaSetAllocated($default_variable$,\n" | 230 " $name$_.UnsafeArenaSetAllocated($default_variable$,\n" |
| 230 " $name$, GetArenaNoVirtual());\n" | 231 " $name$, GetArenaNoVirtual());\n" |
| 231 " // @@protoc_insertion_point(field_set_allocated:$full_name$)\n" | 232 " // @@protoc_insertion_point(field_unsafe_arena_set_allocated:" |
| 233 "$full_name$)\n" |
| 232 "}\n"); | 234 "}\n"); |
| 233 } else { | 235 } else { |
| 234 // No-arena case. | 236 // No-arena case. |
| 235 printer->Print(variables, | 237 printer->Print(variables, |
| 236 "$inline$ const ::std::string& $classname$::$name$() const {\n" | 238 "$inline$ const ::std::string& $classname$::$name$() const {\n" |
| 237 " // @@protoc_insertion_point(field_get:$full_name$)\n" | 239 " // @@protoc_insertion_point(field_get:$full_name$)\n" |
| 238 " return $name$_.GetNoArena($default_variable$);\n" | 240 " return $name$_.GetNoArena($default_variable$);\n" |
| 239 "}\n" | 241 "}\n" |
| 240 "$inline$ void $classname$::set_$name$(const ::std::string& value) {\n" | 242 "$inline$ void $classname$::set_$name$(const ::std::string& value) {\n" |
| 241 " $set_hasbit$\n" | 243 " $set_hasbit$\n" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 254 " $name$_.SetNoArena($default_variable$,\n" | 256 " $name$_.SetNoArena($default_variable$,\n" |
| 255 " $string_piece$(reinterpret_cast<const char*>(value), size));\n" | 257 " $string_piece$(reinterpret_cast<const char*>(value), size));\n" |
| 256 " // @@protoc_insertion_point(field_set_pointer:$full_name$)\n" | 258 " // @@protoc_insertion_point(field_set_pointer:$full_name$)\n" |
| 257 "}\n" | 259 "}\n" |
| 258 "$inline$ ::std::string* $classname$::mutable_$name$() {\n" | 260 "$inline$ ::std::string* $classname$::mutable_$name$() {\n" |
| 259 " $set_hasbit$\n" | 261 " $set_hasbit$\n" |
| 260 " // @@protoc_insertion_point(field_mutable:$full_name$)\n" | 262 " // @@protoc_insertion_point(field_mutable:$full_name$)\n" |
| 261 " return $name$_.MutableNoArena($default_variable$);\n" | 263 " return $name$_.MutableNoArena($default_variable$);\n" |
| 262 "}\n" | 264 "}\n" |
| 263 "$inline$ ::std::string* $classname$::$release_name$() {\n" | 265 "$inline$ ::std::string* $classname$::$release_name$() {\n" |
| 266 " // @@protoc_insertion_point(field_release:$full_name$)\n" |
| 264 " $clear_hasbit$\n" | 267 " $clear_hasbit$\n" |
| 265 " return $name$_.ReleaseNoArena($default_variable$);\n" | 268 " return $name$_.ReleaseNoArena($default_variable$);\n" |
| 266 "}\n" | 269 "}\n" |
| 267 "$inline$ void $classname$::set_allocated_$name$(::std::string* $name$) {\
n" | 270 "$inline$ void $classname$::set_allocated_$name$(::std::string* $name$) {\
n" |
| 268 " if ($name$ != NULL) {\n" | 271 " if ($name$ != NULL) {\n" |
| 269 " $set_hasbit$\n" | 272 " $set_hasbit$\n" |
| 270 " } else {\n" | 273 " } else {\n" |
| 271 " $clear_hasbit$\n" | 274 " $clear_hasbit$\n" |
| 272 " }\n" | 275 " }\n" |
| 273 " $name$_.SetAllocatedNoArena($default_variable$, $name$);\n" | 276 " $name$_.SetAllocatedNoArena($default_variable$, $name$);\n" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 362 } | 365 } |
| 363 | 366 |
| 364 void StringFieldGenerator:: | 367 void StringFieldGenerator:: |
| 365 GenerateMergeFromCodedStream(io::Printer* printer) const { | 368 GenerateMergeFromCodedStream(io::Printer* printer) const { |
| 366 printer->Print(variables_, | 369 printer->Print(variables_, |
| 367 "DO_(::google::protobuf::internal::WireFormatLite::Read$declared_type$(\n" | 370 "DO_(::google::protobuf::internal::WireFormatLite::Read$declared_type$(\n" |
| 368 " input, this->mutable_$name$()));\n"); | 371 " input, this->mutable_$name$()));\n"); |
| 369 | 372 |
| 370 if (descriptor_->type() == FieldDescriptor::TYPE_STRING) { | 373 if (descriptor_->type() == FieldDescriptor::TYPE_STRING) { |
| 371 GenerateUtf8CheckCodeForString( | 374 GenerateUtf8CheckCodeForString( |
| 372 descriptor_, true, variables_, | 375 descriptor_, options_, true, variables_, |
| 373 "this->$name$().data(), this->$name$().length(),\n", printer); | 376 "this->$name$().data(), this->$name$().length(),\n", printer); |
| 374 } | 377 } |
| 375 } | 378 } |
| 376 | 379 |
| 377 void StringFieldGenerator:: | 380 void StringFieldGenerator:: |
| 378 GenerateSerializeWithCachedSizes(io::Printer* printer) const { | 381 GenerateSerializeWithCachedSizes(io::Printer* printer) const { |
| 379 if (descriptor_->type() == FieldDescriptor::TYPE_STRING) { | 382 if (descriptor_->type() == FieldDescriptor::TYPE_STRING) { |
| 380 GenerateUtf8CheckCodeForString( | 383 GenerateUtf8CheckCodeForString( |
| 381 descriptor_, false, variables_, | 384 descriptor_, options_, false, variables_, |
| 382 "this->$name$().data(), this->$name$().length(),\n", printer); | 385 "this->$name$().data(), this->$name$().length(),\n", printer); |
| 383 } | 386 } |
| 384 printer->Print(variables_, | 387 printer->Print(variables_, |
| 385 "::google::protobuf::internal::WireFormatLite::Write$declared_type$MaybeAlia
sed(\n" | 388 "::google::protobuf::internal::WireFormatLite::Write$declared_type$MaybeAlia
sed(\n" |
| 386 " $number$, this->$name$(), output);\n"); | 389 " $number$, this->$name$(), output);\n"); |
| 387 } | 390 } |
| 388 | 391 |
| 389 void StringFieldGenerator:: | 392 void StringFieldGenerator:: |
| 390 GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const { | 393 GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const { |
| 391 if (descriptor_->type() == FieldDescriptor::TYPE_STRING) { | 394 if (descriptor_->type() == FieldDescriptor::TYPE_STRING) { |
| 392 GenerateUtf8CheckCodeForString( | 395 GenerateUtf8CheckCodeForString( |
| 393 descriptor_, false, variables_, | 396 descriptor_, options_, false, variables_, |
| 394 "this->$name$().data(), this->$name$().length(),\n", printer); | 397 "this->$name$().data(), this->$name$().length(),\n", printer); |
| 395 } | 398 } |
| 396 printer->Print(variables_, | 399 printer->Print(variables_, |
| 397 "target =\n" | 400 "target =\n" |
| 398 " ::google::protobuf::internal::WireFormatLite::Write$declared_type$ToArray
(\n" | 401 " ::google::protobuf::internal::WireFormatLite::Write$declared_type$ToArray
(\n" |
| 399 " $number$, this->$name$(), target);\n"); | 402 " $number$, this->$name$(), target);\n"); |
| 400 } | 403 } |
| 401 | 404 |
| 402 void StringFieldGenerator:: | 405 void StringFieldGenerator:: |
| 403 GenerateByteSize(io::Printer* printer) const { | 406 GenerateByteSize(io::Printer* printer) const { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 " if (!has_$name$()) {\n" | 473 " if (!has_$name$()) {\n" |
| 471 " clear_$oneof_name$();\n" | 474 " clear_$oneof_name$();\n" |
| 472 " set_has_$name$();\n" | 475 " set_has_$name$();\n" |
| 473 " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n" | 476 " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n" |
| 474 " }\n" | 477 " }\n" |
| 475 " return $oneof_prefix$$name$_.Mutable($default_variable$,\n" | 478 " return $oneof_prefix$$name$_.Mutable($default_variable$,\n" |
| 476 " GetArenaNoVirtual());\n" | 479 " GetArenaNoVirtual());\n" |
| 477 " // @@protoc_insertion_point(field_mutable:$full_name$)\n" | 480 " // @@protoc_insertion_point(field_mutable:$full_name$)\n" |
| 478 "}\n" | 481 "}\n" |
| 479 "$inline$ ::std::string* $classname$::$release_name$() {\n" | 482 "$inline$ ::std::string* $classname$::$release_name$() {\n" |
| 483 " // @@protoc_insertion_point(field_release:$full_name$)\n" |
| 480 " if (has_$name$()) {\n" | 484 " if (has_$name$()) {\n" |
| 481 " clear_has_$oneof_name$();\n" | 485 " clear_has_$oneof_name$();\n" |
| 482 " return $oneof_prefix$$name$_.Release($default_variable$,\n" | 486 " return $oneof_prefix$$name$_.Release($default_variable$,\n" |
| 483 " GetArenaNoVirtual());\n" | 487 " GetArenaNoVirtual());\n" |
| 484 " } else {\n" | 488 " } else {\n" |
| 485 " return NULL;\n" | 489 " return NULL;\n" |
| 486 " }\n" | 490 " }\n" |
| 487 "}\n" | 491 "}\n" |
| 488 "$inline$ ::std::string* $classname$::unsafe_arena_release_$name$() {\n" | 492 "$inline$ ::std::string* $classname$::unsafe_arena_release_$name$() {\n" |
| 493 " // @@protoc_insertion_point(field_unsafe_arena_release:$full_name$)\n" |
| 489 " GOOGLE_DCHECK(GetArenaNoVirtual() != NULL);\n" | 494 " GOOGLE_DCHECK(GetArenaNoVirtual() != NULL);\n" |
| 490 " if (has_$name$()) {\n" | 495 " if (has_$name$()) {\n" |
| 491 " clear_has_$oneof_name$();\n" | 496 " clear_has_$oneof_name$();\n" |
| 492 " return $oneof_prefix$$name$_.UnsafeArenaRelease(\n" | 497 " return $oneof_prefix$$name$_.UnsafeArenaRelease(\n" |
| 493 " $default_variable$, GetArenaNoVirtual());\n" | 498 " $default_variable$, GetArenaNoVirtual());\n" |
| 494 " } else {\n" | 499 " } else {\n" |
| 495 " return NULL;\n" | 500 " return NULL;\n" |
| 496 " }\n" | 501 " }\n" |
| 497 "}\n" | 502 "}\n" |
| 498 "$inline$ void $classname$::set_allocated_$name$(::std::string* $name$) {\
n" | 503 "$inline$ void $classname$::set_allocated_$name$(::std::string* $name$) {\
n" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 512 " GOOGLE_DCHECK(GetArenaNoVirtual() != NULL);\n" | 517 " GOOGLE_DCHECK(GetArenaNoVirtual() != NULL);\n" |
| 513 " if (!has_$name$()) {\n" | 518 " if (!has_$name$()) {\n" |
| 514 " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n" | 519 " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n" |
| 515 " }\n" | 520 " }\n" |
| 516 " clear_$oneof_name$();\n" | 521 " clear_$oneof_name$();\n" |
| 517 " if ($name$) {\n" | 522 " if ($name$) {\n" |
| 518 " set_has_$name$();\n" | 523 " set_has_$name$();\n" |
| 519 " $oneof_prefix$$name$_.UnsafeArenaSetAllocated($default_variable$, " | 524 " $oneof_prefix$$name$_.UnsafeArenaSetAllocated($default_variable$, " |
| 520 "$name$, GetArenaNoVirtual());\n" | 525 "$name$, GetArenaNoVirtual());\n" |
| 521 " }\n" | 526 " }\n" |
| 522 " // @@protoc_insertion_point(field_set_allocated:$full_name$)\n" | 527 " // @@protoc_insertion_point(field_unsafe_arena_set_allocated:" |
| 528 "$full_name$)\n" |
| 523 "}\n"); | 529 "}\n"); |
| 524 } else { | 530 } else { |
| 525 // No-arena case. | 531 // No-arena case. |
| 526 printer->Print(variables, | 532 printer->Print(variables, |
| 527 "$inline$ const ::std::string& $classname$::$name$() const {\n" | 533 "$inline$ const ::std::string& $classname$::$name$() const {\n" |
| 528 " // @@protoc_insertion_point(field_get:$full_name$)\n" | 534 " // @@protoc_insertion_point(field_get:$full_name$)\n" |
| 529 " if (has_$name$()) {\n" | 535 " if (has_$name$()) {\n" |
| 530 " return $oneof_prefix$$name$_.GetNoArena($default_variable$);\n" | 536 " return $oneof_prefix$$name$_.GetNoArena($default_variable$);\n" |
| 531 " }\n" | 537 " }\n" |
| 532 " return *$default_variable$;\n" | 538 " return *$default_variable$;\n" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 "$inline$ ::std::string* $classname$::mutable_$name$() {\n" | 571 "$inline$ ::std::string* $classname$::mutable_$name$() {\n" |
| 566 " if (!has_$name$()) {\n" | 572 " if (!has_$name$()) {\n" |
| 567 " clear_$oneof_name$();\n" | 573 " clear_$oneof_name$();\n" |
| 568 " set_has_$name$();\n" | 574 " set_has_$name$();\n" |
| 569 " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n" | 575 " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n" |
| 570 " }\n" | 576 " }\n" |
| 571 " // @@protoc_insertion_point(field_mutable:$full_name$)\n" | 577 " // @@protoc_insertion_point(field_mutable:$full_name$)\n" |
| 572 " return $oneof_prefix$$name$_.MutableNoArena($default_variable$);\n" | 578 " return $oneof_prefix$$name$_.MutableNoArena($default_variable$);\n" |
| 573 "}\n" | 579 "}\n" |
| 574 "$inline$ ::std::string* $classname$::$release_name$() {\n" | 580 "$inline$ ::std::string* $classname$::$release_name$() {\n" |
| 581 " // @@protoc_insertion_point(field_release:$full_name$)\n" |
| 575 " if (has_$name$()) {\n" | 582 " if (has_$name$()) {\n" |
| 576 " clear_has_$oneof_name$();\n" | 583 " clear_has_$oneof_name$();\n" |
| 577 " return $oneof_prefix$$name$_.ReleaseNoArena($default_variable$);\n" | 584 " return $oneof_prefix$$name$_.ReleaseNoArena($default_variable$);\n" |
| 578 " } else {\n" | 585 " } else {\n" |
| 579 " return NULL;\n" | 586 " return NULL;\n" |
| 580 " }\n" | 587 " }\n" |
| 581 "}\n" | 588 "}\n" |
| 582 "$inline$ void $classname$::set_allocated_$name$(::std::string* $name$) {\
n" | 589 "$inline$ void $classname$::set_allocated_$name$(::std::string* $name$) {\
n" |
| 583 " if (!has_$name$()) {\n" | 590 " if (!has_$name$()) {\n" |
| 584 " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n" | 591 " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 651 } | 658 } |
| 652 | 659 |
| 653 void StringOneofFieldGenerator:: | 660 void StringOneofFieldGenerator:: |
| 654 GenerateMergeFromCodedStream(io::Printer* printer) const { | 661 GenerateMergeFromCodedStream(io::Printer* printer) const { |
| 655 printer->Print(variables_, | 662 printer->Print(variables_, |
| 656 "DO_(::google::protobuf::internal::WireFormatLite::Read$declared_type$(\n" | 663 "DO_(::google::protobuf::internal::WireFormatLite::Read$declared_type$(\n" |
| 657 " input, this->mutable_$name$()));\n"); | 664 " input, this->mutable_$name$()));\n"); |
| 658 | 665 |
| 659 if (descriptor_->type() == FieldDescriptor::TYPE_STRING) { | 666 if (descriptor_->type() == FieldDescriptor::TYPE_STRING) { |
| 660 GenerateUtf8CheckCodeForString( | 667 GenerateUtf8CheckCodeForString( |
| 661 descriptor_, true, variables_, | 668 descriptor_, options_, true, variables_, |
| 662 "this->$name$().data(), this->$name$().length(),\n", printer); | 669 "this->$name$().data(), this->$name$().length(),\n", printer); |
| 663 } | 670 } |
| 664 } | 671 } |
| 665 | 672 |
| 666 | 673 |
| 667 // =================================================================== | 674 // =================================================================== |
| 668 | 675 |
| 669 RepeatedStringFieldGenerator:: | 676 RepeatedStringFieldGenerator::RepeatedStringFieldGenerator( |
| 670 RepeatedStringFieldGenerator(const FieldDescriptor* descriptor, | 677 const FieldDescriptor* descriptor, const Options& options) |
| 671 const Options& options) | 678 : FieldGenerator(options), descriptor_(descriptor) { |
| 672 : descriptor_(descriptor) { | |
| 673 SetStringVariables(descriptor, &variables_, options); | 679 SetStringVariables(descriptor, &variables_, options); |
| 674 } | 680 } |
| 675 | 681 |
| 676 RepeatedStringFieldGenerator::~RepeatedStringFieldGenerator() {} | 682 RepeatedStringFieldGenerator::~RepeatedStringFieldGenerator() {} |
| 677 | 683 |
| 678 void RepeatedStringFieldGenerator:: | 684 void RepeatedStringFieldGenerator:: |
| 679 GeneratePrivateMembers(io::Printer* printer) const { | 685 GeneratePrivateMembers(io::Printer* printer) const { |
| 680 printer->Print(variables_, | 686 printer->Print(variables_, |
| 681 "::google::protobuf::RepeatedPtrField< ::std::string> $name$_;\n"); | 687 "::google::protobuf::RepeatedPtrField< ::std::string> $name$_;\n"); |
| 682 } | 688 } |
| 683 | 689 |
| 684 void RepeatedStringFieldGenerator:: | 690 void RepeatedStringFieldGenerator:: |
| 685 GenerateAccessorDeclarations(io::Printer* printer) const { | 691 GenerateAccessorDeclarations(io::Printer* printer) const { |
| 686 // See comment above about unknown ctypes. | 692 // See comment above about unknown ctypes. |
| 687 bool unknown_ctype = | 693 bool unknown_ctype = |
| 688 descriptor_->options().ctype() != EffectiveStringCType(descriptor_); | 694 descriptor_->options().ctype() != EffectiveStringCType(descriptor_); |
| 689 | 695 |
| 690 if (unknown_ctype) { | 696 if (unknown_ctype) { |
| 691 printer->Outdent(); | 697 printer->Outdent(); |
| 692 printer->Print( | 698 printer->Print( |
| 693 " private:\n" | 699 " private:\n" |
| 694 " // Hidden due to unknown ctype option.\n"); | 700 " // Hidden due to unknown ctype option.\n"); |
| 695 printer->Indent(); | 701 printer->Indent(); |
| 696 } | 702 } |
| 697 | 703 |
| 698 printer->Print(variables_, | 704 printer->Print(variables_, |
| 699 "const ::std::string& $name$(int index) const$deprecation$;\n" | 705 "$deprecated_attr$const ::std::string& $name$(int index) const;\n" |
| 700 "::std::string* mutable_$name$(int index)$deprecation$;\n" | 706 "$deprecated_attr$::std::string* mutable_$name$(int index);\n" |
| 701 "void set_$name$(int index, const ::std::string& value)$deprecation$;\n" | 707 "$deprecated_attr$void set_$name$(int index, const ::std::string& value);\n" |
| 702 "void set_$name$(int index, const char* value)$deprecation$;\n" | 708 "$deprecated_attr$void set_$name$(int index, const char* value);\n" |
| 703 "" | 709 "" |
| 704 "void set_$name$(int index, const $pointer_type$* value, size_t size)" | 710 "$deprecated_attr$void set_$name$(" |
| 705 "$deprecation$;\n" | 711 "int index, const $pointer_type$* value, size_t size);\n" |
| 706 "::std::string* add_$name$()$deprecation$;\n" | 712 "$deprecated_attr$::std::string* add_$name$();\n" |
| 707 "void add_$name$(const ::std::string& value)$deprecation$;\n" | 713 "$deprecated_attr$void add_$name$(const ::std::string& value);\n" |
| 708 "void add_$name$(const char* value)$deprecation$;\n" | 714 "$deprecated_attr$void add_$name$(const char* value);\n" |
| 709 "void add_$name$(const $pointer_type$* value, size_t size)" | 715 "$deprecated_attr$void add_$name$(const $pointer_type$* value, size_t size)" |
| 710 "$deprecation$;\n"); | 716 ";\n"); |
| 711 | 717 |
| 712 printer->Print(variables_, | 718 printer->Print(variables_, |
| 713 "const ::google::protobuf::RepeatedPtrField< ::std::string>& $name$() const" | 719 "$deprecated_attr$const ::google::protobuf::RepeatedPtrField< ::std::string>
& $name$() " |
| 714 "$deprecation$;\n" | 720 "const;\n" |
| 715 "::google::protobuf::RepeatedPtrField< ::std::string>* mutable_$name$()" | 721 "$deprecated_attr$::google::protobuf::RepeatedPtrField< ::std::string>* muta
ble_$name$()" |
| 716 "$deprecation$;\n"); | 722 ";\n"); |
| 717 | 723 |
| 718 if (unknown_ctype) { | 724 if (unknown_ctype) { |
| 719 printer->Outdent(); | 725 printer->Outdent(); |
| 720 printer->Print(" public:\n"); | 726 printer->Print(" public:\n"); |
| 721 printer->Indent(); | 727 printer->Indent(); |
| 722 } | 728 } |
| 723 } | 729 } |
| 724 | 730 |
| 725 void RepeatedStringFieldGenerator:: | 731 void RepeatedStringFieldGenerator:: |
| 726 GenerateInlineAccessorDefinitions(io::Printer* printer, | 732 GenerateInlineAccessorDefinitions(io::Printer* printer, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 745 " // @@protoc_insertion_point(field_set_char:$full_name$)\n" | 751 " // @@protoc_insertion_point(field_set_char:$full_name$)\n" |
| 746 "}\n" | 752 "}\n" |
| 747 "$inline$ void " | 753 "$inline$ void " |
| 748 "$classname$::set_$name$" | 754 "$classname$::set_$name$" |
| 749 "(int index, const $pointer_type$* value, size_t size) {\n" | 755 "(int index, const $pointer_type$* value, size_t size) {\n" |
| 750 " $name$_.Mutable(index)->assign(\n" | 756 " $name$_.Mutable(index)->assign(\n" |
| 751 " reinterpret_cast<const char*>(value), size);\n" | 757 " reinterpret_cast<const char*>(value), size);\n" |
| 752 " // @@protoc_insertion_point(field_set_pointer:$full_name$)\n" | 758 " // @@protoc_insertion_point(field_set_pointer:$full_name$)\n" |
| 753 "}\n" | 759 "}\n" |
| 754 "$inline$ ::std::string* $classname$::add_$name$() {\n" | 760 "$inline$ ::std::string* $classname$::add_$name$() {\n" |
| 761 " // @@protoc_insertion_point(field_add_mutable:$full_name$)\n" |
| 755 " return $name$_.Add();\n" | 762 " return $name$_.Add();\n" |
| 756 "}\n" | 763 "}\n" |
| 757 "$inline$ void $classname$::add_$name$(const ::std::string& value) {\n" | 764 "$inline$ void $classname$::add_$name$(const ::std::string& value) {\n" |
| 758 " $name$_.Add()->assign(value);\n" | 765 " $name$_.Add()->assign(value);\n" |
| 759 " // @@protoc_insertion_point(field_add:$full_name$)\n" | 766 " // @@protoc_insertion_point(field_add:$full_name$)\n" |
| 760 "}\n" | 767 "}\n" |
| 761 "$inline$ void $classname$::add_$name$(const char* value) {\n" | 768 "$inline$ void $classname$::add_$name$(const char* value) {\n" |
| 762 " $name$_.Add()->assign(value);\n" | 769 " $name$_.Add()->assign(value);\n" |
| 763 " // @@protoc_insertion_point(field_add_char:$full_name$)\n" | 770 " // @@protoc_insertion_point(field_add_char:$full_name$)\n" |
| 764 "}\n" | 771 "}\n" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 // Not needed for repeated fields. | 807 // Not needed for repeated fields. |
| 801 } | 808 } |
| 802 | 809 |
| 803 void RepeatedStringFieldGenerator:: | 810 void RepeatedStringFieldGenerator:: |
| 804 GenerateMergeFromCodedStream(io::Printer* printer) const { | 811 GenerateMergeFromCodedStream(io::Printer* printer) const { |
| 805 printer->Print(variables_, | 812 printer->Print(variables_, |
| 806 "DO_(::google::protobuf::internal::WireFormatLite::Read$declared_type$(\n" | 813 "DO_(::google::protobuf::internal::WireFormatLite::Read$declared_type$(\n" |
| 807 " input, this->add_$name$()));\n"); | 814 " input, this->add_$name$()));\n"); |
| 808 if (descriptor_->type() == FieldDescriptor::TYPE_STRING) { | 815 if (descriptor_->type() == FieldDescriptor::TYPE_STRING) { |
| 809 GenerateUtf8CheckCodeForString( | 816 GenerateUtf8CheckCodeForString( |
| 810 descriptor_, true, variables_, | 817 descriptor_, options_, true, variables_, |
| 811 "this->$name$(this->$name$_size() - 1).data(),\n" | 818 "this->$name$(this->$name$_size() - 1).data(),\n" |
| 812 "this->$name$(this->$name$_size() - 1).length(),\n", | 819 "this->$name$(this->$name$_size() - 1).length(),\n", |
| 813 printer); | 820 printer); |
| 814 } | 821 } |
| 815 } | 822 } |
| 816 | 823 |
| 817 void RepeatedStringFieldGenerator:: | 824 void RepeatedStringFieldGenerator:: |
| 818 GenerateSerializeWithCachedSizes(io::Printer* printer) const { | 825 GenerateSerializeWithCachedSizes(io::Printer* printer) const { |
| 819 printer->Print(variables_, | 826 printer->Print(variables_, |
| 820 "for (int i = 0; i < this->$name$_size(); i++) {\n"); | 827 "for (int i = 0; i < this->$name$_size(); i++) {\n"); |
| 821 printer->Indent(); | 828 printer->Indent(); |
| 822 if (descriptor_->type() == FieldDescriptor::TYPE_STRING) { | 829 if (descriptor_->type() == FieldDescriptor::TYPE_STRING) { |
| 823 GenerateUtf8CheckCodeForString( | 830 GenerateUtf8CheckCodeForString( |
| 824 descriptor_, false, variables_, | 831 descriptor_, options_, false, variables_, |
| 825 "this->$name$(i).data(), this->$name$(i).length(),\n", printer); | 832 "this->$name$(i).data(), this->$name$(i).length(),\n", printer); |
| 826 } | 833 } |
| 827 printer->Outdent(); | 834 printer->Outdent(); |
| 828 printer->Print(variables_, | 835 printer->Print(variables_, |
| 829 " ::google::protobuf::internal::WireFormatLite::Write$declared_type$(\n" | 836 " ::google::protobuf::internal::WireFormatLite::Write$declared_type$(\n" |
| 830 " $number$, this->$name$(i), output);\n" | 837 " $number$, this->$name$(i), output);\n" |
| 831 "}\n"); | 838 "}\n"); |
| 832 } | 839 } |
| 833 | 840 |
| 834 void RepeatedStringFieldGenerator:: | 841 void RepeatedStringFieldGenerator:: |
| 835 GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const { | 842 GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const { |
| 836 printer->Print(variables_, | 843 printer->Print(variables_, |
| 837 "for (int i = 0; i < this->$name$_size(); i++) {\n"); | 844 "for (int i = 0; i < this->$name$_size(); i++) {\n"); |
| 838 printer->Indent(); | 845 printer->Indent(); |
| 839 if (descriptor_->type() == FieldDescriptor::TYPE_STRING) { | 846 if (descriptor_->type() == FieldDescriptor::TYPE_STRING) { |
| 840 GenerateUtf8CheckCodeForString( | 847 GenerateUtf8CheckCodeForString( |
| 841 descriptor_, false, variables_, | 848 descriptor_, options_, false, variables_, |
| 842 "this->$name$(i).data(), this->$name$(i).length(),\n", printer); | 849 "this->$name$(i).data(), this->$name$(i).length(),\n", printer); |
| 843 } | 850 } |
| 844 printer->Outdent(); | 851 printer->Outdent(); |
| 845 printer->Print(variables_, | 852 printer->Print(variables_, |
| 846 " target = ::google::protobuf::internal::WireFormatLite::\n" | 853 " target = ::google::protobuf::internal::WireFormatLite::\n" |
| 847 " Write$declared_type$ToArray($number$, this->$name$(i), target);\n" | 854 " Write$declared_type$ToArray($number$, this->$name$(i), target);\n" |
| 848 "}\n"); | 855 "}\n"); |
| 849 } | 856 } |
| 850 | 857 |
| 851 void RepeatedStringFieldGenerator:: | 858 void RepeatedStringFieldGenerator:: |
| 852 GenerateByteSize(io::Printer* printer) const { | 859 GenerateByteSize(io::Printer* printer) const { |
| 853 printer->Print(variables_, | 860 printer->Print(variables_, |
| 854 "total_size += $tag_size$ * this->$name$_size();\n" | 861 "total_size += $tag_size$ * this->$name$_size();\n" |
| 855 "for (int i = 0; i < this->$name$_size(); i++) {\n" | 862 "for (int i = 0; i < this->$name$_size(); i++) {\n" |
| 856 " total_size += ::google::protobuf::internal::WireFormatLite::$declared_typ
e$Size(\n" | 863 " total_size += ::google::protobuf::internal::WireFormatLite::$declared_typ
e$Size(\n" |
| 857 " this->$name$(i));\n" | 864 " this->$name$(i));\n" |
| 858 "}\n"); | 865 "}\n"); |
| 859 } | 866 } |
| 860 | 867 |
| 861 } // namespace cpp | 868 } // namespace cpp |
| 862 } // namespace compiler | 869 } // namespace compiler |
| 863 } // namespace protobuf | 870 } // namespace protobuf |
| 864 } // namespace google | 871 } // namespace google |
| OLD | NEW |