本文整理汇总了C++中OptionalAttribute::get方法的典型用法代码示例。如果您正苦于以下问题:C++ OptionalAttribute::get方法的具体用法?C++ OptionalAttribute::get怎么用?C++ OptionalAttribute::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OptionalAttribute
的用法示例。
在下文中一共展示了OptionalAttribute::get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: container
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
}