1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 2 /* */ 3 /* This file is part of the class library */ 4 /* SoPlex --- the Sequential object-oriented simPlex. */ 5 /* */ 6 /* Copyright (c) 1996-2023 Zuse Institute Berlin (ZIB) */ 7 /* */ 8 /* Licensed under the Apache License, Version 2.0 (the "License"); */ 9 /* you may not use this file except in compliance with the License. */ 10 /* You may obtain a copy of the License at */ 11 /* */ 12 /* http://www.apache.org/licenses/LICENSE-2.0 */ 13 /* */ 14 /* Unless required by applicable law or agreed to in writing, software */ 15 /* distributed under the License is distributed on an "AS IS" BASIS, */ 16 /* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ 17 /* See the License for the specific language governing permissions and */ 18 /* limitations under the License. */ 19 /* */ 20 /* You should have received a copy of the Apache-2.0 license */ 21 /* along with SoPlex; see the file LICENSE. If not email to soplex@zib.de. */ 22 /* */ 23 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 24 25 /**@file timerfactory.h 26 * @brief TimerFactory class. 27 */ 28 29 #ifndef _TIMERFACTORY_H_ 30 #define _TIMERFACTORY_H_ 31 32 #include "soplex/spxdefines.h" 33 #include "soplex/spxalloc.h" 34 #include "soplex/timer.h" 35 #include "soplex/notimer.h" 36 #include "soplex/usertimer.h" 37 #include "soplex/wallclocktimer.h" 38 39 namespace soplex 40 { 41 /**@class TimerFactory 42 @ingroup Elementary 43 44 @brief Class to create new timers and to switch types of exiting ones 45 */ 46 47 class TimerFactory 48 { 49 50 public: 51 52 /// create timers and allocate memory for them 53 static Timer* createTimer(Timer::TYPE ttype) 54 { 55 Timer* timer = 0; 56 57 switch(ttype) 58 { 59 case Timer::OFF: 60 spx_alloc(timer, sizeof(NoTimer)); 61 timer = new(timer) NoTimer(); 62 break; 63 64 case Timer::USER_TIME: 65 spx_alloc(timer, sizeof(UserTimer)); 66 timer = new(timer) UserTimer(); 67 break; 68 69 case Timer::WALLCLOCK_TIME: 70 spx_alloc(timer, sizeof(WallclockTimer)); 71 timer = new(timer) WallclockTimer(); 72 break; 73 74 default: 75 SPX_MSG_ERROR(std::cerr << "wrong timer specified" << std::endl;) 76 } 77 78 return timer; 79 } 80 81 static Timer* switchTimer(Timer* timer, Timer::TYPE ttype) 82 { 83 // check whether the type is different from the current one 84 if(ttype != timer->type()) 85 { 86 // @todo transfer the old times 87 spx_free(timer); 88 timer = createTimer(ttype); 89 } 90 91 return timer; 92 } 93 94 }; 95 } // namespace soplex 96 #endif // _TIMERFACTORY_H_ 97