# codegen **Repository Path**: tangm421/codegen ## Basic Information - **Project Name**: codegen - **Description**: No description available - **Primary Language**: C++ - **License**: 0BSD - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-02-05 - **Last Updated**: 2021-10-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # codegen code gengrator for sipserver xml and json class file ## how to use ``` Usage: ./codegen.exe [OPTION...] file/directory -b, --base=STRING The class name of the parent class that needs to be inherited -t, --type=json|xml|auto Type of in file content -e, --ext=STRING Extension of out file, such as `h` or `hxx`, default is `hxx` -l, --log=FILE Output generation log to FILE -v, --version Show version Options for indentation --disable-indent Flag Whether to disable indentation --reserve-tab Flag Whether to reserver tab as indentation leading, effective when --disable-indent is specified -s, --space=SIZE Replace tabs with spaces counted by SIZE as indentation, effective when --disable-indent is specified Options for help -h, --help Show this help message -u, --usage Display brief usage message ``` ### 说明 |选项|参数类型|参数|说明|默认值| |-|-|-|-|-| |-b, --base|string||需要继承(public)的父类类名|默认无继承| |-t, --type|string|`json`/`xml`(暂未实现)/`auto`|描述文件类型|默认为`auto`| |-e, --ext|string||生成的类文件名后缀,例如`h`、`hxx`、`hpp`|默认为`h`| |-l, --log|string||用于生成过程的日志文件路径|默认为空,不生成日志文件| |-v, --version||无|显示本工具版本号|| |--disable-indent||无|是否启用缩进|默认启用| |--reserve-tab||无|是否保留tab符,在启用缩进时有效|默认不保留,使用空格替换| |-s, --space|unsigned int||空格替换tab符时的空格个数,在启用缩进时有效|默认4个空格符替换一个tab符| 命令中无选项的参数 file/directory 代表指定的文件名或者文件夹路径,当指定路径为文件夹时,生成工具会遍历(无递归)文件夹中所有的文件并启动生成,生成的文件位于该文件夹下。 ### 示例 文件: ``` ./codegen.exe -t json -l gen.log /e/gitlab/sipserver/docs/internal-rules/AppServer/json-message/.4508-45.899-7800_56-adew-78.hxx.json ``` 文件夹: ``` ./codegen.exe -t json -l gen.log /e/gitlab/sipserver/docs/internal-rules/AppServer/json-message/ ``` ## build cmake ## 规则 ### 描述文件 即输入文件, 目前的生成工具仅根据`xml`和`json`格式的描述文件生成对应类文件。 ### 类文件 即输出文件, 类文件的文件名和描述文件的文件名一致,只是文件后缀替换为指定的后缀名。 生成工具根据描述文件格式解析并生成对应的文件类及其嵌套类,并将声明和定义统一实现在单个文件中。 每个文件生成类的类名是根据描述文件的文件名生成,具体规则如下: - 描述文件的文件名中凡是不属于`_`、`a-z`、`A-Z`此三类的字符均会被替换为`_` - 描述文件的文件名后缀若是多级,则只有最后一级后缀被去除 例如 输入文件:`./45-899-7800_56-adew-78.hxx.json` 输出文件:`./_______________adew____hxx.h` ## 描述文件 ### json - 不支持空的数组或者嵌套数组的形式 - 键值对中的值会作为对象成员的初始化值 - 数组对应STL的vector - 数组元素为对象时元素对象以指针形式存储,构建对象时需要调用方申请动态对象并传入(不需要释放) - 字符串对应STL的string,当json生成类指定继承类时,字符串类型会定义为ASString。 ```json { "Sequence": "39009a13da365d6d071cd469a952bb77", "Command": "ConfigMSNotify", "Config": [ { "Action": 1, "MediaServerId": "ZKMS1001", "MaxConf": 2, "MaxMember": 20 }, { "Action": 3, "MediaServerId": "ZKMS1002", "MaxConf": 1, "MaxMember": 9 } ] } ``` ### xml