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

Side by Side Diff: runtime/bin/resources.h

Issue 125103004: Move service into VM (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 11 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 | Annotate | Revision Log
OLDNEW
(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 // Map from Blink to Dart VM.
12 #if defined(_DEBUG)
13 #define DEBUG
14 #endif
15
16 #include "platform/assert.h"
17
18
19 namespace dart {
20 namespace bin {
21
22 class Resources {
23 public:
24 static const int kNoSuchInstance = -1;
25
26 static int ResourceLookup(const char* path, const char** resource) {
27 for (int i = 0; i < get_resource_count(); i++) {
28 resource_map_entry* entry = get_resource(i);
29 if (strcmp(path, entry->path_) == 0) {
30 *resource = entry->resource_;
31 ASSERT(entry->length_ > 0);
32 return entry->length_;
33 }
34 }
35 return kNoSuchInstance;
36 }
37
38 static intptr_t get_resource_count() {
39 return builtin_resources_count_;
40 }
41
42 static const char* get_resource_path(intptr_t i) {
43 return get_resource(i)->path_;
44 }
45
46 private:
47 struct resource_map_entry {
48 const char* path_;
49 const char* resource_;
50 intptr_t length_;
51 };
52
53 // These fields are generated by resources_gen.cc.
54 static resource_map_entry builtin_resources_[];
55 static const intptr_t builtin_resources_count_;
56
57 static resource_map_entry* get_resource(int i) {
58 ASSERT(i >= 0 && i < builtin_resources_count_);
59 return &builtin_resources_[i];
60 }
61
62 DISALLOW_ALLOCATION();
63 DISALLOW_IMPLICIT_CONSTRUCTORS(Resources);
64 };
65
66 } // namespace bin
67 } // namespace dart
68
69 #endif // BIN_RESOURCES_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698