Units.h Source File documentation

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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 namespace libpagemaker
16 {
17 const unsigned PAGE_UNITS_PER_INCH = 720;
18 const unsigned SHAPE_UNITS_PER_INCH = 1440;
19
20 template <unsigned PER_INCH> class LengthUnit
21 {
22 typedef LengthUnit<PER_INCH> T;
23 public:
24 int m_value;
25
26 LengthUnit(int value) : m_value(value) { }
27
28 double toInches() const
29 {
30 return m_value / ((double)PER_INCH);
31 }
32 };
33
34 template<unsigned PER_INCH> const LengthUnit<PER_INCH>
35 operator+(LengthUnit<PER_INCH> left, LengthUnit<PER_INCH> right)
36 {
37 return LengthUnit<PER_INCH>(left.m_value + right.m_value);
38 }
39
40 template<unsigned PER_INCH> const LengthUnit<PER_INCH>
41 operator*(LengthUnit<PER_INCH> left, int right)
42 {
43 return LengthUnit<PER_INCH>(left.m_value * right);
44 }
45
46 template<unsigned PER_INCH> const LengthUnit<PER_INCH>
47 operator*(int left, LengthUnit<PER_INCH> right)
48 {
49 return right * left;
50 }
51
52 template<unsigned PER_INCH> const LengthUnit<PER_INCH>
53 operator-(LengthUnit<PER_INCH> left, LengthUnit<PER_INCH> right)
54 {
55 return LengthUnit<PER_INCH>(left.m_value - right.m_value);
56 }
57
58 typedef LengthUnit<PAGE_UNITS_PER_INCH> PMDPageUnit;
59 typedef LengthUnit<SHAPE_UNITS_PER_INCH> PMDShapeUnit;
60
61 }
62
63 #endif /* LIBPAGEMAKER_UNITS_H */
64
65 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */
libpagemaker::SHAPE_UNITS_PER_INCH
const unsigned SHAPE_UNITS_PER_INCH
Definition: Units.h:18
libpagemaker::LengthUnit::LengthUnit
LengthUnit(int value)
Definition: Units.h:26
libpagemaker::PMDShapeUnit
LengthUnit< SHAPE_UNITS_PER_INCH > PMDShapeUnit
Definition: Units.h:59
libpagemaker::operator*
const LengthUnit< PER_INCH > operator*(LengthUnit< PER_INCH > left, int right)
Definition: Units.h:41
libpagemaker::PAGE_UNITS_PER_INCH
const unsigned PAGE_UNITS_PER_INCH
Definition: Units.h:17
libpagemaker::LengthUnit::toInches
double toInches() const
Definition: Units.h:28
libpagemaker::LengthUnit::T
LengthUnit< PER_INCH > T
Definition: Units.h:22
libpagemaker::LengthUnit::m_value
int m_value
Definition: Units.h:24
libpagemaker::operator-
const LengthUnit< PER_INCH > operator-(LengthUnit< PER_INCH > left, LengthUnit< PER_INCH > right)
Definition: Units.h:53
libpagemaker::LengthUnit
Definition: Units.h:20
libpagemaker::PMDPageUnit
LengthUnit< PAGE_UNITS_PER_INCH > PMDPageUnit
Definition: Units.h:58
libpagemaker
Definition: geometry.h:20
libpagemaker::operator+
const LengthUnit< PER_INCH > operator+(LengthUnit< PER_INCH > left, LengthUnit< PER_INCH > right)
Definition: Units.h:35