Laxkit  0.0.7.1
Public Member Functions | Public Attributes | Protected Member Functions
Laxkit::SimpleUnit Class Reference

Small class to help with the conversion of simple units. More...

List of all members.

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< charnames
SimpleUnitnext
int defaultunits

Protected Member Functions

virtual SimpleUnitfind (const char *name, int len=-1)
virtual SimpleUnitfind (int units)

Detailed Description

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.


Member Function Documentation

int Laxkit::SimpleUnit::AddUnits ( int  nid,
double  scale,
const char shortname,
const char singular,
const char plural 
)
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().

double Laxkit::SimpleUnit::Convert ( double  value,
const char from,
const char to,
int error_ret 
)
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.

double Laxkit::SimpleUnit::Convert ( double  value,
int  from_id,
int  to_id,
int error_ret 
)
virtual

If the units were not found, ther error_ret gets set to a nonzero value. Else it is 0.

int Laxkit::SimpleUnit::PixelSize ( double  pixelsize,
int  intheseunits 
)
virtual

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().

int Laxkit::SimpleUnit::UnitInfo ( const char name,
int iid,
double *  scale,
char **  shortname,
char **  singular,
char **  plural 
)
virtual

Retrieve some information about a unit.

Return 0 for success or nonzero for error.

Referenced by Laxkit::RulerWindow::RulerWindow(), and Laxkit::RulerWindow::SetCurrentUnits().

int Laxkit::SimpleUnit::UnitInfoId ( int  id,
double *  scale,
char **  shortname,
char **  singular,
char **  plural 
)
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().

int Laxkit::SimpleUnit::UnitInfoIndex ( int  index,
int iid,
double *  scale,
char **  shortname,
char **  singular,
char **  plural 
)
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().


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

Mon Feb 17 2014 11:53:00, Laxkit