| [833] | 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.13 2006/11/23 00:41:56 asaim Exp $
|
|---|
| [1058] | 28 | // GEANT4 tag $Name: geant4-09-02-ref-02 $
|
|---|
| [833] | 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 | //
|
|---|
| 42 | G4StateManager* G4StateManager::theStateManager = 0;
|
|---|
| 43 |
|
|---|
| 44 | G4StateManager::G4StateManager()
|
|---|
| 45 | : theCurrentState(G4State_PreInit),
|
|---|
| 46 | thePreviousState(G4State_PreInit),
|
|---|
| 47 | theBottomDependent(0),
|
|---|
| 48 | suppressAbortion(0),
|
|---|
| 49 | msgptr(0),
|
|---|
| 50 | exceptionHandler(0)
|
|---|
| 51 | {
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|
| 54 | G4StateManager::~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(); i++)
|
|---|
| 64 | {
|
|---|
| 65 | if (*i==state)
|
|---|
| 66 | {
|
|---|
| 67 | theDependentsList.erase(i);
|
|---|
| 68 | i--;
|
|---|
| 69 | }
|
|---|
| 70 | }
|
|---|
| 71 | if ( state ) { delete state; }
|
|---|
| 72 | }
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | // -------------------------------------------------------------------------
|
|---|
| 76 | // No matter how copy-constructor and operators below are implemented ...
|
|---|
| 77 | // just dummy implementations, since not relevant for the singleton and
|
|---|
| 78 | // declared private.
|
|---|
| 79 | //
|
|---|
| 80 | G4StateManager::G4StateManager(const G4StateManager &right)
|
|---|
| 81 | : theCurrentState(right.theCurrentState),
|
|---|
| 82 | thePreviousState(right.thePreviousState),
|
|---|
| 83 | theDependentsList(right.theDependentsList),
|
|---|
| 84 | theBottomDependent(right.theBottomDependent),
|
|---|
| 85 | suppressAbortion(right.suppressAbortion),
|
|---|
| 86 | msgptr(right.msgptr),
|
|---|
| 87 | exceptionHandler(right.exceptionHandler)
|
|---|
| 88 | {
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | G4StateManager&
|
|---|
| 92 | G4StateManager::operator=(const G4StateManager &right)
|
|---|
| 93 | {
|
|---|
| 94 | if (&right == this) { return *this; }
|
|---|
| 95 |
|
|---|
| 96 | theCurrentState = right.theCurrentState;
|
|---|
| 97 | thePreviousState = right.thePreviousState;
|
|---|
| 98 | theDependentsList = right.theDependentsList;
|
|---|
| 99 | theBottomDependent = right.theBottomDependent;
|
|---|
| 100 | suppressAbortion = right.suppressAbortion;
|
|---|
| 101 | msgptr = right.msgptr;
|
|---|
| 102 | exceptionHandler = right.exceptionHandler;
|
|---|
| 103 |
|
|---|
| 104 | return *this;
|
|---|
| 105 | }
|
|---|
| 106 |
|
|---|
| 107 | G4int
|
|---|
| 108 | G4StateManager::operator==(const G4StateManager &right) const
|
|---|
| 109 | {
|
|---|
| 110 | return (this == &right);
|
|---|
| 111 | }
|
|---|
| 112 |
|
|---|
| 113 | G4int
|
|---|
| 114 | G4StateManager::operator!=(const G4StateManager &right) const
|
|---|
| 115 | {
|
|---|
| 116 | return (this != &right);
|
|---|
| 117 | }
|
|---|
| 118 | //
|
|---|
| 119 | // -------------------------------------------------------------------------
|
|---|
| 120 |
|
|---|
| 121 | G4StateManager*
|
|---|
| 122 | G4StateManager::GetStateManager()
|
|---|
| 123 | {
|
|---|
| 124 | if (!theStateManager)
|
|---|
| 125 | {
|
|---|
| 126 | theStateManager = new G4StateManager;
|
|---|
| 127 | }
|
|---|
| 128 | return theStateManager;
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 | G4bool
|
|---|
| 132 | G4StateManager::RegisterDependent(G4VStateDependent* aDependent, G4bool bottom)
|
|---|
| 133 | {
|
|---|
| [1058] | 134 | printf("G4StateManager::RegisterDependent()\n");
|
|---|
| [833] | 135 | G4bool ack=true;
|
|---|
| 136 | if(!bottom)
|
|---|
| 137 | {
|
|---|
| 138 | theDependentsList.push_back(aDependent);
|
|---|
| 139 | }
|
|---|
| 140 | else
|
|---|
| 141 | {
|
|---|
| 142 | if(theBottomDependent)
|
|---|
| 143 | {
|
|---|
| 144 | theDependentsList.push_back(theBottomDependent);
|
|---|
| 145 | }
|
|---|
| 146 | theBottomDependent = aDependent;
|
|---|
| 147 | }
|
|---|
| 148 | return ack;
|
|---|
| 149 | }
|
|---|
| 150 |
|
|---|
| 151 | G4bool
|
|---|
| 152 | G4StateManager::DeregisterDependent(G4VStateDependent* aDependent)
|
|---|
| 153 | {
|
|---|
| [1058] | 154 | printf("G4StateManager::DeregisterDependent()\n");
|
|---|
| [833] | 155 | G4VStateDependent* tmp = 0;
|
|---|
| 156 | for (std::vector<G4VStateDependent*>::iterator i=theDependentsList.begin();
|
|---|
| 157 | i!=theDependentsList.end(); i++)
|
|---|
| 158 | {
|
|---|
| 159 | if (**i==*aDependent)
|
|---|
| 160 | {
|
|---|
| 161 | tmp = *i;
|
|---|
| 162 | theDependentsList.erase(i);
|
|---|
| 163 | }
|
|---|
| 164 | }
|
|---|
| 165 | return (tmp != 0);
|
|---|
| 166 | }
|
|---|
| 167 |
|
|---|
| 168 | G4ApplicationState
|
|---|
| 169 | G4StateManager::GetCurrentState() const
|
|---|
| 170 | {
|
|---|
| [1058] | 171 | printf("G4StateManager::GetCurrentState() = %s\n",GetStateString(theCurrentState).c_str());
|
|---|
| [833] | 172 | return theCurrentState;
|
|---|
| 173 | }
|
|---|
| 174 |
|
|---|
| 175 | G4ApplicationState
|
|---|
| 176 | G4StateManager::GetPreviousState() const
|
|---|
| 177 | {
|
|---|
| [1058] | 178 | printf("G4StateManager::GetPreviousState() = %s\n",GetStateString(thePreviousState).c_str());
|
|---|
| [833] | 179 | return thePreviousState;
|
|---|
| 180 | }
|
|---|
| 181 |
|
|---|
| 182 | G4bool
|
|---|
| 183 | G4StateManager::SetNewState(G4ApplicationState requestedState)
|
|---|
| [1058] | 184 | { printf("G4StateManager::SetNewState(%s)\n",GetStateString(requestedState).c_str());
|
|---|
| 185 | return SetNewState(requestedState,0); }
|
|---|
| [833] | 186 |
|
|---|
| 187 | G4bool
|
|---|
| 188 | G4StateManager::SetNewState(G4ApplicationState requestedState, const char* msg)
|
|---|
| 189 | {
|
|---|
| [1058] | 190 | printf("G4StateManager::SetNewState(%s , ...) vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\n",GetStateString(requestedState).c_str());
|
|---|
| [833] | 191 | if(requestedState==G4State_Abort && suppressAbortion>0)
|
|---|
| 192 | {
|
|---|
| 193 | if(suppressAbortion==2) { return false; }
|
|---|
| 194 | if(theCurrentState==G4State_EventProc) { return false; }
|
|---|
| 195 | }
|
|---|
| 196 | msgptr = msg;
|
|---|
| 197 | size_t i=0;
|
|---|
| 198 | G4bool ack = true;
|
|---|
| 199 | G4ApplicationState savedState = thePreviousState;
|
|---|
| 200 | thePreviousState = theCurrentState;
|
|---|
| [1058] | 201 | printf("G4StateManager::SetNewState(.. , ...) middle\n");
|
|---|
| [833] | 202 | while ((ack) && (i<theDependentsList.size()))
|
|---|
| 203 | {
|
|---|
| [1058] | 204 | printf("G4StateManager::SetNewState(.. , ...) while...\n");
|
|---|
| [833] | 205 | ack = theDependentsList[i]->Notify(requestedState);
|
|---|
| 206 | i++;
|
|---|
| 207 | }
|
|---|
| 208 | if(theBottomDependent)
|
|---|
| 209 | {
|
|---|
| 210 | ack = theBottomDependent->Notify(requestedState);
|
|---|
| 211 | }
|
|---|
| 212 |
|
|---|
| 213 | if(!ack)
|
|---|
| 214 | { thePreviousState = savedState; }
|
|---|
| 215 | else
|
|---|
| 216 | { theCurrentState = requestedState; }
|
|---|
| 217 | msgptr = 0;
|
|---|
| [1058] | 218 | printf("G4StateManager::SetNewState(%s , ...) END ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n",GetStateString(requestedState).c_str());
|
|---|
| [833] | 219 | return ack;
|
|---|
| 220 | }
|
|---|
| 221 |
|
|---|
| 222 | G4VStateDependent*
|
|---|
| 223 | G4StateManager::RemoveDependent(const G4VStateDependent* aDependent)
|
|---|
| 224 | {
|
|---|
| 225 | G4VStateDependent* tmp = 0;
|
|---|
| 226 | for (std::vector<G4VStateDependent*>::iterator i=theDependentsList.begin();
|
|---|
| 227 | i!=theDependentsList.end(); i++)
|
|---|
| 228 | {
|
|---|
| 229 | if (**i==*aDependent)
|
|---|
| 230 | {
|
|---|
| 231 | tmp = *i;
|
|---|
| 232 | theDependentsList.erase(i);
|
|---|
| 233 | }
|
|---|
| 234 | }
|
|---|
| 235 | return tmp;
|
|---|
| 236 | }
|
|---|
| 237 |
|
|---|
| 238 | G4String
|
|---|
| 239 | G4StateManager::GetStateString(G4ApplicationState aState) const
|
|---|
| 240 | {
|
|---|
| 241 | G4String stateName;
|
|---|
| 242 | switch(aState)
|
|---|
| 243 | {
|
|---|
| 244 | case G4State_PreInit:
|
|---|
| 245 | stateName = "PreInit"; break;
|
|---|
| 246 | case G4State_Init:
|
|---|
| 247 | stateName = "Init"; break;
|
|---|
| 248 | case G4State_Idle:
|
|---|
| 249 | stateName = "Idle"; break;
|
|---|
| 250 | case G4State_GeomClosed:
|
|---|
| 251 | stateName = "GeomClosed"; break;
|
|---|
| 252 | case G4State_EventProc:
|
|---|
| 253 | stateName = "EventProc"; break;
|
|---|
| 254 | case G4State_Quit:
|
|---|
| 255 | stateName = "Quit"; break;
|
|---|
| 256 | case G4State_Abort:
|
|---|
| 257 | stateName = "Abort"; break;
|
|---|
| 258 | default:
|
|---|
| 259 | stateName = "Unknown"; break;
|
|---|
| 260 | }
|
|---|
| 261 | return stateName;
|
|---|
| 262 | }
|
|---|
| 263 |
|
|---|
| 264 | //void G4StateManager::Pause()
|
|---|
| 265 | //{
|
|---|
| 266 | // Pause("G4_pause> ");
|
|---|
| 267 | //}
|
|---|
| 268 | //
|
|---|
| 269 | //void G4StateManager::Pause(const char* msg)
|
|---|
| 270 | //{
|
|---|
| 271 | // G4String msgS = msg;
|
|---|
| 272 | // Pause(msgS);
|
|---|
| 273 | //}
|
|---|
| 274 | //
|
|---|
| 275 | //void G4StateManager::Pause(G4String msg)
|
|---|
| 276 | //{
|
|---|
| 277 | // G4UImanager::GetUIpointer()->PauseSession(msg);
|
|---|
| 278 | //}
|
|---|