예제 #1
0
void OSQuantityVector::push_back(Quantity q) {
  if (!(q.units() == units())) {
    LOG_AND_THROW("Quantity " << q << " is incompatible with this OSQuantityVector, which has "
                  "units " << units() << ".");
  }
  else if (q.scale() != scale()) {
    q.setScale(scale().exponent);
  }
  m_values.push_back(q.value());
}
예제 #2
0
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();
    }
  }
}