The Battle for Wesnoth
1.13.4+dev
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Modules
Pages
formatter.hpp
Go to the documentation of this file.
1
/*
2
Copyright (C) 2007 - 2016 by David White <dave.net>
3
Part of the Silver Tree Project
4
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by or later.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY.
9
10
See the COPYING file for more details.
11
*/
12
13
#ifndef FORMATTER_HPP_INCLUDED
14
#define FORMATTER_HPP_INCLUDED
15
16
#include <sstream>
17
18
/**
19
* std::ostringstream wrapper.
20
*
21
* ostringstream's operator<< doesn't return a ostringstream&. It returns an
22
* ostream& instead. This is unfortunate, because it means that you can't do
23
* something like this: (ostringstream() << n).str() to convert an integer to a
24
* string, all in one line instead you have to use this far more tedious
25
* approach:
26
* ostringstream s;
27
* s << n;
28
* s.str();
29
* This class corrects this shortcoming, allowing something like this:
30
* string result = (formatter() << "blah " << n << x << " blah").str();
31
*/
32
class
formatter
33
{
34
public
:
35
formatter
() :
36
stream_
()
37
{
38
}
39
40
template
<
typename
T>
41
formatter
&
operator<<
(
const
T& o) {
42
stream_
<< o;
43
return
*
this
;
44
}
45
46
std::string
str
() {
47
return
stream_
.str();
48
}
49
50
private
:
51
std::ostringstream
stream_
;
52
};
53
54
#endif
formatter::operator<<
formatter & operator<<(const T &o)
Definition:
formatter.hpp:41
formatter::formatter
formatter()
Definition:
formatter.hpp:35
formatter
std::ostringstream wrapper.
Definition:
formatter.hpp:32
formatter::str
std::string str()
Definition:
formatter.hpp:46
formatter::stream_
std::ostringstream stream_
Definition:
formatter.hpp:51
string
GLsizei const GLcharARB ** string
Definition:
glew.h:4503
Generated by
1.8.8