OpenDDS  Snapshot(2023/04/28-20:55)
RestoreOutputStreamState.h
Go to the documentation of this file.
1 /*
2  * Distributed under the OpenDDS License.
3  * See: http://www.opendds.org/license.html
4  */
5 
6 #ifndef OPENDDS_DCPS_RESTORE_OUTPUT_STREAM_STATE_H
7 #define OPENDDS_DCPS_RESTORE_OUTPUT_STREAM_STATE_H
8 
9 // This file is used by opendds_idl, so it must be relative.
10 #include "../Versioned_Namespace.h"
11 
12 #include <ostream>
13 
15 
16 namespace OpenDDS {
17 namespace DCPS {
18 
19 /**
20  * Save and automatically restore various formatting properties of a
21  * std::ostream. This should be used in custom operator<< overload functions
22  * when changing these properties.
23  */
25 public:
26  explicit RestoreOutputStreamState(std::ostream& stream)
27  : stream_(stream)
28  , saved_(0)
29  {
30  saved_.copyfmt(stream);
31  }
32 
34  {
35  stream_.copyfmt(saved_);
36  }
37 
38 private:
39  std::ostream& stream_;
40  std::ios saved_;
41 };
42 
43 } // namespace DCPS
44 } // namespace OpenDDS
45 
47 
48 #endif /* OPENDDS_DCPS_RESTORE_OUTPUT_STREAM_STATE_H */
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28