Changeset 2053
- Timestamp:
- Sep 6, 2009, 7:55:57 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/yat/utility/StreamRedirect.h
r2052 r2053 38 38 \brief Redirect a stream to another stream. 39 39 40 40 This class can be used to redirect a stream so it uses the buffer 41 of another stream. This another stream is either a stream 42 provided by the caller or if the caller provide a string the an 43 internal fstream is created. In the destructor the stream is 44 restored to use its own buffer. See documentation of CommandLine 45 for an example of usage. 41 46 42 47 \note It is important that an instance of this class is … … 53 58 public: 54 59 /** 55 Constructor for ostream60 \brief redirect istream to another istream 56 61 57 62 \a is1 is redirected to get its input from the buffer of \a is2 … … 66 71 67 72 /** 68 Constructor for istream 69 70 If \a active is false, the class does nothing. 71 */ 72 BasicStreamRedirect(std::basic_istream<charT, traits>& os1, 73 \brief redirect istream to ifstream. 74 75 An ifstream with path \a file is created, and \a is is 76 redirected to get its input from the buffer of this ifstream. 77 78 If \a active is false, the class does nothing. 79 */ 80 BasicStreamRedirect(std::basic_istream<charT, traits>& is, 73 81 const std::string& file, bool active=true); 74 82 75 83 /** 76 Constructor for ostream84 \brief redirect ostream to another ostream 77 85 78 86 \a os1 is redirected to send its output to the buffer of \a os2 … … 87 95 88 96 /** 89 Constructor for ostream 90 91 If \a active is false, the class does nothing. 92 */ 93 BasicStreamRedirect(std::basic_ostream<charT, traits>& os1, 97 \brief redirect ostream to ofstream. 98 99 An ofstream with path \a file is created, and \a os is 100 redirected to send its output to the buffer of this ofstream. 101 102 If \a active is false, the class does nothing. 103 */ 104 BasicStreamRedirect(std::basic_ostream<charT, traits>& os, 94 105 const std::string& file, bool active=true); 95 106 … … 101 112 102 113 \note It is important that the stream held is not deallocated 103 before this object is destroyed. 1) The behavior of this 104 destructor is undefined. 2) The stream destroys the streambuf 105 in its destructor, so if the stream is destroyed before it is 106 restored, the streambuf will likely be deallocated twice. In 107 addition, the original streambuf of the stream will not be 108 closed and deallocated; hence a memory and resource leak. 114 before this object is destroyed. There are two reasons for 115 this: 1) The behavior of this destructor is undefined. 2) The 116 stream destroys the streambuf in its destructor, so if the 117 stream is destroyed before it is restored, the streambuf will 118 likely be deallocated twice. In addition, the original 119 streambuf of the stream will not be closed and deallocated; 120 hence a memory and resource leak. 109 121 */ 110 122 ~BasicStreamRedirect(void);
Note: See TracChangeset
for help on using the changeset viewer.