22 #ifndef PHYS_UNITS_QUANTITY_IO_HPP_INCLUDED 23 #define PHYS_UNITS_QUANTITY_IO_HPP_INCLUDED 47 : std::runtime_error( text ) { }
60 inline Rep
prefix( std::string
const prefix_ )
62 std::map<std::string, Rep> table
86 auto pos = table.find( prefix_ );
88 if ( pos == table.end() )
90 throw prefix_error(
"quantity: unrecognized prefix '" + prefix_ +
"'" );
102 template <
typename Dims>
109 return Dims::is_base;
123 std::ostringstream os;
127 emit_dim( os,
"m", Dims::dim1, first );
128 emit_dim( os,
"kg", Dims::dim2, first );
129 emit_dim( os,
"s", Dims::dim3, first );
130 emit_dim( os,
"A", Dims::dim4, first );
131 emit_dim( os,
"K", Dims::dim5, first );
132 emit_dim( os,
"mol", Dims::dim6, first );
133 emit_dim( os,
"cd", Dims::dim7, first );
134 emit_dim( os,
"eV", Dims::dim8, first );
141 static void emit_dim( std::ostream & os,
const char * label,
int exp,
bool & first )
167 #include "quantity_io_mole.hpp" 175 #if defined(QUANTITY_USE_CELSIUS) && defined(QUANTITY_USE_KELVIN) 176 # error At most define one of QUANTITY_USE_CELSIUS, QUANTITY_USE_KELVIN 178 #ifdef QUANTITY_USE_CELSIUS 181 #ifdef QUANTITY_USE_KELVIN 185 namespace phys {
namespace units {
189 template<
typename Dims,
typename T >
192 std::ostringstream os;
199 template<
typename Dims,
typename T >
207 template<
typename Dims,
typename T >
217 std::ostringstream os;
228 template<
typename Dims,
typename T >
229 std::ostream & operator<<( std::ostream & os, quantity<Dims, T>
const & q )
236 template<
typename Dims,
typename T >
239 std::ostringstream os;
248 #endif // PHYS_UNITS_QUANTITY_IO_HPP_INCLUDED std::string to_magnitude(quantity< Dims, T > const &q)
magnitude as string.
quantity error base class (not used by quantity itself).
candela, fundamental dimension.
std::string to_unit_name(quantity< Dims, T > const &)
unit name.
std::string to_unit_symbol(quantity< Dims, T > const &)
unit symbol.
Zero-overhead dimensional analysis and unit/quantity manipulation and conversion. ...
meter, fundamental dimension.
kilogram, fundamental dimension.
static std::string symbol()
provide unit's symbol.
std::string to_string(long double const value)
string representation of value.
Rep prefix(std::string const prefix_)
return factor for given prefix.
class "quantity" is the heart of the library.
constexpr value_type magnitude() const
the quantity's magnitude.
static bool single()
true if base dimension.
Provide SI units-and-exponents in as close to NIST-specified format as possible with plain ascii...
ampere, electrical current, a fundamental dimension.
celsius, thermodynamic temperature.
static void emit_dim(std::ostream &os, const char *label, int exp, bool &first)
emit a single dimension.
prefix error, e.g. when prefix is unrecognized.
second, fundamental dimension.
static std::string name()
provide unit's name.
kelvin, fundamental dimension.