KWStyle - itkFileOutputWindow.cxx
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkFileOutputWindow.cxx.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:35 $
7   Version:   $Revision: 1.4 $
8
9   Copyright (c) Insight Software Consortium. All rights reserved.
10   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11
12      This software is distributed WITHOUT ANY WARRANTY; without even 
13      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14      PURPOSE.  See the above copyright notices for more information.
15
16 DEF =========================================================================*/
17 #include "itkFileOutputWindow.h"
18
19 namespace itk
20 {
21   
22 /**
23  * Prompting off by default
24  */
25 FileOutputWindow
26 ::FileOutputWindow()
27 {
28   m_Flush = false;
29   m_Append = false;
30   m_Stream = 0;
31   m_FileName = "";
32 }
33
34 FileOutputWindow
35 ::~FileOutputWindow()
36 {
37   if (m_Stream)
38     {
39     delete m_Stream;
40     m_Stream = 0;
41     }
42 }
43
44 void 
45 FileOutputWindow
46 ::PrintSelf(std::ostream& os, Indent indent) const
47 {
48   Superclass::PrintSelf(os, indent);
49
50   os << indent << "FileName: " << m_FileName << std::endl;
51   os << indent << "Stream: " << m_Stream << std::endl;
52   os << indent << "Append: " << (m_Append ? "On\n" : "Off\n") << std::endl;
53   os << indent << "Flush: " << (m_Flush ? "On\n" : "Off\n") << std::endl;
54 }
55
56
57 void
58 FileOutputWindow
59 ::Initialize() 
60 {
61   if (!m_Stream)
62     {
63     if (m_FileName == "")
64       {
65       m_FileName = "itkMessageLog.txt";
66       }
67     if (m_Append)
68       {
69       m_Stream = new std::ofstream(m_FileName.c_str(), std::ios::app);
70       }
71     else
72       {
73       m_Stream = new std::ofstream(m_FileName.c_str());
74       }
75     }
76 }
77
78
79 /**
80  * 
81  */
82 void 
83 FileOutputWindow
84 ::DisplayText(const char* txt)
85 {
86   if (!txt)
87     {
88     return;
89     }
90
91   if (!m_Stream)
92     {
93     this->Initialize();
94     }
95   *m_Stream << txt << std::endl;
96   
97   if (m_Flush)
98     {
99     m_Stream->flush();
100     }
101 }
102
103 // end namespace itk
104

Generated by KWStyle 1.0b on Tuesday January,17 at 02:14:07PM
© Kitware Inc.