units.h revision 9622b20e1241107619ee74c18f5e4a65e2f863cb
/*
* Inkscape Units
* These classes are used for defining different unit systems.
*
* Authors:
* Matthew Petroff <matthew@mpetroff.net>
*
* Copyright (C) 2013 Matthew Petroff
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#ifndef INKSCAPE_UTIL_UNITS_H
#define INKSCAPE_UTIL_UNITS_H
#include <map>
#include <boost/operators.hpp>
#include "svg/svg-length.h"
#include "unordered-containers.h"
enum UnitType {
UNIT_TYPE_DIMENSIONLESS, /* Percentage */
UNIT_TYPE_NONE = -1
};
const char DEG[] = "°";
{
Unit();
double factor,
void clear();
/**
* Returns the suggested precision to use for displaying numbers
* of this unit.
*/
int defaultDigits() const;
/** Checks if a unit is compatible with the specified unit. */
bool compatibleWith(Unit const *u) const;
bool compatibleWith(char const *) const;
double factor;
/** Check if units are equal. */
/** Get SVG unit code. */
int svgUnit() const;
};
{
double quantity;
/** Initialize a quantity. */
Quantity(double q, char const *u);
/** Checks if a quantity is compatible with the specified unit. */
bool compatibleWith(Unit const *u) const;
bool compatibleWith(char const *u) const;
/** Return the quantity's value in the specified unit. */
double value(char const *u) const;
/** Return a printable string of the value in the specified unit. */
/** Convert distances.
no NULL check is performed on the passed pointers to Unit objects! */
/** Comparison operators. */
};
{
}
/**
* Initializes the unit tables and identifies the primary unit types.
*
* The primary unit's conversion factor is required to be 1.00
*/
UnitTable();
/** Add a new unit to the table */
/** Retrieve a given unit based on its string identifier */
/** Retrieve a given unit based on its SVGLength unit */
/** Retrieve a quantity based on its string identifier */
/** Remove a unit definition from the given unit type table * /
* DISABLED, unsafe with the current passing around pointers to Unit objects in this table */
//bool deleteUnit(Unit const &u);
/** Returns true if the given string 'name' is a valid unit in the table */
/** Provides an iteratable list of items in the given unit table */
/** Returns the default unit abbr for the given type */
double getScale() const;
void setScale();
/** Load units from an XML file.
*
* Loads and merges the contents of the given file into the UnitTable,
* possibly overwriting existing unit definitions.
*
* @param filename file to be loaded
*/
/* * Saves the current UnitTable to the given file. */
//bool save(std::string const &filename);
double _linear_scale;
static Unit _empty_unit;
};
extern UnitTable unit_table;
} // namespace Util
} // namespace Inkscape
#endif // define INKSCAPE_UTIL_UNITS_H
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :