1 /*========================================================================= 2 * 3 * Copyright Insight Software Consortium 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0.txt 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 *=========================================================================*/ 18 #ifndef itkStdStreamLogOutput_h 19 #define itkStdStreamLogOutput_h 20 21 #include <iostream> 22 #include <string> 23 24 #include <mutex> 25 #include "itkLogOutput.h" 26 27 namespace itk 28 { 29 /** \class StdStreamLogOutput 30 * \brief Represents a standard stream output stream. 31 * 32 * This class provides thread safety for the standard stream output stream. 33 * 34 * \author Hee-Su Kim, Compute Science Dept. Kyungpook National University, 35 * ISIS Center, Georgetown University. 36 * 37 * 38 * \ingroup OSSystemObjects LoggingObjects 39 * \ingroup ITKCommon 40 */ 41 42 class ITKCommon_EXPORT StdStreamLogOutput:public LogOutput 43 { 44 public: 45 46 using Self = StdStreamLogOutput; 47 using Superclass = LogOutput; 48 using Pointer = SmartPointer< Self >; 49 using ConstPointer = SmartPointer< const Self >; 50 51 using StreamType = std::ostream; 52 53 using StreamPointerType = std::ostream *; 54 55 itkTypeMacro(StdStreamLogOutput, LogOutput); 56 57 itkNewMacro(StdStreamLogOutput); 58 59 itkGetConstMacro(Stream, StreamPointerType); 60 61 /** Set a standard stream pointer */ 62 void SetStream(StreamType & Stream); 63 64 /** flush a buffer */ 65 void Flush() override; 66 67 /** Write to multiple outputs */ 68 void Write(double timestamp) override; 69 70 /** Write to a buffer */ 71 void Write(std::string const & content) override; 72 73 /** Write to a buffer */ 74 void Write(std::string const & content, double timestamp) override; 75 76 protected: 77 /** Constructor */ 78 StdStreamLogOutput(); 79 80 /** Destructor */ 81 ~StdStreamLogOutput() override; 82 83 void PrintSelf(std::ostream & os, Indent indent) const override; 84 85 private: 86 87 StreamPointerType m_Stream; 88 89 std::mutex m_Mutex; 90 }; 91 } 92 93 #endif //itkStdStreamLogOutput_h 94