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 class Resources { | |
| 12 public: | |
| 13 static const int kNoSuchInstance = -1; | |
| 14 | |
| 15 static int ResourceLookup(const char* path, const char** resource) { | |
| 16 for (unsigned i = 0; i < get_resource_count(); i++) { | |
|
srdjan
2013/03/05 23:17:30
for (int i = 0 ...
Tom Ball
2013/03/06 00:34:43
Done.
| |
| 17 resource_map_entry* entry = get_resource(i); | |
| 18 if (!strcmp(path, entry->path_)) { | |
|
srdjan
2013/03/05 23:17:30
strcmp(..) == 0
Tom Ball
2013/03/06 00:34:43
Done.
| |
| 19 *resource = entry->resource_; | |
|
siva
2013/03/05 23:12:44
ASSERT(entry->length_ > 0);
Tom Ball
2013/03/06 00:34:43
Done.
| |
| 20 return entry->length_; | |
| 21 } | |
| 22 } | |
| 23 return kNoSuchInstance; | |
| 24 } | |
| 25 | |
| 26 private: | |
| 27 typedef struct { | |
|
srdjan
2013/03/05 23:17:30
struct resource_map_entry {
...
};
Tom Ball
2013/03/06 00:34:43
Done.
| |
| 28 const char* path_; | |
| 29 const char* resource_; | |
| 30 size_t length_; | |
| 31 } resource_map_entry; | |
| 32 | |
| 33 // These fields are generated by resources_gen.cc. | |
| 34 static resource_map_entry builtin_resources_[]; | |
| 35 static const size_t builtin_resources_count_; | |
|
siva
2013/03/05 23:12:44
Wouldn't this just be
sizeof(builtin_resources_)
srdjan
2013/03/05 23:17:30
s/size_t/intptr_t/ ? (also below).
Tom Ball
2013/03/06 00:34:43
Done.
Tom Ball
2013/03/06 00:34:43
Done.
Tom Ball
2013/03/06 00:34:43
sizeof(builtin_resources_) won't compile because i
| |
| 36 | |
| 37 static resource_map_entry* get_resource(int i) { | |
|
siva
2013/03/05 23:12:44
ASSERT(i >= 0 && i < builtin_resources_count_);
Tom Ball
2013/03/06 00:34:43
Done.
| |
| 38 return builtin_resources_ + i; | |
| 39 } | |
| 40 | |
| 41 static size_t get_resource_count() { return builtin_resources_count_; } | |
|
siva
2013/03/05 23:12:44
Since all methods in here are static, you could ad
Tom Ball
2013/03/06 00:34:43
Done.
| |
| 42 }; | |
| 43 | |
| 44 #endif // BIN_RESOURCES_H_ | |
| OLD | NEW |