Yayin Story Studio logo Yayin Story Studio 项目文档
回到主页 用户手册

ASERStudio::AStorySyntax::AStoryXValueMeta Class

class ASERStudio::AStorySyntax::AStoryXValueMeta

AStoryXValue用于对AStoryX中的参数进行类型定义和检查. 详情...

头文件: #include <AStoryXValueMeta>
自以下版本: ASERStudio 2.0

公开类型

(自 ASERStudio 2.0 引入) enum Type { Undefined, String, Number, Integer, Float, …, MacroParameter }

公开成员函数

(自 ASERStudio 2.0 引入) AStoryXValueMeta()
(自 ASERStudio 2.0 引入) AStoryXValueMeta(const ASERStudio::AStorySyntax::AStoryXValueMeta &other)
(自 ASERStudio 2.0 引入) AStoryXValueMeta(ASERStudio::AStorySyntax::AStoryXValueMeta &&other)
(自 ASERStudio 2.0 引入) ~AStoryXValueMeta()
(自 ASERStudio 2.0 引入) QString getDefaultValue() const
(自 ASERStudio 2.1 引入) QList<qint64> getEnumCheckDimensions() const
(自 ASERStudio 2.0 引入) QStringList getEnumCheckList() const
(自 ASERStudio 2.0 引入) QPair<double, double> getFloatCheckRange() const
(自 ASERStudio 2.0 引入) QPair<qint64, qint64> getIntegerCheckRange() const
(自 ASERStudio 2.0 引入) QString getParameterName() const
(自 ASERStudio 2.0 引入) QString getStringCheckRegex() const
(自 ASERStudio 2.0 引入) ASERStudio::AStorySyntax::AStoryXValueMeta::Type getType() const
(自 ASERStudio 2.0 引入) QString getTypeString() const
(自 ASERStudio 2.1 引入) QList<qint64> getVectorCheckDimensions() const
(自 ASERStudio 2.0 引入) QList<QPair<double, double>> getVectorCheckRange() const
(自 ASERStudio 2.0 引入) ASERStudio::AStorySyntax::AStoryXDiagnosticData::DiagnosticType isTypeMatching(const QString &value) const
(自 ASERStudio 2.0 引入) void setDefaultValue(const QString &defaultValue)
(自 ASERStudio 2.1 引入) void setEnumCheckDimensions(const QList<qint64> &dimensions)
(自 ASERStudio 2.0 引入) void setEnumCheckList(const QStringList &enumList)
(自 ASERStudio 2.0 引入) void setFloatCheckRange(double min, double max)
(自 ASERStudio 2.0 引入) void setIntegerCheckRange(qint64 min, qint64 max)
(自 ASERStudio 2.0 引入) void setMetaData(const QString &paramName, const Visindigo::Utility::JsonConfig &metaData)
(自 ASERStudio 2.0 引入) void setParameterName(const QString &paramName)
(自 ASERStudio 2.0 引入) void setStringCheckRegex(const QString &regex)
(自 ASERStudio 2.0 引入) void setType(ASERStudio::AStorySyntax::AStoryXValueMeta::Type type)
(自 ASERStudio 2.1 引入) void setVectorCheckRange(const QList<QPair<double, double>> &range, const QList<qint64> &dimensions)
(自 ASERStudio 2.0 引入) ASERStudio::AStorySyntax::AStoryXValueMeta &operator=(ASERStudio::AStorySyntax::AStoryXValueMeta &&other)
(自 ASERStudio 2.0 引入) ASERStudio::AStorySyntax::AStoryXValueMeta &operator=(const ASERStudio::AStorySyntax::AStoryXValueMeta &other)

静态公开成员

(自 ASERStudio 2.0 引入) ASERStudio::AStorySyntax::AStoryXValueMeta::Type guessType(const QString &value)
(自 ASERStudio 2.0 引入) bool toBool(const QString &value)
(自 ASERStudio 2.0 引入) double toFloat(const QString &value)
(自 ASERStudio 2.0 引入) qint64 toInteger(const QString &value)
(自 ASERStudio 2.0 引入) QList<double> toVector(const QString &value)
(自 ASERStudio 2.0 引入) QString typeToString(ASERStudio::AStorySyntax::AStoryXValueMeta::Type type)

详细说明

AStoryXValueMeta提供了对AStoryX参数类型的定义和检查功能。用户可以为参数设置类型、 默认值以及各种检查规则(如正则表达式、数值范围等)。在解析AStoryX时,可以使用isTypeMatching方法来检查参数值是否符合预设的类型和规则, 并获取相应的诊断信息。

值得反复强调的是,AStoryXValueMeta是用于语法检查和数据转换的工具类, 而非类似于std::variant或QVariant的通用数据容器。虽然它提供了从字符串解析获得 其他数据类型的能力,但主要是为了方便在AStoryX语法解析过程中进行类型验证和错误诊断, 而不是作为一个通用的值存储类。

ValueMetaJSON

AStoryXValueMeta的元数据可以通过JSON配置进行设置,JSON的基础结构如下:

{
        "__ControllerName__":{
                "__ParameterName__":{
                        "type": "__ParameterType__",
                        "defaultValue": "__ParameterDefaultValue__"
                }
        }
}

即,对于每一个控制器,分别设置每个参数的元信息。其中ControllerName就是AStoryXController中给定的 枚举量的名称。ParameterName则为ASE-Remake文档中定义的参数名称。

值得指出的是,由于AStoryX的预处理部分不允许用户通过Rule.json自由定义,因此在本 ASERStudio和ASE-Remake本体中均为硬编码的,并非数据驱动配置。因此, ASERStudio::AStoryXSyntax::AStoryXController::ControllerType中的Preprocessor在本类中无效。

值的限制

整型和浮点型的范围限制

对于整型和浮点型量,如果同时存在上下限,则可以在参数中通过range字段,提供一个二元数组进行钳制,例如

"__ParameterName__":{
        "type": "Float",
        "defaultValue": "__ParameterDefaultValue__"
        "range": [0.0, 1.0]
}

如果只有上限或只有下限,则只对需设限的上限(max)或下限(min)进行单独设置即可。

Note: 值得指出的是,虽然整型和浮点型在设置默认值时需要用字符串表示,但在设置钳制范围时则应使用数字类型。

如果range和min、max同时存在,则range优先级更高,min和max将被忽略。 注意,即使没有设置对应的上限/下限,程序内部也会自动初始化为该类型的理论容限。 如整型上下限为int64的最小值和最大值,浮点型上下限为double的最小值和最大值。 因此,可以通过检查上下限的钳制设置是否为默认值来判断是否对该参数进行了钳制。

向量形的限制

对于向量类型,使用dimensions字段指定向量的许用维度。不指定时默认只有三维许用。

对于向量中的每一个分量,通过定义limit数组进行钳制,其中每一个数组内容都和设置单一浮点型/整型的钳制类似。 不需要设限的分量留空(但不能置为null)即可,例如:

"__ParameterName__":{
        "type": "Vector",
        "defaultValue": "0.0,0.0,0.0",
        "dimensions":  [3],
        "limit": [
                {
                        "min": 0.0
                },
                { },
                {
                        "range": [-1.0, 1.0]
                }
        ]
}

每个分量的钳制规则、优先级策略和默认值都和单一的整型/浮点型参数相同。

枚举型的限制

对于枚举型,则需要通过”enums"字段声明该枚举量的枚举列表名称,然后直接在MetaJson的根节点上 定义__GeneralMetaData__,并在其中用该名称定义具有全部枚举值的枚举列表,例如

{
        "__ControllerName__":{
                "__ParameterName__":{
                        "type": "Enum",
                        "defaultValue": "Value1",
                        "enums": "MyEnum1",
                        "dimensions": [1]
                }
        },
        "__GeneralMetaData__":{
                "MyEnum1": ["Value1", "Value2", "Value3"]
        }
}

此外,枚举型也可以使用dimensions字段来指定许用维度,以支持向量形枚举量(枚举组)的定义。 由于多数情况下枚举是单一值的,因此如果不指定dimensions字段,则默认为单值枚举。

字符串的限制

对于字符串类型,可以通过regex字段提供一个正则表达式来限制字符串的格式,例如

"__ParameterName__":{
        "type": "String",
        "defaultValue": "__ParameterDefaultValue__",
        "regex": "^[a-zA-Z0-9_]+$"
}

不提供regex时,不进行任何限制。

成员类型文档

[since ASERStudio 2.0] enum AStoryXValueMeta::Type

ConstantValueDescription
ASERStudio::AStorySyntax::AStoryXValueMeta::Undefined-1未定义类型,表示尚未设置具体类型。
ASERStudio::AStorySyntax::AStoryXValueMeta::String0字符串类型,参数值应为文本。
ASERStudio::AStorySyntax::AStoryXValueMeta::Number1数字类型,参数值应为数值(整数或浮点数)。
ASERStudio::AStorySyntax::AStoryXValueMeta::Integer2整数类型,参数值应为整数。
ASERStudio::AStorySyntax::AStoryXValueMeta::Float3浮点数类型,参数值应为浮点数。
ASERStudio::AStorySyntax::AStoryXValueMeta::Enum4枚举类型,参数值应为预定义的枚举值之一。
ASERStudio::AStorySyntax::AStoryXValueMeta::Vector5向量类型,参数值应为逗号分隔的数值列表。
ASERStudio::AStorySyntax::AStoryXValueMeta::Bool6布尔类型,参数值应为true/false、1/0、yes/no等表示布尔值的字符串。
ASERStudio::AStorySyntax::AStoryXValueMeta::None7无类型,参数值应为空字符串。
ASERStudio::AStorySyntax::AStoryXValueMeta::__META__8元类型起始,表示以下类型为元类型。
ASERStudio::AStorySyntax::AStoryXValueMeta::Comment9注释类型,表示该参数为注释。
ASERStudio::AStorySyntax::AStoryXValueMeta::Function10函数类型,表示该参数为函数名或符号。
ASERStudio::AStorySyntax::AStoryXValueMeta::Parameter11参数类型,表示该参数为函数参数
ASERStudio::AStorySyntax::AStoryXValueMeta::Keyword12关键字类型,表示该参数为关键字。
ASERStudio::AStorySyntax::AStoryXValueMeta::Macro13宏类型,表示该参数为宏名或符号。
ASERStudio::AStorySyntax::AStoryXValueMeta::MacroParameter14宏参数类型,表示该参数为宏参数。(自ASERStudio 2.1起添加)

这个enum 从 ASERStudio 2.0 开始支持。

成员函数文档

[since ASERStudio 2.0] AStoryXValueMeta::AStoryXValueMeta()

构造函数

这个function 从 ASERStudio 2.0 开始支持。

[since ASERStudio 2.0] AStoryXValueMeta::AStoryXValueMeta(const ASERStudio::AStorySyntax::AStoryXValueMeta &other)

other 另一个AStoryXValueMeta对象。

复制构造函数

这个function 从 ASERStudio 2.0 开始支持。

[noexcept, since ASERStudio 2.0] AStoryXValueMeta::AStoryXValueMeta(ASERStudio::AStorySyntax::AStoryXValueMeta &&other)

other 另一个AStoryXValueMeta对象。

移动构造函数

这个function 从 ASERStudio 2.0 开始支持。

[noexcept, since ASERStudio 2.0] AStoryXValueMeta::~AStoryXValueMeta()

析构函数

这个function 从 ASERStudio 2.0 开始支持。

[since ASERStudio 2.0] QString AStoryXValueMeta::getDefaultValue() const

return 默认值。

返回一个QString对象。如果未设置默认值,则返回空字符串。

这个function 从 ASERStudio 2.0 开始支持。

[since ASERStudio 2.1] QList<qint64> AStoryXValueMeta::getEnumCheckDimensions() const

return 枚举检查的维度。请注意,它和向量检查维度共用一个内部对象

保存数据,因此如果你中途切换该类的元数据,那么先前设置的维度可能会被覆盖或丢失。请确保在设置元数据时正确配置维度以避免潜在的问题。

这个function 从 ASERStudio 2.1 开始支持。

[since ASERStudio 2.0] QStringList AStoryXValueMeta::getEnumCheckList() const

return 枚举检查的列表。

返回一个QStringList对象,包含所有有效的枚举值。

如果未设置枚举检查列表,则返回一个空的QStringList对象。

这个function 从 ASERStudio 2.0 开始支持。

[since ASERStudio 2.0] QPair<double, double> AStoryXValueMeta::getFloatCheckRange() const

return 浮点数检查的范围。

返回一个QPair<double, double>对象,其中first表示最小值,second表示最大值。 如果未设置范围,则返回默认的QPair对象,其first和second均为0.0。

这个function 从 ASERStudio 2.0 开始支持。

[since ASERStudio 2.0] QPair<qint64, qint64> AStoryXValueMeta::getIntegerCheckRange() const

return 整数检查的范围。

返回一个QPair<qint64, qint64>对象,其中first表示最小值,second表示最大值。 如果未设置范围,则返回默认的QPair对象,其first和second均为0。

这个function 从 ASERStudio 2.0 开始支持。

[since ASERStudio 2.0] QString AStoryXValueMeta::getParameterName() const

return 参数名称。

返回一个QString对象。如果未设置参数名称,则返回空字符串。

这个function 从 ASERStudio 2.0 开始支持。

[since ASERStudio 2.0] QString AStoryXValueMeta::getStringCheckRegex() const

return 字符串检查的正则表达式。

返回一个QString对象。如果未设置正则表达式,则返回空字符串。

这个function 从 ASERStudio 2.0 开始支持。

[since ASERStudio 2.0] ASERStudio::AStorySyntax::AStoryXValueMeta::Type AStoryXValueMeta::getType() const

return 参数类型。

返回值为AStoryXValue::Type枚举中的一个值。

这个function 从 ASERStudio 2.0 开始支持。

[since ASERStudio 2.0] QString AStoryXValueMeta::getTypeString() const

return 参数类型的字符串表示。

这个function 从 ASERStudio 2.0 开始支持。

[since ASERStudio 2.1] QList<qint64> AStoryXValueMeta::getVectorCheckDimensions() const

return 向量检查的维度。

返回一个qint64的列表,代表允许的维度值列表。

如果未设置维度,则返回0。

这个function 从 ASERStudio 2.1 开始支持。

[since ASERStudio 2.0] QList<QPair<double, double>> AStoryXValueMeta::getVectorCheckRange() const

return 向量检查的范围。

返回一个QList<QPair<double, double>>对象,其中每个QPair表示一个维度的最小值和最大值。

如果未设置范围,则返回一个空的QList对象。

这个function 从 ASERStudio 2.0 开始支持。

[static, since ASERStudio 2.0] ASERStudio::AStorySyntax::AStoryXValueMeta::Type AStoryXValueMeta::guessType(const QString &value)

value 参数值,必须是一个QString对象。该函数将根据参数值的格式进行分析和判断,以猜测其可能的类型。

return 根据参数值的格式猜测参数类型。

注意,这个函数只会在如下类型中按顺序猜测:Integer、Float、Vector、Bool和String。 该函数最差(即前四种假设均失败时)也会返回String类型,而不会返回Undefined。

这个function 从 ASERStudio 2.0 开始支持。

[since ASERStudio 2.0] ASERStudio::AStorySyntax::AStoryXDiagnosticData::DiagnosticType AStoryXValueMeta::isTypeMatching(const QString &value) const

检查给定的参数值是否符合预设的类型和规则。

value 参数值,必须是一个QString对象。该值将根据当前设置的类型和检查规则进行验证。

return 诊断结果,返回一个AStoryXDiagnosticData::DiagnosticType枚举值,表示参数值的验证结果。

如果参数值符合预设的类型和规则,则返回AStoryXDiagnosticData::DiagnosticType::Undefined

如果参数值不符合预设的类型或规则,则返回相应的错误类型,如ParameterFormatError或ParameterOutOfRange等。

对于数字类型的超出范围以及枚举类型的无效值、或者向量某分量超出范围、枚举组某单值超出范围,返回ParameterOutOfRange;

对于格式错误的值,例如未满足维度要求的向量或枚举组,返回ParameterFormatError;

注意,这函数只检查Type在__META__之前的类型。__META__之后的类型是作为token使用的,不进行类型检查。 如果你检查它们,则永远得到Undefined的结果。

此外,它对空参数永远返回Undefined。

Note: 如果输入的参数值有块参数引用或变量引用,它会永远识别其为String类型从而导致ParameterFormatError结果。 因此,除了使用本函数检查外,你还应该单独确认参数值是否包含块参数引用或变量引用,并在诊断结果中适当处理这些情况。

这个function 从 ASERStudio 2.0 开始支持。

[since ASERStudio 2.0] void AStoryXValueMeta::setDefaultValue(const QString &defaultValue)

设置默认值。 defaultValue 默认值,必须是一个QString对象。默认值的格式应与参数类型相匹配。

这个function 从 ASERStudio 2.0 开始支持。

[since ASERStudio 2.1] void AStoryXValueMeta::setEnumCheckDimensions(const QList<qint64> &dimensions)

dimensions 枚举检查的维度,必须是一个QList<qint64>对象,表示允许的维度值列表。

设置枚举检查的维度。请注意,它和向量检查维度共用一个内部对象

保存数据,因此如果你中途切换该类的元数据,那么先前设置的维度可能会被覆盖或丢失。请确保在设置元数据时正确配置维度以避免潜在的问题。

这个function 从 ASERStudio 2.1 开始支持。

[since ASERStudio 2.0] void AStoryXValueMeta::setEnumCheckList(const QStringList &enumList)

设置枚举检查的列表。 enumList 枚举检查列表,必须是一个QStringList对象,包含所有有效的枚举值。

这个function 从 ASERStudio 2.0 开始支持。

[since ASERStudio 2.0] void AStoryXValueMeta::setFloatCheckRange(double min, double max)

设置浮点数检查的范围。 min 最小值,必须是一个double类型的数值。 max 最大值,必须是一个double类型的数值。max必须大于或等于min。

这个function 从 ASERStudio 2.0 开始支持。

[since ASERStudio 2.0] void AStoryXValueMeta::setIntegerCheckRange(qint64 min, qint64 max)

设置整数检查的范围。 min 最小值,必须是一个qint64类型的整数。 max 最大值,必须是一个qint64类型的整数。max必须大于或等于min。

这个function 从 ASERStudio 2.0 开始支持。

[since ASERStudio 2.0] void AStoryXValueMeta::setMetaData(const QString &paramName, const Visindigo::Utility::JsonConfig &metaData)

paramName 参数名称,必须是一个有效的QString对象。 metaData 元数据配置,必须是一个有效的Visindigo::Utility::JsonConfig对象,且应包含与参数名称对应的元数据信息。

设置元数据。

这个function 从 ASERStudio 2.0 开始支持。

[since ASERStudio 2.0] void AStoryXValueMeta::setParameterName(const QString &paramName)

设置参数名称。 paramName 参数名称,必须是一个有效的QString对象。

这个function 从 ASERStudio 2.0 开始支持。

[since ASERStudio 2.0] void AStoryXValueMeta::setStringCheckRegex(const QString &regex)

设置字符串检查的正则表达式。

regex 正则表达式,必须是一个有效的QString对象。该正则表达式将用于验证字符串类型参数的格式。

这个function 从 ASERStudio 2.0 开始支持。

[since ASERStudio 2.0] void AStoryXValueMeta::setType(ASERStudio::AStorySyntax::AStoryXValueMeta::Type type)

设置参数类型。 type 参数类型,必须是AStoryXValue::Type枚举中的一个值。

这个function 从 ASERStudio 2.0 开始支持。

[since ASERStudio 2.1] void AStoryXValueMeta::setVectorCheckRange(const QList<QPair<double, double>> &range, const QList<qint64> &dimensions)

设置向量检查的范围和维度。

range 向量检查范围,必须是一个QList<QPair<double, double>>对象,其中每个QPair表示一个维度的最小值和最大值。 range的大小必须等于dimensions中的最大值。

dimensions 向量维度,必须是一个QList<qint64>对象,表示允许的维度值列表。dimensions中的每个值必须大于0。

这个function 从 ASERStudio 2.1 开始支持。

[static, since ASERStudio 2.0] bool AStoryXValueMeta::toBool(const QString &value)

将参数值转换为布尔值。

value 参数值,必须是一个符合布尔类型要求的QString对象,例如"true"、"false"、"1"、"0"、"yes"或"no"等。

return 转换结果,返回一个bool类型的值。如果转换失败(例如参数值不符合布尔格式),则返回false。

这函数不做任何检查。

这个function 从 ASERStudio 2.0 开始支持。

[static, since ASERStudio 2.0] double AStoryXValueMeta::toFloat(const QString &value)

将参数值转换为浮点数。

value 参数值,必须是一个符合浮点数类型要求的QString对象。

return 转换结果,返回一个double类型的数值。如果转换失败(例如参数值不符合浮点数格式),则返回0.0。

这函数不做任何检查。

这个function 从 ASERStudio 2.0 开始支持。

[static, since ASERStudio 2.0] qint64 AStoryXValueMeta::toInteger(const QString &value)

将参数值转换为整数。

value 参数值,必须是一个符合整数类型要求的QString对象。

return 转换结果,返回一个qint64类型的整数。如果转换失败(例如参数值不符合整数格式),则返回0。

这函数不做任何检查。

这个function 从 ASERStudio 2.0 开始支持。

[static, since ASERStudio 2.0] QList<double> AStoryXValueMeta::toVector(const QString &value)

将参数值转换为向量。

value 参数值,必须是一个符合向量类型要求的QString对象,即逗号分隔的数值列表。

return 转换结果,返回一个QList<double>对象,包含向量的各个分量。

如果整体切分失败,可能返回一个包含唯一0值的列表;如果切分成功但某个分量转换失败,则该分量的值为0。

这函数不做任何检查。

这个function 从 ASERStudio 2.0 开始支持。

[static, since ASERStudio 2.0] QString AStoryXValueMeta::typeToString(ASERStudio::AStorySyntax::AStoryXValueMeta::Type type)

type 参数类型,必须是AStoryXValueMeta::Type枚举中的一个值。

return 将参数类型枚举值转换为字符串表示。

这个function 从 ASERStudio 2.0 开始支持。

[noexcept, since ASERStudio 2.0] ASERStudio::AStorySyntax::AStoryXValueMeta &AStoryXValueMeta::operator=(ASERStudio::AStorySyntax::AStoryXValueMeta &&other)

other 另一个AStoryXValueMeta对象。

移动赋值运算符

这个function 从 ASERStudio 2.0 开始支持。

[since ASERStudio 2.0] ASERStudio::AStorySyntax::AStoryXValueMeta &AStoryXValueMeta::operator=(const ASERStudio::AStorySyntax::AStoryXValueMeta &other)

other 另一个AStoryXValueMeta对象。

复制赋值运算符

这个function 从 ASERStudio 2.0 开始支持。