source: trunk/source/global/management/src/G4StateManager.cc@ 1343

Last change on this file since 1343 was 1340, checked in by garnier, 15 years ago

update ti head

File size: 7.3 KB
Line 
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27// $Id: G4StateManager.cc,v 1.15 2010/10/01 16:36:31 gcosmo Exp $
28// GEANT4 tag $Name: global-V09-03-22 $
29//
30//
31// ------------------------------------------------------------
32// GEANT 4 class implementation file
33//
34// ---------------- G4StateManager ----------------
35// by Gabriele Cosmo, November 1996
36// ------------------------------------------------------------
37
38#include "G4StateManager.hh"
39
40// Initialization of the static pointer of the single class instance
41//
42G4StateManager* G4StateManager::theStateManager = 0;
43
44G4StateManager::G4StateManager()
45 : theCurrentState(G4State_PreInit),
46 thePreviousState(G4State_PreInit),
47 theBottomDependent(0),
48 suppressAbortion(0),
49 msgptr(0),
50 exceptionHandler(0)
51{
52}
53
54G4StateManager::~G4StateManager()
55{
56 G4VStateDependent* state=0;
57
58 while (theDependentsList.size()>0)
59 {
60 state = theDependentsList.back();
61 theDependentsList.pop_back();
62 for (std::vector<G4VStateDependent*>::iterator
63 i=theDependentsList.begin(); i!=theDependentsList.end();)
64 {
65 if (*i==state)
66 {
67 i = theDependentsList.erase(i);
68 }
69 else
70 {
71 ++i;
72 }
73 }
74 if ( state ) { delete state; }
75 }
76}
77
78// -------------------------------------------------------------------------
79// No matter how copy-constructor and operators below are implemented ...
80// just dummy implementations, since not relevant for the singleton and
81// declared private.
82//
83G4StateManager::G4StateManager(const G4StateManager &right)
84 : theCurrentState(right.theCurrentState),
85 thePreviousState(right.thePreviousState),
86 theDependentsList(right.theDependentsList),
87 theBottomDependent(right.theBottomDependent),
88 suppressAbortion(right.suppressAbortion),
89 msgptr(right.msgptr),
90 exceptionHandler(right.exceptionHandler)
91{
92}
93
94G4StateManager&
95G4StateManager::operator=(const G4StateManager &right)
96{
97 if (&right == this) { return *this; }
98
99 theCurrentState = right.theCurrentState;
100 thePreviousState = right.thePreviousState;
101 theDependentsList = right.theDependentsList;
102 theBottomDependent = right.theBottomDependent;
103 suppressAbortion = right.suppressAbortion;
104 msgptr = right.msgptr;
105 exceptionHandler = right.exceptionHandler;
106
107 return *this;
108}
109
110G4int
111G4StateManager::operator==(const G4StateManager &right) const
112{
113 return (this == &right);
114}
115
116G4int
117G4StateManager::operator!=(const G4StateManager &right) const
118{
119 return (this != &right);
120}
121//
122// -------------------------------------------------------------------------
123
124G4StateManager*
125G4StateManager::GetStateManager()
126{
127 if (!theStateManager)
128 {
129 theStateManager = new G4StateManager;
130 }
131 return theStateManager;
132}
133
134G4bool
135G4StateManager::RegisterDependent(G4VStateDependent* aDependent, G4bool bottom)
136{
137 G4bool ack=true;
138 if(!bottom)
139 {
140 theDependentsList.push_back(aDependent);
141 }
142 else
143 {
144 if(theBottomDependent)
145 {
146 theDependentsList.push_back(theBottomDependent);
147 }
148 theBottomDependent = aDependent;
149 }
150 return ack;
151}
152
153G4bool
154G4StateManager::DeregisterDependent(G4VStateDependent* aDependent)
155{
156 G4VStateDependent* tmp = 0;
157 for (std::vector<G4VStateDependent*>::iterator i=theDependentsList.begin();
158 i!=theDependentsList.end();)
159 {
160 if (**i==*aDependent)
161 {
162 tmp = *i;
163 i = theDependentsList.erase(i);
164 }
165 else
166 {
167 ++i;
168 }
169 }
170 return (tmp != 0);
171}
172
173G4ApplicationState
174G4StateManager::GetCurrentState() const
175{
176 return theCurrentState;
177}
178
179G4ApplicationState
180G4StateManager::GetPreviousState() const
181{
182 return thePreviousState;
183}
184
185G4bool
186G4StateManager::SetNewState(G4ApplicationState requestedState)
187{ return SetNewState(requestedState,0); }
188
189G4bool
190G4StateManager::SetNewState(G4ApplicationState requestedState, const char* msg)
191{
192 if(requestedState==G4State_Abort && suppressAbortion>0)
193 {
194 if(suppressAbortion==2) { return false; }
195 if(theCurrentState==G4State_EventProc) { return false; }
196 }
197 msgptr = msg;
198 size_t i=0;
199 G4bool ack = true;
200 G4ApplicationState savedState = thePreviousState;
201 thePreviousState = theCurrentState;
202 while ((ack) && (i<theDependentsList.size()))
203 {
204 ack = theDependentsList[i]->Notify(requestedState);
205 i++;
206 }
207 if(theBottomDependent)
208 {
209 ack = theBottomDependent->Notify(requestedState);
210 }
211
212 if(!ack)
213 { thePreviousState = savedState; }
214 else
215 { theCurrentState = requestedState; }
216 msgptr = 0;
217 return ack;
218}
219
220G4VStateDependent*
221G4StateManager::RemoveDependent(const G4VStateDependent* aDependent)
222{
223 G4VStateDependent* tmp = 0;
224 for (std::vector<G4VStateDependent*>::iterator i=theDependentsList.begin();
225 i!=theDependentsList.end();)
226 {
227 if (**i==*aDependent)
228 {
229 tmp = *i;
230 i = theDependentsList.erase(i);
231 }
232 else
233 {
234 ++i;
235 }
236 }
237 return tmp;
238}
239
240G4String
241G4StateManager::GetStateString(G4ApplicationState aState) const
242{
243 G4String stateName;
244 switch(aState)
245 {
246 case G4State_PreInit:
247 stateName = "PreInit"; break;
248 case G4State_Init:
249 stateName = "Init"; break;
250 case G4State_Idle:
251 stateName = "Idle"; break;
252 case G4State_GeomClosed:
253 stateName = "GeomClosed"; break;
254 case G4State_EventProc:
255 stateName = "EventProc"; break;
256 case G4State_Quit:
257 stateName = "Quit"; break;
258 case G4State_Abort:
259 stateName = "Abort"; break;
260 default:
261 stateName = "Unknown"; break;
262 }
263 return stateName;
264}
265
266//void G4StateManager::Pause()
267//{
268// Pause("G4_pause> ");
269//}
270//
271//void G4StateManager::Pause(const char* msg)
272//{
273// G4String msgS = msg;
274// Pause(msgS);
275//}
276//
277//void G4StateManager::Pause(G4String msg)
278//{
279// G4UImanager::GetUIpointer()->PauseSession(msg);
280//}
Note: See TracBrowser for help on using the repository browser.