// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
/** \file
\brief Provides a type-safe framework for doing real-world unit-of-measure conversion and I/O
\author Tim Shead (tshead@k-3d.com)
*/
#include <cassert>
#include <iosfwd>
#include <map>
#include <string>
namespace k3d
{
namespace measurement
{
namespace conversion
{
/// Conversion policy for real world units that can be converted solely through multiplication
class multiplicative
{
public:
const double to_si(const double RHS) const
{
return RHS * m_constant;
}
const double from_si(const double RHS) const
{
return RHS / m_constant;
}
protected:
explicit multiplicative(const double Constant) :
m_constant(Constant)
{
assert(m_constant);
}
private:
double m_constant;
};
} // namespace conversion
/// Defines a real-world unit of measure, including singular written name, plural written name, and functions to_si() and from_si() for converting quantities to-and-from their corresponding SI standard units