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
00035 template<typename T>
00036 class format_detail;
00037
00038 template<typename T> std::ostream&
00039 operator << (std::ostream&, format_detail<T> const&);
00040 template<> std::ostream&
00041 operator << (std::ostream&, format_detail<bool> const&);
00042 template<> std::ostream&
00043 operator << (std::ostream&, format_detail<string_list> const&);
00044
00048 template<typename T>
00049 class format_detail
00050 {
00058 public:
00059 format_detail (std::string const& name,
00060 T const& value):
00061 name(name),
00062 value(value)
00063 {}
00064
00065 friend std::ostream&
00066 operator << <>(std::ostream&, format_detail<T> const&);
00067
00068
00069 private:
00071 std::string const& name;
00073 T const& value;
00074 };
00075
00083 template<typename T>
00084 inline std::ostream&
00085 operator << (std::ostream& stream,
00086 format_detail<T> const& rhs)
00087 {
00088 return stream << " "
00089 << std::setw(22) << std::left << rhs.name
00090 << rhs.value << '\n';
00091 }
00092
00101 template<>
00102 inline std::ostream&
00103 operator << (std::ostream& stream,
00104 format_detail<bool> const& rhs)
00105 {
00106 const char *desc = 0;
00107 if (rhs.value)
00108 desc = _("true");
00109 else
00110 desc = _("false");
00111 return stream << format_detail<std::string>(rhs.name, desc);
00112 }
00113
00122 template<>
00123 inline std::ostream&
00124 operator << (std::ostream& stream,
00125 format_detail<string_list> const& rhs)
00126 {
00127 return stream <<
00128 format_detail<std::string>(rhs.name,
00129 string_list_to_string(rhs.value, " "));
00130 }
00131
00140 template<typename T>
00141 inline format_detail<T>
00142 format_details (std::string const& name,
00143 T const& value)
00144 {
00145 return format_detail<T>(name, value);
00146 }
00147
00148 }
00149
00150 #endif
00151
00152
00153
00154
00155
00156