SIT/templates/README.md

48 lines
1.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 代码模板说明
本目录包含用于自动生成C/C++代码的Jinja2模板。
## 模板结构
### cpp/ 目录
包含C++代码生成模板:
- **tcp_receiver.template**: TCP协议数据接收器模板
- **dds_receiver.template**: DDS协议数据接收器模板
- **deserializer.template**: 反序列化器模板支持JSON/XML/Binary
- **mapper.template**: 字段映射器模板
- **serializer.template**: 序列化器模板支持JSON/XML/Binary
- **sender.template**: 数据发送器模板
## 模板变量
模板中可用的变量:
- `source_message`: 源消息对象
- `target_message`: 目标消息对象
- `mapping_path`: 映射路径(边列表)
- `protocol`: 传输协议TCP/UDP/DDS等
- `serialization`: 序列化格式JSON/XML/Binary
- `language_standard`: 语言标准C++11/14/17/20
- `part`: 当前生成部分('header' 或 'source'
## 自定义模板
可以添加自定义模板来支持其他协议或语言:
1. 在相应目录下创建 `.template` 文件
2. 使用Jinja2语法编写模板
3.`code_generator_service.py` 中注册模板
## 示例
```jinja2
{# 示例模板 #}
{% if part == 'header' %}
#pragma once
// 头文件内容
{% else %}
#include "header.h"
// 源文件内容
{% endif %}