00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef PHYSICAL_FORMAT
00015 #define PHYSICAL_FORMAT
00016
00017 #include <ostream>
00018
00019 #include "physical/dynamicphysical.hpp"
00020 #include "physical/formatspec.hpp"
00021
00022
00023 namespace physical {
00024
00025 namespace format {
00026
00027 namespace detail {
00028
00029 template<class UnitSystem>
00030 std::ostream& format_to_spec(std::ostream& os, DynamicPhysical<UnitSystem> quantity, FormatSpec<UnitSystem> spec);
00031
00032 };
00033
00034
00035
00036
00037 template<class UnitSystem>
00038 struct formatted {
00039 FormatSpec<UnitSystem> spec;
00040 DynamicPhysical<UnitSystem> quantity;
00041 formatted(const DynamicPhysical<UnitSystem>& q, const FormatSpec<UnitSystem>& s): quantity(q), spec(s) {};
00042 };
00043
00044
00045 template<class UnitSystem>
00046 struct formatter {
00047 FormatSpec<UnitSystem> spec;
00048 formatter(const FormatSpec<UnitSystem>& s): spec(s) {};
00049 formatted<UnitSystem> operator()(const DynamicPhysical<UnitSystem>& q) {return formatted<UnitSystem>(q, spec);};
00050 };
00051
00052
00053 template<class UnitSystem>
00054 inline formatter<UnitSystem> format(const FormatSpec<UnitSystem>& s) {return formatter<UnitSystem>(s);};
00055
00056 template<class UnitSystem>
00057 inline formatted<UnitSystem> format(const DynamicPhysical<UnitSystem>& q, const FormatSpec<UnitSystem>& s) {return formatted<UnitSystem>(q,s);};
00058
00059
00060
00061 template<class UnitSystem>
00062 inline std::ostream& operator<<(std::ostream& os, const formatted<UnitSystem>& f) {
00063 return detail::format_to_spec(os, f.quantity, f.spec);
00064 };
00065
00066 };
00067
00068 };
00069
00070 #include "physical/detail/format_impl.hpp"
00071
00072 #endif // PHYSICAL_FORMAT