Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members  

Quantity Class Reference

Represent a number along with its native units. More...

Collaboration diagram for Quantity:

Collaboration graph
[legend]
List of all members.

Public Methods

 Quantity ()
 Quantity ( const Quantity& qty )
 Quantity ( const char* dimNum )
 Quantity ( double v, UnitExpr* e )
 ~Quantity ()
double val () const
void val ( double num )
double scale () const
DimensionGroupgroup () const
const vector<DimensionPower>& dimension () const
vector<DimensionPower>& dimension ()
void print ()
xmlNodePtr mathML () const
bool operator== ( const Quantity& o ) const

Protected Methods

void eval ( UnitExpr* e, vector<UnitPower>& upwr, vector<DimensionPower>& dpwr, double& s )
void p_eval ( UnitExpr* e, int x, vector<UnitPower>& upwr, vector<DimensionPower>& dpwr, double& s )

Protected Attributes

double m_val
vector<UnitPowerm_units
vector<DimensionPowerm_dimn
DimensionGroupm_dgrp
double m_scale

Friends

class  QUnitParser
int convert ( Quantity* to, const Quantity* from )

Detailed Description

Represent a number along with its native units.

This class represents a number and the units associated with that number. Objects of this type can be created explicitly or by calling a parser that takes a string, produces a UnitExpr tree, and then constructs a Quantity by traversing the tree.


Constructor & Destructor Documentation

Quantity::Quantity ( )
 

Default constructor for a quantity.

You must have called @UnitInit() for this constructor to work, as Unit::dimensionless() will return NULL otherwise.

Quantity::Quantity ( const Quantity & qty )
 

Copy constructor.

Quantity::Quantity ( const char * dimNum )
 

Construct a Quantity from a string in the format "num [ unit_expr ]".

An example would be "6 kJ/s". You must have called Unit::initialize() for this constructor to work, as no units will be defined otherwise.

Quantity::Quantity ( double v,
UnitExpr * e )
 

Construct a quantity from a number and a tree of operations on units

Quantity::~Quantity ( )
 

Destroy a quantity


Member Function Documentation

vector< DimensionPower >& Quantity::dimension ( ) [inline]
 

Return a copy of the (Dimension, exponent) tuples associated with this Quantity

const vector< DimensionPower >& Quantity::dimension ( ) const [inline]
 

Return the (Dimension, exponent) tuples associated with this Quantity

void Quantity::eval ( UnitExpr * e,
vector< UnitPower >& upwr,
vector< DimensionPower >& dpwr,
double & s ) [protected]
 

Call this to "flatten" a UnitExpr.

"Flattening" a UnitExpr tree involves carrying out all of the operations to produce vectors of DimensionPowers and UnitPowers and a scale factor.

Parameters:
e   The tree of UnitExpr elements to flatten
upwr   The resulting list of (Unit,exponent) pairs
dpwr   The resulting list of (Dimension,exponent) pairs
s   The resulting scale factor.

DimensionGroup * Quantity::group ( ) const [inline]
 

Return the DimensionGroup this quantity is a part of, or NULL.

xmlNodePtr Quantity::mathML ( ) const
 

Return reference to an XML tree representing this quantity in MathML. You are responsible for destroying the tree when you're done with it.

bool Quantity::operator== ( const Quantity & o ) const
 

Test equality.

Checks that both the numerical value and the units are exactly the same. So, even though 9.81 kg m/s^2 is the same as 32.2 lbf, they would not be considered equivalent.

void Quantity::p_eval ( UnitExpr * e,
int x,
vector< UnitPower >& upwr,
vector< DimensionPower >& dpwr,
double & s ) [protected]
 

This is a recursive routine used by Quantity::eval.

Parameters:
x   The current working exponent above this node in the tree @seealso Quantity::eval()

void Quantity::print ( )
 

Print a quantity to stdout (for debugging purposes)

double Quantity::scale ( ) const [inline]
 

Return the scale that will convert val() into Citrus' default units

void Quantity::val ( double num ) [inline]
 

Set the number associated with the Quantity

double Quantity::val ( ) const [inline]
 

Return the number associated with the Quantity


Friends And Related Function Documentation

int convert ( Quantity * to,
const Quantity * from ) [friend]
 

Convert a number from one set of units into another. The value for <to> will be overwritten by dtNaN if <to> and <from> do not belong to the same unit groups and do not have the same dimensionality.

Parameters:
to   the quantity containing the units to convert to. Note that the value of this quantity will be overwritten with the result or dtNaN if there was a problem.
from   the quantity containing the units and value to convert from.
Returns:
the return value is a 0 on success or 1 when units fail to match.


Member Data Documentation

DimensionGroup * Quantity::m_dgrp [protected]
 

The dimension group to which the expression belongs, if any.

vector< DimensionPower > Quantity::m_dimn [protected]
 

The dimension of the value (a vector of DimensionPowers)

double Quantity::m_scale [protected]
 

The scale factor to convert m_val to native units.

vector< UnitPower > Quantity::m_units [protected]
 

The units of the value (a vector of UnitPowers)

double Quantity::m_val [protected]
 

The value


The documentation for this class was generated from the following files:
Citrus C++ Reference Manual  20010520