Roll src/third_party/WebKit c8d1660:ae3684d (svn 197337:197343)
[chromium-blink-merge.git] / tools / json_schema_compiler / util_cc_helper.py
blobd69122dfc38cb1baba864f64d56c1735aceacb4c
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 PopulateArrayFromListFunction(self, optional):
16 """Returns the function to turn a list into a vector.
17 """
18 populate_list_fn = ('PopulateOptionalArrayFromList' if optional
19 else 'PopulateArrayFromList')
20 return ('%s::%s') % (_API_UTIL_NAMESPACE, populate_list_fn)
22 def CreateValueFromArray(self, src, optional):
23 """Generates code to create a scoped_pt<Value> from the array at src.
25 |src| The variable to convert, either a vector or scoped_ptr<vector>.
26 |optional| Whether |type_| was optional. Optional types are pointers so
27 must be treated differently.
28 """
29 if optional:
30 name = 'CreateValueFromOptionalArray'
31 else:
32 name = 'CreateValueFromArray'
33 return '%s::%s(%s)' % (_API_UTIL_NAMESPACE, name, src)
35 def GetIncludePath(self):
36 return '#include "tools/json_schema_compiler/util.h"'
38 def GetValueTypeString(self, value, is_ptr=False):
39 call = '.GetType()'
40 if is_ptr:
41 call = '->GetType()'
42 return 'json_schema_compiler::util::ValueTypeToString(%s%s)' % (value, call)