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
90 auto pos = table.find( prefix_ );
92 if ( pos == table.end() )
94 throw prefix_error(
"quantity: unrecognized prefix '" + prefix_ +
"'" );
106 template <
typename Dims>
113 return Dims::is_base;
127 std::ostringstream os;
131 emit_dim( os,
"m", Dims::dim1, first );
132 emit_dim( os,
"kg", Dims::dim2, first );
133 emit_dim( os,
"s", Dims::dim3, first );
134 emit_dim( os,
"A", Dims::dim4, first );
135 emit_dim( os,
"K", Dims::dim5, first );
136 emit_dim( os,
"mol", Dims::dim6, first );
137 emit_dim( os,
"cd", Dims::dim7, first );
138 emit_dim( os,
"eV", Dims::dim8, first );
145 static void emit_dim( std::ostream & os,
const char * label,
int exp,
bool & first )
171 #include "quantity_io_mole.hpp" 179 #if defined(QUANTITY_USE_CELSIUS) && defined(QUANTITY_USE_KELVIN) 180 # error At most define one of QUANTITY_USE_CELSIUS, QUANTITY_USE_KELVIN 182 #ifdef QUANTITY_USE_CELSIUS 185 #ifdef QUANTITY_USE_KELVIN 189 namespace phys {
namespace units {
193 template<
typename Dims,
typename T >
196 std::ostringstream os;
203 template<
typename Dims,
typename T >
211 template<
typename Dims,
typename T >
221 std::ostringstream os;
232 template<
typename Dims,
typename T >
233 std::ostream & operator<<( std::ostream & os, quantity<Dims, T>
const & q )
240 template<
typename Dims,
typename T >
243 std::ostringstream os;
252 #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.