-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase.mako
More file actions
157 lines (147 loc) · 4.5 KB
/
Copy pathbase.mako
File metadata and controls
157 lines (147 loc) · 4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<%doc>
Copyright (c) 2015 Thomson Reuters
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
</%doc>
<%doc>
Utility functions
</%doc>\
<%!
def firstlower(value):
return value[0].lower() + value[1:]
##
## equalto = lambda value, other: value == other
def firstupper(value):
return value[0].upper() + value[1:]
def inst_name(value):
## return 'm' + value[0].upper() + value[1:]
return normalize_prop_name(value)
%>
<%
def normalize_class_name(value):
## return 'm' + value[0].upper() + value[1:]
return value
%>\
<%doc>
Maps for mapping JSON types to Obj C types.
</%doc>\
<%!
typeMap = {
'string': 'std::string',
'dict': 'std::unordered_map',
'integer': 'int',
'number': 'double',
'boolean': 'bool',
'null': 'void',
'any': 'void'
}
primitivesTypeMap = {
'string': 'std::string',
'dict': 'std::unordered_map',
'integer': 'int',
'number': 'double',
'boolean': 'bool',
'null': 'void',
'any': 'void'
}
primitivesTypeIsRef = {
'string': True,
'dict': True,
'integer': False,
'number': False,
'boolean': False,
'null': True,
'any': True
}
%>\
<%doc>
Make sure property names are valid per C++ rules.
</%doc>
<%!
def normalize_prop_name(propName):
#return "id_" if propName == "id" else propName
return propName
%>\
<%
def inst_name(value):
#return 'm' + normalize_prop_name(value[0].upper() + value[1:])
return normalize_prop_name(value)
%>\
##<%!
## def convertJsTypeToObjc(jsType, usePrimitives=False):
##
## if usePrimitives:
## if jsType in primitivesTypeMap:
## varType = primitivesTypeMap[jsType]
## isRef = primitivesTypeIsRef[jsType]
## else:
## varType = variableDef.type + ' *'
## isRef = True
## else:
## varType = jsType + ' *' if not jsType in typeMap else typeMap[jsType]
## isRef = True
##
## return (varType, isRef)
##%>
<%doc>
Convert a JSON type to an Objective C type.
</%doc>
<%!
def convertType(variableDef, usePrimitives=False):
if usePrimitives:
if variableDef.type in primitivesTypeMap:
cppType = primitivesTypeMap[variableDef.type]
isRef = primitivesTypeIsRef[variableDef.type]
else:
cppType = variableDef.type
isRef = True
else:
cppType = variableDef.type if not variableDef.type in typeMap else typeMap[variableDef.type]
isRef = True
if variableDef.isArray:
varType = "std::vector<%s>" % cppType
itemType = cppType
else:
varType = cppType
itemType = None
return (varType, isRef, itemType)
%>\
<%def name='initVarToDefault(variableDef, usePrimitives=False)'>\
<%
(varType, isRef, itemsType) = convertType(variableDef, usePrimitives)
%>\
% if not variableDef.default == None:
<%
propName = variableDef.name
ivarName = '_' + propName
%>\
% if not isRef:
${ivarName} = ${variableDef.default};
% elif varType == "NSNumber *":
% if varDef.default == False:
${ivarName} = @NO;
% elif varDef.default == True:
${ivarName} = @YES;
% endif
% endif
% endif
</%def>\
//
// ${file_name}
//
// Created by js2Model on ${timestamp}.
//
<%block name="code" />