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 27 matching lines...) Expand all Loading... |
38 #include <google/protobuf/descriptor.pb.h> | 38 #include <google/protobuf/descriptor.pb.h> |
39 #include <google/protobuf/repeated_field.h> | 39 #include <google/protobuf/repeated_field.h> |
40 #include <google/protobuf/extension_set.h> | 40 #include <google/protobuf/extension_set.h> |
41 #include <google/protobuf/generated_message_util.h> | 41 #include <google/protobuf/generated_message_util.h> |
42 #include <google/protobuf/stubs/common.h> | 42 #include <google/protobuf/stubs/common.h> |
43 | 43 |
44 namespace google { | 44 namespace google { |
45 namespace protobuf { | 45 namespace protobuf { |
46 namespace internal { | 46 namespace internal { |
47 | 47 |
48 namespace { const string kEmptyString; } | |
49 | |
50 bool ParseNamedEnum(const EnumDescriptor* descriptor, | 48 bool ParseNamedEnum(const EnumDescriptor* descriptor, |
51 const string& name, | 49 const string& name, |
52 int* value) { | 50 int* value) { |
53 const EnumValueDescriptor* d = descriptor->FindValueByName(name); | 51 const EnumValueDescriptor* d = descriptor->FindValueByName(name); |
54 if (d == NULL) return false; | 52 if (d == NULL) return false; |
55 *value = d->number(); | 53 *value = d->number(); |
56 return true; | 54 return true; |
57 } | 55 } |
58 | 56 |
59 const string& NameOfEnum(const EnumDescriptor* descriptor, int value) { | 57 const string& NameOfEnum(const EnumDescriptor* descriptor, int value) { |
60 static string kEmptyString; | |
61 const EnumValueDescriptor* d = descriptor->FindValueByNumber(value); | 58 const EnumValueDescriptor* d = descriptor->FindValueByNumber(value); |
62 return (d == NULL ? kEmptyString : d->name()); | 59 return (d == NULL ? kEmptyString : d->name()); |
63 } | 60 } |
64 | 61 |
65 // =================================================================== | 62 // =================================================================== |
66 // Helpers for reporting usage errors (e.g. trying to use GetInt32() on | 63 // Helpers for reporting usage errors (e.g. trying to use GetInt32() on |
67 // a string field). | 64 // a string field). |
68 | 65 |
69 namespace { | 66 namespace { |
70 | 67 |
(...skipping 1139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1210 inline Type* GeneratedMessageReflection::AddField( | 1207 inline Type* GeneratedMessageReflection::AddField( |
1211 Message* message, const FieldDescriptor* field) const { | 1208 Message* message, const FieldDescriptor* field) const { |
1212 RepeatedPtrField<Type>* repeated = | 1209 RepeatedPtrField<Type>* repeated = |
1213 MutableRaw<RepeatedPtrField<Type> >(message, field); | 1210 MutableRaw<RepeatedPtrField<Type> >(message, field); |
1214 return repeated->Add(); | 1211 return repeated->Add(); |
1215 } | 1212 } |
1216 | 1213 |
1217 } // namespace internal | 1214 } // namespace internal |
1218 } // namespace protobuf | 1215 } // namespace protobuf |
1219 } // namespace google | 1216 } // namespace google |
OLD | NEW |