libqalculate-0.9.8
Public Member Functions | Protected Attributes | List of all members
Unit Class Reference

A unit for measurement. More...

#include <Unit.h>

Inheritance diagram for Unit:
ExpressionItem AliasUnit CompositeUnit AliasUnit_Composite

Public Member Functions

 Unit (string cat_, string name_, string plural_="", string singular_="", string title_="", bool is_local=true, bool is_builtin=false, bool is_active=true)
 
 Unit (const Unit *unit)
 
virtual ExpressionItemcopy () const
 
virtual void set (const ExpressionItem *item)
 
bool isSIUnit () const
 
void setAsSIUnit ()
 
void setSystem (string s_system)
 
const string & system () const
 
bool useWithPrefixesByDefault () const
 
void setUseWithPrefixesByDefault (bool use_with_prefixes)
 
bool isCurrency () const
 
virtual string print (bool plural_, bool short_, bool use_unicode=false, bool(*can_display_unicode_string_function)(const char *, void *)=NULL, void *can_display_unicode_string_arg=NULL) const
 
virtual const string & plural (bool return_singular_if_no_plural=true, bool use_unicode=false, bool(*can_display_unicode_string_function)(const char *, void *)=NULL, void *can_display_unicode_string_arg=NULL) const
 
virtual const string & singular (bool return_abbreviation_if_no_singular=true, bool use_unicode=false, bool(*can_display_unicode_string_function)(const char *, void *)=NULL, void *can_display_unicode_string_arg=NULL) const
 
virtual const string & abbreviation (bool return_singular_if_no_abbreviation=true, bool use_unicode=false, bool(*can_display_unicode_string_function)(const char *, void *)=NULL, void *can_display_unicode_string_arg=NULL) const
 
virtual bool isUsedByOtherUnits () const
 
virtual UnitbaseUnit () const
 
virtual MathStructureconvertToBaseUnit (MathStructure &mvalue, MathStructure &mexp) const
 
virtual MathStructureconvertFromBaseUnit (MathStructure &mvalue, MathStructure &mexp) const
 
virtual MathStructureconvertToBaseUnit (MathStructure &mvalue) const
 
virtual MathStructureconvertFromBaseUnit (MathStructure &mvalue) const
 
virtual MathStructure convertToBaseUnit () const
 
virtual MathStructure convertFromBaseUnit () const
 
virtual int baseExponent (int exp=1) const
 
virtual int type () const
 
virtual int subtype () const
 
virtual bool isChildOf (Unit *u) const
 
virtual bool isParentOf (Unit *u) const
 
virtual bool hasComplexRelationTo (Unit *u) const
 
bool convert (Unit *u, MathStructure &mvalue, MathStructure &exp) const
 
bool convert (Unit *u, MathStructure &mvalue) const
 
MathStructure convert (Unit *u, bool *converted=NULL) const
 
- Public Member Functions inherited from ExpressionItem
 ExpressionItem (string cat_, string name_, string title_="", string descr_="", bool is_local=true, bool is_builtin=false, bool is_active=true)
 
virtual bool destroy ()
 
bool isRegistered () const
 
void setRegistered (bool is_registered)
 For internal use.
 
virtual const string & name (bool use_unicode=false, bool(*can_display_unicode_string_function)(const char *, void *)=NULL, void *can_display_unicode_string_arg=NULL) const
 
virtual const string & referenceName () const
 
virtual const ExpressionNamepreferredName (bool abbreviation=false, bool use_unicode=false, bool plural=false, bool reference=false, bool(*can_display_unicode_string_function)(const char *, void *)=NULL, void *can_display_unicode_string_arg=NULL) const
 
virtual const ExpressionNamepreferredInputName (bool abbreviation=false, bool use_unicode=false, bool plural=false, bool reference=false, bool(*can_display_unicode_string_function)(const char *, void *)=NULL, void *can_display_unicode_string_arg=NULL) const
 
virtual const ExpressionNamepreferredDisplayName (bool abbreviation=false, bool use_unicode=false, bool plural=false, bool reference=false, bool(*can_display_unicode_string_function)(const char *, void *)=NULL, void *can_display_unicode_string_arg=NULL) const
 
virtual const ExpressionNamegetName (size_t index) const
 
virtual void setName (const ExpressionName &ename, size_t index=1, bool force=true)
 
virtual void setName (string sname, size_t index, bool force=true)
 
virtual void addName (const ExpressionName &ename, size_t index=0, bool force=true)
 
virtual void addName (string sname, size_t index=0, bool force=true)
 
virtual size_t countNames () const
 
virtual void clearNames ()
 
virtual void clearNonReferenceNames ()
 
virtual void removeName (size_t index)
 
virtual size_t hasName (const string &sname, bool case_sensitive=true) const
 
virtual size_t hasNameCaseSensitive (const string &sname) const
 
virtual const ExpressionNamefindName (int abbreviation=-1, int use_unicode=-1, int plural=-1, bool(*can_display_unicode_string_function)(const char *, void *)=NULL, void *can_display_unicode_string_arg=NULL) const
 
virtual const string & title (bool return_name_if_no_title=true, bool use_unicode=false, bool(*can_display_unicode_string_function)(const char *, void *)=NULL, void *can_display_unicode_string_arg=NULL) const
 
virtual void setTitle (string title_)
 
virtual const string & description () const
 
virtual void setDescription (string descr_)
 
virtual const string & category () const
 
virtual void setCategory (string cat_)
 
virtual bool hasChanged () const
 
virtual void setChanged (bool has_changed)
 
virtual bool isLocal () const
 
virtual bool setLocal (bool is_local=true, int will_be_active=-1)
 
virtual bool isBuiltin () const
 
virtual bool isApproximate () const
 
virtual void setApproximate (bool is_approx=true)
 
virtual int precision () const
 
virtual void setPrecision (int prec)
 
virtual bool isActive () const
 
virtual void setActive (bool is_active)
 
virtual bool isHidden () const
 
virtual void setHidden (bool is_hidden)
 
virtual int refcount () const
 
virtual void ref ()
 
virtual void unref ()
 
virtual void ref (ExpressionItem *o)
 
virtual void unref (ExpressionItem *o)
 
virtual ExpressionItemgetReferencer (size_t index=1) const
 
virtual bool changeReference (ExpressionItem *o_from, ExpressionItem *o_to)
 

Protected Attributes

string ssystem
 
bool b_si
 
bool b_use_with_prefixes
 
- Protected Attributes inherited from ExpressionItem
string scat
 
string stitle
 
string sdescr
 
bool b_local
 
bool b_changed
 
bool b_builtin
 
bool b_approx
 
bool b_active
 
bool b_registered
 
bool b_hidden
 
bool b_destroyed
 
int i_ref
 
int i_precision
 
vector< ExpressionItem * > v_refs
 
vector< ExpressionNamenames
 

Detailed Description

A unit for measurement.

The Unit class both represents a base unit and is the base class for other unit types. Base units are units defined as basis for other units. Meters and seconds are typical base units.

For base units, a name is all that is needed. Base units do however normally have three different names defined for use in expressions - abbreviation (ex. "m"), singular ("meter") and plural ("meters").

Member Function Documentation

bool Unit::convert ( Unit u,
MathStructure mvalue,
MathStructure exp 
) const

Converts a value from specified unit and exponent to this unit. value * (unit^exponent) = new value * (this^new exponent) This function cannot convert to or from CompositeUnit.

Parameters
uUnit to convert from.
[in,out]mvalueQuantity value.
[in,out]expExponent.
Returns
true if the value was successfully converted.
bool Unit::convert ( Unit u,
MathStructure mvalue 
) const

Converts a value from specified unit and exponent to this unit. value * unit = new value * this This function cannot convert to or from CompositeUnit.

Parameters
uUnit to convert from.
[in,out]mvalueQuantity value.
Returns
true if the value was successfully converted.
virtual bool Unit::isChildOf ( Unit u) const
virtual

If specified unit is a base unit for this unit, directly or with other units in between. Equivalent to u->isParentOf(this).

Reimplemented in AliasUnit.

bool Unit::isCurrency ( ) const

Returns if the unit is a currency (Euro is base unit).

Returns
true if the unit is a currency.
virtual bool Unit::isParentOf ( Unit u) const
virtual

If this unit is a base unit for specified unit, directly or with other units in between. Equivalent to u->isChildOf(this).

Reimplemented in AliasUnit.

bool Unit::isSIUnit ( ) const

Returns if the unit is part of the SI standard.

Returns
true if the unit is part of the SI standard.
virtual string Unit::print ( bool  plural_,
bool  short_,
bool  use_unicode = false,
bool(*)(const char *, void *)  can_display_unicode_string_function = NULL,
void *  can_display_unicode_string_arg = NULL 
) const
virtual

Returns a display string representing the unit in an expression.

Equivalent to preferredName() for Unit and AliasUnit, but closer to MathStructure::print() for CompositeUnit (prints out base expression).

Reimplemented in CompositeUnit, and AliasUnit_Composite.

void Unit::setAsSIUnit ( )

State that the unit is part of the SI standard. Sets system to "SI".

void Unit::setSystem ( string  s_system)

Sets which system/standard ("SI", "CGS", etc.) the unit is part of. Setting system to "SI" (case-insensitive), is equivalent to setAsSIUnit().

void Unit::setUseWithPrefixesByDefault ( bool  use_with_prefixes)

Sets wether prefixes are approriate with this unit or not.

virtual int Unit::subtype ( ) const
virtual

Returns the subtype of the unit, corresponding to which subsubclass the object belongs to.

Returns
UnitSubtype.

Implements ExpressionItem.

Reimplemented in CompositeUnit, and AliasUnit.

const string& Unit::system ( ) const

Returns the system/standard that the unit is part of.

Returns
System string.
virtual int Unit::type ( ) const
virtual

Returns the type of the expression item, corresponding to which subclass the object belongs to.

Returns
ExpressionItemType.

Implements ExpressionItem.

bool Unit::useWithPrefixesByDefault ( ) const

Returns wether prefixes should be used with this unit or not.

Returns
true if the prefixes is appropriate for this unit.

The documentation for this class was generated from the following file: