当前位置: 首页>>代码示例>>C++>>正文


C++ OptionalAttribute::get方法代码示例

本文整理汇总了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;
 }
开发者ID:MatthewSteen,项目名称:OpenStudio,代码行数:27,代码来源:OutputAttributeVariable.cpp

示例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

}
开发者ID:Anto-F,项目名称:OpenStudio,代码行数:79,代码来源:Attribute_GTest.cpp


注:本文中的OptionalAttribute::get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。