Scippy

SoPlex

Sequential object-oriented simPlex

timerfactory.h
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the class library */
4 /* SoPlex --- the Sequential object-oriented simPlex. */
5 /* */
6 /* Copyright (C) 1996-2022 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SoPlex is distributed under the terms of the ZIB Academic Licence. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SoPlex; see the file COPYING. If not email to soplex@zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file timerfactory.h
17  * @brief TimerFactory class.
18  */
19 
20 #ifndef _TIMERFACTORY_H_
21 #define _TIMERFACTORY_H_
22 
23 #include "soplex/spxdefines.h"
24 #include "soplex/spxalloc.h"
25 #include "soplex/timer.h"
26 #include "soplex/notimer.h"
27 #include "soplex/usertimer.h"
28 #include "soplex/wallclocktimer.h"
29 
30 namespace soplex
31 {
32 /**@class TimerFactory
33  @ingroup Elementary
34 
35  @brief Class to create new timers and to switch types of exiting ones
36  */
37 
39 {
40 
41 public:
42 
43  /// create timers and allocate memory for them
44  static Timer* createTimer(Timer::TYPE ttype)
45  {
46  Timer* timer = 0;
47 
48  switch(ttype)
49  {
50  case Timer::OFF:
51  spx_alloc(timer, sizeof(NoTimer));
52  timer = new(timer) NoTimer();
53  break;
54 
55  case Timer::USER_TIME:
56  spx_alloc(timer, sizeof(UserTimer));
57  timer = new(timer) UserTimer();
58  break;
59 
61  spx_alloc(timer, sizeof(WallclockTimer));
62  timer = new(timer) WallclockTimer();
63  break;
64 
65  default:
66  MSG_ERROR(std::cerr << "wrong timer specified" << std::endl;)
67  }
68 
69  return timer;
70  }
71 
72  static Timer* switchTimer(Timer* timer, Timer::TYPE ttype)
73  {
74  // check whether the type is different from the current one
75  if(ttype != timer->type())
76  {
77  // @todo transfer the old times
78  spx_free(timer);
79  timer = createTimer(ttype);
80  }
81 
82  return timer;
83  }
84 
85 };
86 } // namespace soplex
87 #endif // _TIMERFACTORY_H_
Memory allocation routines.
NoTimer class.
WallclockTimer class.
void spx_alloc(T &p, int n=1)
Allocate memory.
Definition: spxalloc.h:49
#define MSG_ERROR(x)
Prints out message x if the verbosity level is at least SPxOut::ERROR.
Definition: spxdefines.h:152
Class to create new timers and to switch types of exiting ones.
Definition: timerfactory.h:38
static Timer * switchTimer(Timer *timer, Timer::TYPE ttype)
Definition: timerfactory.h:72
static Timer * createTimer(Timer::TYPE ttype)
create timers and allocate memory for them
Definition: timerfactory.h:44
Debugging, floating point type and parameter definitions.
Everything should be within this namespace.
Timer class.
TYPE
types of timers
Definition: timer.h:99
UserTimer class.
Wrapper for the system time query methods.
Definition: timer.h:76
void spx_free(T &p)
Release memory.
Definition: spxalloc.h:111
virtual TYPE type()=0
return type of timer