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

Unified Diff: tools/json_schema_compiler/any_helper.py

Issue 9491002: json_schema_compiler: any, additionalProperties, functions on types (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: rework, better errors Created 8 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 side-by-side diff with in-line comments
Download patch
Index: tools/json_schema_compiler/any_helper.py
diff --git a/tools/json_schema_compiler/any_helper.py b/tools/json_schema_compiler/any_helper.py
new file mode 100644
index 0000000000000000000000000000000000000000..8e46b576d411f3d5579518e86a59f8c01d48af21
--- /dev/null
+++ b/tools/json_schema_compiler/any_helper.py
@@ -0,0 +1,37 @@
+# Copyright (c) 2012 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.
+
+ANY_NAMESPACE = 'json_schema_compiler::any'
+ANY_CLASS = ANY_NAMESPACE + '::Any'
+
+class AnyHelper(object):
+ """A util class that generates code that uses
+ tools/json_schema_compiler/any.cc.
+ """
+ def Create(self, any_prop, src):
+ """Create an empty Any instance.
+ """
+ return 'new %s' % ANY_CLASS
+
+ def CopyInto(self, any_prop, src, dst):
+ """Copy |src| into |dst|.|any_prop|.
+
+ src: Value*
+ dst: Type*
+ """
+ if any_prop.optional:
+ return '%s->%s->Init(*%s)' % (dst, any_prop.name, src)
+ else:
+ return '%s->%s.Init(*%s)' % (dst, any_prop.name, src)
+
+ def GetValue(self, any_prop, var):
+ """Get |var| as a const Value&.
+
+ var: Any* or Any
+ """
+ if any_prop.optional:
+ return '%s->value()' % var
+ else:
+ return '%s.value()' % var
+

Powered by Google App Engine
This is Rietveld 408576698