Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-core / tags / synfig_0_61_07_rc1 / src / synfig / distance.h
1 /* === S Y N F I G ========================================================= */
2 /*!     \file distance.h
3 **      \brief Template Header
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **
10 **      This package is free software; you can redistribute it and/or
11 **      modify it under the terms of the GNU General Public License as
12 **      published by the Free Software Foundation; either version 2 of
13 **      the License, or (at your option) any later version.
14 **
15 **      This package is distributed in the hope that it will be useful,
16 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
17 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 **      General Public License for more details.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === S T A R T =========================================================== */
24
25 #ifndef __SYNFIG_DISTANCE_H
26 #define __SYNFIG_DISTANCE_H
27
28 /* === H E A D E R S ======================================================= */
29
30 #include "real.h"
31 #include "string.h"
32
33 /* === M A C R O S ========================================================= */
34
35 /* === T Y P E D E F S ===================================================== */
36
37 /* === C L A S S E S & S T R U C T S ======================================= */
38
39 namespace synfig {
40
41 class RendDesc;
42
43 class Distance
44 {
45 public:
46         typedef Real value_type;
47
48         enum System
49         {
50                 SYSTEM_UNITS,           //!<
51                 SYSTEM_PIXELS,          //!<
52
53                 SYSTEM_POINTS,          //!<
54                 SYSTEM_INCHES,          //!<
55                 SYSTEM_METERS,          //!<
56                 SYSTEM_MILLIMETERS,     //!<
57                 SYSTEM_CENTIMETERS,     //!<
58
59                 SYSTEM_END                      //!< \internal
60         };
61
62         class BadSystem { };
63
64 private:
65         value_type value_;
66
67         System system_;
68
69
70 public:
71
72         Distance(){ }
73         Distance(const value_type& value, System system):value_(value),system_(system) { }
74         explicit Distance(const synfig::String& string);
75
76         operator Real()const { return value_; }
77
78         Distance& operator=(const Real& rhs) { value_=rhs; return *this; }
79
80         Distance& operator=(const synfig::String& rhs);
81
82         synfig::String get_string(int digits=4)const;
83
84         const System& get_system()const { return system_; }
85
86         const Real& get()const { return value_; }
87
88         Real get(System system, const RendDesc& rend_desc)const;
89
90         void convert(System system, const RendDesc& rend_desc);
91
92         Real meters()const;
93         Real meters(const RendDesc& rend_desc)const;
94         Real units(const RendDesc& rend_desc)const;
95
96         static Real meters_to_system(Real x, System target_system);
97         static System ident_system(const synfig::String& str);
98         static synfig::String system_name(System system);
99         static synfig::String system_local_name(System system);
100
101         const Distance& operator+=(const Distance &rhs) { value_+=meters_to_system(rhs.meters(),system_); return *this; }
102         const Distance& operator-=(const Distance &rhs) { value_-=meters_to_system(rhs.meters(),system_); return *this; }
103
104         const Distance& operator+=(const float &rhs) { value_+=rhs; return *this; }
105         const Distance& operator-=(const float &rhs) { value_-=rhs; return *this; }
106         const Distance& operator*=(const float &rhs) { value_*=rhs; return *this; }
107         const Distance& operator/=(const float &rhs) { value_/=rhs; return *this; }
108
109 /*
110         template<typename U> const Time& operator+=(const U &rhs) { value_+=rhs; return *this; }
111         template<typename U> const Time& operator-=(const U &rhs) { value_-=rhs; return *this; }
112         template<typename U> const Time& operator*=(const U &rhs) { value_*=rhs; return *this; }
113         template<typename U> const Time& operator/=(const U &rhs) { value_/=rhs; return *this; }
114
115         template<typename U> Time operator+(const U &rhs)const { return value_+rhs; }
116         template<typename U> Time operator-(const U &rhs)const { return value_-rhs; }
117         template<typename U> Time operator*(const U &rhs)const { return value_*rhs; }
118         template<typename U> Time operator/(const U &rhs)const { return value_/rhs; }
119
120         Time operator-()const { return -value_; }
121 */
122 }; // END of class Distance
123
124 }; // END of namespace synfig
125
126 /* === E N D =============================================================== */
127
128 #endif