]> Creatis software - clitk.git/blob - common/clitkFilterBase.cxx
Removed memory leak
[clitk.git] / common / clitkFilterBase.cxx
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to: 
5   - University of LYON              http://www.universite-lyon.fr/
6   - Léon Bérard cancer center       http://oncora1.lyon.fnclcc.fr
7   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
8
9   This software is distributed WITHOUT ANY WARRANTY; without even
10   the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11   PURPOSE.  See the copyright notices for more information.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17   ======================================================================-====*/
18
19 // clitk
20 #include "clitkFilterBase.h"
21
22 //--------------------------------------------------------------------
23 clitk::FilterBase::FilterBase() 
24 {
25   SetMustStop(false);
26   SetVerboseOption(false);
27   SetCurrentStepNumber(0);
28   SetCurrentStepBaseId("");
29   StopOnErrorOn();
30   ResetLastError();
31   VerboseWarningOffOn(); // OffOn, it's cool no ?
32   SetWarning("");
33 }
34 //--------------------------------------------------------------------
35
36
37 //--------------------------------------------------------------------
38 void clitk::FilterBase::ResetLastError()
39 {
40   m_LastError = "";
41 }
42 //--------------------------------------------------------------------
43
44
45 //--------------------------------------------------------------------
46 void clitk::FilterBase::SetLastError(std::string e)
47 {
48   m_LastError = e;
49   if (GetStopOnError()) {
50     std::cerr << GetLastError() << std::endl;
51     exit(0);
52   }
53 }
54 //--------------------------------------------------------------------
55
56
57 //--------------------------------------------------------------------
58 void clitk::FilterBase::SetWarning(std::string e)
59 {
60   m_Warning = e;
61   if (!GetVerboseWarningOff()) {
62     std::cout << GetWarning() << std::endl;
63   }
64 }
65 //--------------------------------------------------------------------
66
67
68 //--------------------------------------------------------------------
69 void clitk::FilterBase::StartNewStep(std::string s) 
70 {
71   //m_CurrentStepTimer.Reset();
72   // m_CurrentStepTimer.Start();
73   m_CurrentStepNumber++;
74   if (GetCurrentStepBaseId() != "") {
75     std::ostringstream oss;
76     oss << GetCurrentStepBaseId() << "." << m_CurrentStepNumber;
77     SetCurrentStepId(oss.str());
78   }
79   else {
80     std::ostringstream oss;
81     oss << m_CurrentStepNumber;
82     SetCurrentStepId(oss.str());
83   }
84
85   m_CurrentStepName = "Step "+GetCurrentStepId()+" -- "+s;
86   if (m_VerboseStep) {
87     std::cout << m_CurrentStepName << std::endl;
88     //"Step " << GetCurrentStepId() << " -- " << s << std::endl;
89   }
90 }
91 //--------------------------------------------------------------------
92
93
94 //--------------------------------------------------------------------
95 void clitk::FilterBase::StopCurrentStep() 
96 {
97   // m_CurrentStepTimer.Stop();
98   //  m_CurrentStepTimer.Print(std::cout);
99   //  std::ostringstream oss;
100   //oss << " (" << 
101     //  m_CurrentStepName = m_CurrentStepName +"
102 }
103 //--------------------------------------------------------------------
104
105
106 //--------------------------------------------------------------------
107 void clitk::FilterBase::SetMustStop(bool b)
108 {
109   m_MustStop = b;
110   if (GetMustStop()) {
111     SetLastError("Filter is interrupted.");  
112   }
113 }
114 //--------------------------------------------------------------------
115
116
117 //--------------------------------------------------------------------
118 bool clitk::FilterBase::GetMustStop()
119 {
120   if (m_MustStop) return true;
121   if (HasError()) return true;
122   return false;
123 }
124 //--------------------------------------------------------------------
125
126