#ifndef __JEEP__JSCALE__ #define __JEEP__JSCALE__ #include #include "JLang/JException.hh" /** * \file * Enumeration for scaling of quantity. * \author mdejong */ namespace JEEP {} namespace JPP { using namespace JEEP; } namespace JEEP { using JLANG::JValueOutOfRange; /** * Enumeration for scaling of quantity. */ enum JScale_t { femto_t = -15, //!< femto pico_t = -12, //!< pico nano_t = -9, //!< nano micro_t = -6, //!< micro milli_t = -3, //!< milli unit_t = 0, //!< unit kilo_t = +3, //!< kilo mega_t = +6, //!< mega giga_t = +9, //!< giga tera_t = +12, //!< tera peta_t = +15, //!< peta exa_t = +18 //!< exa }; /** * Get numerical value corresponding to scale. * * \param scale scale * \return value */ inline double getValue(const JScale_t scale) { return pow(10.0, scale); } /** * Get textual unit corresponding to scale. * * \param scale scale * \return textual unit */ inline const char* getUnit(const int scale) { switch (scale) { case femto_t: return "f"; case pico_t: return "p"; case nano_t: return "n"; case micro_t: return "u"; case milli_t: return "m"; case unit_t: return ""; case kilo_t: return "k"; case mega_t: return "M"; case giga_t: return "G"; case tera_t: return "T"; case peta_t: return "P"; case exa_t: return "E"; default: THROW(JValueOutOfRange, "getUnit(): invalid scale " << scale); }; } /** * Get scale corresponding to textual unit * * \param unit textual unit * \return scale */ inline JScale_t getScale(const char unit) { switch (unit) { case 'f': return femto_t; case 'p': return pico_t; case 'n': return nano_t; case 'u': return micro_t; case 'm': return milli_t; case ' ': return unit_t; case 'k': return kilo_t; case 'M': return mega_t; case 'G': return giga_t; case 'T': return tera_t; case 'P': return peta_t; case 'E': return exa_t; default: THROW(JValueOutOfRange, "getScale(): invalid unit " << unit); }; } } #endif