1 /* === S Y N F I G ========================================================= */
3 ** \brief Template Header
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
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.
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.
21 /* ========================================================================= */
23 /* === S T A R T =========================================================== */
25 #ifndef __SYNFIG_DISTANCE_H
26 #define __SYNFIG_DISTANCE_H
28 /* === H E A D E R S ======================================================= */
33 /* === M A C R O S ========================================================= */
35 /* === T Y P E D E F S ===================================================== */
37 /* === C L A S S E S & S T R U C T S ======================================= */
46 typedef Real value_type;
56 SYSTEM_MILLIMETERS, //!<
57 SYSTEM_CENTIMETERS, //!<
59 SYSTEM_END //!< \internal
73 Distance(const value_type& value, System system):value_(value),system_(system) { }
74 explicit Distance(const synfig::String& string);
76 operator Real()const { return value_; }
78 Distance& operator=(const Real& rhs) { value_=rhs; return *this; }
80 Distance& operator=(const synfig::String& rhs);
82 synfig::String get_string(int digits=4)const;
84 const System& get_system()const { return system_; }
86 const Real& get()const { return value_; }
88 Real get(System system, const RendDesc& rend_desc)const;
90 void convert(System system, const RendDesc& rend_desc);
93 Real meters(const RendDesc& rend_desc)const;
94 Real units(const RendDesc& rend_desc)const;
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);
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; }
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; }
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; }
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; }
120 Time operator-()const { return -value_; }
122 }; // END of class Distance
124 }; // END of namespace synfig
126 /* === E N D =============================================================== */