| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 #include <google/protobuf/stubs/strutil.h> | 52 #include <google/protobuf/stubs/strutil.h> |
| 53 | 53 |
| 54 namespace google { | 54 namespace google { |
| 55 namespace protobuf { | 55 namespace protobuf { |
| 56 namespace compiler { | 56 namespace compiler { |
| 57 namespace cpp { | 57 namespace cpp { |
| 58 | 58 |
| 59 using internal::WireFormat; | 59 using internal::WireFormat; |
| 60 | 60 |
| 61 void SetCommonFieldVariables(const FieldDescriptor* descriptor, | 61 void SetCommonFieldVariables(const FieldDescriptor* descriptor, |
| 62 std::map<string, string>* variables, | 62 map<string, string>* variables, |
| 63 const Options& options) { | 63 const Options& options) { |
| 64 (*variables)["name"] = FieldName(descriptor); | 64 (*variables)["name"] = FieldName(descriptor); |
| 65 (*variables)["index"] = SimpleItoa(descriptor->index()); | 65 (*variables)["index"] = SimpleItoa(descriptor->index()); |
| 66 (*variables)["number"] = SimpleItoa(descriptor->number()); | 66 (*variables)["number"] = SimpleItoa(descriptor->number()); |
| 67 (*variables)["classname"] = ClassName(FieldScope(descriptor), false); | 67 (*variables)["classname"] = ClassName(FieldScope(descriptor), false); |
| 68 (*variables)["declared_type"] = DeclaredTypeMethodName(descriptor->type()); | 68 (*variables)["declared_type"] = DeclaredTypeMethodName(descriptor->type()); |
| 69 | 69 |
| 70 // non_null_ptr_to_name is usable only if has_$name$ is true. It yields a | 70 // non_null_ptr_to_name is usable only if has_$name$ is true. It yields a |
| 71 // pointer that will not be NULL. Subclasses of FieldGenerator may set | 71 // pointer that will not be NULL. Subclasses of FieldGenerator may set |
| 72 // (*variables)["non_null_ptr_to_name"] differently. | 72 // (*variables)["non_null_ptr_to_name"] differently. |
| 73 (*variables)["non_null_ptr_to_name"] = | 73 (*variables)["non_null_ptr_to_name"] = |
| 74 StrCat("&this->", FieldName(descriptor), "()"); | 74 StrCat("&this->", FieldName(descriptor), "()"); |
| 75 | 75 |
| 76 (*variables)["tag_size"] = SimpleItoa( | 76 (*variables)["tag_size"] = SimpleItoa( |
| 77 WireFormat::TagSize(descriptor->number(), descriptor->type())); | 77 WireFormat::TagSize(descriptor->number(), descriptor->type())); |
| 78 (*variables)["deprecation"] = descriptor->options().deprecated() | 78 (*variables)["deprecation"] = descriptor->options().deprecated() |
| 79 ? " PROTOBUF_DEPRECATED" : ""; | 79 ? " PROTOBUF_DEPRECATED" : ""; |
| 80 (*variables)["deprecated_attr"] = descriptor->options().deprecated() | 80 (*variables)["deprecated_attr"] = descriptor->options().deprecated() |
| 81 ? "GOOGLE_PROTOBUF_DEPRECATED_ATTR " : ""; | 81 ? "PROTOBUF_DEPRECATED_ATTR " : ""; |
| 82 | 82 |
| 83 (*variables)["cppget"] = "Get"; | 83 (*variables)["cppget"] = "Get"; |
| 84 | 84 |
| 85 if (HasFieldPresence(descriptor->file())) { | 85 if (HasFieldPresence(descriptor->file())) { |
| 86 (*variables)["set_hasbit"] = | 86 (*variables)["set_hasbit"] = |
| 87 "set_has_" + FieldName(descriptor) + "();"; | 87 "set_has_" + FieldName(descriptor) + "();"; |
| 88 (*variables)["clear_hasbit"] = | 88 (*variables)["clear_hasbit"] = |
| 89 "clear_has_" + FieldName(descriptor) + "();"; | 89 "clear_has_" + FieldName(descriptor) + "();"; |
| 90 } else { | 90 } else { |
| 91 (*variables)["set_hasbit"] = ""; | 91 (*variables)["set_hasbit"] = ""; |
| 92 (*variables)["clear_hasbit"] = ""; | 92 (*variables)["clear_hasbit"] = ""; |
| 93 } | 93 } |
| 94 | 94 |
| 95 // By default, empty string, so that generic code used for both oneofs and | 95 // By default, empty string, so that generic code used for both oneofs and |
| 96 // singular fields can be written. | 96 // singular fields can be written. |
| 97 (*variables)["oneof_prefix"] = ""; | 97 (*variables)["oneof_prefix"] = ""; |
| 98 } | 98 } |
| 99 | 99 |
| 100 void SetCommonOneofFieldVariables(const FieldDescriptor* descriptor, | 100 void SetCommonOneofFieldVariables(const FieldDescriptor* descriptor, |
| 101 std::map<string, string>* variables) { | 101 map<string, string>* variables) { |
| 102 const string prefix = descriptor->containing_oneof()->name() + "_."; | 102 const string prefix = descriptor->containing_oneof()->name() + "_."; |
| 103 (*variables)["oneof_prefix"] = prefix; | 103 (*variables)["oneof_prefix"] = prefix; |
| 104 (*variables)["oneof_name"] = descriptor->containing_oneof()->name(); | 104 (*variables)["oneof_name"] = descriptor->containing_oneof()->name(); |
| 105 (*variables)["non_null_ptr_to_name"] = | 105 (*variables)["non_null_ptr_to_name"] = |
| 106 StrCat(prefix, (*variables)["name"], "_"); | 106 StrCat(prefix, (*variables)["name"], "_"); |
| 107 } | 107 } |
| 108 | 108 |
| 109 FieldGenerator::~FieldGenerator() {} | 109 FieldGenerator::~FieldGenerator() {} |
| 110 | 110 |
| 111 void FieldGenerator:: | 111 void FieldGenerator:: |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 const FieldDescriptor* field) const { | 192 const FieldDescriptor* field) const { |
| 193 GOOGLE_CHECK_EQ(field->containing_type(), descriptor_); | 193 GOOGLE_CHECK_EQ(field->containing_type(), descriptor_); |
| 194 return *field_generators_[field->index()]; | 194 return *field_generators_[field->index()]; |
| 195 } | 195 } |
| 196 | 196 |
| 197 | 197 |
| 198 } // namespace cpp | 198 } // namespace cpp |
| 199 } // namespace compiler | 199 } // namespace compiler |
| 200 } // namespace protobuf | 200 } // namespace protobuf |
| 201 } // namespace google | 201 } // namespace google |
| OLD | NEW |