Unregister from GCM when the only GCM app is removed
[chromium-blink-merge.git] / tools / json_schema_compiler / util_cc_helper.py
blobc3acd5fa1d1ac4d9da3e5f52dd1693cd3672b5a0
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.
5 _API_UTIL_NAMESPACE = 'json_schema_compiler::util'
8 class UtilCCHelper(object):
9 """A util class that generates code that uses
10 tools/json_schema_compiler/util.cc.
11 """
12 def __init__(self, type_manager):
13 self._type_manager = type_manager
15 def PopulateArrayFromList(self, src, dst, optional):
16 """Generates code to get an array from src into dst.
18 src: ListValue*
19 dst: std::vector or scoped_ptr<std::vector>
20 """
21 populate_list_fn = ('PopulateOptionalArrayFromList' if optional
22 else 'PopulateArrayFromList')
23 return ('%s::%s(*%s, &%s)') % (_API_UTIL_NAMESPACE,
24 populate_list_fn,
25 src,
26 dst)
28 def CreateValueFromArray(self, src, optional):
29 """Generates code to create a scoped_pt<Value> from the array at src.
31 |src| The variable to convert, either a vector or scoped_ptr<vector>.
32 |optional| Whether |type_| was optional. Optional types are pointers so
33 must be treated differently.
34 """
35 if optional:
36 name = 'CreateValueFromOptionalArray'
37 else:
38 name = 'CreateValueFromArray'
39 return '%s::%s(%s)' % (_API_UTIL_NAMESPACE, name, src)
41 def GetIncludePath(self):
42 return '#include "tools/json_schema_compiler/util.h"'
44 def GetValueTypeString(self, value, is_ptr=False):
45 call = '.GetType()'
46 if is_ptr:
47 call = '->GetType()'
48 return 'json_schema_compiler::util::ValueTypeToString(%s%s)' % (value, call)