Line data Source code
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 : 14 : OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL 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 : */ 24 : class RestoreOutputStreamState { 25 : public: 26 3 : explicit RestoreOutputStreamState(std::ostream& stream) 27 3 : : stream_(stream) 28 3 : , saved_(0) 29 : { 30 3 : saved_.copyfmt(stream); 31 3 : } 32 : 33 3 : ~RestoreOutputStreamState() 34 : { 35 3 : stream_.copyfmt(saved_); 36 3 : } 37 : 38 : private: 39 : std::ostream& stream_; 40 : std::ios saved_; 41 : }; 42 : 43 : } // namespace DCPS 44 : } // namespace OpenDDS 45 : 46 : OPENDDS_END_VERSIONED_NAMESPACE_DECL 47 : 48 : #endif /* OPENDDS_DCPS_RESTORE_OUTPUT_STREAM_STATE_H */