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 // http://code.google.com/p/protobuf/ | 3 // http://code.google.com/p/protobuf/ |
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 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 } | 263 } |
264 | 264 |
265 void StringFieldGenerator:: | 265 void StringFieldGenerator:: |
266 GenerateByteSize(io::Printer* printer) const { | 266 GenerateByteSize(io::Printer* printer) const { |
267 printer->Print(variables_, | 267 printer->Print(variables_, |
268 "total_size += $tag_size$ +\n" | 268 "total_size += $tag_size$ +\n" |
269 " ::google::protobuf::internal::WireFormatLite::$declared_type$Size(\n" | 269 " ::google::protobuf::internal::WireFormatLite::$declared_type$Size(\n" |
270 " this->$name$());\n"); | 270 " this->$name$());\n"); |
271 } | 271 } |
272 | 272 |
| 273 void StringFieldGenerator:: |
| 274 GenerateVisitInterface(io::Printer* printer) const { |
| 275 printer->Print(variables_, |
| 276 "virtual void Visit$camelcase$(const ::std::string& value);\n"); |
| 277 } |
| 278 |
| 279 void StringFieldGenerator:: |
| 280 GenerateVisitMethods(io::Printer* printer) const { |
| 281 printer->Print(variables_, |
| 282 "void $classname$_Visitor::Visit$camelcase$(const ::std::string& value){}\n" |
| 283 "void $classname$_Writer::Visit$camelcase$(const ::std::string& value) {\n" |
| 284 " ::google::protobuf::internal::WireFormatLite::Write$declared_type$(\n" |
| 285 " $number$, value, output_);\n" |
| 286 "}\n" |
| 287 "void $classname$_Filler::Visit$camelcase$(const ::std::string& value) {\n" |
| 288 " message_->set_$name$(value);\n" |
| 289 "}\n"); |
| 290 } |
| 291 |
| 292 void StringFieldGenerator:: |
| 293 GenerateReaderCode(io::Printer* printer) const { |
| 294 printer->Print(variables_, |
| 295 "::std::string value;\n" |
| 296 "DO_(::google::protobuf::internal::WireFormatLite::Read$declared_type$(\n" |
| 297 " input, &value));\n" |
| 298 "visitor->Visit$camelcase$(value);\n"); |
| 299 } |
| 300 |
| 301 void StringFieldGenerator:: |
| 302 GenerateWalkerCode(io::Printer* printer) const { |
| 303 printer->Print(variables_, |
| 304 "visitor->Visit$camelcase$(message_.$name$());\n"); |
| 305 } |
| 306 |
273 // =================================================================== | 307 // =================================================================== |
274 | 308 |
275 RepeatedStringFieldGenerator:: | 309 RepeatedStringFieldGenerator:: |
276 RepeatedStringFieldGenerator(const FieldDescriptor* descriptor) | 310 RepeatedStringFieldGenerator(const FieldDescriptor* descriptor) |
277 : descriptor_(descriptor) { | 311 : descriptor_(descriptor) { |
278 SetStringVariables(descriptor, &variables_); | 312 SetStringVariables(descriptor, &variables_); |
279 } | 313 } |
280 | 314 |
281 RepeatedStringFieldGenerator::~RepeatedStringFieldGenerator() {} | 315 RepeatedStringFieldGenerator::~RepeatedStringFieldGenerator() {} |
282 | 316 |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 void RepeatedStringFieldGenerator:: | 474 void RepeatedStringFieldGenerator:: |
441 GenerateByteSize(io::Printer* printer) const { | 475 GenerateByteSize(io::Printer* printer) const { |
442 printer->Print(variables_, | 476 printer->Print(variables_, |
443 "total_size += $tag_size$ * this->$name$_size();\n" | 477 "total_size += $tag_size$ * this->$name$_size();\n" |
444 "for (int i = 0; i < this->$name$_size(); i++) {\n" | 478 "for (int i = 0; i < this->$name$_size(); i++) {\n" |
445 " total_size += ::google::protobuf::internal::WireFormatLite::$declared_typ
e$Size(\n" | 479 " total_size += ::google::protobuf::internal::WireFormatLite::$declared_typ
e$Size(\n" |
446 " this->$name$(i));\n" | 480 " this->$name$(i));\n" |
447 "}\n"); | 481 "}\n"); |
448 } | 482 } |
449 | 483 |
| 484 void RepeatedStringFieldGenerator:: |
| 485 GenerateVisitInterface(io::Printer* printer) const { |
| 486 printer->Print(variables_, |
| 487 "virtual void Visit$camelcase$(const ::std::string& value);\n"); |
| 488 } |
| 489 |
| 490 void RepeatedStringFieldGenerator:: |
| 491 GenerateVisitMethods(io::Printer* printer) const { |
| 492 printer->Print(variables_, |
| 493 "void $classname$_Visitor::Visit$camelcase$(const ::std::string& value){}\n" |
| 494 "void $classname$_Writer::Visit$camelcase$(const ::std::string& value) {\n" |
| 495 " ::google::protobuf::internal::WireFormatLite::Write$declared_type$(\n" |
| 496 " $number$, value, output_);\n" |
| 497 "}\n" |
| 498 "void $classname$_Filler::Visit$camelcase$(const ::std::string& value) {\n" |
| 499 " message_->add_$name$(value);\n" |
| 500 "}\n"); |
| 501 } |
| 502 |
| 503 void RepeatedStringFieldGenerator:: |
| 504 GenerateReaderCode(io::Printer* printer) const { |
| 505 printer->Print(variables_, |
| 506 "::std::string value;\n" |
| 507 "DO_(::google::protobuf::internal::WireFormatLite::Read$declared_type$(\n" |
| 508 " input, &value));\n" |
| 509 "visitor->Visit$camelcase$(value);\n"); |
| 510 } |
| 511 |
| 512 void RepeatedStringFieldGenerator:: |
| 513 GenerateWalkerCode(io::Printer* printer) const { |
| 514 printer->Print(variables_, |
| 515 "for (int i = 0; i < message_.$name$_size(); i++) {\n" |
| 516 " visitor->Visit$camelcase$(message_.$name$(i));\n" |
| 517 "}\n"); |
| 518 } |
| 519 |
450 } // namespace cpp | 520 } // namespace cpp |
451 } // namespace compiler | 521 } // namespace compiler |
452 } // namespace protobuf | 522 } // namespace protobuf |
453 } // namespace google | 523 } // namespace google |
OLD | NEW |