OLD | NEW |
(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 Init(self, any_prop, src, dst): |
| 13 """Initialize |dst|.|any_prop| to |src|. |
| 14 |
| 15 src: Value* |
| 16 dst: Type* |
| 17 """ |
| 18 if any_prop.optional: |
| 19 return '%s->%s->Init(*%s)' % (dst, any_prop.name, src) |
| 20 else: |
| 21 return '%s->%s.Init(*%s)' % (dst, any_prop.name, src) |
| 22 |
| 23 def GetValue(self, any_prop, var): |
| 24 """Get |var| as a const Value&. |
| 25 |
| 26 var: Any* or Any |
| 27 """ |
| 28 if any_prop.optional: |
| 29 return '%s->value()' % var |
| 30 else: |
| 31 return '%s.value()' % var |
| 32 |
OLD | NEW |