File indexing completed on 2024-05-19 05:42:15

0001 import sys
0002 from handlers import HANDLERS
0003 
0004 
0005 if __name__ == "__main__":
0006     # Note: Please don't use JINJA for code generation, since some users don't have it installed.
0007     output_path = sys.argv[1]
0008     filename = 'ct_lvtplg_basicpluginhandlers.h'
0009 
0010     contents = []
0011     contents.append("// This file is automatically generated. Do not modify it directly - Use the generator file instead.")
0012     contents.append('')
0013     contents.append('')
0014 
0015     contents.append(f"// ct_lvtplg_{filename}.h                                         -*-C++-*-")
0016     contents.append('')
0017     contents.append('// Copyright 2023 Codethink Ltd <codethink@codethink.co.uk>')
0018     contents.append('// SPDX-License-Identifier: Apache-2.0')
0019     contents.append('//')
0020     contents.append('// Licensed under the Apache License, Version 2.0 (the "License");')
0021     contents.append('// you may not use this file except in compliance with the License.')
0022     contents.append('// You may obtain a copy of the License at')
0023     contents.append('//')
0024     contents.append('//     http://www.apache.org/licenses/LICENSE-2.0')
0025     contents.append('//')
0026     contents.append('// Unless required by applicable law or agreed to in writing, software')
0027     contents.append('// distributed under the License is distributed on an "AS IS" BASIS,')
0028     contents.append('// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.')
0029     contents.append('// See the License for the specific language governing permissions and')
0030     contents.append('// limitations under the License.')
0031 
0032     contents.append("#ifndef DIAGRAM_SERVER_CT_LVTPLG_BASICPLUGINHANDLERS_H")
0033     contents.append("#define DIAGRAM_SERVER_CT_LVTPLG_BASICPLUGINHANDLERS_H")
0034     contents.append('')
0035     contents.append(f'#include <ct_lvtplg_plugindatatypes.h>')
0036     contents.append(f'')
0037     contents.append('#include <any>')
0038     contents.append('#include <functional>')
0039     contents.append('#include <optional>')
0040     contents.append('#include <string>')
0041     contents.append('#include <tuple>')
0042     contents.append('#include <vector>')
0043     contents.append('')
0044 
0045     for handler_info in HANDLERS:
0046         contents.append(f'struct {handler_info.name};')
0047     contents.append('')
0048 
0049     for handler_info in HANDLERS:
0050         contents.append(f'struct {handler_info.name} {{')
0051         for f in handler_info.functions:
0052             params = ','.join([f'{p.type} {p.name}' for p in f.params])
0053             contents.append(f'// {f.docs}')
0054             contents.append(f'std::function<{f.return_type}({params})> const {f.name};')
0055             contents.append(f'')
0056         contents.append(f'}};')
0057         contents.append(f'')
0058     contents.append('')
0059 
0060     contents.append("#endif")
0061 
0062     with open(output_path + "/" + filename, 'w') as f:
0063         f.write('\n'.join(contents))