C:/nobackup/private/physical_svn/trunk/include/physical/format.hpp

Go to the documentation of this file.
00001 
00002 /*=============================================================================
00003     physical quantities / units / constants
00004     Copyright (c) 2006, 2007 Martin Schulz
00005     http://physical.sourceforge.net
00006   
00007     This is private code by Martin Schulz.
00008   
00009     Use, modification and distribution is subject to the Boost Software
00010     License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
00011     http://www.boost.org/LICENSE_1_0.txt)
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                 }; // namespace detail
00033 
00034                 // formatting objects to be used with std::ostreams:
00035         
00036                 // FIXME: what members to hold as copy, which as reference?
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                 // FIXME: what members to hold as copy, which as reference?
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         }; // namespace format
00067 
00068 }; // namespace physical
00069 
00070 #include "physical/detail/format_impl.hpp"
00071 
00072 #endif // PHYSICAL_FORMAT

Generated on Mon Apr 2 22:25:03 2007 for physical_svn by  doxygen 1.5.1-p1
hosted on SourceForge.net Logo