Units.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /*
00003  * This file is part of the libpagemaker project.
00004  *
00005  * This Source Code Form is subject to the terms of the Mozilla Public
00006  * License, v. 2.0. If a copy of the MPL was not distributed with this
00007  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
00008  */
00009 
00010 #ifndef LIBPAGEMAKER_UNITS_H
00011 #define LIBPAGEMAKER_UNITS_H
00012 
00013 #include <string>
00014 
00015 namespace libpagemaker
00016 {
00017 const unsigned PAGE_UNITS_PER_INCH = 720;
00018 const unsigned SHAPE_UNITS_PER_INCH = 1440;
00019 
00020 template <unsigned PER_INCH> class LengthUnit
00021 {
00022   typedef LengthUnit<PER_INCH> T;
00023 public:
00024   int m_value;
00025 
00026   LengthUnit(int value) : m_value(value) { }
00027 
00028   double toInches() const
00029   {
00030     return m_value / ((double)PER_INCH);
00031   }
00032 };
00033 
00034 template<unsigned PER_INCH> const LengthUnit<PER_INCH>
00035 operator+(LengthUnit<PER_INCH> left, LengthUnit<PER_INCH> right)
00036 {
00037   return LengthUnit<PER_INCH>(left.m_value + right.m_value);
00038 }
00039 
00040 template<unsigned PER_INCH> const LengthUnit<PER_INCH>
00041 operator*(LengthUnit<PER_INCH> left, int right)
00042 {
00043   return LengthUnit<PER_INCH>(left.m_value * right);
00044 }
00045 
00046 template<unsigned PER_INCH> const LengthUnit<PER_INCH>
00047 operator*(int left, LengthUnit<PER_INCH> right)
00048 {
00049   return right * left;
00050 }
00051 
00052 template<unsigned PER_INCH> const LengthUnit<PER_INCH>
00053 operator-(LengthUnit<PER_INCH> left, LengthUnit<PER_INCH> right)
00054 {
00055   return LengthUnit<PER_INCH>(left.m_value - right.m_value);
00056 }
00057 
00058 typedef LengthUnit<PAGE_UNITS_PER_INCH> PMDPageUnit;
00059 typedef LengthUnit<SHAPE_UNITS_PER_INCH> PMDShapeUnit;
00060 
00061 }
00062 
00063 #endif /* LIBPAGEMAKER_UNITS_H */
00064 
00065 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */