source: XMLIO_V2/external/include/Poco/TeeStream.h @ 80

Last change on this file since 80 was 80, checked in by ymipsl, 14 years ago

ajout lib externe

  • Property svn:eol-style set to native
File size: 4.2 KB
Line 
1//
2// TeeStream.h
3//
4// $Id: //poco/1.3/Foundation/include/Poco/TeeStream.h#1 $
5//
6// Library: Foundation
7// Package: Streams
8// Module:  TeeStream
9//
10// Definition of the TeeStream class.
11//
12// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
13// and Contributors.
14//
15// Permission is hereby granted, free of charge, to any person or organization
16// obtaining a copy of the software and accompanying documentation covered by
17// this license (the "Software") to use, reproduce, display, distribute,
18// execute, and transmit the Software, and to prepare derivative works of the
19// Software, and to permit third-parties to whom the Software is furnished to
20// do so, all subject to the following:
21//
22// The copyright notices in the Software and this entire statement, including
23// the above license grant, this restriction and the following disclaimer,
24// must be included in all copies of the Software, in whole or in part, and
25// all derivative works of the Software, unless such copies or derivative
26// works are solely in the form of machine-executable object code generated by
27// a source language processor.
28//
29// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
32// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
33// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
34// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
35// DEALINGS IN THE SOFTWARE.
36//
37
38
39#ifndef Foundation_TeeStream_INCLUDED
40#define Foundation_TeeStream_INCLUDED
41
42
43#include "Poco/Foundation.h"
44#include "Poco/UnbufferedStreamBuf.h"
45#include <vector>
46#include <istream>
47#include <ostream>
48
49
50namespace Poco {
51
52
53class Foundation_API TeeStreamBuf: public UnbufferedStreamBuf
54        /// This stream buffer copies all data written to or
55        /// read from it to one or multiple output streams.
56{
57public:
58        TeeStreamBuf();
59                /// Creates an unconnected CountingStreamBuf.
60                /// Use addStream() to attach output streams.
61       
62        TeeStreamBuf(std::istream& istr);
63                /// Creates the CountingStreamBuf and connects it
64                /// to the given input stream.
65
66        TeeStreamBuf(std::ostream& ostr);
67                /// Creates the CountingStreamBuf and connects it
68                /// to the given output stream.
69
70        ~TeeStreamBuf();
71                /// Destroys the CountingStream.
72
73        void addStream(std::ostream& ostr);
74                /// Adds the given output stream.
75
76protected:
77        int readFromDevice();
78        int writeToDevice(char c);
79
80private:
81        typedef std::vector<std::ostream*> StreamVec;
82       
83        std::istream* _pIstr;
84        StreamVec     _streams;
85};
86
87
88class Foundation_API TeeIOS: public virtual std::ios
89        /// The base class for TeeInputStream and TeeOutputStream.
90        ///
91        /// This class is needed to ensure the correct initialization
92        /// order of the stream buffer and base classes.
93{
94public:
95        TeeIOS();
96                /// Creates the basic stream and leaves it unconnected.
97
98        TeeIOS(std::istream& istr);
99                /// Creates the basic stream and connects it
100                /// to the given input stream.
101
102        TeeIOS(std::ostream& ostr);
103                /// Creates the basic stream and connects it
104                /// to the given output stream.
105
106        ~TeeIOS();
107                /// Destroys the stream.
108
109        void addStream(std::ostream& ostr);
110                /// Adds the given output stream.
111
112        TeeStreamBuf* rdbuf();
113                /// Returns a pointer to the underlying streambuf.
114
115protected:
116        TeeStreamBuf _buf;
117};
118
119
120class Foundation_API TeeInputStream: public TeeIOS, public std::istream
121        /// This stream copies all characters read through it
122        /// to one or multiple output streams.
123{
124public:
125        TeeInputStream(std::istream& istr);
126                /// Creates the TeeInputStream and connects it
127                /// to the given input stream.
128
129        ~TeeInputStream();
130                /// Destroys the TeeInputStream.
131};
132
133
134class Foundation_API TeeOutputStream: public TeeIOS, public std::ostream
135        /// This stream copies all characters written to it
136        /// to one or multiple output streams.
137{
138public:
139        TeeOutputStream();
140                /// Creates an unconnected TeeOutputStream.
141       
142        TeeOutputStream(std::ostream& ostr);
143                /// Creates the TeeOutputStream and connects it
144                /// to the given input stream.
145
146        ~TeeOutputStream();
147                /// Destroys the TeeOutputStream.
148};
149
150
151} // namespace Poco
152
153
154#endif // Foundation_TeeStream_INCLUDED
Note: See TracBrowser for help on using the repository browser.