Statistics
| Branch: | Revision:

root / include / simtime_t.h @ master

History | View | Annotate | Download (2.65 KB)

1
//==========================================================================
2
//  SIMTIME_T.H - part of
3
//                     OMNeT++/OMNEST
4
//            Discrete System Simulation in C++
5
//
6
//==========================================================================
7

    
8
/*--------------------------------------------------------------*
9
  Copyright (C) 1992-2008 Andras Varga
10
  Copyright (C) 2006-2008 OpenSim Ltd.
11

12
  This file is distributed WITHOUT ANY WARRANTY. See the file
13
  `license' for details on this and other legal matters.
14
*--------------------------------------------------------------*/
15

    
16
#ifndef __SIMTIME_T_H
17
#define __SIMTIME_T_H
18

    
19
#include <stdlib.h>
20
#include <string>
21
#include <math.h>
22
#include <float.h>
23
#include "simkerneldefs.h"
24
#include "simtime.h"
25

    
26
//
27
// simtime_t: simulation time.
28
//
29
// There are two sets of definitions. By default, OMNeT++ 4.x uses
30
// an int64-based simtime_t (class SimTime), but it also supports
31
// "double" which was in use in earlier versions (2.x and 3.x).
32
// This "legacy mode" can be enabled at compile-time by #defining
33
// USE_DOUBLE_SIMTIME. One use of legacy mode is simulation fingerprint
34
// verification across 3.x and 4.x.
35
//
36
// The macros SIMTIME_STR(), SIMTIME_DBL(), SIMTIME_RAW(), STR_SIMTIME()
37
// perform conversions to double and to/from string; they should only be
38
// used in models that should be able to compile with USE_DOUBLE_SIMTIME
39
// as well. Otherwise, methods of the SimTime class can be directly
40
// invoked.
41
//
42
// It is expected that support for legacy mode (double) will be dropped
43
// in some future version, together with the SIMTIME_STR(), etc macros.
44
//
45
#ifdef USE_DOUBLE_SIMTIME
46

    
47
// "Legacy" module: double simtime_t
48
typedef double         simtime_t;
49
typedef double         simtime_t_cref;
50
typedef const double   const_simtime_t;
51
#define MAXTIME        DBL_MAX
52
#define SIMTIME_ZERO   0.0
53
#define SIMTIME_STR(t) double_to_str(t).c_str()
54
#define SIMTIME_DBL(t) (t)
55
#define SIMTIME_RAW(t) (t)
56
#define STR_SIMTIME(s) strToSimtime(s)
57
#define SIMTIME_TTOA(buf,t) gcvt(t,16,buf)
58

    
59
#else
60

    
61
// OMNeT++ 4.x native mode: int64-based fixed-point simtime_t (class SimTime)
62

    
63
typedef OPP::SimTime   simtime_t;
64
typedef const simtime_t& simtime_t_cref;  // in many configurations (e.g. debug builds), it is more efficient to return a SimTime from a function as a const ref than by value
65
typedef const double   const_simtime_t;
66
#define MAXTIME        OPP::SimTime::getMaxTime()
67
#define SIMTIME_ZERO   OPP::SimTime()
68
#define SIMTIME_STR(t) ((t).str().c_str())
69
#define SIMTIME_DBL(t) ((t).dbl())
70
#define SIMTIME_RAW(t) ((t).raw())
71
#define STR_SIMTIME(s) OPP::SimTime::parse(s)
72
#define SIMTIME_TTOA(buf,t) ((t).str(buf))
73

    
74
#endif  //USE_DOUBLE_SIMTIME
75

    
76
#endif
77