Skip to content

Commit

Permalink
Provide generic accessor for single data type.
Browse files Browse the repository at this point in the history
  • Loading branch information
john-preston committed Aug 23, 2021
1 parent dd1b2a4 commit f8ea3a1
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion tl/generate_tl.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ def handleTemplate(name, process = fullTypeName):
bufferType = primitiveTypeNames.get('buffer', '')

writeConversion = 'conversion' in scheme
optimizeSingleData = 'optimizeSingleData' in scheme
conversionScheme = scheme.get('conversion', {})
conversionInclude = conversionScheme.get('include') if writeConversion else ''
conversionNamespace = conversionScheme.get('namespace') if writeConversion else ''
Expand Down Expand Up @@ -943,6 +944,8 @@ def isBuiltinType(name):

switchLines += '\tcase ' + idPrefix + name + ': '; # for by-type-id type constructor
getters += '\t[[nodiscard]] const ' + fullDataName(name) + ' &c_' + name + '() const;\n'; # const getter
if optimizeSingleData and withData and not withType:
getters += '\t[[nodiscard]] const ' + fullDataName(name) + ' &data() const;\n';
visitor += '\tcase ' + idPrefix + name + ': return base::match_method(c_' + name + '(), std::forward<Method>(method), std::forward<Methods>(methods)...);\n'

forwards += 'class ' + fullDataName(name) + ';\n'; # data class forward declaration
Expand All @@ -957,6 +960,11 @@ def isBuiltinType(name):
constructsBodies += '\treturn queryData<' + fullDataName(name) + '>();\n'
constructsBodies += '}\n'

if optimizeSingleData and withData and not withType:
constructsBodies += 'const ' + fullDataName(name) + ' &' + fullTypeName(restype) + '::data() const {\n'
constructsBodies += '\treturn queryData<' + fullDataName(name) + '>();\n'
constructsBodies += '}\n'

constructsText += '\texplicit ' + fullTypeName(restype) + '(const ' + fullDataName(name) + ' *data);\n'; # by-data type constructor
constructsBodies += fullTypeName(restype) + '::' + fullTypeName(restype) + '(const ' + fullDataName(name) + ' *data) : type_owner(data)'
if (withType):
Expand Down Expand Up @@ -1275,7 +1283,7 @@ def isBuiltinType(name):
methods += 'template void ' + fullTypeName(restype) + '::write<::tl::details::LengthCounter>(::tl::details::LengthCounter &to) const;\n'

typesText += '\n\tusing ResponseType = void;\n'; # no response types declared
if writeConversion:
if optimizeSingleData:
if withData and not withType:
for data in v:
name = data[0]
Expand Down

0 comments on commit f8ea3a1

Please sign in to comment.