OpenStudioCore:utilities
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Related Functions | List of all members
openstudio::OSQuantityVector Class Reference

#include <OSQuantityVector.hpp>

Public Member Functions

Constructors and Destructors
 OSQuantityVector (const Unit &units=Unit())
 
 OSQuantityVector (const Unit &units, unsigned n, double value=0.0)
 
 OSQuantityVector (const Unit &units, const std::vector< double > &values)
 
 OSQuantityVector (const std::vector< Quantity > &values)
 
 OSQuantityVector (const OSQuantityVector &other)
 
OSQuantityVectoroperator= (const OSQuantityVector &other)
 
Getters and Queries
Unit units () const
 Returns a clone of this object's units. More...
 
UnitSystem system () const
 
Scale scale () const
 
std::vector< Quantityquantities () const
 Creates a vector of separate quantities. More...
 
std::vector< double > values () const
 Returns the underlying values of this OSQuantityVector. More...
 
Quantity getQuantity (unsigned i) const
 
bool empty () const
 Return value is equivalent to values().empty(). More...
 
unsigned size () const
 Return value is equivalent to values().size(). More...
 
Setters
bool setScale (int scaleExponent)
 Sets the scale to the one registered in ScaleFactory for 10^scaleExponent. More...
 
bool setScale (const std::string &scaleAbbreviation)
 Sets the scale to the one registered in ScaleFactory under scaleAbbreviation. More...
 
void push_back (Quantity q)
 Pushes q onto this vector if possible, otherwise throws. More...
 
void pop_back ()
 Removes the last value in this OSQuantityVector. More...
 
void resize (unsigned n, double value=0.0)
 Changes the size of this OSQuantityVector to n, using value to fill in any newly created elements as necessary. More...
 
void clear ()
 Empties all values out of this OSQuantityVector. More...
 
Temperature Methods

Quantities that have units of temperature need several extra functions to distinguish between absolute and relative measures.

bool isTemperature () const
 Returns true if units().optionalCast<TemperatureUnit>(). More...
 
bool isAbsolute () const
 Throws if !units().optionalCast<TemperatureUnit>(). More...
 
bool isRelative () const
 Throws if !units().optionalCast<TemperatureUnit>(). More...
 
void setAsAbsolute ()
 Set temperature as absolute. More...
 
void setAsRelative ()
 Set temperature as relative. More...
 
IP Methods
void lbmToLbf ()
 Conversions for pounds mass to pounds force. More...
 
void lbfToLbm ()
 Conversions for pounds mass to pounds force. More...
 
Mathematical Operators
OSQuantityVectoroperator+= (OSQuantityVector rVector)
 Adds rVector to this vector, if possible. More...
 
OSQuantityVectoroperator+= (Quantity rQuantity)
 Adds rQuantity to this vector element-wise, if possible. More...
 
OSQuantityVectoroperator-= (OSQuantityVector rVector)
 Subtracts rVector from this vector, if possible. More...
 
OSQuantityVectoroperator-= (Quantity rQuantity)
 Subtracts rQuantity from this vector element-wise, if possible. More...
 
OSQuantityVectoroperator*= (const Quantity &rQuantity)
 Multiplies all values of this vector by rQuantity. More...
 
OSQuantityVectoroperator/= (const Quantity &rQuantity)
 Divides all values of this vector by rQuantity. More...
 
OSQuantityVectoroperator*= (double d)
 Multiplies all values of this vector by d. More...
 
OSQuantityVectoroperator/= (double d)
 Divides all values of this vector by d. More...
 

Related Functions

(Note that these are not member functions.)

OSQuantityVector convert (const OSQuantityVector &original, UnitSystem sys)
 Non-member function that uses just two calls to QuantityConverter to convert an entire OSQuantityVector. More...
 
OSQuantityVector convert (const OSQuantityVector &original, const Unit &targetUnits)
 Non-member function that uses just two calls to QuantityConverter to convert an entire OSQuantityVector. More...
 
Quantity dot (OSQuantityVector lVector, const OSQuantityVector &rVector)
 
bool operator!= (const OSQuantityVector &lVector, const OSQuantityVector &rVector)
 
OSQuantityVector operator* (const OSQuantityVector &lVector, const Quantity &rQuantity)
 
OSQuantityVector operator* (const OSQuantityVector &lVector, double d)
 
OSQuantityVector operator* (const Quantity &lQuantity, const OSQuantityVector &rVector)
 
OSQuantityVector operator* (double d, const OSQuantityVector &rVector)
 
OSQuantityVector operator+ (const OSQuantityVector &lVector, const OSQuantityVector &rVector)
 
OSQuantityVector operator+ (const OSQuantityVector &lVector, const Quantity &rQuantity)
 
OSQuantityVector operator+ (const Quantity &lQuantity, const OSQuantityVector &rVector)
 
OSQuantityVector operator- (const OSQuantityVector &rVector)
 
OSQuantityVector operator- (const OSQuantityVector &lVector, const OSQuantityVector &rVector)
 
OSQuantityVector operator- (const OSQuantityVector &lVector, const Quantity &rQuantity)
 
OSQuantityVector operator- (const Quantity &lQuantity, const OSQuantityVector &rVector)
 
OSQuantityVector operator/ (const OSQuantityVector &lVector, const Quantity &rQuantity)
 
OSQuantityVector operator/ (const OSQuantityVector &lVector, double d)
 
bool operator== (const OSQuantityVector &lVector, const OSQuantityVector &rVector)
 

Detailed Description

Represents a vector of quantities all with the same units.

Provides performance improvements over directly operating on std::vector<Quantity>. The constructors and assignment operator ensure that this class behaves as "plain old data" (POD) by cloning any units information (to avoid multiple objects pointing to the exact same unit data).

Constructor & Destructor Documentation

openstudio::OSQuantityVector::OSQuantityVector ( const Unit units = Unit())
explicit
openstudio::OSQuantityVector::OSQuantityVector ( const Unit units,
unsigned  n,
double  value = 0.0 
)
openstudio::OSQuantityVector::OSQuantityVector ( const Unit units,
const std::vector< double > &  values 
)
openstudio::OSQuantityVector::OSQuantityVector ( const std::vector< Quantity > &  values)
explicit
openstudio::OSQuantityVector::OSQuantityVector ( const OSQuantityVector other)

Member Function Documentation

void openstudio::OSQuantityVector::clear ( )

Empties all values out of this OSQuantityVector.

Postcondition
{size() == 0u}
{empty()}
bool openstudio::OSQuantityVector::empty ( ) const

Return value is equivalent to values().empty().

Quantity openstudio::OSQuantityVector::getQuantity ( unsigned  i) const
bool openstudio::OSQuantityVector::isAbsolute ( ) const

Throws if !units().optionalCast<TemperatureUnit>().

bool openstudio::OSQuantityVector::isRelative ( ) const

Throws if !units().optionalCast<TemperatureUnit>().

bool openstudio::OSQuantityVector::isTemperature ( ) const

Returns true if units().optionalCast<TemperatureUnit>().

void openstudio::OSQuantityVector::lbfToLbm ( )

Conversions for pounds mass to pounds force.

These functions will throw if !units().optionalCast<IPUnit>().

Postcondition
{units().baseUnitExponent("lbf") == 0}
void openstudio::OSQuantityVector::lbmToLbf ( )

Conversions for pounds mass to pounds force.

These functions will throw if !units().optionalCast<IPUnit>().

Postcondition
{units().baseUnitExponent("lbm") == 0}
OSQuantityVector& openstudio::OSQuantityVector::operator*= ( const Quantity rQuantity)

Multiplies all values of this vector by rQuantity.

OSQuantityVector& openstudio::OSQuantityVector::operator*= ( double  d)

Multiplies all values of this vector by d.

OSQuantityVector& openstudio::OSQuantityVector::operator+= ( OSQuantityVector  rVector)

Adds rVector to this vector, if possible.

Throws if vectors are of different size or units are different.

OSQuantityVector& openstudio::OSQuantityVector::operator+= ( Quantity  rQuantity)

Adds rQuantity to this vector element-wise, if possible.

Throws if units are different.

OSQuantityVector& openstudio::OSQuantityVector::operator-= ( OSQuantityVector  rVector)

Subtracts rVector from this vector, if possible.

Throws if vectors are of different size or units are different.

OSQuantityVector& openstudio::OSQuantityVector::operator-= ( Quantity  rQuantity)

Subtracts rQuantity from this vector element-wise, if possible.

Throws if units are different.

OSQuantityVector& openstudio::OSQuantityVector::operator/= ( const Quantity rQuantity)

Divides all values of this vector by rQuantity.

OSQuantityVector& openstudio::OSQuantityVector::operator/= ( double  d)

Divides all values of this vector by d.

OSQuantityVector& openstudio::OSQuantityVector::operator= ( const OSQuantityVector other)
void openstudio::OSQuantityVector::pop_back ( )

Removes the last value in this OSQuantityVector.

void openstudio::OSQuantityVector::push_back ( Quantity  q)

Pushes q onto this vector if possible, otherwise throws.

std::vector<Quantity> openstudio::OSQuantityVector::quantities ( ) const

Creates a vector of separate quantities.

Note that it is better to do mathematical operations and convert units using OSOptionalQuantity. Only use this method once the values and units of this OSOptionalQuantity are fixed.

void openstudio::OSQuantityVector::resize ( unsigned  n,
double  value = 0.0 
)

Changes the size of this OSQuantityVector to n, using value to fill in any newly created elements as necessary.

Postcondition
{size() == n}
Scale openstudio::OSQuantityVector::scale ( ) const
void openstudio::OSQuantityVector::setAsAbsolute ( )

Set temperature as absolute.

Throws if !units().optionalCast<TemperatureUnit>().

Postcondition
{isAbsolute()}
void openstudio::OSQuantityVector::setAsRelative ( )

Set temperature as relative.

Throws if !units().optionalCast<TemperatureUnit>().

Postcondition
{isRelative()}
bool openstudio::OSQuantityVector::setScale ( int  scaleExponent)

Sets the scale to the one registered in ScaleFactory for 10^scaleExponent.

bool openstudio::OSQuantityVector::setScale ( const std::string &  scaleAbbreviation)

Sets the scale to the one registered in ScaleFactory under scaleAbbreviation.

unsigned openstudio::OSQuantityVector::size ( ) const

Return value is equivalent to values().size().

UnitSystem openstudio::OSQuantityVector::system ( ) const
Unit openstudio::OSQuantityVector::units ( ) const

Returns a clone of this object's units.

std::vector<double> openstudio::OSQuantityVector::values ( ) const

Returns the underlying values of this OSQuantityVector.

Friends And Related Function Documentation

OSQuantityVector convert ( const OSQuantityVector original,
UnitSystem  sys 
)
related

Non-member function that uses just two calls to QuantityConverter to convert an entire OSQuantityVector.

OSQuantityVector convert ( const OSQuantityVector original,
const Unit targetUnits 
)
related

Non-member function that uses just two calls to QuantityConverter to convert an entire OSQuantityVector.

Quantity dot ( OSQuantityVector  lVector,
const OSQuantityVector rVector 
)
related
bool operator!= ( const OSQuantityVector lVector,
const OSQuantityVector rVector 
)
related
OSQuantityVector operator* ( const OSQuantityVector lVector,
const Quantity rQuantity 
)
related
OSQuantityVector operator* ( const OSQuantityVector lVector,
double  d 
)
related
OSQuantityVector operator* ( const Quantity lQuantity,
const OSQuantityVector rVector 
)
related
OSQuantityVector operator* ( double  d,
const OSQuantityVector rVector 
)
related
OSQuantityVector operator+ ( const OSQuantityVector lVector,
const OSQuantityVector rVector 
)
related
OSQuantityVector operator+ ( const OSQuantityVector lVector,
const Quantity rQuantity 
)
related
OSQuantityVector operator+ ( const Quantity lQuantity,
const OSQuantityVector rVector 
)
related
OSQuantityVector operator- ( const OSQuantityVector rVector)
related
OSQuantityVector operator- ( const OSQuantityVector lVector,
const OSQuantityVector rVector 
)
related
OSQuantityVector operator- ( const OSQuantityVector lVector,
const Quantity rQuantity 
)
related
OSQuantityVector operator- ( const Quantity lQuantity,
const OSQuantityVector rVector 
)
related
OSQuantityVector operator/ ( const OSQuantityVector lVector,
const Quantity rQuantity 
)
related
OSQuantityVector operator/ ( const OSQuantityVector lVector,
double  d 
)
related
bool operator== ( const OSQuantityVector lVector,
const OSQuantityVector rVector 
)
related