sbuild-format-detail.h

Go to the documentation of this file.
00001 /* Copyright © 2005-2006  Roger Leigh <rleigh@debian.org>
00002  *
00003  * schroot is free software; you can redistribute it and/or modify it
00004  * under the terms of the GNU General Public License as published by
00005  * the Free Software Foundation; either version 2 of the License, or
00006  * (at your option) any later version.
00007  *
00008  * schroot is distributed in the hope that it will be useful, but
00009  * WITHOUT ANY WARRANTY; without even the implied warranty of
00010  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011  * General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU General Public License
00014  * along with this program; if not, write to the Free Software
00015  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00016  * MA  02111-1307  USA
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 /* SBUILD_FORMAT_DETAIL_H */
00151 
00152 /*
00153  * Local Variables:
00154  * mode:C++
00155  * End:
00156  */

Generated on Sat May 27 15:46:00 2006 for schroot by  doxygen 1.4.6