00001 //========================================================================== 00002 // SIMTIME_T.H - part of 00003 // OMNeT++/OMNEST 00004 // Discrete System Simulation in C++ 00005 // 00006 //========================================================================== 00007 00008 /*--------------------------------------------------------------* 00009 Copyright (C) 1992-2008 Andras Varga 00010 Copyright (C) 2006-2008 OpenSim Ltd. 00011 00012 This file is distributed WITHOUT ANY WARRANTY. See the file 00013 `license' for details on this and other legal matters. 00014 *--------------------------------------------------------------*/ 00015 00016 #ifndef __SIMTIME_T_H 00017 #define __SIMTIME_T_H 00018 00019 #include <stdlib.h> 00020 #include <string> 00021 #include <math.h> 00022 #include <float.h> 00023 #include "simkerneldefs.h" 00024 #include "simtime.h" 00025 00026 // 00027 // simtime_t: simulation time. 00028 // 00029 // There are two sets of definitions. By default, OMNeT++ 4.x uses 00030 // an int64-based simtime_t (class SimTime), but it also supports 00031 // "double" which was in use in earlier versions (2.x and 3.x). 00032 // This "legacy mode" can be enabled at compile-time by #defining 00033 // USE_DOUBLE_SIMTIME. One use of legacy mode is simulation fingerprint 00034 // verification across 3.x and 4.x. 00035 // 00036 // The macros SIMTIME_STR(), SIMTIME_DBL(), SIMTIME_RAW(), STR_SIMTIME() 00037 // perform conversions to double and to/from string; they should only be 00038 // used in models that should be able to compile with USE_DOUBLE_SIMTIME 00039 // as well. Otherwise, methods of the SimTime class can be directly 00040 // invoked. 00041 // 00042 // It is expected that support for legacy mode (double) will be dropped 00043 // in some future version, together with the SIMTIME_STR(), etc macros. 00044 // 00045 #ifdef USE_DOUBLE_SIMTIME 00046 00047 // "Legacy" module: double simtime_t 00048 typedef double simtime_t; 00049 typedef double simtime_t_cref; 00050 typedef const double const_simtime_t; 00051 #define MAXTIME DBL_MAX 00052 #define SIMTIME_ZERO 0.0 00053 #define SIMTIME_STR(t) double_to_str(t).c_str() 00054 #define SIMTIME_DBL(t) (t) 00055 #define SIMTIME_RAW(t) (t) 00056 #define STR_SIMTIME(s) strToSimtime(s) 00057 #define SIMTIME_TTOA(buf,t) gcvt(t,16,buf) 00058 00059 #else 00060 00061 // OMNeT++ 4.x native mode: int64-based fixed-point simtime_t (class SimTime) 00062 00063 typedef OPP::SimTime simtime_t; 00064 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 00065 typedef const double const_simtime_t; 00066 #define MAXTIME OPP::SimTime::getMaxTime() 00067 #define SIMTIME_ZERO OPP::SimTime() 00068 #define SIMTIME_STR(t) ((t).str().c_str()) 00069 #define SIMTIME_DBL(t) ((t).dbl()) 00070 #define SIMTIME_RAW(t) ((t).raw()) 00071 #define STR_SIMTIME(s) OPP::SimTime::parse(s) 00072 #define SIMTIME_TTOA(buf,t) ((t).str(buf)) 00073 00074 #endif //USE_DOUBLE_SIMTIME 00075 00076 #endif 00077