util_cc_helper.py 1.2 KB

123456789101112131415161718192021222324252627282930313233
  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. _API_UTIL_NAMESPACE = 'json_schema_compiler::util'
  5. class UtilCCHelper(object):
  6. """A util class that generates code that uses
  7. tools/json_schema_compiler/util.cc.
  8. """
  9. def __init__(self, type_manager):
  10. self._type_manager = type_manager
  11. def PopulateArrayFromListFunction(self, optional):
  12. """Returns the function to turn a list into a vector.
  13. """
  14. populate_list_fn = ('PopulateOptionalArrayFromList' if optional
  15. else 'PopulateArrayFromList')
  16. return ('%s::%s') % (_API_UTIL_NAMESPACE, populate_list_fn)
  17. def CreateValueFromArray(self, src):
  18. """Generates code to create a scoped_pt<Value> from the array at src.
  19. |src| The variable to convert, either a vector or std::unique_ptr<vector>.
  20. """
  21. return '%s::CreateValueFromArray(%s)' % (_API_UTIL_NAMESPACE, src)
  22. def GetIncludePath(self):
  23. return '#include "tools/json_schema_compiler/util.h"'
  24. def GetValueTypeString(self, value):
  25. return 'UTF8ToUTF16(base::Value::GetTypeName(%s.type()))' % value