Loading [MathJax]/extensions/tex2jax.js
ug4
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
string_table_stream.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2013-2015: G-CSC, Goethe University Frankfurt
3 * Author: Martin Rupp
4 *
5 * This file is part of UG4.
6 *
7 * UG4 is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License version 3 (as published by the
9 * Free Software Foundation) with the following additional attribution
10 * requirements (according to LGPL/GPL v3 §7):
11 *
12 * (1) The following notice must be displayed in the Appropriate Legal Notices
13 * of covered and combined works: "Based on UG4 (www.ug4.org/license)".
14 *
15 * (2) The following notice must be displayed at a prominent place in the
16 * terminal output of covered works: "Based on UG4 (www.ug4.org/license)".
17 *
18 * (3) The following bibliography is recommended for citation and must be
19 * preserved in all covered files:
20 * "Reiter, S., Vogel, A., Heppner, I., Rupp, M., and Wittum, G. A massively
21 * parallel geometric multigrid solver on hierarchically distributed grids.
22 * Computing and visualization in science 16, 4 (2013), 151-164"
23 * "Vogel, A., Reiter, S., Rupp, M., Nägel, A., and Wittum, G. UG4 -- a novel
24 * flexible software system for simulating pde based models on high performance
25 * computers. Computing and visualization in science 16, 4 (2013), 165-179"
26 *
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU Lesser General Public License for more details.
31 */
32
33#ifndef STRING_TABLE_STREAM_H_
34#define STRING_TABLE_STREAM_H_
35
36#include <vector>
37#include "table.h"
38#include "string_util.h"
39#include "stringify.h"
40
44
64namespace ug{
66{
67private:
69 size_t m_curRow;
70 size_t m_curCol;
71
72public:
74 {
76 }
77
78 StringTable &table() { return s; }
79
85 template<typename T>
87 {
88 s(m_curRow, m_curCol++) = ToString(t);
89 return *this;
90 }
91
98 {
99 size_t l = strlen(c);
100// size_t begin=0;
101 std::vector<char> vc;
102 for(size_t i=0; i<l; i++)
103 {
104 if(c[i] == '\n')
105 {
106 vc.push_back(0);
107 s(m_curRow, m_curCol) = &vc[0];
108 vc.clear();
109 m_curRow++;
110 m_curCol=0;
111 if(i == l-1) return *this;
112 }
113 else
114 vc.push_back(c[i]);
115 }
116 vc.push_back(0);
117 s(m_curRow, m_curCol++) = &vc[0];
118 return *this;
119 }
120
121
122
124 {
125 RepeatedCol(std::string _content, size_t _number) :
126 content(_content), number(_number) {}
127 std::string content;
128 size_t number;
129 };
130
132 {
133 for(size_t i=0; i<c.number; i++)
134 *this << c.content;
135 return *this;
136 }
137
138
157 {
158 return RepeatedCol("", i);
159 }
160
178 template<typename T>
179 RepeatedCol repeat_col(size_t nrRepeat, T contentToRepeat)
180 {
181 return RepeatedCol(ToString(contentToRepeat), nrRepeat);
182 }
183
184 template<typename T>
185 void set(size_t r, size_t c, T t)
186 {
187 s(r, c) = ToString(t);
188 }
189
191 {
192 *this << str.c_str();
193 return *this;
194 }
195 std::string to_string() const
196 {
197 return s.to_string();
198 }
199
200 void clear()
201 {
202 m_curRow=m_curCol = 0;
203 s.clear();
204 }
205};
206
207inline std::ostream& operator << (std::ostream& os, const StringTableStream &sts)
208{
209 os << sts.to_string();
210 return os;
211}
212
213}
214#endif /* STRING_TABLE_STREAM_H_ */
Definition string_table_stream.h:66
std::string to_string() const
Definition table_impl.hpp:153
void clear()
Definition table_impl.hpp:73
std::ostream & operator<<(std::ostream &outStream, const ug::MathMatrix< 2, 2 > &m)
Definition math_matrix.cpp:38
StringTable & table()
Definition string_table_stream.h:78
void clear()
Definition string_table_stream.h:200
StringTableStream()
Definition string_table_stream.h:73
size_t number
Definition string_table_stream.h:128
RepeatedCol empty_col(size_t i)
Definition string_table_stream.h:156
std::string to_string() const
Definition string_table_stream.h:195
size_t m_curRow
Definition string_table_stream.h:69
void set(size_t r, size_t c, T t)
Definition string_table_stream.h:185
StringTable s
Definition string_table_stream.h:68
std::string content
Definition string_table_stream.h:127
StringTableStream & operator<<(T t)
Definition string_table_stream.h:86
RepeatedCol repeat_col(size_t nrRepeat, T contentToRepeat)
Definition string_table_stream.h:179
size_t m_curCol
Definition string_table_stream.h:70
RepeatedCol(std::string _content, size_t _number)
Definition string_table_stream.h:125
std::string ToString(const T &t)
Convert a object supporting 'std::cout << obj' to a string.
Definition string_util.h:362
double number
Definition types.h:124
the ug namespace
Definition string_table_stream.h:124