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-2024 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"
38
39namespace 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
48{
49
50public:
51
52 /// create timers and allocate memory for them
54 {
55 Timer* timer = nullptr;
56
57 switch(ttype)
58 {
59 case Timer::OFF:
60 spx_alloc(timer, sizeof(NoTimer));
61 timer = new(timer) NoTimer();
62 break;
63
65 spx_alloc(timer, sizeof(UserTimer));
66 timer = new(timer) UserTimer();
67 break;
68
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_
Class to create new timers and to switch types of exiting ones.
Definition: timerfactory.h:48
static Timer * switchTimer(Timer *timer, Timer::TYPE ttype)
Definition: timerfactory.h:81
static Timer * createTimer(Timer::TYPE ttype)
create timers and allocate memory for them
Definition: timerfactory.h:53
Wrapper for the system time query methods.
Definition: timer.h:86
TYPE
types of timers
Definition: timer.h:109
@ WALLCLOCK_TIME
Definition: timer.h:112
virtual TYPE type()=0
return type of timer
Everything should be within this namespace.
void spx_free(T &p)
Release memory.
Definition: spxalloc.h:121
void spx_alloc(T &p, int n=1)
Allocate memory.
Definition: spxalloc.h:58
NoTimer class.
Memory allocation routines.
Debugging, floating point type and parameter definitions.
#define SPX_MSG_ERROR(x)
Prints out message x if the verbosity level is at least SPxOut::ERROR.
Definition: spxdefines.h:163
Timer class.
UserTimer class.
WallclockTimer class.