Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

参数规范文件支持自定义枚举类型 #99

Merged

Conversation

zhaoxi-scut
Copy link
Member

Pull Request 合并请求准备清单

详情参见此处

  • 我同意在 Apache 2 开源许可下为本项目做贡献
  • 此 pull request 是在正确的分支上提出的
  • 此 pull request 有对应的错误报告或其他待改进的内容
  • 我本地的 RMVL 进行了单元测试、性能测试,有对应的测试数据
  • 我提交的 feature 有很好的文档记录,并且可以使用 CMake 项目构建示例代码

具体内容

新的 pull requrest 可以让参数规范文件支持自定义枚举类型,并对标 C++ 中的有作用域枚举 enum class,以下是 *.para 参数规范文件中使用自定义枚举的示例

enum ColorMode # 颜色模式
  BLUE = 1     # 蓝色
  GREEN        # 绿色
  RED
endenum

ColorMode COLOR_MODE = ColorMode::BLUE # 颜色模式

可以为每一个枚举项设置注释和值

生成的 *.h(*.hpp) 文件对应内容为

//! 颜色模式
enum class ColorMode
{
    //! 蓝色
    BLUE = 1,
    //! 绿色
    GREEN,
    //! RED
    RED,
};

    /* code */
    //! 颜色模式 @note 默认值:`ColorMode::BLUE`
    ColorMode COLOR_MODE = ColorMode::BLUE;
    /* code */

生成的 *.cpp 文件对应内容为

static const std::unordered_map<std::string, ColorMode> map_ColorMode = {
    {"BLUE", ColorMode::BLUE},
    {"GREEN", ColorMode::GREEN},
    {"RED", ColorMode::RED},
};

    /* code */
    node = fs["COLOR_MODE"];
    if (!node.isNone())
    {
        std::string tmp{};
        node >> tmp;
        COLOR_MODE = map_ColorMode.at(tmp);
    }
    /* code */
  • 此外,RMVL 对应的 Visual Studio Code 扩展插件也更新至了 1.3.2,添加了此功能的语法高亮

@zhaoxi-scut zhaoxi-scut added the feature 新特性、新功能 label Jun 22, 2024
@zhaoxi-scut zhaoxi-scut added this to the 1.4.0 milestone Jun 22, 2024
@zhaoxi-scut zhaoxi-scut force-pushed the rmvlpara-custom-enum-support branch from 2563bdd to 67ebe5e Compare June 22, 2024 10:07
@zhaoxi-scut zhaoxi-scut merged commit 9cc8a5e into cv-rmvl:master Jun 22, 2024
4 checks passed
@zhaoxi-scut zhaoxi-scut deleted the rmvlpara-custom-enum-support branch June 22, 2024 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature 新特性、新功能
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant