| | |
| | | enum PropertyType { |
| | | kPropertyTypeBoolean, |
| | | kPropertyTypeInteger, |
| | | kPropertyTypeNumber, |
| | | kPropertyTypeString |
| | | }; |
| | | |
| | |
| | | private: |
| | | std::string name_; |
| | | PropertyType type_; |
| | | std::variant<bool, int, std::string> value_; |
| | | std::variant<bool, int, double, std::string> value_; |
| | | bool has_default_value_; |
| | | std::optional<int> min_value_; // 新增:整数最小值 |
| | | std::optional<int> max_value_; // 新增:整数最大值 |
| | |
| | | if (max_value_.has_value()) { |
| | | cJSON_AddNumberToObject(json, "maximum", max_value_.value()); |
| | | } |
| | | } else if (type_ == kPropertyTypeNumber) { |
| | | cJSON_AddStringToObject(json, "type", "number"); |
| | | if (has_default_value_) { |
| | | cJSON_AddNumberToObject(json, "default", value<double>()); |
| | | } |
| | | } else if (type_ == kPropertyTypeString) { |
| | | cJSON_AddStringToObject(json, "type", "string"); |
| | | if (has_default_value_) { |