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 """Utilies and constants specific to Chromium C++ code. |
| 5 """ |
| 6 |
| 7 from datetime import datetime |
| 8 from model import PropertyType |
| 9 |
| 10 CHROMIUM_LICENSE = ( |
| 11 """// Copyright (c) %d The Chromium Authors. All rights reserved. |
| 12 // Use of this source code is governed by a BSD-style license that can be |
| 13 // found in the LICENSE file.""" % datetime.now().year |
| 14 ) |
| 15 GENERATED_FILE_MESSAGE = """// GENERATED FROM THE API DEFINITION IN |
| 16 // %s |
| 17 // DO NOT EDIT. |
| 18 """ |
| 19 |
| 20 |
| 21 def CppName(s): |
| 22 """Translates a namespace name or function name into something more |
| 23 suited to C++. |
| 24 |
| 25 eg experimental.downloads -> Experimental_Downloads |
| 26 updateAll -> UpdateAll. |
| 27 """ |
| 28 return '_'.join([x[0].upper() + x[1:] for x in s.split('.')]) |
| 29 |
| 30 def CreateFundamentalValue(prop, var): |
| 31 """Returns the C++ code for creating a value of the given property type |
| 32 using the given variable. |
| 33 """ |
| 34 return { |
| 35 PropertyType.STRING: 'Value::CreateStringValue(%s)', |
| 36 PropertyType.BOOLEAN: 'Value::CreateBooleanValue(%s)', |
| 37 PropertyType.INTEGER: 'Value::CreateIntegerValue(%s)', |
| 38 PropertyType.DOUBLE: 'Value::CreateDoubleValue(%s)', |
| 39 }[prop.type_] % var |
| 40 |
| 41 |
| 42 def GetFundamentalValue(prop, var): |
| 43 """Returns the C++ code for retrieving a fundamental type from a Value |
| 44 into a variable. |
| 45 """ |
| 46 return { |
| 47 PropertyType.STRING: 'GetAsString(%s)', |
| 48 PropertyType.BOOLEAN: 'GetAsBoolean(%s)', |
| 49 PropertyType.INTEGER: 'GetAsInteger(%s)', |
| 50 PropertyType.DOUBLE: 'GetAsDouble(%s)', |
| 51 }[prop.type_] % var |
OLD | NEW |