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 
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 /* SBUILD_FORMAT_DETAIL_H */
00139 
00140 /*
00141  * Local Variables:
00142  * mode:C++
00143  * End:
00144  */

Generated on Sat Jun 17 14:41:22 2006 for schroot by  doxygen 1.4.6