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.
Loading...
Searching...
No Matches
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#include <string>
19
20template <char _symbol, typename _exponent, typename _type, typename _ratio>
21std::ostream &
22operator<<(std::ostream &stream,
24 stream << unit.value() << " "
26 return stream;
27}
28
29// @todo add implicit optiona conversion when reading strings of the correct
30// unit but the wrong ratio
31template <char _symbol, typename _exponent, typename _type, typename _ratio>
32std::istream &
33operator>>(std::istream &stream,
35 _type v;
36 std::string unit_symbol;
37 stream >> v >> unit_symbol;
38
39 if (unit_symbol.compare(SI::unit_symbol<_symbol, _ratio, _exponent>::str) !=
40 0) {
41 stream.setstate(std::ios::failbit);
42 }
43 obj.setValue(v);
44 return stream;
45}
46
47namespace SI {
48template <char _symbol, typename _exponent, typename _type, typename _ratio>
49std::string
51 return std::to_string(value.value())
52 .append(" ")
54}
55} // namespace SI
Definition absorbed_dose.h:18
std::string to_string(const SI::detail::unit_t< _symbol, _exponent, _type, _ratio > &value)
Definition stream.h:50
std::istream & operator>>(std::istream &stream, SI::detail::unit_t< _symbol, _exponent, _type, _ratio > &obj)
Definition stream.h:33
std::ostream & operator<<(std::ostream &stream, const SI::detail::unit_t< _symbol, _exponent, _type, _ratio > &unit)
Definition stream.h:22
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