00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef SBUILD_FORMAT_DETAIL_H
00021 #define SBUILD_FORMAT_DETAIL_H
00022
00023 #include "sbuild-config.h"
00024
00025 #include <iomanip>
00026 #include <ostream>
00027 #include <string>
00028
00029 #include "sbuild-types.h"
00030 #include "sbuild-util.h"
00031
00032 namespace sbuild
00033 {
00034
00042 template<typename T>
00043 class format_detail;
00044
00045 template<typename T> std::ostream&
00046 operator << (std::ostream&, format_detail<T> const&);
00047
00056 template<> std::ostream&
00057 operator << (std::ostream&, format_detail<bool> const&);
00058
00067 template<> std::ostream&
00068 operator << (std::ostream&, format_detail<string_list> const&);
00069
00073 template<typename T>
00074 class format_detail
00075 {
00083 public:
00084 format_detail (std::string const& name,
00085 T const& value):
00086 name(name),
00087 value(value)
00088 {}
00089
00090 friend std::ostream&
00091 operator << <>(std::ostream&, format_detail<T> const&);
00092
00093 private:
00095 std::string const& name;
00097 T const& value;
00098 };
00099
00100 template<typename T>
00101 inline std::ostream&
00102 operator << (std::ostream& stream,
00103 format_detail<T> const& rhs)
00104 {
00105 return stream << " "
00106 << std::setw(22) << std::left << rhs.name
00107 << rhs.value << '\n';
00108 }
00109
00110 template<>
00111 inline std::ostream&
00112 operator << (std::ostream& stream,
00113 format_detail<string_list> const& rhs)
00114 {
00115 return stream <<
00116 format_detail<std::string>(rhs.name,
00117 string_list_to_string(rhs.value, " "));
00118 }
00119
00128 template<typename T>
00129 inline format_detail<T>
00130 format_details (std::string const& name,
00131 T const& value)
00132 {
00133 return format_detail<T>(name, value);
00134 }
00135
00136 }
00137
00138 #endif
00139
00140
00141
00142
00143
00144