Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(582)

Side by Side Diff: third_party/protobuf/src/google/protobuf/descriptor_database.cc

Issue 1842653006: Update //third_party/protobuf to version 3. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update README.chromium Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // 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.
11 // * Redistributions in binary form must reproduce the above 11 // * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer 12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the 13 // in the documentation and/or other materials provided with the
(...skipping 19 matching lines...) Expand all
33 // Sanjay Ghemawat, Jeff Dean, and others. 33 // Sanjay Ghemawat, Jeff Dean, and others.
34 34
35 #include <google/protobuf/descriptor_database.h> 35 #include <google/protobuf/descriptor_database.h>
36 36
37 #include <set> 37 #include <set>
38 38
39 #include <google/protobuf/descriptor.pb.h> 39 #include <google/protobuf/descriptor.pb.h>
40 #include <google/protobuf/wire_format_lite_inl.h> 40 #include <google/protobuf/wire_format_lite_inl.h>
41 #include <google/protobuf/stubs/strutil.h> 41 #include <google/protobuf/stubs/strutil.h>
42 #include <google/protobuf/stubs/stl_util.h> 42 #include <google/protobuf/stubs/stl_util.h>
43 #include <google/protobuf/stubs/map-util.h> 43 #include <google/protobuf/stubs/map_util.h>
44 44
45 namespace google { 45 namespace google {
46 namespace protobuf { 46 namespace protobuf {
47 47
48 DescriptorDatabase::~DescriptorDatabase() {} 48 DescriptorDatabase::~DescriptorDatabase() {}
49 49
50 // =================================================================== 50 // ===================================================================
51 51
52 template <typename Value> 52 template <typename Value>
53 bool SimpleDescriptorDatabase::DescriptorIndex<Value>::AddFile( 53 bool SimpleDescriptorDatabase::DescriptorIndex<Value>::AddFile(
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 return true; 146 return true;
147 } 147 }
148 148
149 template <typename Value> 149 template <typename Value>
150 bool SimpleDescriptorDatabase::DescriptorIndex<Value>::AddExtension( 150 bool SimpleDescriptorDatabase::DescriptorIndex<Value>::AddExtension(
151 const FieldDescriptorProto& field, 151 const FieldDescriptorProto& field,
152 Value value) { 152 Value value) {
153 if (!field.extendee().empty() && field.extendee()[0] == '.') { 153 if (!field.extendee().empty() && field.extendee()[0] == '.') {
154 // The extension is fully-qualified. We can use it as a lookup key in 154 // The extension is fully-qualified. We can use it as a lookup key in
155 // the by_symbol_ table. 155 // the by_symbol_ table.
156 if (!InsertIfNotPresent(&by_extension_, 156 if (!InsertIfNotPresent(
157 make_pair(field.extendee().substr(1), 157 &by_extension_,
158 field.number()), 158 std::make_pair(field.extendee().substr(1), field.number()),
159 value)) { 159 value)) {
160 GOOGLE_LOG(ERROR) << "Extension conflicts with extension already in databa se: " 160 GOOGLE_LOG(ERROR) << "Extension conflicts with extension already in databa se: "
161 "extend " << field.extendee() << " { " 161 "extend " << field.extendee() << " { "
162 << field.name() << " = " << field.number() << " }"; 162 << field.name() << " = " << field.number() << " }";
163 return false; 163 return false;
164 } 164 }
165 } else { 165 } else {
166 // Not fully-qualified. We can't really do anything here, unfortunately. 166 // Not fully-qualified. We can't really do anything here, unfortunately.
167 // We don't consider this an error, though, because the descriptor is 167 // We don't consider this an error, though, because the descriptor is
168 // valid. 168 // valid.
169 } 169 }
(...skipping 12 matching lines...) Expand all
182 typename map<string, Value>::iterator iter = FindLastLessOrEqual(name); 182 typename map<string, Value>::iterator iter = FindLastLessOrEqual(name);
183 183
184 return (iter != by_symbol_.end() && IsSubSymbol(iter->first, name)) ? 184 return (iter != by_symbol_.end() && IsSubSymbol(iter->first, name)) ?
185 iter->second : Value(); 185 iter->second : Value();
186 } 186 }
187 187
188 template <typename Value> 188 template <typename Value>
189 Value SimpleDescriptorDatabase::DescriptorIndex<Value>::FindExtension( 189 Value SimpleDescriptorDatabase::DescriptorIndex<Value>::FindExtension(
190 const string& containing_type, 190 const string& containing_type,
191 int field_number) { 191 int field_number) {
192 return FindWithDefault(by_extension_, 192 return FindWithDefault(
193 make_pair(containing_type, field_number), 193 by_extension_, std::make_pair(containing_type, field_number), Value());
194 Value());
195 } 194 }
196 195
197 template <typename Value> 196 template <typename Value>
198 bool SimpleDescriptorDatabase::DescriptorIndex<Value>::FindAllExtensionNumbers( 197 bool SimpleDescriptorDatabase::DescriptorIndex<Value>::FindAllExtensionNumbers(
199 const string& containing_type, 198 const string& containing_type,
200 vector<int>* output) { 199 vector<int>* output) {
201 typename map<pair<string, int>, Value >::const_iterator it = 200 typename map<pair<string, int>, Value>::const_iterator it =
202 by_extension_.lower_bound(make_pair(containing_type, 0)); 201 by_extension_.lower_bound(std::make_pair(containing_type, 0));
203 bool success = false; 202 bool success = false;
204 203
205 for (; it != by_extension_.end() && it->first.first == containing_type; 204 for (; it != by_extension_.end() && it->first.first == containing_type;
206 ++it) { 205 ++it) {
207 output->push_back(it->first.second); 206 output->push_back(it->first.second);
208 success = true; 207 success = true;
209 } 208 }
210 209
211 return success; 210 return success;
212 } 211 }
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 FileDescriptorProto* output) { 281 FileDescriptorProto* output) {
283 return MaybeCopy(index_.FindExtension(containing_type, field_number), output); 282 return MaybeCopy(index_.FindExtension(containing_type, field_number), output);
284 } 283 }
285 284
286 bool SimpleDescriptorDatabase::FindAllExtensionNumbers( 285 bool SimpleDescriptorDatabase::FindAllExtensionNumbers(
287 const string& extendee_type, 286 const string& extendee_type,
288 vector<int>* output) { 287 vector<int>* output) {
289 return index_.FindAllExtensionNumbers(extendee_type, output); 288 return index_.FindAllExtensionNumbers(extendee_type, output);
290 } 289 }
291 290
291
292 bool SimpleDescriptorDatabase::MaybeCopy(const FileDescriptorProto* file, 292 bool SimpleDescriptorDatabase::MaybeCopy(const FileDescriptorProto* file,
293 FileDescriptorProto* output) { 293 FileDescriptorProto* output) {
294 if (file == NULL) return false; 294 if (file == NULL) return false;
295 output->CopyFrom(*file); 295 output->CopyFrom(*file);
296 return true; 296 return true;
297 } 297 }
298 298
299 // ------------------------------------------------------------------- 299 // -------------------------------------------------------------------
300 300
301 EncodedDescriptorDatabase::EncodedDescriptorDatabase() {} 301 EncodedDescriptorDatabase::EncodedDescriptorDatabase() {}
302 EncodedDescriptorDatabase::~EncodedDescriptorDatabase() { 302 EncodedDescriptorDatabase::~EncodedDescriptorDatabase() {
303 for (int i = 0; i < files_to_delete_.size(); i++) { 303 for (int i = 0; i < files_to_delete_.size(); i++) {
304 operator delete(files_to_delete_[i]); 304 operator delete(files_to_delete_[i]);
305 } 305 }
306 } 306 }
307 307
308 bool EncodedDescriptorDatabase::Add( 308 bool EncodedDescriptorDatabase::Add(
309 const void* encoded_file_descriptor, int size) { 309 const void* encoded_file_descriptor, int size) {
310 FileDescriptorProto file; 310 FileDescriptorProto file;
311 if (file.ParseFromArray(encoded_file_descriptor, size)) { 311 if (file.ParseFromArray(encoded_file_descriptor, size)) {
312 return index_.AddFile(file, make_pair(encoded_file_descriptor, size)); 312 return index_.AddFile(file, std::make_pair(encoded_file_descriptor, size));
313 } else { 313 } else {
314 GOOGLE_LOG(ERROR) << "Invalid file descriptor data passed to " 314 GOOGLE_LOG(ERROR) << "Invalid file descriptor data passed to "
315 "EncodedDescriptorDatabase::Add()."; 315 "EncodedDescriptorDatabase::Add().";
316 return false; 316 return false;
317 } 317 }
318 } 318 }
319 319
320 bool EncodedDescriptorDatabase::AddCopy( 320 bool EncodedDescriptorDatabase::AddCopy(
321 const void* encoded_file_descriptor, int size) { 321 const void* encoded_file_descriptor, int size) {
322 void* copy = operator new(size); 322 void* copy = operator new(size);
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 517
518 bool MergedDescriptorDatabase::FindAllExtensionNumbers( 518 bool MergedDescriptorDatabase::FindAllExtensionNumbers(
519 const string& extendee_type, 519 const string& extendee_type,
520 vector<int>* output) { 520 vector<int>* output) {
521 set<int> merged_results; 521 set<int> merged_results;
522 vector<int> results; 522 vector<int> results;
523 bool success = false; 523 bool success = false;
524 524
525 for (int i = 0; i < sources_.size(); i++) { 525 for (int i = 0; i < sources_.size(); i++) {
526 if (sources_[i]->FindAllExtensionNumbers(extendee_type, &results)) { 526 if (sources_[i]->FindAllExtensionNumbers(extendee_type, &results)) {
527 copy(results.begin(), results.end(), 527 std::copy(
528 insert_iterator<set<int> >(merged_results, merged_results.begin())); 528 results.begin(), results.end(),
529 insert_iterator<set<int> >(merged_results, merged_results.begin()));
529 success = true; 530 success = true;
530 } 531 }
531 results.clear(); 532 results.clear();
532 } 533 }
533 534
534 copy(merged_results.begin(), merged_results.end(), 535 std::copy(merged_results.begin(), merged_results.end(),
535 insert_iterator<vector<int> >(*output, output->end())); 536 insert_iterator<vector<int> >(*output, output->end()));
536 537
537 return success; 538 return success;
538 } 539 }
539 540
541
540 } // namespace protobuf 542 } // namespace protobuf
541 } // namespace google 543 } // namespace google
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698