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-2018 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  switch( ttype )
48  {
49  case Timer::OFF:
50  spx_alloc(timer, sizeof(NoTimer));
51  timer = new (timer) NoTimer();
52  break;
53  case Timer::USER_TIME:
54  spx_alloc(timer, sizeof(UserTimer));
55  timer = new (timer) UserTimer();
56  break;
58  spx_alloc(timer, sizeof(WallclockTimer));
59  timer = new (timer) WallclockTimer();
60  break;
61  default:
62  MSG_ERROR( std::cerr << "wrong timer specified" << std::endl; )
63  }
64  return timer;
65  }
66 
67  static Timer* switchTimer(Timer* timer, Timer::TYPE ttype)
68  {
69  // check whether the type is different from the current one
70  if( ttype != timer->type() )
71  {
72  // @todo transfer the old times
73  spx_free(timer);
74  timer = createTimer(ttype);
75  }
76  return timer;
77  }
78 
79 };
80 } // namespace soplex
81 #endif // _TIMERFACTORY_H_
Memory allocation routines.
NoTimer class.
WallclockTimer class.
void spx_alloc(T &p, int n=1)
Allocate memory.
Definition: spxalloc.h:48
#define MSG_ERROR(x)
Prints out message x if the verbosity level is at least SPxOut::ERROR.
Definition: spxdefines.h:114
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:67
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:109
virtual TYPE type()=0
return type of timer