Line data Source code
1 : /*
2 : * Copyright (c) 2011-2015: G-CSC, Goethe University Frankfurt
3 : * Author: Sebastian Reiter
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 : #include "ostream_buffer_splitter.h"
34 :
35 : using namespace std;
36 :
37 : namespace ug{
38 :
39 1 : OStreamBufferSplitter::
40 1 : OStreamBufferSplitter() : m_buf1(NULL), m_buf2(NULL)
41 : {
42 1 : setp(m_buf, m_buf + BUF_SIZE);
43 1 : }
44 :
45 0 : OStreamBufferSplitter::
46 0 : OStreamBufferSplitter(std::streambuf* buf1, std::streambuf* buf2)
47 : {
48 0 : set_buffers(buf1, buf2);
49 0 : }
50 :
51 1 : OStreamBufferSplitter::
52 1 : ~OStreamBufferSplitter()
53 : {
54 1 : flush();
55 1 : }
56 :
57 3 : void OStreamBufferSplitter::flush()
58 : {
59 3 : if(m_buf1 && m_buf2 && (pptr() != pbase())){
60 : // write whats left in the buffer to the split-buffers
61 0 : m_buf1->sputn(pbase(), pptr() - pbase());
62 0 : m_buf2->sputn(pbase(), pptr() - pbase());
63 : }
64 3 : setp(m_buf, m_buf + BUF_SIZE);
65 3 : }
66 :
67 1 : void OStreamBufferSplitter::
68 : set_buffers(std::streambuf* buf1, std::streambuf* buf2)
69 : {
70 1 : flush();
71 :
72 1 : m_buf1 = buf1;
73 1 : m_buf2 = buf2;
74 1 : }
75 :
76 0 : ostream::int_type OStreamBufferSplitter::
77 : overflow(ostream::int_type c)
78 : {
79 0 : if(m_buf1 && m_buf2){
80 0 : m_buf1->sputn(pbase(), pptr() - pbase());
81 0 : m_buf2->sputn(pbase(), pptr() - pbase());
82 0 : if(!traits_type::eq_int_type(m_buf1->sputc(c), traits_type::eof())
83 0 : && !traits_type::eq_int_type(m_buf2->sputc(c), traits_type::eof()))
84 : {
85 0 : setp(m_buf, m_buf + BUF_SIZE);
86 : return traits_type::not_eof(c);
87 : }
88 : }
89 : return traits_type::eof();
90 : }
91 :
92 : }// end of namespace
|