Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 #ifndef BIN_RESOURCES_H_ | |
| 6 #define BIN_RESOURCES_H_ | |
| 7 | |
| 8 #include <stddef.h> | |
| 9 #include <string.h> | |
| 10 | |
| 11 #include "platform/assert.h" | |
| 12 | |
| 13 | |
| 14 class Resources { | |
| 15 public: | |
| 16 static const int kNoSuchInstance = -1; | |
| 17 | |
| 18 static int ResourceLookup(const char* path, const char** resource) { | |
| 19 for (int i = 0; i < get_resource_count(); i++) { | |
| 20 resource_map_entry* entry = get_resource(i); | |
| 21 if (strcmp(path, entry->path_) == 0) { | |
| 22 *resource = entry->resource_; | |
| 23 ASSERT(entry->length_ > 0); | |
| 24 return entry->length_; | |
| 25 } | |
| 26 } | |
| 27 return kNoSuchInstance; | |
| 28 } | |
| 29 | |
| 30 private: | |
| 31 struct resource_map_entry { | |
| 32 const char* path_; | |
| 33 const char* resource_; | |
| 34 intptr_t length_; | |
| 35 }; | |
| 36 | |
| 37 // These fields are generated by resources_gen.cc. | |
| 38 static resource_map_entry builtin_resources_[]; | |
| 39 static const intptr_t builtin_resources_count_; | |
| 40 | |
| 41 static resource_map_entry* get_resource(int i) { | |
| 42 ASSERT(i >= 0 && i < builtin_resources_count_); | |
| 43 return builtin_resources_ + i; | |
|
srdjan
2013/03/06 01:14:37
&builtin_resources_[i]
Tom Ball
2013/03/06 17:47:17
Done.
| |
| 44 } | |
| 45 | |
| 46 static intptr_t get_resource_count() { | |
| 47 return builtin_resources_count_; } | |
| 48 | |
| 49 DISALLOW_ALLOCATION(); | |
| 50 DISALLOW_IMPLICIT_CONSTRUCTORS(Resources); | |
| 51 }; | |
| 52 | |
| 53 #endif // BIN_RESOURCES_H_ | |
| OLD | NEW |