Laxkit
0.0.7.1
|
Small class to help with the conversion of simple units. More...
Public Member Functions | |
virtual int | UnitId (const char *name, int len=-1) |
Return the unit id corresponding to name, or UNITS_None if not found. | |
virtual int | UnitInfo (const char *name, int *iid, double *scale, char **shortname, char **singular, char **plural) |
Retrieve some information about a unit. | |
virtual int | UnitInfoIndex (int index, int *iid, double *scale, char **shortname, char **singular, char **plural) |
Retrieve some information about a unit, using index value as a key (not id #). | |
virtual int | UnitInfoId (int id, double *scale, char **shortname, char **singular, char **plural) |
Retrieve some information about a unit, using id value as a key (not index #). | |
virtual double | GetFactor (int fromunits, int tounits) |
Return a value you would multiply numbers in fromunits when you want tounits. | |
virtual int | DefaultUnits () |
Return the id of whatever are the default units, as set by DefaultUnits(const char *). | |
virtual int | DefaultUnits (const char *units) |
Set default units, and return id of the current units. | |
virtual int | DefaultUnits (int units) |
virtual int | PixelSize (double pixelsize, int intheseunits) |
Set the size of a pixel in the specified units, or the default units if intheseunits==0. | |
virtual int | NumberOfUnits () |
virtual int | AddUnits (int nid, double scale, const char *shortname, const char *singular, const char *plural) |
virtual double | Convert (double value, const char *from, const char *to, int *error_ret) |
virtual double | Convert (double value, int from_id, int to_id, int *error_ret) |
Public Attributes | |
int | id |
double | scaling |
PtrStack< char > | names |
SimpleUnit * | next |
int | defaultunits |
Protected Member Functions | |
virtual SimpleUnit * | find (const char *name, int len=-1) |
virtual SimpleUnit * | find (int units) |
Small class to help with the conversion of simple units.
Units are defined with a some id number, a scaling to a base unit, and possibly many names. The base unit can be what ever you want, but by default in the Laxkit via GetUnitManager() and CreateDefaultUnits(), meters is assumed to be 1.
|
virtual |
You should always define shortname. You may pass NULL for singular or plural.
References newstr(), and Laxkit::PtrStack< T >::push().
Referenced by Laxkit::CreateDefaultUnits().
|
virtual |
From and to are matched ignoring case to all the names for each unit, until a match is found.
If the units were not found, ther error_ret gets set to a nonzero value. Else it is 0.
References Laxkit::PtrStack< T >::e, and Laxkit::PtrStack< T >::n.
|
virtual |
If the units were not found, ther error_ret gets set to a nonzero value. Else it is 0.
Set the size of a pixel in the specified units, or the default units if intheseunits==0.
Return 0 for success or nonzero for error and nothing done.
Referenced by LaxInterfaces::ViewerWindow::SetRealUnits().
|
virtual |
Retrieve some information about a unit.
Return 0 for success or nonzero for error.
Referenced by Laxkit::RulerWindow::RulerWindow(), and Laxkit::RulerWindow::SetCurrentUnits().
|
virtual |
Retrieve some information about a unit, using id value as a key (not index #).
Return 0 for success or nonzero for error.
References Laxkit::PtrStack< T >::e.
Referenced by Laxkit::RulerWindow::dump_out_atts(), Laxkit::RulerWindow::SetBaseUnits(), and Laxkit::RulerWindow::SetCurrentUnits().
|
virtual |
Retrieve some information about a unit, using index value as a key (not id #).
Return 0 for success or nonzero for error.
References Laxkit::PtrStack< T >::e.
Referenced by Laxkit::RulerWindow::UnitInfo().