util.h

Go to the documentation of this file.
00001 /* libthrowable - a C++ library to ease error handling and debugging
00002  *
00003  * Copyright (C) Matthias Langer 2006 <mlangc@gmx.at>
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Library General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2.1 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Library General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Library General Public
00016  * License along with this library; if not, write to the Free
00017  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018  */
00019 
00020 #ifndef H_LIBTHROWABLE_UTIL
00021 #define H_LIBTHROWABLE_UTIL
00022 #include <string>
00023 #include <sstream>
00024 #include "libthrowable/system.h"
00025 namespace libthrowable {
00029 namespace util {
00030 
00035 template<class OStreamableT> 
00036 std::string LIBTHROWABLE_API stringify(const OStreamableT& arg) throw();
00037 
00041 int LIBTHROWABLE_API getTerminalWidth() throw();
00042 
00045 std::string LIBTHROWABLE_API addIndent(const std::string& str, unsigned indent) throw();
00046 
00050 std::string LIBTHROWABLE_API optimizeForLineWidth(const std::string& str, int width) throw();
00051 
00056 inline std::string LIBTHROWABLE_API 
00057     optimizeForTerminalWidth(const std::string& str) throw()
00058 { return optimizeForLineWidth(str, getTerminalWidth()); }
00059 
00060 template<class OStreamableT> 
00061 std::string stringify(const OStreamableT& arg) throw()
00062 {
00063     std::ostringstream os;
00064     os << arg;
00065     return os.str();
00066 }
00067 
00068 inline std::string stringify(bool arg) throw()
00069 {
00070     return (arg ? "true" : "false");
00071 }
00072 
00073 }}//namespaces
00074 #endif
00075 

Generated on Wed Jan 9 18:07:17 2008 for libthrowable by  doxygen 1.5.4  Hosted on  SourceForge.net Logo