Units.h
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/*
3 * This file is part of the libpagemaker project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9
10#ifndef LIBPAGEMAKER_UNITS_H
11#define LIBPAGEMAKER_UNITS_H
12
13#include <string>
14
15// TODO: remove this pointless abstraction.
16
17namespace libpagemaker
18{
19const unsigned SHAPE_UNITS_PER_INCH = 1440;
20
21template <unsigned PER_INCH> class LengthUnit
22{
24public:
26
27 LengthUnit(int value) : m_value(value) { }
28
29 double toInches() const
30 {
31 return m_value / ((double)PER_INCH);
32 }
33};
34
35template<unsigned PER_INCH> const LengthUnit<PER_INCH>
37{
38 return LengthUnit<PER_INCH>(left.m_value + right.m_value);
39}
40
41template<unsigned PER_INCH> const LengthUnit<PER_INCH>
43{
44 return LengthUnit<PER_INCH>(left.m_value * right);
45}
46
47template<unsigned PER_INCH> const LengthUnit<PER_INCH>
49{
50 return right * left;
51}
52
53template<unsigned PER_INCH> const LengthUnit<PER_INCH>
55{
56 return LengthUnit<PER_INCH>(left.m_value - right.m_value);
57}
58
60
61}
62
63#endif /* LIBPAGEMAKER_UNITS_H */
64
65/* vim:set shiftwidth=2 softtabstop=2 expandtab: */
Definition: Units.h:22
LengthUnit(int value)
Definition: Units.h:27
int m_value
Definition: Units.h:25
double toInches() const
Definition: Units.h:29
LengthUnit< PER_INCH > T
Definition: Units.h:23
Definition: geometry.h:23
const LengthUnit< PER_INCH > operator*(LengthUnit< PER_INCH > left, int right)
Definition: Units.h:42
const unsigned SHAPE_UNITS_PER_INCH
Definition: Units.h:19
LengthUnit< SHAPE_UNITS_PER_INCH > PMDShapeUnit
Definition: Units.h:59
const LengthUnit< PER_INCH > operator+(LengthUnit< PER_INCH > left, LengthUnit< PER_INCH > right)
Definition: Units.h:36
const LengthUnit< PER_INCH > operator-(LengthUnit< PER_INCH > left, LengthUnit< PER_INCH > right)
Definition: Units.h:54

Generated for libpagemaker by doxygen 1.9.6