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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 | 54 |
55 namespace protobuf { | 55 namespace protobuf { |
56 namespace compiler { | 56 namespace compiler { |
57 namespace cpp { | 57 namespace cpp { |
58 | 58 |
59 // Helper function: set variables in the map that are the same for all | 59 // Helper function: set variables in the map that are the same for all |
60 // field code generators. | 60 // field code generators. |
61 // ['name', 'index', 'number', 'classname', 'declared_type', 'tag_size', | 61 // ['name', 'index', 'number', 'classname', 'declared_type', 'tag_size', |
62 // 'deprecation']. | 62 // 'deprecation']. |
63 void SetCommonFieldVariables(const FieldDescriptor* descriptor, | 63 void SetCommonFieldVariables(const FieldDescriptor* descriptor, |
64 map<string, string>* variables, | 64 std::map<string, string>* variables, |
65 const Options& options); | 65 const Options& options); |
66 | 66 |
67 void SetCommonOneofFieldVariables(const FieldDescriptor* descriptor, | 67 void SetCommonOneofFieldVariables(const FieldDescriptor* descriptor, |
68 map<string, string>* variables); | 68 std::map<string, string>* variables); |
69 | 69 |
70 class FieldGenerator { | 70 class FieldGenerator { |
71 public: | 71 public: |
72 explicit FieldGenerator(const Options& options) : options_(options) {} | 72 explicit FieldGenerator(const Options& options) : options_(options) {} |
73 virtual ~FieldGenerator(); | 73 virtual ~FieldGenerator(); |
74 | 74 |
75 // Generate lines of code declaring members fields of the message class | 75 // Generate lines of code declaring members fields of the message class |
76 // needed to represent this field. These are placed inside the message | 76 // needed to represent this field. These are placed inside the message |
77 // class. | 77 // class. |
78 virtual void GeneratePrivateMembers(io::Printer* printer) const = 0; | 78 virtual void GeneratePrivateMembers(io::Printer* printer) const = 0; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 virtual void GenerateInlineAccessorDefinitions( | 117 virtual void GenerateInlineAccessorDefinitions( |
118 io::Printer* printer, bool is_inline) const = 0; | 118 io::Printer* printer, bool is_inline) const = 0; |
119 | 119 |
120 // Generate definitions of accessors that aren't inlined. These are | 120 // Generate definitions of accessors that aren't inlined. These are |
121 // placed somewhere in the .cc file. | 121 // placed somewhere in the .cc file. |
122 // Most field types don't need this, so the default implementation is empty. | 122 // Most field types don't need this, so the default implementation is empty. |
123 virtual void GenerateNonInlineAccessorDefinitions( | 123 virtual void GenerateNonInlineAccessorDefinitions( |
124 io::Printer* /*printer*/) const {} | 124 io::Printer* /*printer*/) const {} |
125 | 125 |
126 // Generate lines of code (statements, not declarations) which clear the | 126 // Generate lines of code (statements, not declarations) which clear the |
127 // field. This is used to define the clear_$name$() method as well as | 127 // field. This is used to define the clear_$name$() method |
128 // the Clear() method for the whole message. | |
129 virtual void GenerateClearingCode(io::Printer* printer) const = 0; | 128 virtual void GenerateClearingCode(io::Printer* printer) const = 0; |
130 | 129 |
| 130 // Generate lines of code (statements, not declarations) which clear the field |
| 131 // as part of the Clear() method for the whole message. For message types |
| 132 // which have field presence bits, MessageGenerator::GenerateClear will have |
| 133 // already checked the presence bits. |
| 134 // |
| 135 // Since most field types can re-use GenerateClearingCode, this method is not |
| 136 // pure virtual. |
| 137 virtual void GenerateMessageClearingCode(io::Printer* printer) const { |
| 138 GenerateClearingCode(printer); |
| 139 } |
| 140 |
131 // Generate lines of code (statements, not declarations) which merges the | 141 // Generate lines of code (statements, not declarations) which merges the |
132 // contents of the field from the current message to the target message, | 142 // contents of the field from the current message to the target message, |
133 // which is stored in the generated code variable "from". | 143 // which is stored in the generated code variable "from". |
134 // This is used to fill in the MergeFrom method for the whole message. | 144 // This is used to fill in the MergeFrom method for the whole message. |
135 // Details of this usage can be found in message.cc under the | 145 // Details of this usage can be found in message.cc under the |
136 // GenerateMergeFrom method. | 146 // GenerateMergeFrom method. |
137 virtual void GenerateMergingCode(io::Printer* printer) const = 0; | 147 virtual void GenerateMergingCode(io::Printer* printer) const = 0; |
138 | 148 |
| 149 // Generates a copy constructor |
| 150 virtual void GenerateCopyConstructorCode(io::Printer* printer) const = 0; |
| 151 |
139 // Generate lines of code (statements, not declarations) which swaps | 152 // Generate lines of code (statements, not declarations) which swaps |
140 // this field and the corresponding field of another message, which | 153 // this field and the corresponding field of another message, which |
141 // is stored in the generated code variable "other". This is used to | 154 // is stored in the generated code variable "other". This is used to |
142 // define the Swap method. Details of usage can be found in | 155 // define the Swap method. Details of usage can be found in |
143 // message.cc under the GenerateSwap method. | 156 // message.cc under the GenerateSwap method. |
144 virtual void GenerateSwappingCode(io::Printer* printer) const = 0; | 157 virtual void GenerateSwappingCode(io::Printer* printer) const = 0; |
145 | 158 |
146 // Generate initialization code for private members declared by | 159 // Generate initialization code for private members declared by |
147 // GeneratePrivateMembers(). These go into the message class's SharedCtor() | 160 // GeneratePrivateMembers(). These go into the message class's SharedCtor() |
148 // method, invoked by each of the generated constructors. | 161 // method, invoked by each of the generated constructors. |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGeneratorMap); | 233 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGeneratorMap); |
221 }; | 234 }; |
222 | 235 |
223 | 236 |
224 } // namespace cpp | 237 } // namespace cpp |
225 } // namespace compiler | 238 } // namespace compiler |
226 } // namespace protobuf | 239 } // namespace protobuf |
227 | 240 |
228 } // namespace google | 241 } // namespace google |
229 #endif // GOOGLE_PROTOBUF_COMPILER_CPP_FIELD_H__ | 242 #endif // GOOGLE_PROTOBUF_COMPILER_CPP_FIELD_H__ |
OLD | NEW |