本文整理汇总了C++中OSArgument::hasDomain方法的典型用法代码示例。如果您正苦于以下问题:C++ OSArgument::hasDomain方法的具体用法?C++ OSArgument::hasDomain怎么用?C++ OSArgument::hasDomain使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OSArgument
的用法示例。
在下文中一共展示了OSArgument::hasDomain方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
TEST_F(RulesetFixture, OSArgument_Domain) {
OSArgument doubleArg = OSArgument::makeDoubleArgument("double", true);
OSArgument integerArg = OSArgument::makeIntegerArgument("integer", true);
OSArgument stringArg = OSArgument::makeStringArgument("string", true);
EXPECT_FALSE(doubleArg.hasDomain());
EXPECT_FALSE(integerArg.hasDomain());
EXPECT_FALSE(stringArg.hasDomain());
double d = 0.0;
int i = 0;
EXPECT_TRUE(doubleArg.setMinValue(d));
EXPECT_TRUE(integerArg.setMinValue(i));
EXPECT_FALSE(stringArg.setMinValue(0.0));
ASSERT_TRUE(doubleArg.hasDomain());
ASSERT_TRUE(integerArg.hasDomain());
EXPECT_FALSE(stringArg.hasDomain());
EXPECT_EQ(0.0, doubleArg.domainAsDouble()[0]);
EXPECT_EQ(std::numeric_limits<double>::max(), doubleArg.domainAsDouble()[1]);
EXPECT_EQ(0, integerArg.domainAsInteger()[0]);
EXPECT_EQ(std::numeric_limits<int>::max(), integerArg.domainAsDouble()[1]);
d = 1.0;
i = 1;
EXPECT_TRUE(doubleArg.setMaxValue(i));
EXPECT_TRUE(integerArg.setMaxValue(d));
EXPECT_FALSE(stringArg.setMaxValue(1));
ASSERT_TRUE(doubleArg.hasDomain());
ASSERT_TRUE(integerArg.hasDomain());
EXPECT_FALSE(stringArg.hasDomain());
EXPECT_EQ(0.0, doubleArg.domainAsDouble()[0]);
EXPECT_EQ(1.0, doubleArg.domainAsDouble()[1]);
EXPECT_EQ(0, integerArg.domainAsInteger()[0]);
EXPECT_EQ(1, integerArg.domainAsDouble()[1]);
// the domain is not currently used to validate these values
EXPECT_TRUE(doubleArg.setValue(-1.0));
EXPECT_TRUE(doubleArg.setValue(0.0));
EXPECT_TRUE(doubleArg.setValue(0.5));
EXPECT_TRUE(doubleArg.setValue(1.0));
EXPECT_TRUE(doubleArg.setValue(2.0));
EXPECT_TRUE(integerArg.setValue(-1));
EXPECT_TRUE(integerArg.setValue(0));
EXPECT_TRUE(integerArg.setValue(1));
EXPECT_TRUE(integerArg.setValue(2));
}
示例2: toVariant
QVariant toVariant(const OSArgument& argument) {
QVariantMap argumentData;
argumentData["uuid"] = toQString(removeBraces(argument.uuid()));
argumentData["version_uuid"] = toQString(removeBraces(argument.versionUUID()));
argumentData["name"] = toQString(argument.name());
if (!argument.displayName().empty()) {
argumentData["display_name"] = toQString(argument.displayName());
}
if (argument.description() && !argument.description()->empty()) {
argumentData["description"] = toQString(argument.description().get());
}
OSArgumentType type = argument.type();
if (argument.units() && !argument.units()->empty()) {
argumentData["units"] = toQString(argument.units().get());
}
argumentData["type"] = toQString(type.valueName());
argumentData["required"] = argument.required();
argumentData["model_dependent"] = argument.modelDependent();
if (argument.hasValue()) {
if (type == OSArgumentType::Quantity) {
Quantity value = argument.valueAsQuantity();
argumentData["value"] = value.value();
argumentData["value_units"] = toQString(value.units().standardString());
}
else {
// use QVariant directly
argumentData["value"] = argument.valueAsQVariant();
}
}
if (argument.hasDefaultValue()) {
if (type == OSArgumentType::Quantity) {
Quantity defaultValue = argument.defaultValueAsQuantity();
argumentData["default_value"] = defaultValue.value();
argumentData["default_value_units"] = toQString(defaultValue.units().standardString());
}
else {
// use QVariant directly
argumentData["default_value"] = argument.defaultValueAsQVariant();
}
}
argumentData["domain_type"] = toQString(argument.domainType().valueName());
if (argument.hasDomain()) {
QVariantList domainList;
int index(0);
for (const QVariant& dval : argument.domainAsQVariant()) {
QVariantMap domainValueMap;
domainValueMap["domain_value_index"] = index;
if (type == OSArgumentType::Quantity) {
Quantity q = dval.value<openstudio::Quantity>();
domainValueMap["value"] = q.value();
domainValueMap["units"] = toQString(q.units().standardString());
}
else {
domainValueMap["value"] = dval;
}
domainList.push_back(domainValueMap);
++index;
}
argumentData["domain"] = domainList;
}
if (type == OSArgumentType::Choice) {
QVariantList choicesList;
StringVector displayNames = argument.choiceValueDisplayNames();
int index(0), displayNamesN(displayNames.size());
for (const std::string& choice : argument.choiceValues()) {
QVariantMap choiceMap;
choiceMap["choice_index"] = index;
choiceMap["value"] = toQString(choice);
if (index < displayNamesN) {
choiceMap["display_name"] = toQString(displayNames[index]);
}
choicesList.push_back(choiceMap);
++index;
}
argumentData["choices"] = QVariant(choicesList);
}
if (type == OSArgumentType::Path) {
argumentData["is_read"] = argument.isRead();
argumentData["extension"] = toQString(argument.extension());
}
return QVariant(argumentData);
}