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

Side by Side 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, 9 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
OLDNEW
(Empty)
1 # Copyright (c) 2012 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 ANY_NAMESPACE = 'json_schema_compiler::any'
6 ANY_CLASS = ANY_NAMESPACE + '::Any'
7
8 class AnyHelper(object):
9 """A util class that generates code that uses
10 tools/json_schema_compiler/any.cc.
11 """
12 def Create(self, any_prop, src):
13 """Create an empty Any instance.
14 """
15 return 'new %s' % ANY_CLASS
16
17 def CopyInto(self, any_prop, src, dst):
18 """Copy |src| into |dst|.|any_prop|.
19
20 src: Value*
21 dst: Type*
22 """
23 if any_prop.optional:
24 return '%s->%s->Init(*%s)' % (dst, any_prop.name, src)
25 else:
26 return '%s->%s.Init(*%s)' % (dst, any_prop.name, src)
27
28 def GetValue(self, any_prop, var):
29 """Get |var| as a const Value&.
30
31 var: Any* or Any
32 """
33 if any_prop.optional:
34 return '%s->value()' % var
35 else:
36 return '%s.value()' % var
37
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698