/src/libprotobuf-mutator/src/field_instance.h
Line | Count | Source |
1 | | // Copyright 2016 Google Inc. All rights reserved. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | |
15 | | #ifndef SRC_FIELD_INSTANCE_H_ |
16 | | #define SRC_FIELD_INSTANCE_H_ |
17 | | |
18 | | #include <memory> |
19 | | #include <string> |
20 | | |
21 | | #include "port/protobuf.h" |
22 | | |
23 | | namespace protobuf_mutator { |
24 | | |
25 | | // Helper class for common protobuf fields operations. |
26 | | class ConstFieldInstance { |
27 | | public: |
28 | | static const size_t kInvalidIndex = -1; |
29 | | |
30 | | struct Enum { |
31 | | size_t index; |
32 | | size_t count; |
33 | | }; |
34 | | |
35 | | ConstFieldInstance() |
36 | 0 | : message_(nullptr), descriptor_(nullptr), index_(kInvalidIndex) {} |
37 | | |
38 | | ConstFieldInstance(const protobuf::Message* message, |
39 | | const protobuf::FieldDescriptor* field, size_t index) |
40 | 0 | : message_(message), descriptor_(field), index_(index) { |
41 | 0 | assert(message_); |
42 | 0 | assert(descriptor_); |
43 | 0 | assert(index_ != kInvalidIndex); |
44 | 0 | assert(descriptor_->is_repeated()); |
45 | 0 | } |
46 | | |
47 | | ConstFieldInstance(const protobuf::Message* message, |
48 | | const protobuf::FieldDescriptor* field) |
49 | 3.39k | : message_(message), descriptor_(field), index_(kInvalidIndex) { |
50 | 3.39k | assert(message_); |
51 | 3.39k | assert(descriptor_); |
52 | 3.39k | assert(!descriptor_->is_repeated()); |
53 | 3.39k | } |
54 | | |
55 | 19 | void GetDefault(int32_t* out) const { |
56 | 19 | *out = descriptor_->default_value_int32(); |
57 | 19 | } |
58 | | |
59 | 429 | void GetDefault(int64_t* out) const { |
60 | 429 | *out = descriptor_->default_value_int64(); |
61 | 429 | } |
62 | | |
63 | 0 | void GetDefault(uint32_t* out) const { |
64 | 0 | *out = descriptor_->default_value_uint32(); |
65 | 0 | } |
66 | | |
67 | 0 | void GetDefault(uint64_t* out) const { |
68 | 0 | *out = descriptor_->default_value_uint64(); |
69 | 0 | } |
70 | | |
71 | 15 | void GetDefault(double* out) const { |
72 | 15 | *out = descriptor_->default_value_double(); |
73 | 15 | } |
74 | | |
75 | 9 | void GetDefault(float* out) const { |
76 | 9 | *out = descriptor_->default_value_float(); |
77 | 9 | } |
78 | | |
79 | 337 | void GetDefault(bool* out) const { *out = descriptor_->default_value_bool(); } |
80 | | |
81 | 1.10k | void GetDefault(Enum* out) const { |
82 | 1.10k | const protobuf::EnumValueDescriptor* value = |
83 | 1.10k | descriptor_->default_value_enum(); |
84 | 1.10k | const protobuf::EnumDescriptor* type = value->type(); |
85 | 1.10k | *out = {static_cast<size_t>(value->index()), |
86 | 1.10k | static_cast<size_t>(type->value_count())}; |
87 | 1.10k | } |
88 | | |
89 | 134 | void GetDefault(std::string* out) const { |
90 | 134 | *out = descriptor_->default_value_string(); |
91 | 134 | } |
92 | | |
93 | 1.35k | void GetDefault(std::unique_ptr<protobuf::Message>* out) const { |
94 | 1.35k | out->reset(reflection() |
95 | 1.35k | .GetMessageFactory() |
96 | 1.35k | ->GetPrototype(descriptor_->message_type()) |
97 | 1.35k | ->New()); |
98 | 1.35k | } |
99 | | |
100 | 0 | void Load(int32_t* value) const { |
101 | 0 | *value = is_repeated() |
102 | 0 | ? reflection().GetRepeatedInt32(*message_, descriptor_, index_) |
103 | 0 | : reflection().GetInt32(*message_, descriptor_); |
104 | 0 | } |
105 | | |
106 | 0 | void Load(int64_t* value) const { |
107 | 0 | *value = is_repeated() |
108 | 0 | ? reflection().GetRepeatedInt64(*message_, descriptor_, index_) |
109 | 0 | : reflection().GetInt64(*message_, descriptor_); |
110 | 0 | } |
111 | | |
112 | 0 | void Load(uint32_t* value) const { |
113 | 0 | *value = is_repeated() ? reflection().GetRepeatedUInt32(*message_, |
114 | 0 | descriptor_, index_) |
115 | 0 | : reflection().GetUInt32(*message_, descriptor_); |
116 | 0 | } |
117 | | |
118 | 0 | void Load(uint64_t* value) const { |
119 | 0 | *value = is_repeated() ? reflection().GetRepeatedUInt64(*message_, |
120 | 0 | descriptor_, index_) |
121 | 0 | : reflection().GetUInt64(*message_, descriptor_); |
122 | 0 | } |
123 | | |
124 | 0 | void Load(double* value) const { |
125 | 0 | *value = is_repeated() ? reflection().GetRepeatedDouble(*message_, |
126 | 0 | descriptor_, index_) |
127 | 0 | : reflection().GetDouble(*message_, descriptor_); |
128 | 0 | } |
129 | | |
130 | 0 | void Load(float* value) const { |
131 | 0 | *value = is_repeated() |
132 | 0 | ? reflection().GetRepeatedFloat(*message_, descriptor_, index_) |
133 | 0 | : reflection().GetFloat(*message_, descriptor_); |
134 | 0 | } |
135 | | |
136 | 0 | void Load(bool* value) const { |
137 | 0 | *value = is_repeated() |
138 | 0 | ? reflection().GetRepeatedBool(*message_, descriptor_, index_) |
139 | 0 | : reflection().GetBool(*message_, descriptor_); |
140 | 0 | } |
141 | | |
142 | 0 | void Load(Enum* value) const { |
143 | 0 | const protobuf::EnumValueDescriptor* value_descriptor = |
144 | 0 | is_repeated() |
145 | 0 | ? reflection().GetRepeatedEnum(*message_, descriptor_, index_) |
146 | 0 | : reflection().GetEnum(*message_, descriptor_); |
147 | 0 | *value = {static_cast<size_t>(value_descriptor->index()), |
148 | 0 | static_cast<size_t>(value_descriptor->type()->value_count())}; |
149 | 0 | if (value->index >= value->count) GetDefault(value); |
150 | 0 | } |
151 | | |
152 | 0 | void Load(std::string* value) const { |
153 | 0 | *value = is_repeated() ? reflection().GetRepeatedString(*message_, |
154 | 0 | descriptor_, index_) |
155 | 0 | : reflection().GetString(*message_, descriptor_); |
156 | 0 | } |
157 | | |
158 | 0 | void Load(std::unique_ptr<protobuf::Message>* value) const { |
159 | 0 | const protobuf::Message& source = |
160 | 0 | is_repeated() |
161 | 0 | ? reflection().GetRepeatedMessage(*message_, descriptor_, index_) |
162 | 0 | : reflection().GetMessage(*message_, descriptor_); |
163 | 0 | value->reset(source.New()); |
164 | 0 | (*value)->CopyFrom(source); |
165 | 0 | } |
166 | | |
167 | | template <class T> |
168 | 0 | bool CanStore(const T& value) const { |
169 | 0 | return true; |
170 | 0 | } Unexecuted instantiation: bool protobuf_mutator::ConstFieldInstance::CanStore<int>(int const&) const Unexecuted instantiation: bool protobuf_mutator::ConstFieldInstance::CanStore<long>(long const&) const Unexecuted instantiation: bool protobuf_mutator::ConstFieldInstance::CanStore<unsigned int>(unsigned int const&) const Unexecuted instantiation: bool protobuf_mutator::ConstFieldInstance::CanStore<unsigned long>(unsigned long const&) const Unexecuted instantiation: bool protobuf_mutator::ConstFieldInstance::CanStore<double>(double const&) const Unexecuted instantiation: bool protobuf_mutator::ConstFieldInstance::CanStore<float>(float const&) const Unexecuted instantiation: bool protobuf_mutator::ConstFieldInstance::CanStore<bool>(bool const&) const Unexecuted instantiation: bool protobuf_mutator::ConstFieldInstance::CanStore<protobuf_mutator::ConstFieldInstance::Enum>(protobuf_mutator::ConstFieldInstance::Enum const&) const Unexecuted instantiation: bool protobuf_mutator::ConstFieldInstance::CanStore<std::__1::unique_ptr<google::protobuf::Message, std::__1::default_delete<google::protobuf::Message> > >(std::__1::unique_ptr<google::protobuf::Message, std::__1::default_delete<google::protobuf::Message> > const&) const |
171 | | |
172 | 0 | bool CanStore(const std::string& value) const { |
173 | 0 | if (!EnforceUtf8()) return true; |
174 | 0 | using protobuf::internal::WireFormatLite; |
175 | 0 | return WireFormatLite::VerifyUtf8String(value.data(), value.length(), |
176 | 0 | WireFormatLite::PARSE, ""); |
177 | 0 | } |
178 | | |
179 | 0 | std::string name() const { return descriptor_->name(); } |
180 | | |
181 | 3.39k | protobuf::FieldDescriptor::CppType cpp_type() const { |
182 | 3.39k | return descriptor_->cpp_type(); |
183 | 3.39k | } |
184 | | |
185 | 0 | const protobuf::EnumDescriptor* enum_type() const { |
186 | 0 | return descriptor_->enum_type(); |
187 | 0 | } |
188 | | |
189 | 0 | const protobuf::Descriptor* message_type() const { |
190 | 0 | return descriptor_->message_type(); |
191 | 0 | } |
192 | | |
193 | 0 | bool EnforceUtf8() const { |
194 | 0 | return descriptor_->type() == protobuf::FieldDescriptor::TYPE_STRING && |
195 | 0 | descriptor()->file()->syntax() == |
196 | 0 | protobuf::FileDescriptor::SYNTAX_PROTO3; |
197 | 0 | } |
198 | | |
199 | 7.90k | const protobuf::FieldDescriptor* descriptor() const { return descriptor_; } |
200 | | |
201 | 0 | std::string DebugString() const { |
202 | 0 | std::string s = descriptor_->DebugString(); |
203 | 0 | if (is_repeated()) s += "[" + std::to_string(index_) + "]"; |
204 | 0 | return s + " of\n" + message_->DebugString(); |
205 | 0 | } |
206 | | |
207 | | protected: |
208 | 6.79k | bool is_repeated() const { return descriptor_->is_repeated(); } |
209 | | |
210 | 4.74k | const protobuf::Reflection& reflection() const { |
211 | 4.74k | return *message_->GetReflection(); |
212 | 4.74k | } |
213 | | |
214 | 0 | size_t index() const { return index_; } |
215 | | |
216 | | private: |
217 | | template <class Fn, class T> |
218 | | friend struct FieldFunction; |
219 | | |
220 | | const protobuf::Message* message_; |
221 | | const protobuf::FieldDescriptor* descriptor_; |
222 | | size_t index_; |
223 | | }; |
224 | | |
225 | | class FieldInstance : public ConstFieldInstance { |
226 | | public: |
227 | | static const size_t kInvalidIndex = -1; |
228 | | |
229 | 0 | FieldInstance() : ConstFieldInstance(), message_(nullptr) {} |
230 | | |
231 | | FieldInstance(protobuf::Message* message, |
232 | | const protobuf::FieldDescriptor* field, size_t index) |
233 | 0 | : ConstFieldInstance(message, field, index), message_(message) {} |
234 | | |
235 | | FieldInstance(protobuf::Message* message, |
236 | | const protobuf::FieldDescriptor* field) |
237 | 3.39k | : ConstFieldInstance(message, field), message_(message) {} |
238 | | |
239 | 0 | void Delete() const { |
240 | 0 | if (!is_repeated()) return reflection().ClearField(message_, descriptor()); |
241 | 0 | int field_size = reflection().FieldSize(*message_, descriptor()); |
242 | | // API has only method to delete the last message, so we move method from |
243 | | // the |
244 | | // middle to the end. |
245 | 0 | for (int i = index() + 1; i < field_size; ++i) |
246 | 0 | reflection().SwapElements(message_, descriptor(), i, i - 1); |
247 | 0 | reflection().RemoveLast(message_, descriptor()); |
248 | 0 | } |
249 | | |
250 | | template <class T> |
251 | 3.39k | void Create(const T& value) const { |
252 | 3.39k | if (!is_repeated()) return Store(value); |
253 | 0 | InsertRepeated(value); |
254 | 0 | } void protobuf_mutator::FieldInstance::Create<int>(int const&) const Line | Count | Source | 251 | 19 | void Create(const T& value) const { | 252 | 19 | if (!is_repeated()) return Store(value); | 253 | 0 | InsertRepeated(value); | 254 | 0 | } |
void protobuf_mutator::FieldInstance::Create<long>(long const&) const Line | Count | Source | 251 | 429 | void Create(const T& value) const { | 252 | 429 | if (!is_repeated()) return Store(value); | 253 | 0 | InsertRepeated(value); | 254 | 0 | } |
Unexecuted instantiation: void protobuf_mutator::FieldInstance::Create<unsigned int>(unsigned int const&) const Unexecuted instantiation: void protobuf_mutator::FieldInstance::Create<unsigned long>(unsigned long const&) const void protobuf_mutator::FieldInstance::Create<double>(double const&) const Line | Count | Source | 251 | 15 | void Create(const T& value) const { | 252 | 15 | if (!is_repeated()) return Store(value); | 253 | 0 | InsertRepeated(value); | 254 | 0 | } |
void protobuf_mutator::FieldInstance::Create<float>(float const&) const Line | Count | Source | 251 | 9 | void Create(const T& value) const { | 252 | 9 | if (!is_repeated()) return Store(value); | 253 | 0 | InsertRepeated(value); | 254 | 0 | } |
void protobuf_mutator::FieldInstance::Create<bool>(bool const&) const Line | Count | Source | 251 | 337 | void Create(const T& value) const { | 252 | 337 | if (!is_repeated()) return Store(value); | 253 | 0 | InsertRepeated(value); | 254 | 0 | } |
void protobuf_mutator::FieldInstance::Create<protobuf_mutator::ConstFieldInstance::Enum>(protobuf_mutator::ConstFieldInstance::Enum const&) const Line | Count | Source | 251 | 1.10k | void Create(const T& value) const { | 252 | 1.10k | if (!is_repeated()) return Store(value); | 253 | 0 | InsertRepeated(value); | 254 | 0 | } |
void protobuf_mutator::FieldInstance::Create<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const Line | Count | Source | 251 | 134 | void Create(const T& value) const { | 252 | 134 | if (!is_repeated()) return Store(value); | 253 | 0 | InsertRepeated(value); | 254 | 0 | } |
void protobuf_mutator::FieldInstance::Create<std::__1::unique_ptr<google::protobuf::Message, std::__1::default_delete<google::protobuf::Message> > >(std::__1::unique_ptr<google::protobuf::Message, std::__1::default_delete<google::protobuf::Message> > const&) const Line | Count | Source | 251 | 1.35k | void Create(const T& value) const { | 252 | 1.35k | if (!is_repeated()) return Store(value); | 253 | 0 | InsertRepeated(value); | 254 | 0 | } |
|
255 | | |
256 | 19 | void Store(int32_t value) const { |
257 | 19 | if (is_repeated()) |
258 | 0 | reflection().SetRepeatedInt32(message_, descriptor(), index(), value); |
259 | 19 | else |
260 | 19 | reflection().SetInt32(message_, descriptor(), value); |
261 | 19 | } |
262 | | |
263 | 429 | void Store(int64_t value) const { |
264 | 429 | if (is_repeated()) |
265 | 0 | reflection().SetRepeatedInt64(message_, descriptor(), index(), value); |
266 | 429 | else |
267 | 429 | reflection().SetInt64(message_, descriptor(), value); |
268 | 429 | } |
269 | | |
270 | 0 | void Store(uint32_t value) const { |
271 | 0 | if (is_repeated()) |
272 | 0 | reflection().SetRepeatedUInt32(message_, descriptor(), index(), value); |
273 | 0 | else |
274 | 0 | reflection().SetUInt32(message_, descriptor(), value); |
275 | 0 | } |
276 | | |
277 | 0 | void Store(uint64_t value) const { |
278 | 0 | if (is_repeated()) |
279 | 0 | reflection().SetRepeatedUInt64(message_, descriptor(), index(), value); |
280 | 0 | else |
281 | 0 | reflection().SetUInt64(message_, descriptor(), value); |
282 | 0 | } |
283 | | |
284 | 15 | void Store(double value) const { |
285 | 15 | if (is_repeated()) |
286 | 0 | reflection().SetRepeatedDouble(message_, descriptor(), index(), value); |
287 | 15 | else |
288 | 15 | reflection().SetDouble(message_, descriptor(), value); |
289 | 15 | } |
290 | | |
291 | 9 | void Store(float value) const { |
292 | 9 | if (is_repeated()) |
293 | 0 | reflection().SetRepeatedFloat(message_, descriptor(), index(), value); |
294 | 9 | else |
295 | 9 | reflection().SetFloat(message_, descriptor(), value); |
296 | 9 | } |
297 | | |
298 | 337 | void Store(bool value) const { |
299 | 337 | if (is_repeated()) |
300 | 0 | reflection().SetRepeatedBool(message_, descriptor(), index(), value); |
301 | 337 | else |
302 | 337 | reflection().SetBool(message_, descriptor(), value); |
303 | 337 | } |
304 | | |
305 | 1.10k | void Store(const Enum& value) const { |
306 | 1.10k | assert(value.index < value.count); |
307 | 1.10k | const protobuf::EnumValueDescriptor* enum_value = |
308 | 1.10k | descriptor()->enum_type()->value(value.index); |
309 | 1.10k | if (is_repeated()) |
310 | 0 | reflection().SetRepeatedEnum(message_, descriptor(), index(), enum_value); |
311 | 1.10k | else |
312 | 1.10k | reflection().SetEnum(message_, descriptor(), enum_value); |
313 | 1.10k | } |
314 | | |
315 | 134 | void Store(const std::string& value) const { |
316 | 134 | if (is_repeated()) |
317 | 0 | reflection().SetRepeatedString(message_, descriptor(), index(), value); |
318 | 134 | else |
319 | 134 | reflection().SetString(message_, descriptor(), value); |
320 | 134 | } |
321 | | |
322 | 1.35k | void Store(const std::unique_ptr<protobuf::Message>& value) const { |
323 | 1.35k | protobuf::Message* mutable_message = |
324 | 1.35k | is_repeated() ? reflection().MutableRepeatedMessage( |
325 | 0 | message_, descriptor(), index()) |
326 | 1.35k | : reflection().MutableMessage(message_, descriptor()); |
327 | 1.35k | mutable_message->Clear(); |
328 | 1.35k | if (value) mutable_message->CopyFrom(*value); |
329 | 1.35k | } |
330 | | |
331 | | private: |
332 | | template <class T> |
333 | 0 | void InsertRepeated(const T& value) const { |
334 | 0 | PushBackRepeated(value); |
335 | 0 | size_t field_size = reflection().FieldSize(*message_, descriptor()); |
336 | 0 | if (field_size == 1) return; |
337 | | // API has only method to add field to the end of the list. So we add |
338 | | // descriptor() |
339 | | // and move it into the middle. |
340 | 0 | for (size_t i = field_size - 1; i > index(); --i) |
341 | 0 | reflection().SwapElements(message_, descriptor(), i, i - 1); |
342 | 0 | } Unexecuted instantiation: void protobuf_mutator::FieldInstance::InsertRepeated<int>(int const&) const Unexecuted instantiation: void protobuf_mutator::FieldInstance::InsertRepeated<long>(long const&) const Unexecuted instantiation: void protobuf_mutator::FieldInstance::InsertRepeated<unsigned int>(unsigned int const&) const Unexecuted instantiation: void protobuf_mutator::FieldInstance::InsertRepeated<unsigned long>(unsigned long const&) const Unexecuted instantiation: void protobuf_mutator::FieldInstance::InsertRepeated<double>(double const&) const Unexecuted instantiation: void protobuf_mutator::FieldInstance::InsertRepeated<float>(float const&) const Unexecuted instantiation: void protobuf_mutator::FieldInstance::InsertRepeated<bool>(bool const&) const Unexecuted instantiation: void protobuf_mutator::FieldInstance::InsertRepeated<protobuf_mutator::ConstFieldInstance::Enum>(protobuf_mutator::ConstFieldInstance::Enum const&) const Unexecuted instantiation: void protobuf_mutator::FieldInstance::InsertRepeated<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) const Unexecuted instantiation: void protobuf_mutator::FieldInstance::InsertRepeated<std::__1::unique_ptr<google::protobuf::Message, std::__1::default_delete<google::protobuf::Message> > >(std::__1::unique_ptr<google::protobuf::Message, std::__1::default_delete<google::protobuf::Message> > const&) const |
343 | | |
344 | 0 | void PushBackRepeated(int32_t value) const { |
345 | 0 | assert(is_repeated()); |
346 | 0 | reflection().AddInt32(message_, descriptor(), value); |
347 | 0 | } |
348 | | |
349 | 0 | void PushBackRepeated(int64_t value) const { |
350 | 0 | assert(is_repeated()); |
351 | 0 | reflection().AddInt64(message_, descriptor(), value); |
352 | 0 | } |
353 | | |
354 | 0 | void PushBackRepeated(uint32_t value) const { |
355 | 0 | assert(is_repeated()); |
356 | 0 | reflection().AddUInt32(message_, descriptor(), value); |
357 | 0 | } |
358 | | |
359 | 0 | void PushBackRepeated(uint64_t value) const { |
360 | 0 | assert(is_repeated()); |
361 | 0 | reflection().AddUInt64(message_, descriptor(), value); |
362 | 0 | } |
363 | | |
364 | 0 | void PushBackRepeated(double value) const { |
365 | 0 | assert(is_repeated()); |
366 | 0 | reflection().AddDouble(message_, descriptor(), value); |
367 | 0 | } |
368 | | |
369 | 0 | void PushBackRepeated(float value) const { |
370 | 0 | assert(is_repeated()); |
371 | 0 | reflection().AddFloat(message_, descriptor(), value); |
372 | 0 | } |
373 | | |
374 | 0 | void PushBackRepeated(bool value) const { |
375 | 0 | assert(is_repeated()); |
376 | 0 | reflection().AddBool(message_, descriptor(), value); |
377 | 0 | } |
378 | | |
379 | 0 | void PushBackRepeated(const Enum& value) const { |
380 | 0 | assert(value.index < value.count); |
381 | 0 | const protobuf::EnumValueDescriptor* enum_value = |
382 | 0 | descriptor()->enum_type()->value(value.index); |
383 | 0 | assert(is_repeated()); |
384 | 0 | reflection().AddEnum(message_, descriptor(), enum_value); |
385 | 0 | } |
386 | | |
387 | 0 | void PushBackRepeated(const std::string& value) const { |
388 | 0 | assert(is_repeated()); |
389 | 0 | reflection().AddString(message_, descriptor(), value); |
390 | 0 | } |
391 | | |
392 | 0 | void PushBackRepeated(const std::unique_ptr<protobuf::Message>& value) const { |
393 | 0 | assert(is_repeated()); |
394 | 0 | protobuf::Message* mutable_message = |
395 | 0 | reflection().AddMessage(message_, descriptor()); |
396 | 0 | mutable_message->Clear(); |
397 | 0 | if (value) mutable_message->CopyFrom(*value); |
398 | 0 | } |
399 | | |
400 | | protobuf::Message* message_; |
401 | | }; |
402 | | |
403 | | template <class Fn, class R = void> |
404 | | struct FieldFunction { |
405 | | template <class Field, class... Args> |
406 | 3.39k | R operator()(const Field& field, const Args&... args) const { |
407 | 3.39k | assert(field.descriptor()); |
408 | 3.39k | using protobuf::FieldDescriptor; |
409 | 3.39k | switch (field.cpp_type()) { |
410 | 19 | case FieldDescriptor::CPPTYPE_INT32: |
411 | 19 | return static_cast<const Fn*>(this)->template ForType<int32_t>(field, |
412 | 19 | args...); |
413 | 429 | case FieldDescriptor::CPPTYPE_INT64: |
414 | 429 | return static_cast<const Fn*>(this)->template ForType<int64_t>(field, |
415 | 429 | args...); |
416 | 0 | case FieldDescriptor::CPPTYPE_UINT32: |
417 | 0 | return static_cast<const Fn*>(this)->template ForType<uint32_t>( |
418 | 0 | field, args...); |
419 | 0 | case FieldDescriptor::CPPTYPE_UINT64: |
420 | 0 | return static_cast<const Fn*>(this)->template ForType<uint64_t>( |
421 | 0 | field, args...); |
422 | 15 | case FieldDescriptor::CPPTYPE_DOUBLE: |
423 | 15 | return static_cast<const Fn*>(this)->template ForType<double>(field, |
424 | 15 | args...); |
425 | 9 | case FieldDescriptor::CPPTYPE_FLOAT: |
426 | 9 | return static_cast<const Fn*>(this)->template ForType<float>(field, |
427 | 9 | args...); |
428 | 337 | case FieldDescriptor::CPPTYPE_BOOL: |
429 | 337 | return static_cast<const Fn*>(this)->template ForType<bool>(field, |
430 | 337 | args...); |
431 | 1.10k | case FieldDescriptor::CPPTYPE_ENUM: |
432 | 1.10k | return static_cast<const Fn*>(this) |
433 | 1.10k | ->template ForType<ConstFieldInstance::Enum>(field, args...); |
434 | 134 | case FieldDescriptor::CPPTYPE_STRING: |
435 | 134 | return static_cast<const Fn*>(this)->template ForType<std::string>( |
436 | 134 | field, args...); |
437 | 1.35k | case FieldDescriptor::CPPTYPE_MESSAGE: |
438 | 1.35k | return static_cast<const Fn*>(this) |
439 | 1.35k | ->template ForType<std::unique_ptr<protobuf::Message>>(field, |
440 | 1.35k | args...); |
441 | 3.39k | } |
442 | 3.39k | assert(false && "Unknown type"); |
443 | 0 | abort(); |
444 | 0 | } Unexecuted instantiation: mutator.cc:bool protobuf_mutator::FieldFunction<protobuf_mutator::(anonymous namespace)::CanCopyAndDifferentField, bool>::operator()<protobuf_mutator::ConstFieldInstance, protobuf_mutator::ConstFieldInstance, int>(protobuf_mutator::ConstFieldInstance const&, protobuf_mutator::ConstFieldInstance const&, int const&) const mutator.cc:void protobuf_mutator::FieldFunction<protobuf_mutator::(anonymous namespace)::CreateDefaultField, void>::operator()<protobuf_mutator::FieldInstance>(protobuf_mutator::FieldInstance const&) const Line | Count | Source | 406 | 3.39k | R operator()(const Field& field, const Args&... args) const { | 407 | 3.39k | assert(field.descriptor()); | 408 | 3.39k | using protobuf::FieldDescriptor; | 409 | 3.39k | switch (field.cpp_type()) { | 410 | 19 | case FieldDescriptor::CPPTYPE_INT32: | 411 | 19 | return static_cast<const Fn*>(this)->template ForType<int32_t>(field, | 412 | 19 | args...); | 413 | 429 | case FieldDescriptor::CPPTYPE_INT64: | 414 | 429 | return static_cast<const Fn*>(this)->template ForType<int64_t>(field, | 415 | 429 | args...); | 416 | 0 | case FieldDescriptor::CPPTYPE_UINT32: | 417 | 0 | return static_cast<const Fn*>(this)->template ForType<uint32_t>( | 418 | 0 | field, args...); | 419 | 0 | case FieldDescriptor::CPPTYPE_UINT64: | 420 | 0 | return static_cast<const Fn*>(this)->template ForType<uint64_t>( | 421 | 0 | field, args...); | 422 | 15 | case FieldDescriptor::CPPTYPE_DOUBLE: | 423 | 15 | return static_cast<const Fn*>(this)->template ForType<double>(field, | 424 | 15 | args...); | 425 | 9 | case FieldDescriptor::CPPTYPE_FLOAT: | 426 | 9 | return static_cast<const Fn*>(this)->template ForType<float>(field, | 427 | 9 | args...); | 428 | 337 | case FieldDescriptor::CPPTYPE_BOOL: | 429 | 337 | return static_cast<const Fn*>(this)->template ForType<bool>(field, | 430 | 337 | args...); | 431 | 1.10k | case FieldDescriptor::CPPTYPE_ENUM: | 432 | 1.10k | return static_cast<const Fn*>(this) | 433 | 1.10k | ->template ForType<ConstFieldInstance::Enum>(field, args...); | 434 | 134 | case FieldDescriptor::CPPTYPE_STRING: | 435 | 134 | return static_cast<const Fn*>(this)->template ForType<std::string>( | 436 | 134 | field, args...); | 437 | 1.35k | case FieldDescriptor::CPPTYPE_MESSAGE: | 438 | 1.35k | return static_cast<const Fn*>(this) | 439 | 1.35k | ->template ForType<std::unique_ptr<protobuf::Message>>(field, | 440 | 1.35k | args...); | 441 | 3.39k | } | 442 | 3.39k | assert(false && "Unknown type"); | 443 | 0 | abort(); | 444 | 0 | } |
Unexecuted instantiation: mutator.cc:void protobuf_mutator::FieldFunction<protobuf_mutator::(anonymous namespace)::CreateField, void>::operator()<protobuf_mutator::FieldInstance, int, std::__1::vector<google::protobuf::Message const*, std::__1::allocator<google::protobuf::Message const*> >, protobuf_mutator::Mutator*>(protobuf_mutator::FieldInstance const&, int const&, std::__1::vector<google::protobuf::Message const*, std::__1::allocator<google::protobuf::Message const*> > const&, protobuf_mutator::Mutator* const&) const Unexecuted instantiation: mutator.cc:void protobuf_mutator::FieldFunction<protobuf_mutator::(anonymous namespace)::MutateField, void>::operator()<protobuf_mutator::FieldInstance, int, std::__1::vector<google::protobuf::Message const*, std::__1::allocator<google::protobuf::Message const*> >, protobuf_mutator::Mutator*>(protobuf_mutator::FieldInstance const&, int const&, std::__1::vector<google::protobuf::Message const*, std::__1::allocator<google::protobuf::Message const*> > const&, protobuf_mutator::Mutator* const&) const Unexecuted instantiation: mutator.cc:void protobuf_mutator::FieldFunction<protobuf_mutator::(anonymous namespace)::DeleteField, void>::operator()<protobuf_mutator::FieldInstance>(protobuf_mutator::FieldInstance const&) const Unexecuted instantiation: mutator.cc:void protobuf_mutator::FieldFunction<protobuf_mutator::(anonymous namespace)::CopyField, void>::operator()<protobuf_mutator::ConstFieldInstance, protobuf_mutator::FieldInstance>(protobuf_mutator::ConstFieldInstance const&, protobuf_mutator::FieldInstance const&) const |
445 | | }; |
446 | | |
447 | | } // namespace protobuf_mutator |
448 | | |
449 | | #endif // SRC_FIELD_INSTANCE_H_ |