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-2016 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 "spxdefines.h"
24 #include "spxalloc.h"
25 #include "notimer.h"
26 #include "usertimer.h"
27 #include "wallclocktimer.h"
28 
29 namespace soplex
30 {
31 /**@class TimerFactory
32  @ingroup Elementary
33 
34  @brief Class to create new timers and to switch types of exiting ones
35  */
36 
38 {
39 
40 public:
41 
42  /// create timers and allocate memory for them
43  static Timer* createTimer(Timer::TYPE ttype)
44  {
45  Timer* timer = 0;
46  switch( ttype )
47  {
48  case Timer::OFF:
49  spx_alloc(timer, sizeof(NoTimer));
50  timer = new (timer) NoTimer();
51  break;
52  case Timer::USER_TIME:
53  spx_alloc(timer, sizeof(UserTimer));
54  timer = new (timer) UserTimer();
55  break;
57  spx_alloc(timer, sizeof(WallclockTimer));
58  timer = new (timer) WallclockTimer();
59  break;
60  default:
61  MSG_ERROR( std::cerr << "wrong timer specified" << std::endl; )
62  }
63  return timer;
64  }
65 
66  static Timer* switchTimer(Timer* timer, Timer::TYPE ttype)
67  {
68  // check whether the type is different from the current one
69  if( ttype != timer->type() )
70  {
71  // @todo transfer the old times
72  spx_free(timer);
73  timer = createTimer(ttype);
74  }
75  return timer;
76  }
77 
78 };
79 } // namespace soplex
80 #endif // _TIMERFACTORY_H_
Memory allocation routines.
NoTimer class.
WallclockTimer class.
void spx_alloc(T &p, int n=1)
Allocate memory.
Definition: spxalloc.h:48
Class to create new timers and to switch types of exiting ones.
Definition: timerfactory.h:37
#define MSG_ERROR(x)
Prints out message x if the verbosity level is at least SPxOut::ERROR.
Definition: spxdefines.h:109
static Timer * switchTimer(Timer *timer, Timer::TYPE ttype)
Definition: timerfactory.h:66
static Timer * createTimer(Timer::TYPE ttype)
create timers and allocate memory for them
Definition: timerfactory.h:43
Debugging, floating point type and parameter definitions.
Everything should be within this namespace.
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