C++ API

The class structure is shown in Figure 1. Most of the objects are created when you initialize the library and the XML configuration file, units.xml is read. We'll discuss this process first and then move on to how a string is parsed into a tree of unit operations and then flattened into a structure that represents the units of one or more numbers.

Initialization

Figure 2 shows a portion of the units.xml configuration file. Each XML object is read using a SAX parser and turned into one of the classes from Figure 1. The XML file is organized into 3 separate regions. In the first, the base dimensions are defined. The ASTM standard recognizes 8 of these. The others are defined either for convenience or to accomodate something unscientific (such as money).

You can think of each one as being a separate coordinate axis along which something can be measured. Only axes that are completely independant of one another can serve as base dimensions. The space between the tick marks on each axis is determined by the unit you are referring to. For instance, both meters and inches measure something along the "length" axis, but the tick marks are much closer together when you use inches instead of meters.

Parsing

Figure 3 shows a simple example of how a string is parsed to produce a tree of operators. Each operator is a branching point on the tree. The operands of any of the mathematical operators are either DimensionPower/UnitPower objects or expressions consisting of other operations.