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

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

Issue 2495533002: third_party/protobuf: Update to HEAD (83d681ee2c) (Closed)
Patch Set: Make chrome settings proto generated file a component Created 4 years 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 // 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 // extendee_type, and appends them to output in an undefined 90 // extendee_type, and appends them to output in an undefined
91 // order. This method is best-effort: it's not guaranteed that the 91 // order. This method is best-effort: it's not guaranteed that the
92 // database will find all extensions, and it's not guaranteed that 92 // database will find all extensions, and it's not guaranteed that
93 // FindFileContainingExtension will return true on all of the found 93 // FindFileContainingExtension will return true on all of the found
94 // numbers. Returns true if the search was successful, otherwise 94 // numbers. Returns true if the search was successful, otherwise
95 // returns false and leaves output unchanged. 95 // returns false and leaves output unchanged.
96 // 96 //
97 // This method has a default implementation that always returns 97 // This method has a default implementation that always returns
98 // false. 98 // false.
99 virtual bool FindAllExtensionNumbers(const string& /* extendee_type */, 99 virtual bool FindAllExtensionNumbers(const string& /* extendee_type */,
100 vector<int>* /* output */) { 100 std::vector<int>* /* output */) {
101 return false; 101 return false;
102 } 102 }
103 103
104 104
105 private: 105 private:
106 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DescriptorDatabase); 106 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DescriptorDatabase);
107 }; 107 };
108 108
109 // A DescriptorDatabase into which you can insert files manually. 109 // A DescriptorDatabase into which you can insert files manually.
110 // 110 //
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 143
144 // implements DescriptorDatabase ----------------------------------- 144 // implements DescriptorDatabase -----------------------------------
145 bool FindFileByName(const string& filename, 145 bool FindFileByName(const string& filename,
146 FileDescriptorProto* output); 146 FileDescriptorProto* output);
147 bool FindFileContainingSymbol(const string& symbol_name, 147 bool FindFileContainingSymbol(const string& symbol_name,
148 FileDescriptorProto* output); 148 FileDescriptorProto* output);
149 bool FindFileContainingExtension(const string& containing_type, 149 bool FindFileContainingExtension(const string& containing_type,
150 int field_number, 150 int field_number,
151 FileDescriptorProto* output); 151 FileDescriptorProto* output);
152 bool FindAllExtensionNumbers(const string& extendee_type, 152 bool FindAllExtensionNumbers(const string& extendee_type,
153 vector<int>* output); 153 std::vector<int>* output);
154 154
155 private: 155 private:
156 // So that it can use DescriptorIndex. 156 // So that it can use DescriptorIndex.
157 friend class EncodedDescriptorDatabase; 157 friend class EncodedDescriptorDatabase;
158 158
159 // An index mapping file names, symbol names, and extension numbers to 159 // An index mapping file names, symbol names, and extension numbers to
160 // some sort of values. 160 // some sort of values.
161 template <typename Value> 161 template <typename Value>
162 class DescriptorIndex { 162 class DescriptorIndex {
163 public: 163 public:
164 // Helpers to recursively add particular descriptors and all their contents 164 // Helpers to recursively add particular descriptors and all their contents
165 // to the index. 165 // to the index.
166 bool AddFile(const FileDescriptorProto& file, 166 bool AddFile(const FileDescriptorProto& file,
167 Value value); 167 Value value);
168 bool AddSymbol(const string& name, Value value); 168 bool AddSymbol(const string& name, Value value);
169 bool AddNestedExtensions(const DescriptorProto& message_type, 169 bool AddNestedExtensions(const DescriptorProto& message_type,
170 Value value); 170 Value value);
171 bool AddExtension(const FieldDescriptorProto& field, 171 bool AddExtension(const FieldDescriptorProto& field,
172 Value value); 172 Value value);
173 173
174 Value FindFile(const string& filename); 174 Value FindFile(const string& filename);
175 Value FindSymbol(const string& name); 175 Value FindSymbol(const string& name);
176 Value FindExtension(const string& containing_type, int field_number); 176 Value FindExtension(const string& containing_type, int field_number);
177 bool FindAllExtensionNumbers(const string& containing_type, 177 bool FindAllExtensionNumbers(const string& containing_type,
178 vector<int>* output); 178 std::vector<int>* output);
179 179
180 private: 180 private:
181 map<string, Value> by_name_; 181 std::map<string, Value> by_name_;
182 map<string, Value> by_symbol_; 182 std::map<string, Value> by_symbol_;
183 map<pair<string, int>, Value> by_extension_; 183 std::map<std::pair<string, int>, Value> by_extension_;
184 184
185 // Invariant: The by_symbol_ map does not contain any symbols which are 185 // Invariant: The by_symbol_ map does not contain any symbols which are
186 // prefixes of other symbols in the map. For example, "foo.bar" is a 186 // prefixes of other symbols in the map. For example, "foo.bar" is a
187 // prefix of "foo.bar.baz" (but is not a prefix of "foo.barbaz"). 187 // prefix of "foo.bar.baz" (but is not a prefix of "foo.barbaz").
188 // 188 //
189 // This invariant is important because it means that given a symbol name, 189 // This invariant is important because it means that given a symbol name,
190 // we can find a key in the map which is a prefix of the symbol in O(lg n) 190 // we can find a key in the map which is a prefix of the symbol in O(lg n)
191 // time, and we know that there is at most one such key. 191 // time, and we know that there is at most one such key.
192 // 192 //
193 // The prefix lookup algorithm works like so: 193 // The prefix lookup algorithm works like so:
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 // 9) Therefore, the found key must match the match key. 228 // 9) Therefore, the found key must match the match key.
229 // 229 //
230 // The above proof assumes the match key exists. In the case that the 230 // The above proof assumes the match key exists. In the case that the
231 // match key does not exist, then step (1) will return some other symbol. 231 // match key does not exist, then step (1) will return some other symbol.
232 // That symbol cannot be a super-symbol of the search key since if it were, 232 // That symbol cannot be a super-symbol of the search key since if it were,
233 // then it would be a match, and we're assuming the match key doesn't exist. 233 // then it would be a match, and we're assuming the match key doesn't exist.
234 // Therefore, step 2 will correctly return no match. 234 // Therefore, step 2 will correctly return no match.
235 235
236 // Find the last entry in the by_symbol_ map whose key is less than or 236 // Find the last entry in the by_symbol_ map whose key is less than or
237 // equal to the given name. 237 // equal to the given name.
238 typename map<string, Value>::iterator FindLastLessOrEqual( 238 typename std::map<string, Value>::iterator FindLastLessOrEqual(
239 const string& name); 239 const string& name);
240 240
241 // True if either the arguments are equal or super_symbol identifies a 241 // True if either the arguments are equal or super_symbol identifies a
242 // parent symbol of sub_symbol (e.g. "foo.bar" is a parent of 242 // parent symbol of sub_symbol (e.g. "foo.bar" is a parent of
243 // "foo.bar.baz", but not a parent of "foo.barbaz"). 243 // "foo.bar.baz", but not a parent of "foo.barbaz").
244 bool IsSubSymbol(const string& sub_symbol, const string& super_symbol); 244 bool IsSubSymbol(const string& sub_symbol, const string& super_symbol);
245 245
246 // Returns true if and only if all characters in the name are alphanumerics, 246 // Returns true if and only if all characters in the name are alphanumerics,
247 // underscores, or periods. 247 // underscores, or periods.
248 bool ValidateSymbolName(const string& name); 248 bool ValidateSymbolName(const string& name);
249 }; 249 };
250 250
251 251
252 DescriptorIndex<const FileDescriptorProto*> index_; 252 DescriptorIndex<const FileDescriptorProto*> index_;
253 vector<const FileDescriptorProto*> files_to_delete_; 253 std::vector<const FileDescriptorProto*> files_to_delete_;
254 254
255 // If file is non-NULL, copy it into *output and return true, otherwise 255 // If file is non-NULL, copy it into *output and return true, otherwise
256 // return false. 256 // return false.
257 bool MaybeCopy(const FileDescriptorProto* file, 257 bool MaybeCopy(const FileDescriptorProto* file,
258 FileDescriptorProto* output); 258 FileDescriptorProto* output);
259 259
260 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(SimpleDescriptorDatabase); 260 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(SimpleDescriptorDatabase);
261 }; 261 };
262 262
263 // Very similar to SimpleDescriptorDatabase, but stores all the descriptors 263 // Very similar to SimpleDescriptorDatabase, but stores all the descriptors
(...skipping 24 matching lines...) Expand all
288 288
289 // implements DescriptorDatabase ----------------------------------- 289 // implements DescriptorDatabase -----------------------------------
290 bool FindFileByName(const string& filename, 290 bool FindFileByName(const string& filename,
291 FileDescriptorProto* output); 291 FileDescriptorProto* output);
292 bool FindFileContainingSymbol(const string& symbol_name, 292 bool FindFileContainingSymbol(const string& symbol_name,
293 FileDescriptorProto* output); 293 FileDescriptorProto* output);
294 bool FindFileContainingExtension(const string& containing_type, 294 bool FindFileContainingExtension(const string& containing_type,
295 int field_number, 295 int field_number,
296 FileDescriptorProto* output); 296 FileDescriptorProto* output);
297 bool FindAllExtensionNumbers(const string& extendee_type, 297 bool FindAllExtensionNumbers(const string& extendee_type,
298 vector<int>* output); 298 std::vector<int>* output);
299 299
300 private: 300 private:
301 SimpleDescriptorDatabase::DescriptorIndex<pair<const void*, int> > index_; 301 SimpleDescriptorDatabase::DescriptorIndex<std::pair<const void*, int> >
302 vector<void*> files_to_delete_; 302 index_;
303 std::vector<void*> files_to_delete_;
303 304
304 // If encoded_file.first is non-NULL, parse the data into *output and return 305 // If encoded_file.first is non-NULL, parse the data into *output and return
305 // true, otherwise return false. 306 // true, otherwise return false.
306 bool MaybeParse(pair<const void*, int> encoded_file, 307 bool MaybeParse(std::pair<const void*, int> encoded_file,
307 FileDescriptorProto* output); 308 FileDescriptorProto* output);
308 309
309 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EncodedDescriptorDatabase); 310 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(EncodedDescriptorDatabase);
310 }; 311 };
311 312
312 // A DescriptorDatabase that fetches files from a given pool. 313 // A DescriptorDatabase that fetches files from a given pool.
313 class LIBPROTOBUF_EXPORT DescriptorPoolDatabase : public DescriptorDatabase { 314 class LIBPROTOBUF_EXPORT DescriptorPoolDatabase : public DescriptorDatabase {
314 public: 315 public:
315 explicit DescriptorPoolDatabase(const DescriptorPool& pool); 316 explicit DescriptorPoolDatabase(const DescriptorPool& pool);
316 ~DescriptorPoolDatabase(); 317 ~DescriptorPoolDatabase();
317 318
318 // implements DescriptorDatabase ----------------------------------- 319 // implements DescriptorDatabase -----------------------------------
319 bool FindFileByName(const string& filename, 320 bool FindFileByName(const string& filename,
320 FileDescriptorProto* output); 321 FileDescriptorProto* output);
321 bool FindFileContainingSymbol(const string& symbol_name, 322 bool FindFileContainingSymbol(const string& symbol_name,
322 FileDescriptorProto* output); 323 FileDescriptorProto* output);
323 bool FindFileContainingExtension(const string& containing_type, 324 bool FindFileContainingExtension(const string& containing_type,
324 int field_number, 325 int field_number,
325 FileDescriptorProto* output); 326 FileDescriptorProto* output);
326 bool FindAllExtensionNumbers(const string& extendee_type, 327 bool FindAllExtensionNumbers(const string& extendee_type,
327 vector<int>* output); 328 std::vector<int>* output);
328 329
329 private: 330 private:
330 const DescriptorPool& pool_; 331 const DescriptorPool& pool_;
331 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DescriptorPoolDatabase); 332 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DescriptorPoolDatabase);
332 }; 333 };
333 334
334 // A DescriptorDatabase that wraps two or more others. It first searches the 335 // A DescriptorDatabase that wraps two or more others. It first searches the
335 // first database and, if that fails, tries the second, and so on. 336 // first database and, if that fails, tries the second, and so on.
336 class LIBPROTOBUF_EXPORT MergedDescriptorDatabase : public DescriptorDatabase { 337 class LIBPROTOBUF_EXPORT MergedDescriptorDatabase : public DescriptorDatabase {
337 public: 338 public:
338 // Merge just two databases. The sources remain property of the caller. 339 // Merge just two databases. The sources remain property of the caller.
339 MergedDescriptorDatabase(DescriptorDatabase* source1, 340 MergedDescriptorDatabase(DescriptorDatabase* source1,
340 DescriptorDatabase* source2); 341 DescriptorDatabase* source2);
341 // Merge more than two databases. The sources remain property of the caller. 342 // Merge more than two databases. The sources remain property of the caller.
342 // The vector may be deleted after the constructor returns but the 343 // The vector may be deleted after the constructor returns but the
343 // DescriptorDatabases need to stick around. 344 // DescriptorDatabases need to stick around.
344 explicit MergedDescriptorDatabase(const vector<DescriptorDatabase*>& sources); 345 explicit MergedDescriptorDatabase(
346 const std::vector<DescriptorDatabase*>& sources);
345 ~MergedDescriptorDatabase(); 347 ~MergedDescriptorDatabase();
346 348
347 // implements DescriptorDatabase ----------------------------------- 349 // implements DescriptorDatabase -----------------------------------
348 bool FindFileByName(const string& filename, 350 bool FindFileByName(const string& filename,
349 FileDescriptorProto* output); 351 FileDescriptorProto* output);
350 bool FindFileContainingSymbol(const string& symbol_name, 352 bool FindFileContainingSymbol(const string& symbol_name,
351 FileDescriptorProto* output); 353 FileDescriptorProto* output);
352 bool FindFileContainingExtension(const string& containing_type, 354 bool FindFileContainingExtension(const string& containing_type,
353 int field_number, 355 int field_number,
354 FileDescriptorProto* output); 356 FileDescriptorProto* output);
355 // Merges the results of calling all databases. Returns true iff any 357 // Merges the results of calling all databases. Returns true iff any
356 // of the databases returned true. 358 // of the databases returned true.
357 bool FindAllExtensionNumbers(const string& extendee_type, 359 bool FindAllExtensionNumbers(const string& extendee_type,
358 vector<int>* output); 360 std::vector<int>* output);
359 361
360 362
361 private: 363 private:
362 vector<DescriptorDatabase*> sources_; 364 std::vector<DescriptorDatabase*> sources_;
363 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MergedDescriptorDatabase); 365 GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MergedDescriptorDatabase);
364 }; 366 };
365 367
366 } // namespace protobuf 368 } // namespace protobuf
367 369
368 } // namespace google 370 } // namespace google
369 #endif // GOOGLE_PROTOBUF_DESCRIPTOR_DATABASE_H__ 371 #endif // GOOGLE_PROTOBUF_DESCRIPTOR_DATABASE_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698