1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
/*=========================================================================
Program: Image Guided Surgery Software Toolkit
Module: $RCSfile: igstkFLTKTextLogOutput.cxx,v $
Language: C++
Date: $Date: 2010-10-29 21:06:42 $
Version: $Revision: 1.11 $
Copyright (c) ISC Insight Software Consortium. All rights reserved.
See IGSTKCopyright.txt or http://www.igstk.org/copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include <iostream>
#include <stdio.h>
#include <itkMacro.h>
#include "igstkFLTKTextLogOutput.h"
#if defined(_MSC_VER)
// Disabling warning C4355: 'this' : used in base member initializer list
#pragma warning ( disable : 4355 )
// Warning about: identifier was truncated to '255' characters in the
// debug information (MVC6.0 Debug)
#pragma warning( disable : 4786 )
#endif
namespace igstk
{
/** Constructor */
FLTKTextLogOutput::FLTKTextLogOutput():m_StateMachine(this)
{
this->m_Stream = 0;
}
/** Destructor */
FLTKTextLogOutput::~FLTKTextLogOutput()
{
free( m_Stream->buffer()->text() );
}
/** Set an output stream */
void FLTKTextLogOutput::SetStream(StreamType &Stream)
{
this->m_Stream = &Stream;
}
/** Flush a buffer */
void FLTKTextLogOutput::Flush()
{
// Flushing is immediately done. (we don't need)
}
/** Write to a buffer */
void FLTKTextLogOutput::Write(double timestamp)
{
FLTKTextLogOutput::m_Mutex.Lock();
if( this->m_Stream && this->m_Stream->buffer() )
{
std::ostringstream ostr;
ostr.precision(30);
ostr << timestamp;
this->m_Stream->insert( ostr.str().c_str() );
}
FLTKTextLogOutput::m_Mutex.Unlock();
}
/** Write to a buffer */
void FLTKTextLogOutput::Write(std::string const &content)
{
FLTKTextLogOutput::m_Mutex.Lock();
if( this->m_Stream && this->m_Stream->buffer() )
{
this->m_Stream->insert( content.c_str() );
}
FLTKTextLogOutput::m_Mutex.Unlock();
}
/** Write to a buffer */
void FLTKTextLogOutput::Write(std::string const &content, double timestamp)
{
FLTKTextLogOutput::m_Mutex.Lock();
if( this->m_Stream && this->m_Stream->buffer() )
{
std::ostringstream ostr;
ostr.precision(30);
ostr << timestamp << " : " << content;
this->m_Stream->insert( ostr.str().c_str() );
this->m_Stream->scroll(this->m_Stream->insert_position(), 0);
}
FLTKTextLogOutput::m_Mutex.Unlock();
}
/** PrintSelf function */
void FLTKTextLogOutput::PrintSelf( std::ostream& os, itk::Indent indent ) const
{
Superclass::PrintSelf(os, indent);
if( this->m_Stream )
{
os << indent << "Stream is available" << std::endl;
}
else
{
os << indent << "Stream is NULL" << std::endl;
}
}
} // end namespace igstk
|