/* * © Copyright 2014 – Urheberrechtshinweis * Alle Rechte vorbehalten / All Rights Reserved * * Programmcode ist urheberrechtlich geschuetzt. * Das Urheberrecht liegt, soweit nicht ausdruecklich anders gekennzeichnet, bei Frank Ebner. * Keine Verwendung ohne explizite Genehmigung. * (vgl. § 106 ff UrhG / § 97 UrhG) */ #ifndef LENGTH_H #define LENGTH_H /** * unit independent length measurement */ template struct Length { private: const T val; /** delete empty ctor */ Length() = delete; /** hidden value ctor */ Length(const T val) : val(val) {;} public: /** construct from mm */ static Length mm(const T mm) {return Length(mm * mul / 1000);} /** construct from cm */ static Length cm(const T cm) {return Length(cm * mul / 100);} /** construct from m */ static Length m(const T m) {return Length(m * mul / 1);} public: /** get in mm */ T mm() const {return val * 1000 / mul;} /** get in cm */ T cm() const {return val * 100 / mul;} /** get in m */ T m() const {return val * 1 / mul;} public: /** add the given length */ Length operator + (const Length o) {return Length(m+o.m);} /** subtract the given length */ Length operator - (const Length o) {return Length(m+o.m);} }; /** float. internally stored in meters */ typedef Length LengthF; /** int. internally stored in millimeters */ typedef Length LengthI; #endif // LENGTH_H