~charon-developers/charon-core/trunk

« back to all changes in this revision

Viewing changes to src/SplitStream.h

  • Committer: jmgottfried
  • Date: 2010-03-16 15:18:38 UTC
  • Revision ID: svn-v4:7d56a235-2f8b-4627-957e-5f30cc86da59:charon-core/trunk:680
moved header files to seperate include directory

this makes e.g. Compile and Load test work even if charon-core is not yet installed
and gives a chance to get charon-meta working

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*  This file is part of Charon.
2
 
 
3
 
    Charon is free software: you can redistribute it and/or modify
4
 
    it under the terms of the GNU Lesser General Public License as published by
5
 
    the Free Software Foundation, either version 3 of the License, or
6
 
    (at your option) any later version.
7
 
 
8
 
    Charon is distributed in the hope that it will be useful,
9
 
    but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 
    GNU Lesser General Public License for more details.
12
 
 
13
 
    You should have received a copy of the GNU Lesser General Public License
14
 
    along with Charon.  If not, see <http://www.gnu.org/licenses/>.
15
 
*/
16
 
/** @file SplitStream.h
17
 
 *  Declaration of class SplitStream.
18
 
 *  @author  <a href="mailto:jmgottfried@web.de">Jens-Malte Gottfried</a>
19
 
 *  @date    11.08.2008
20
 
 *  @remark  Used Interface from SplitStream Class of Daniel Kondermann
21
 
 */
22
 
 
23
 
#ifndef _SPLIT_STREAM_H_
24
 
#define _SPLIT_STREAM_H_
25
 
 
26
 
#ifdef WINDOWS
27
 
#ifdef DLLEX
28
 
#undef DLLEX
29
 
#endif // DLLEX
30
 
#ifdef CREATE_SHARED
31
 
#define DLLEX __declspec(dllexport)
32
 
#else  // CREATE_SHARED
33
 
#define DLLEX __declspec(dllimport)
34
 
#endif // CREATE_SHARED
35
 
#else  // WINDOWS
36
 
#define DLLEX
37
 
#endif // WINDOWS
38
 
 
39
 
#include <iostream>
40
 
#include <vector>
41
 
 
42
 
/** Buffer to split output on several streams.
43
 
 */
44
 
class DLLEX SplitStreamBuf : public std::streambuf {
45
 
private:
46
 
        /// pointer to stream buffers
47
 
        std::vector<std::streambuf*> buffers_;
48
 
        /// forbid copying
49
 
        SplitStreamBuf(SplitStreamBuf const &);
50
 
        /// forbid assignment
51
 
        void operator= (SplitStreamBuf const &);
52
 
 
53
 
public:
54
 
        /// Constructor initializing the buffers array
55
 
        SplitStreamBuf(const std::vector<std::streambuf*>& buffers);
56
 
        virtual ~SplitStreamBuf();
57
 
 
58
 
        /** Write character in the case of overflow.
59
 
         *  @param c        char value to check
60
 
         *  @return         EOF if overflow occured
61
 
         */
62
 
        int overflow(int c);
63
 
 
64
 
        /** Write sequence of characters.
65
 
         *  @param str      char array to put
66
 
         *  @param size     number of characters
67
 
         *  @return         number of written characters
68
 
         */
69
 
        std::streamsize xsputn(char const * str, std::streamsize size);
70
 
 
71
 
        /** Sync stream buffers.
72
 
         *  @return         EOF on failure
73
 
         */
74
 
        int sync();
75
 
};
76
 
 
77
 
/** This class wraps a list of output streams and
78
 
 *  pipes output made to a splitstream instance to
79
 
 *  all of these output streams.
80
 
 */
81
 
class DLLEX SplitStream : public std::ostream {
82
 
public:
83
 
        /// Default constructor
84
 
        /** Use no output stream.<br>
85
 
         *  Make sure you call assign() before using this SplitStream.
86
 
         */
87
 
        SplitStream();
88
 
 
89
 
        /** Assign one stream to output list.
90
 
         *  @param stream       stream to pipe output to
91
 
         */
92
 
        SplitStream(std::ostream& stream);
93
 
 
94
 
        /** Assign two streams to output list.
95
 
         *  @param stream1      fist output stream to assign
96
 
         *  @param stream2      second stream to assign
97
 
         */
98
 
        SplitStream(std::ostream& stream1, std::ostream& stream2);
99
 
 
100
 
        /** Assing a whole list of streams.
101
 
         *  @param streamList   list of streams to assign
102
 
         */
103
 
        SplitStream(std::vector<std::ostream*>& streamList);
104
 
 
105
 
        /// Default destructor
106
 
        virtual ~SplitStream();
107
 
 
108
 
        ///@name Stream assignment (see constructors for details)
109
 
        //@{
110
 
        void assign(std::ostream& stream = std::cout);
111
 
        void assign(std::ostream& stream1, std::ostream &stream2);
112
 
        void assign(std::vector<std::ostream*>& streamsList);
113
 
        //@}
114
 
 
115
 
        /** Dummy function to fulfill interface
116
 
         *  \deprecated         This function is not used in current plugins,
117
 
         *                      check if it's still needed.
118
 
         *  \return             always true
119
 
         */
120
 
        bool isZeroRank();
121
 
 
122
 
private:
123
 
        std::vector<std::streambuf*> buffers_;  ///< buffer array
124
 
        SplitStreamBuf* buffer_;                        ///< pointer to output stream buffer
125
 
 
126
 
        /**     Set new buffers.
127
 
         *      @param buffers          new buffers to set
128
 
         */
129
 
        void updateBuf(std::vector<std::streambuf*> buffers);
130
 
};
131
 
 
132
 
/// Dummy instance for usage in other files (for interface too).
133
 
extern DLLEX SplitStream sout;
134
 
 
135
 
#endif /* _SPLIT_STREAM_H_ */
136