libqalculate-5.1.1

Public Member Functions | Protected Attributes | List of all members
Prefix Class Referenceabstract

Abstract class for prefixes. More...

`#include <Prefix.h>`

Inheritance diagram for Prefix:

## Public Member Functions
| Prefix (std::string long_name, std::string short_name="", std::string unicode_name="")
const std::string & | shortName (bool return_long_if_no_short=true, bool use_unicode=false) const
const std::string & | longName (bool return_short_if_no_long=true, bool use_unicode=false) const
const std::string & | unicodeName (bool return_short_if_no_uni=true) const
void | setShortName (std::string short_name)
void | setLongName (std::string long_name)
void | setUnicodeName (std::string unicode_name)
const std::string & | name (bool short_default=true, bool use_unicode=false, bool(*can_display_unicode_string_function)(const char *, void *)=NULL, void *can_display_unicode_string_arg=NULL) const
const std::string & | referenceName () const
const ExpressionName & | preferredName (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
const ExpressionName & | preferredInputName (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
const ExpressionName & | preferredDisplayName (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
const ExpressionName & | getName (size_t index) const
void | setName (const ExpressionName &ename, size_t index=1)
void | setName (std::string sname, size_t index)
void | addName (const ExpressionName &ename, size_t index=0)
void | addName (std::string sname, size_t index=0)
size_t | countNames () const
void | clearNames ()
void | clearNonReferenceNames ()
void | removeName (size_t index)
size_t | hasName (const std::string &sname, bool case_sensitive=true) const
size_t | hasNameCaseSensitive (const std::string &sname) const
const ExpressionName & | findName (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 Number | value (const Number &nexp) const =0
virtual Number | value (int iexp) const =0
virtual Number | value () const =0
virtual int | type () const =0

## Protected Attributes
std::vector< ExpressionName > | names

## Detailed Description

Abstract class for prefixes.

A prefix is prepended to a unit to specify a quantity multiplicator. A prefix has a numerical value which raised to the units power defines the quantity. In for example the expression "3 kilometers", meter is the unit, 3 is regular quantity, and kilo is a prefix with a value 1000, thus the example equals "3000 meters". If the unit instead had been squared, the value of the prefix would have been raised by two and the total quantity would have been 3.000.000.

Prefixes can have up to free different three names – a long name, a short name and a short unicode name. The unicode name is an alternative to the short name that is preferred if unicode characters can be displayed. The names or used to reference the prefix in mathematical expressions and to display a prefix in a result.

## Constructor & Destructor Documentation

## ◆ Prefix()

Prefix::Prefix | ( | std::string | long_name,
|  | std::string | short_name = "",
|  | std::string | unicode_name = "" )

Create a prefix.

Parameters

  long_name | Long name.
  short_name | Short name.
  unicode_name | Unicode name.

## Member Function Documentation

## ◆ clearNames()

void Prefix::clearNames | ( |  | ) |

Removes all names.

## ◆ clearNonReferenceNames()

void Prefix::clearNonReferenceNames | ( |  | ) |

Removes all names that are not used for reference (ExpressionName.reference = true).

## ◆ findName()

const ExpressionName & Prefix::findName | ( | int | abbreviation = -1,
|  | int | use_unicode = -1,
|  | int | plural = -1,
|  | bool(*)(const char *, void *) | can_display_unicode_string_function = NULL,
|  | void * | can_display_unicode_string_arg = NULL ) const

Searches for a name with specific properties.

Parameters

  abbreviation | If the name must be abbreviated. 1=true, 0=false, -1=ignore.
  use_unicode | If the name must have unicode characters. 1=true, 0=false, -1=ignore.
  plural | If the name must be in plural form. 1=true, 0=false, -1=ignore.
  can_display_unicode_string_function | Function that tests if the unicode characters in a name can be displayed. If the function returns false, the name will be rejected.
  can_display_unicode_string_arg | Argument to pass to the above test function.

Returns
  The first found name with the specified properties or empty_expression_name if none found.

## ◆ getName()

const ExpressionName & Prefix::getName | ( | size_t | index | ) | const

Returns name for an index (starting at one). All functions can be traversed by starting at index one and increasing the index until empty_expression_name is returned.

Parameters

  index | Index of name.

Returns
  Name for index or empty_expression_name if not found.

## ◆ hasName()

size_t Prefix::hasName | ( | const std::string & | sname,
|  | bool | case_sensitive = true ) const

Checks if the prefix has a name with a specific text string.

Parameters

  sname | A text string to look for (not case sensitive)
  case_sensitive | If the name is case sensitive.

Returns
  Index of the name with the given text string or zero if such a name was not found.

## ◆ hasNameCaseSensitive()

size_t Prefix::hasNameCaseSensitive | ( | const std::string & | sname | ) | const

Checks if the prefix has a name with a specific case sensitive text string.

Parameters

  sname | A text string to look for (case sensitive)

Returns
  Index of the name with the given text string or zero if such a name was not found.

## ◆ longName()

const std::string & Prefix::longName | ( | bool | return_short_if_no_long = true,
|  | bool | use_unicode = false ) const

Returns the long name of the prefix.

Parameters

  return_short_if_no_long | If the short name shall be returned if the prefix has not got a long name (if it is empty).
  use_unicode | If a unicode version of the name is allowed and preferred.

Returns
  The long name of the prefix.

## ◆ name()

const std::string & Prefix::name | ( | bool | short_default = true,
|  | bool | use_unicode = false,
|  | bool(*)(const char *, void *) | can_display_unicode_string_function = NULL,
|  | void * | can_display_unicode_string_arg = NULL ) const

Returns a preferred name of the prefix.

Parameters

  short_default | If a short name is preferred.
  use_unicode | If a unicode name is preferred.
  can_display_unicode_string_function | Function that tests if the unicode characters in a name can be displayed. If the function returns false, the name will be rejected.
  can_display_unicode_string_arg | Argument to pass to the above test function.

Returns
  A preferred name.

## ◆ preferredDisplayName()

const ExpressionName & Prefix::preferredDisplayName | ( | bool | abbreviation = false,
|  | bool | use_unicode = false,
|  | bool | plural = false,
|  | bool | reference = false,
|  | bool(*)(const char *, void *) | can_display_unicode_string_function = NULL,
|  | void * | can_display_unicode_string_arg = NULL ) const

Returns the name that best fulfils provided criterias and is suitable for display. If two names are equally preferred, the one with lowest index is returned.

Parameters

  abbreviation | If an abbreviated name is preferred.
  use_unicode | If a name with unicode characters can be displayed/is preferred (prioritized if false).
  can_display_unicode_string_function | Function that tests if the unicode characters in a name can be displayed. If the function returns false, the name will be rejected.
  can_display_unicode_string_arg | Argument to pass to the above test function.

Returns
  The preferred name.

## ◆ preferredInputName()

const ExpressionName & Prefix::preferredInputName | ( | bool | abbreviation = false,
|  | bool | use_unicode = false,
|  | bool | plural = false,
|  | bool | reference = false,
|  | bool(*)(const char *, void *) | can_display_unicode_string_function = NULL,
|  | void * | can_display_unicode_string_arg = NULL ) const

Returns the name that best fulfils provided criterias and is suitable for user input. If two names are equally preferred, the one with lowest index is returned.

Parameters

  abbreviation | If an abbreviated name is preferred.
  use_unicode | If a name with unicode characters can be displayed/is preferred (prioritized if false).
  plural | If a name in plural form is preferred.
  reference | If a reference name is preferred (ignored if false).
  can_display_unicode_string_function | Function that tests if the unicode characters in a name can be displayed. If the function returns false, the name will be rejected.
  can_display_unicode_string_arg | Argument to pass to the above test function.

Returns
  The preferred name.

## ◆ preferredName()

const ExpressionName & Prefix::preferredName | ( | bool | abbreviation = false,
|  | bool | use_unicode = false,
|  | bool | plural = false,
|  | bool | reference = false,
|  | bool(*)(const char *, void *) | can_display_unicode_string_function = NULL,
|  | void * | can_display_unicode_string_arg = NULL ) const

Returns the name that best fulfils provided criterias. If two names are equally preferred, the one with lowest index is returned.

Parameters

  abbreviation | If an abbreviated name is preferred.
  use_unicode | If a name with unicode characters can be displayed/is preferred (prioritized if false).
  plural | If a name in plural form is preferred.
  reference | If a reference name is preferred (ignored if false).
  can_display_unicode_string_function | Function that tests if the unicode characters in a name can be displayed. If the function returns false, the name will be rejected.
  can_display_unicode_string_arg | Argument to pass to the above test function.

Returns
  The preferred name.

## ◆ setLongName()

void Prefix::setLongName | ( | std::string | long_name | ) |

Sets the long name of the prefix.

Parameters

  long_name | The new long name for the prefix.

## ◆ setName() [1/2]

void Prefix::setName | ( | const ExpressionName & | ename,
|  | size_t | index = 1 )

Changes a name. If a name for the provided index is not present, it is added (equivalent to addName(ename, index)).

Parameters

  ename | The new name.
  index | Index of name to change.

## ◆ setName() [2/2]

void Prefix::setName | ( | std::string | sname,
|  | size_t | index )

Changes the text string of a name. If a name for the provided index is not present, it is added (equivalent to addName(sname, index)).

Parameters

  sname | The new name text string.
  index | Index of name to change.

## ◆ setShortName()

void Prefix::setShortName | ( | std::string | short_name | ) |

Sets the short name of the prefix.

Parameters

  short_name | The new short name for the prefix.

## ◆ setUnicodeName()

void Prefix::setUnicodeName | ( | std::string | unicode_name | ) |

Sets the unicode name of the prefix. The unicode name is an alternative to the short name that is preferred if unicode characters can be displayed.

Parameters

  unicode_name | The new unicode name for the prefix.

## ◆ shortName()

const std::string & Prefix::shortName | ( | bool | return_long_if_no_short = true,
|  | bool | use_unicode = false ) const

Returns the short name of the prefix.

Parameters

  return_long_if_no_short | If the long name shall be returned if the prefix has not got a short name (if it is empty).
  use_unicode | If a unicode version of the name is allowed and preferred.

Returns
  The short name of the prefix.

## ◆ type()

virtual int Prefix::type | ( |  | ) | const
| pure virtual

Returns type, subclass, of the prefix. This can be PREFIX_DECIMAL for prefixes of the class DecimalPrefix, PREFIX_BINARY for BinaryPrefix, or PREFIX_NUMBER for NumberPrefix.

Returns
  The type of the prefix.

Implemented in DecimalPrefix, BinaryPrefix, and NumberPrefix.

## ◆ unicodeName()

const std::string & Prefix::unicodeName | ( | bool | return_short_if_no_uni = true | ) | const

Returns the unicode name of the prefix.

Parameters

  return_short_if_no_uni | If the short name shall be returned if the prefix has not got a unicode name (if it is empty).

Returns
  The unicode name of the prefix.

## ◆ value() [1/3]

virtual Number Prefix::value | ( |  | ) | const
| pure virtual

Returns the value of the prefix.

Returns
  The value of the prefix.

Implemented in DecimalPrefix, BinaryPrefix, and NumberPrefix.

## ◆ value() [2/3]

virtual Number Prefix::value | ( | const Number & | nexp | ) | const
| pure virtual

Returns the value of the prefix.

Parameters

  nexp | The power of the prefixed unit.

Returns
  The value of the prefix.

Implemented in DecimalPrefix, BinaryPrefix, and NumberPrefix.

## ◆ value() [3/3]

virtual Number Prefix::value | ( | int | iexp | ) | const
| pure virtual

Returns the value of the prefix.

Parameters

  iexp | The power of the prefixed unit.

Returns
  The value of the prefix.

Implemented in DecimalPrefix, BinaryPrefix, and NumberPrefix.

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

- /root/tmp/build-libqalculate/libqalculate-5.1.1/libqalculate/Prefix.h