SI  2.5.4
A header only c++ library that provides type safety and user defined literals for handling physical values defined in the International System of Units.
stream.h
Go to the documentation of this file.
1 
12 #pragma once
13 #include "detail/unit.h"
14 #include "detail/unit_symbol.h"
15 
16 #include <istream>
17 #include <ostream>
18 
19 template <char _symbol, typename _exponent, typename _type, typename _ratio>
20 std::ostream &
21 operator<<(std::ostream &stream,
23  stream << unit.value() << " "
25  return stream;
26 }
27 
28 // @todo add implicit optiona conversion when reading strings of the correct
29 // unit but the wrong ratio
30 template <char _symbol, typename _exponent, typename _type, typename _ratio>
31 std::istream &
32 operator>>(std::istream &stream,
34  _type v;
35  std::string unit_symbol;
36  stream >> v >> unit_symbol;
37 
38  if (unit_symbol.compare(SI::unit_symbol<_symbol, _ratio, _exponent>::str) !=
39  0) {
40  stream.setstate(std::ios::failbit);
41  }
42  obj.setValue(v);
43  return stream;
44 }
45 
46 namespace SI {
47 template <char _symbol, typename _exponent, typename _type, typename _ratio>
48 std::string
50  return std::to_string(value.value())
51  .append(" ")
53 }
54 } // namespace SI
Definition: absorbed_dose.h:18
std::string to_string(const SI::detail::unit_t< _symbol, _exponent, _type, _ratio > &value)
Definition: stream.h:49
std::istream & operator>>(std::istream &stream, SI::detail::unit_t< _symbol, _exponent, _type, _ratio > &obj)
Definition: stream.h:32
std::ostream & operator<<(std::ostream &stream, const SI::detail::unit_t< _symbol, _exponent, _type, _ratio > &unit)
Definition: stream.h:21
base template class for holding values of type _type to be multiplied with a ratio _ratio
Definition: unit.h:51
void setValue(_type v)
Definition: unit.h:130
constexpr _type value() const
returns the stored value as raw type
Definition: unit.h:100
Base struct. Unusable needs template overloading.
Definition: unit_symbol.h:64