本文整理汇总了C++中OptionalAttribute类的典型用法代码示例。如果您正苦于以下问题:C++ OptionalAttribute类的具体用法?C++ OptionalAttribute怎么用?C++ OptionalAttribute使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OptionalAttribute类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getOption
int SamplingAlgorithmOptions_Impl::samples() const {
int result;
OptionalAttribute option = getOption("samples");
BOOST_ASSERT(option);
result = option->valueAsInteger();
return result;
}
示例2: getValue
double OutputAttributeVariable_Impl::getValue(const DataPoint& dataPoint) const {
OptionalAttribute oa = dataPoint.getOutputAttribute(m_attributeName);
if (!oa) {
LOG_AND_THROW("Unable to retrieve attribute '" << m_attributeName << "' for DataPoint at "
<< toString(dataPoint.directory()) << ".");
}
Attribute attribute = oa.get();
OptionalDouble result;
AttributeValueType valueType = attribute.valueType();
if (valueType == AttributeValueType::Double) {
result = attribute.valueAsDouble();
}
if (valueType == AttributeValueType::Quantity) {
result = attribute.valueAsQuantity().value();
}
if (valueType == AttributeValueType::Integer) {
result = double(attribute.valueAsInteger());
}
if (valueType == AttributeValueType::Unsigned) {
result = double(attribute.valueAsUnsigned());
}
if (!result) {
LOG_AND_THROW("Unable to extract double value from attribute '" << m_attributeName
<< "' of type " << valueType.valueDescription() << ".");
}
return *result;
}
示例3: LOG
bool SamplingAlgorithmOptions_Impl::setSamples(int value) {
if (value < 1) {
LOG(Warn,"Cannot set SamplingAlgorithmOptions samples to a value less than one.");
return false;
}
OptionalAttribute option = getOption("samples");
BOOST_ASSERT(option);
option->setValue(value);
return true;
}
示例4: setSeed
void DDACEAlgorithmOptions_Impl::setSeed(int value){
OptionalAttribute option;
if ((option = getOption("seed"))) {
option->setValue(value);
}
else {
option = Attribute("seed",value);
saveOption(*option);
}
}
示例5: setSymbols
bool DDACEAlgorithmOptions_Impl::setSymbols(int value) {
OptionalAttribute option;
if ((option = getOption("symbols"))) {
option->setValue(value);
}
else {
option = Attribute("symbols",value);
saveOption(*option);
}
return true;
}
示例6: QString
void OSIntegerEdit::refreshTextAndLabel() {
if (m_modelObject) {
QString textValue;
ModelObject modelObject = m_modelObject.get();
std::stringstream ss;
if (m_isAutosizedProperty) {
Attribute autosized = modelObject.getAttribute(*m_isAutosizedProperty).get();
if (autosized.valueAsBoolean()) {
textValue = QString("autosize");
}
}
if (m_isAutocalculatedProperty) {
Attribute autocalculated = modelObject.getAttribute(*m_isAutocalculatedProperty).get();
if (autocalculated.valueAsBoolean()) {
textValue = QString("autocalculate");
}
}
OptionalAttribute attribute = modelObject.getAttribute(m_property);
if (attribute) {
int value = attribute->valueAsInteger();
if (m_isScientific) {
ss << std::scientific;
}
else {
ss << std::fixed;
}
if (m_precision) {
ss << std::setprecision(*m_precision);
}
ss << value;
textValue = toQString(ss.str());
ss.str("");
}
this->setText(textValue);
if (m_isDefaultedProperty) {
Attribute defaulted = modelObject.getAttribute(*m_isDefaultedProperty).get();
if (defaulted.valueAsBoolean()) {
this->setStyleSheet("color:green");
}
else {
this->setStyleSheet("color:black");
}
}
}
}
示例7: LOG
bool ParameterStudyAlgorithmOptions_Impl::setNumSteps(int value) {
if (value < 1) {
LOG(Warn,"Cannot set ParameterStudyAlgorithmOptions numSteps to a value less than one.");
return false;
}
OptionalAttribute option;
if ((option = getOption("numSteps"))) {
option->setValue(value);
}
else {
option = Attribute("numSteps",value);
saveOption(*option);
}
return true;
}
示例8: LOG
bool PSUADEDaceAlgorithmOptions_Impl::setSamples(int value) {
if (value < 1) {
LOG(Warn,"Cannot set PSUADEDaceAlgorithmOptions samples to a value less than one.");
return false;
}
OptionalAttribute option;
if ((option = getOption("samples"))) {
option->setValue(value);
}
else {
option = Attribute("samples",value);
saveOption(*option);
}
return true;
}
示例9: TEST_F
TEST_F(DataFixture, Attribute_Source) {
AttributeVector attributes;
// create vector of attributes with no sources
attributes.push_back(Attribute("My Boolean Attribute",false));
attributes.push_back(Attribute("My Double Attribute",34.2,"W"));
attributes.push_back(Attribute("My Integer Attribute",5));
attributes.push_back(Attribute("My String Attribute","flat finish"));
attributes.push_back(Attribute("tricky_source","don't talk back"));
// xml and back
Attribute container("Containing Attribute",attributes);
QDomDocument doc = container.toXml();
OptionalAttribute containerCopy = Attribute::loadFromXml(doc);
ASSERT_TRUE(containerCopy);
AttributeVector attributesCopy = containerCopy.get().valueAsAttributeVector();
EXPECT_EQ(attributes.size(),attributesCopy.size());
for (const Attribute& attributeCopy : attributesCopy) {
EXPECT_TRUE(attributeCopy.source().empty());
}
// json and back
QVariant variant = detail::toVariant(attributes);
int n = variant.toMap().size();
attributesCopy = detail::toVectorOfAttribute(variant,VersionString(openStudioVersion()));
EXPECT_EQ(attributes.size(),attributesCopy.size());
for (const Attribute& attributeCopy : attributesCopy) {
EXPECT_TRUE(attributeCopy.source().empty());
}
// apply same source to all attributes
for (Attribute& attribute : attributes) {
attribute.setSource("big data set");
}
// xml and back
doc = container.toXml();
containerCopy = Attribute::loadFromXml(doc);
ASSERT_TRUE(containerCopy);
attributesCopy = containerCopy.get().valueAsAttributeVector();
EXPECT_EQ(attributes.size(),attributesCopy.size());
for (const Attribute& attributeCopy : attributesCopy) {
EXPECT_EQ("big data set",attributeCopy.source());
}
// json and back
variant = detail::toVariant(attributes);
EXPECT_EQ(n+1,variant.toMap().size());
attributesCopy = detail::toVectorOfAttribute(variant,VersionString(openStudioVersion()));
EXPECT_EQ(attributes.size(),attributesCopy.size());
for (const Attribute& attributeCopy : attributesCopy) {
EXPECT_EQ("big data set",attributeCopy.source());
}
// change one attribute's source to something different
attributes[2].setSource("a wiki");
// xml and back
doc = container.toXml();
containerCopy = Attribute::loadFromXml(doc);
ASSERT_TRUE(containerCopy);
attributesCopy = containerCopy.get().valueAsAttributeVector();
EXPECT_EQ(attributes.size(),attributesCopy.size());
for (const Attribute& attributeCopy : attributesCopy) {
EXPECT_FALSE(attributeCopy.source().empty());
}
EXPECT_EQ("a wiki",attributesCopy[2].source());
// json and back
variant = detail::toVariant(attributes);
EXPECT_EQ(n+attributes.size(),variant.toMap().size());
attributesCopy = detail::toVectorOfAttribute(variant,VersionString(openStudioVersion()));
EXPECT_EQ(attributes.size(),attributesCopy.size());
for (const Attribute& attributeCopy : attributesCopy) {
EXPECT_FALSE(attributeCopy.source().empty());
}
// order is not guaranteed
}
示例10: getOption
int SequentialSearchOptions_Impl::objectiveToMinimizeFirst() const {
OptionalAttribute option = getOption("objectiveToMinimizeFirst");
BOOST_ASSERT(option);
return option->valueAsInteger();
}