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

Unified Diff: services/catalog/public/tools/catalog.cc.tmpl

Issue 2659523002: Generate better catalog C++ sources (Closed)
Patch Set: Created 3 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: services/catalog/public/tools/catalog.cc.tmpl
diff --git a/services/catalog/public/tools/catalog.cc.tmpl b/services/catalog/public/tools/catalog.cc.tmpl
new file mode 100644
index 0000000000000000000000000000000000000000..d309ae99979ab8af46420dbc2a767fa52e2b0eb3
--- /dev/null
+++ b/services/catalog/public/tools/catalog.cc.tmpl
@@ -0,0 +1,58 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// This is a generated file. Please see the "catalog_cpp_source" template in
+// src/services/catalog/public/tools/catalog.gni for more details.
+
+#include "{{path}}.h"
+
+#include "base/memory/ptr_util.h"
+#include "base/values.h"
+
+namespace {
+
+template <typename T>
+std::unique_ptr<base::Value> GenerateValue(T generator) { return generator(); }
+
+} // namespace
+
+{%- macro generate_value(source) -%}
+{%- if source|is_dict -%}
+GenerateValue([]() {
+ auto dict = base::MakeUnique<base::DictionaryValue>();
+{%- for key, value in source.iteritems() %}
+ dict->Set("{{key}}", {{generate_value(value)|indent(2)}});
+{%- endfor %}
+ return dict;
+})
+{%- elif source|is_list -%}
+GenerateValue([]() {
+ auto list = base::MakeUnique<base::ListValue>();
+{%- for value in source %}
+ list->Append({{generate_value(value)|indent(2)}});
+{%- endfor %}
+ return list;
+})
+{%- elif source|is_number -%}
+base::MakeUnique<base::FundamentalValue>({{source}})
+{%- elif source|is_bool -%}
+base::MakeUnique<base::FundamentalValue>({{source|lower}})
+{%- elif source|is_string or source|is_unicode -%}
+base::MakeUnique<base::StringValue>("{{source|make_ascii}}")
+{%- else %}
+{{raise("Unknown value type: %s" % source, source)}}
+{%- endif %}
+{%- endmacro -%}
+
+{% for namespace in namespaces %}
+namespace {{namespace}} {
+{%- endfor %}
+
+std::unique_ptr<base::Value> {{function_name}}() {
+ return {{generate_value(catalog)|indent(2)}};
+}
+
+{%- for namespace in namespaces|reverse %}
+} // namespace {{namespace}}
+{%- endfor %}
« 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