formatter.hpp

Go to the documentation of this file.
00001 
00002 /*
00003    Copyright (C) 2007 by David White <dave.net>
00004    Part of the Silver Tree Project
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License version 2 or later.
00008    This program is distributed in the hope that it will be useful,
00009    but WITHOUT ANY WARRANTY.
00010 
00011    See the COPYING file for more details.
00012 */
00013 #ifndef FORMATTER_HPP_INCLUDED
00014 #define FORMATTER_HPP_INCLUDED
00015 
00016 #include <sstream>
00017 
00018 class formatter
00019 {
00020 public:
00021     template<typename T>
00022     formatter& operator<<(const T& o) {
00023         stream_ << o;
00024         return *this;
00025     }
00026 
00027     const std::string str() {
00028         return stream_.str();
00029     }
00030 
00031     const char* c_str() {
00032         return str().c_str();
00033     }
00034 
00035     operator std::string() {
00036         return stream_.str();
00037     }
00038 private:
00039     std::ostringstream stream_;
00040 };
00041 
00042 #endif

Generated by doxygen 1.5.5 on 23 May 2008 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs