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


C++ Quantity::value方法代码示例

本文整理汇总了C++中Quantity::value方法的典型用法代码示例。如果您正苦于以下问题:C++ Quantity::value方法的具体用法?C++ Quantity::value怎么用?C++ Quantity::value使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Quantity的用法示例。


在下文中一共展示了Quantity::value方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: masslessOpaqueMaterial

TEST_F(ModelFixture,MasslessOpaqueMaterial_VisibleAbsorptance_Quantity) {
  Model model;
  // TODO: Check constructor.
  MasslessOpaqueMaterial masslessOpaqueMaterial(model);

  Unit units = masslessOpaqueMaterial.getVisibleAbsorptance(true).units(); // Get IP units.

  // Bounds: 0.0 <= value <= 1.0

  double value(1.0);
  Quantity testQ(value,units);
  EXPECT_TRUE(masslessOpaqueMaterial.setVisibleAbsorptance(testQ));
  Quantity q = masslessOpaqueMaterial.getVisibleAbsorptance(true);
  EXPECT_NEAR(value,q.value(),1.0E-8);
  EXPECT_EQ(units.standardString(),q.units().standardString());
}
开发者ID:jtanaa,项目名称:OpenStudio,代码行数:16,代码来源:MasslessOpaqueMaterial_GTest.cpp

示例2: scale

OSQuantityVector::OSQuantityVector(const std::vector<Quantity>& values)
  : m_units(), m_values(values.size(),0.0)
{
  if (!values.empty()) {
    m_units = values[0].units();
  }
  const Scale& myScale = scale();
  for (unsigned i = 0, n = size(); i < n; ++i) {
    if (!(values[i].units() == m_units)) {
      LOG_AND_THROW("Quantity " << values[i] << " has units inconsistent with the first "
                    << "Quantity in vector values, " << values[0] << ".");
    }
    if (values[i].scale() != myScale) {
      Quantity working = values[i];
      working.setScale(myScale.exponent);
      m_values[i] = working.value();
    }
    else {
      m_values[i] = values[i].value();
    }
  }
}
开发者ID:jtanaa,项目名称:OpenStudio,代码行数:22,代码来源:OSQuantityVector.cpp

示例3: 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);
  }
开发者ID:MatthewSteen,项目名称:OpenStudio,代码行数:84,代码来源:OSArgument.cpp

示例4: len

TEST_F(UnitsFixture,Quantity_ArithmeticOperators)
{
  LOG(Debug,"Quantity_ArithmeticOperators");

  Quantity q1;
  Quantity q2(1.0);

  Unit u3;
  u3.setBaseUnitExponent("ft",1);
  Quantity q3(34.2,u3);

  // addition
  Quantity q4 = q1 + q2;
  q4 += q4;
  testNumbersEqual(2.0,q4.value());
  testStreamOutput("2",q4);
  ASSERT_THROW(q3 + q1,Exception);

  // subtraction;
  ASSERT_THROW(q3 - q1,Exception);
  Quantity len(3.5,u3);
  len -= q3;
  testNumbersEqual(-30.7,len.value());
  testStreamOutput("-30.7 ft",len,1);

  // multiplication
  q3 *= q4;
  testNumbersEqual(68.4,q3.value());
  testStreamOutput("68.4 ft",q3,1);

  Unit u5;
  u5.setBaseUnitExponent("s",-2);
  u5.setBaseUnitExponent("ft",1);
  Quantity q5(0.5,u5);
  Quantity q6 = q5 * q3;
  testNumbersEqual(34.2,q6.value());
  testStreamOutput("34.2 ft^2/s^2",q6,1);

  // division
  len = Quantity(1.1,u3);
  Quantity a = q6/len;
  testNumbersEqual(31.0909090909,a.value());
  EXPECT_EQ("ft/s^2",a.standardUnitsString());

  // pow
  a.pow(6);
  EXPECT_EQ("ft^6/s^12",a.standardUnitsString());
  Quantity b = openstudio::pow(a,1,3);
  EXPECT_EQ("ft^2/s^4",b.standardUnitsString());
  testNumbersEqual(966.644628099,b.value());
  a = b;

  // multiplication and division with double
  a *= 1.21;
  testNumbersEqual(1169.64,a.value());
  b = a/2;
  testNumbersEqual(584.82,b.value());
  EXPECT_EQ("ft^2/s^4",b.standardUnitsString());
  EXPECT_EQ("",b.prettyUnitsString());

  Quantity c = 32.0/b;
  EXPECT_EQ("s^4/ft^2",c.standardUnitsString());
  testNumbersEqual(0.054717690913,c.value());

  // Operations on Quantities with units of temperature
  LOG(Debug,"Quantity_FahrenheitUnit_Arithmetic");

  FahrenheitUnit fu1(1, 0, "");
  Quantity T1(60.0,fu1);
  FahrenheitUnit fu2(1);
  Quantity T2(74.0,fu2);
  Quantity TT1 = pow(T1,2);
  Quantity TT2 = pow(T2,2);

  EXPECT_TRUE(TT1.isAbsolute());
  EXPECT_TRUE(TT2.isAbsolute());

  Quantity q;

  // -, unary
  q = -T1;
  testStreamOutput("-60 F",q);
  q.setAsRelative();
  q = -q;
  testStreamOutput("60 F",q);
  EXPECT_FALSE(q.isAbsolute());

  // +, good units, bad units, absolute + relative = absolute
  q = T1 + T2;
  EXPECT_TRUE(q.isAbsolute());
  testStreamOutput("134 F",q,0);
  EXPECT_THROW(T1 + TT1,Exception);
  q.setAsRelative();
  q += T1;
  EXPECT_TRUE(q.isAbsolute());

  // -, binary, good units, bad units, absolute -> relative when exp == 1, ow same as +
  q = T2 - T1;
  testStreamOutput("14 F",q,0);
  EXPECT_FALSE(q.isAbsolute());
//.........这里部分代码省略.........
开发者ID:pepsi7959,项目名称:OpenStudio,代码行数:101,代码来源:Quantity_GTest.cpp

示例5: validateUserArguments

bool OSRunner::validateUserArguments(const std::vector<OSArgument>& script_arguments,
                                     const std::map<std::string, OSArgument>& user_arguments)
{
    bool result(true);
    std::stringstream ss;
    AttributeVector argumentValueAttributes;
    for (const OSArgument& script_argument : script_arguments) {
        auto it = user_arguments.find(script_argument.name());
        if (it == user_arguments.end()) {
            // script_argument is not in user_arguments
            // this is only okay for purely optional arguments
            if (script_argument.required() || script_argument.hasDefaultValue()) {
                ss << "Argument " << script_argument.name() << " is required or has a default value, ";
                ss << "but is not in user_arguments.";
                registerError(ss.str());
                ss.str("");
                result = false;
            }
        }
        else {
            // script_argument is in user_arguments
            OSArgument user_argument = it->second;

            // check that names still match
            if (user_argument.name() != script_argument.name()) {
                ss << "User argument name '" << user_argument.name() << "' does not match map key ";
                ss << script_argument.name() << ".";
                registerWarning(ss.str());
                ss.str("");
            }

            // check that types still match
            if (user_argument.type() != script_argument.type()) {
                ss << "User argument type " << user_argument.type().valueName() << " does not match ";
                ss << "script argument type " << script_argument.type().valueName() << ".";
                registerError(ss.str());
                ss.str("");
                result = false;
            }

            //  check that we have values
            if ((script_argument.required()) &&
                    !(user_argument.hasValue() || user_argument.hasDefaultValue()))
            {
                ss << "Script argument '" << script_argument.name() << "' is required, ";
                ss << "but the user argument does not have a value or default value set.";
                registerError(ss.str());
                ss.str("");
                result = false;
            }

            // check for default value mismatch
            if (script_argument.hasDefaultValue() && !user_argument.hasDefaultValue()) {
                ss << "Script argument '" << script_argument.name() << "' has a default value, but the ";
                ss << "user-supplied version does not.";
                registerWarning(ss.str());
                ss.str("");
            }
            if (!script_argument.hasDefaultValue() && user_argument.hasDefaultValue()) {
                ss << "Script argument '" << script_argument.name() << "' does not have a default value, ";
                ss << "but the user-supplied version does.";
                registerWarning(ss.str());
                ss.str("");
            }
            if (script_argument.hasDefaultValue() && user_argument.hasDefaultValue() &&
                    (user_argument.type() == script_argument.type()))
            {
                ss << "The default value of script argument " << std::endl << script_argument << std::endl;
                ss << "does not match that of the corresponding user argument " << std::endl << user_argument << ".";
                switch (script_argument.type().value()) {
                case OSArgumentType::Boolean :
                    if (user_argument.defaultValueAsBool() != script_argument.defaultValueAsBool()) {
                        registerWarning(ss.str());
                    }
                    break;
                case OSArgumentType::Double :
                    if (user_argument.defaultValueAsDouble() != script_argument.defaultValueAsDouble()) {
                        registerWarning(ss.str());
                    }
                    break;
                case OSArgumentType::Quantity :
                    if (user_argument.defaultValueAsQuantity() != script_argument.defaultValueAsQuantity()) {
                        registerWarning(ss.str());
                    }
                    break;
                case OSArgumentType::Integer :
                    if (user_argument.defaultValueAsInteger() != script_argument.defaultValueAsInteger()) {
                        registerWarning(ss.str());
                    }
                    break;
                case OSArgumentType::String :
                case OSArgumentType::Choice :
                case OSArgumentType::Path :
                    if (user_argument.defaultValueAsString() != script_argument.defaultValueAsString()) {
                        registerWarning(ss.str());
                    }
                    break;
                default :
                    OS_ASSERT(false);
                }
//.........这里部分代码省略.........
开发者ID:urbanengr,项目名称:OpenStudio,代码行数:101,代码来源:OSRunner.cpp

示例6:

Quantity::Quantity(const Quantity &q)
  : m_value(q.value()), m_units(q.units())
{}
开发者ID:urbanengr,项目名称:OpenStudio,代码行数:3,代码来源:Quantity.cpp

示例7: fFactor

 double FFactorGroundFloorConstruction_Impl::fFactor() const {
   Quantity q = getFFactor(false);
   return q.value();
 }
开发者ID:ORNL-BTRIC,项目名称:OpenStudio,代码行数:4,代码来源:FFactorGroundFloorConstruction.cpp

示例8: perimeterExposed

 double FFactorGroundFloorConstruction_Impl::perimeterExposed() const {
   Quantity q = getPerimeterExposed(false);
   return q.value();
 }
开发者ID:ORNL-BTRIC,项目名称:OpenStudio,代码行数:4,代码来源:FFactorGroundFloorConstruction.cpp


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