Chromium Code Reviews| 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..9ce6ad2b62964c67a54d865fb08e953be421940d |
| --- /dev/null |
| +++ b/tools/json_schema_compiler/any_helper.py |
| @@ -0,0 +1,40 @@ |
| +# 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 a new Any instance, populated with |src|. |
| + |
| + src: Value* |
| + dst: Type* |
|
not at google - send to devlin
2012/02/28 22:41:17
The parameters and documentation seem wrong. Where
not at google - send to devlin
2012/03/01 07:09:37
Ping. I can't see this function being called anywh
|
| + """ |
| + 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->CopyFrom(*%s)' % (dst, any_prop.name, src) |
| + else: |
| + return '%s->%s.CopyFrom(*%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 |
| + |