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

Side by Side Diff: services/catalog/public/tools/catalog.cc.tmpl

Issue 2659523002: Generate better catalog C++ sources (Closed)
Patch Set: Created 3 years, 10 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
« no previous file with comments | « services/catalog/public/tools/catalog.gni ('k') | services/catalog/public/tools/catalog.h.tmpl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // This is a generated file. Please see the "catalog_cpp_source" template in
6 // src/services/catalog/public/tools/catalog.gni for more details.
7
8 #include "{{path}}.h"
9
10 #include "base/memory/ptr_util.h"
11 #include "base/values.h"
12
13 namespace {
14
15 template <typename T>
16 std::unique_ptr<base::Value> GenerateValue(T generator) { return generator(); }
17
18 } // namespace
19
20 {%- macro generate_value(source) -%}
21 {%- if source|is_dict -%}
22 GenerateValue([]() {
23 auto dict = base::MakeUnique<base::DictionaryValue>();
24 {%- for key, value in source.iteritems() %}
25 dict->Set("{{key}}", {{generate_value(value)|indent(2)}});
26 {%- endfor %}
27 return dict;
28 })
29 {%- elif source|is_list -%}
30 GenerateValue([]() {
31 auto list = base::MakeUnique<base::ListValue>();
32 {%- for value in source %}
33 list->Append({{generate_value(value)|indent(2)}});
34 {%- endfor %}
35 return list;
36 })
37 {%- elif source|is_number -%}
38 base::MakeUnique<base::FundamentalValue>({{source}})
39 {%- elif source|is_bool -%}
40 base::MakeUnique<base::FundamentalValue>({{source|lower}})
41 {%- elif source|is_string or source|is_unicode -%}
42 base::MakeUnique<base::StringValue>("{{source|make_ascii}}")
43 {%- else %}
44 {{raise("Unknown value type: %s" % source, source)}}
45 {%- endif %}
46 {%- endmacro -%}
47
48 {% for namespace in namespaces %}
49 namespace {{namespace}} {
50 {%- endfor %}
51
52 std::unique_ptr<base::Value> {{function_name}}() {
53 return {{generate_value(catalog)|indent(2)}};
54 }
55
56 {%- for namespace in namespaces|reverse %}
57 } // namespace {{namespace}}
58 {%- endfor %}
OLDNEW
« no previous file with comments | « services/catalog/public/tools/catalog.gni ('k') | services/catalog/public/tools/catalog.h.tmpl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698