KWStyle - itkOutputWindow.cxx
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkOutputWindow.cxx.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:43 $
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   Portions of this code are covered under the VTK copyright.
13   See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details.
14
15      This software is distributed WITHOUT ANY WARRANTY; without even 
16      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
17 IND *****PURPOSE.  See the above copyright notices for more information.
18
19 DEF =========================================================================*/
20 #include "itkOutputWindow.h"
21 #ifdef _WIN32
22 #include "itkWin32OutputWindow.h"
23 #endif
24 #include "itkObjectFactory.h"
25
26 namespace itk
27 {
28   
29 OutputWindow::Pointer OutputWindow::m_Instance = 0;
30
31 /**
32  * Prompting off by default
33  */
34 OutputWindow
35 ::OutputWindow()
36 {
37   m_PromptUser = 0;
38 }
39
40 OutputWindow
41 ::~OutputWindow()
42 {
43 }
44
45 void 
46 OutputWindowDisplayText(const char* message)
47 {
48   OutputWindow::GetInstance()->DisplayText(message);
49 }
50
51 void 
52 OutputWindowDisplayErrorText(const char* message)
53 {
54   OutputWindow::GetInstance()->DisplayErrorText(message);
55 }
56
57 void 
58 OutputWindowDisplayWarningText(const char* message)
59 {
60   OutputWindow::GetInstance()->DisplayWarningText(message);
61 }
62
63 void 
64 OutputWindowDisplayGenericOutputText(const char* message)
65 {
66   OutputWindow::GetInstance()->DisplayGenericOutputText(message);
67 }
68
69 void 
70 OutputWindowDisplayDebugText(const char* message)
71 {
72   OutputWindow::GetInstance()->DisplayDebugText(message);
73 }
74
75
76 void 
77 OutputWindow
78 ::PrintSelf(std::ostream& os, Indent indent) const
79 {
80   Superclass::PrintSelf(os, indent);
81
82   os << indent << "OutputWindow (single instance): "
83      << (void*)OutputWindow::m_Instance << std::endl;
84
85   os << indent << "Prompt User: " << (m_PromptUser ? "On\n" : "Off\n");
86 }
87
88
89 /**
90  * default implementation outputs to cerr only
91  */
92 void 
93 OutputWindow
94 ::DisplayText(const char* txt)
95 {
96   std::cerr << txt;
97   if ( m_PromptUser )
98     {
99     char c = 'n';
100     std::cerr << "\nDo you want to suppress any further messages (y,n)?." 
101               << std::endl;
102     std::cin >> c;
103     if ( c == 'y' || c == 'Y' )
104       {
105       Object::GlobalWarningDisplayOff(); 
106       }
107     }
108 }
109
110 /**
111  * Return the single instance of the OutputWindow
112  */
113 OutputWindow::Pointer
114 OutputWindow
115 ::GetInstance()
116 {
117   if ( !OutputWindow::m_Instance )
118     {
119     // Try the factory first
120     OutputWindow::m_Instance  = ObjectFactory<Self>::Create();
121     // if the factory did not provide one, then create it here
122     if( ! OutputWindow::m_Instance )
123       {
124       // For the windows OS, use a special output window
125 #ifdef _WIN32
126       OutputWindow::m_Instance = Win32OutputWindow::New();
127 IND #else
128       OutputWindow::m_Instance = new OutputWindow;
129       // Remove extra reference from construction.
130       OutputWindow::m_Instance->UnRegister();
131 #endif
132       }
133     }
134   /**
135    * return the instance
136    */
137   return OutputWindow::m_Instance;
138 }
139
140 void 
141 OutputWindow
142 ::SetInstance(OutputWindow* instance)
143 {
144   if ( OutputWindow::m_Instance == instance )
145     {
146     return;
147     }
148   OutputWindow::m_Instance = instance;
149 }
150
151 /**
152  * This just calls GetInstance
153  */
154 OutputWindow::Pointer 
155 OutputWindow
156 ::New()
157
158   return GetInstance();
159 }
160
161
162 // end namespace itk
163

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