OMNeT++ API 6.1
Discrete Event Simulation Library
ctimestampedvalue.h
1 //==========================================================================
2 // CTIMESTAMPEDVALUE.H - part of
3 // OMNeT++/OMNEST
4 // Discrete System Simulation in C++
5 //
6 //==========================================================================
7 
8 /*--------------------------------------------------------------*
9  Copyright (C) 1992-2017 Andras Varga
10  Copyright (C) 2006-2017 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 __OMNETPP_CTIMESTAMPEDVALUE_H
17 #define __OMNETPP_CTIMESTAMPEDVALUE_H
18 
19 #include "clistener.h" // simsignal_t
20 #include "simtime_t.h"
21 #include "cobject.h"
22 
23 namespace omnetpp {
24 
25 
35 class SIM_API cITimestampedValue
36 {
37  public:
39  virtual ~cITimestampedValue() {}
40 
42  virtual simtime_t_cref getTimestamp(simsignal_t signalID) const = 0;
43 
45  virtual SimsignalType getValueType(simsignal_t signalID) const = 0;
46 
49  virtual bool boolValue(simsignal_t signalID) const = 0;
50  virtual intval_t intValue(simsignal_t signalID) const = 0;
51  virtual uintval_t uintValue(simsignal_t signalID) const = 0;
52  virtual double doubleValue(simsignal_t signalID) const = 0;
53  virtual SimTime simtimeValue(simsignal_t signalID) const = 0;
54  virtual const char *stringValue(simsignal_t signalID) const = 0;
55  virtual cObject *objectValue(simsignal_t signalID) const = 0;
56  [[deprecated]] intval_t longValue(simsignal_t signalID) const {return intValue(signalID);}
57  [[deprecated]] uintval_t unsignedLongValue(simsignal_t signalID) const {return uintValue(signalID);}
59 };
60 
66 class SIM_API cTimestampedValue : public cITimestampedValue, public cObject
67 {
68  public:
69  simtime_t timestamp;
70  SimsignalType type; // selector for the union
71  union {
72  bool b;
73  intval_t l;
74  uintval_t ul;
75  double d;
76  const char *s;
77  cObject *obj;
78  };
79  SimTime t; // cannot go into the union because it has a ctor
80 
81  public:
84  cTimestampedValue() {type=SIMSIGNAL_UNDEF;}
85  cTimestampedValue(simtime_t timestamp, bool b) {set(timestamp,b);}
86  cTimestampedValue(simtime_t timestamp, intval_t l) {set(timestamp,l);}
87  cTimestampedValue(simtime_t timestamp, uintval_t ul) {set(timestamp,ul);}
88  cTimestampedValue(simtime_t timestamp, double d) {set(timestamp,d);}
89  cTimestampedValue(simtime_t timestamp, const SimTime& t) {set(timestamp,t);}
90  cTimestampedValue(simtime_t timestamp, const char *s) {set(timestamp,s);}
91  cTimestampedValue(simtime_t timestamp, cObject *obj) {set(timestamp,obj);}
93 
96  void set(simtime_t timestamp, bool b) {this->timestamp=timestamp; type=SIMSIGNAL_BOOL; this->b=b;}
97  void set(simtime_t timestamp, intval_t l) {this->timestamp=timestamp; type=SIMSIGNAL_INT; this->l=l;}
98  void set(simtime_t timestamp, uintval_t ul) {this->timestamp=timestamp; type=SIMSIGNAL_UINT; this->ul=ul;}
99  void set(simtime_t timestamp, double d) {this->timestamp=timestamp; type=SIMSIGNAL_DOUBLE; this->d=d;}
100  void set(simtime_t timestamp, const SimTime& t) {this->timestamp=timestamp; type=SIMSIGNAL_SIMTIME; this->t=t;}
101  void set(simtime_t timestamp, const char *s) {this->timestamp=timestamp; type=SIMSIGNAL_STRING; this->s=s;}
102  void set(simtime_t timestamp, cObject *obj) {this->timestamp=timestamp; type=SIMSIGNAL_OBJECT; this->obj=obj;}
104 
106  virtual simtime_t_cref getTimestamp(simsignal_t signalID) const override {return timestamp;}
107 
109  virtual SimsignalType getValueType(simsignal_t signalID) const override {return type;}
110 
113  virtual bool boolValue(simsignal_t signalID) const override {return b;}
114  virtual intval_t intValue(simsignal_t signalID) const override {return l;}
115  virtual uintval_t uintValue(simsignal_t signalID) const override {return ul;}
116  virtual double doubleValue(simsignal_t signalID) const override {return d;}
117  virtual SimTime simtimeValue(simsignal_t signalID) const override {return t;}
118  virtual const char *stringValue(simsignal_t signalID) const override {return s;}
119  virtual cObject *objectValue(simsignal_t signalID) const override {return obj;}
121 };
122 
123 } // namespace omnetpp
124 
125 #endif
126 
omnetpp::simtime_t_cref
const typedef simtime_t & simtime_t_cref
Constant reference to a simtime_t.
Definition: simtime_t.h:48
omnetpp::simsignal_t
int simsignal_t
Signal handle.
Definition: clistener.h:27
omnetpp::cObject
cObject is a lightweight class which serves as the root of the OMNeT++ class hierarchy....
Definition: cobject.h:92
omnetpp::cTimestampedValue::getValueType
virtual SimsignalType getValueType(simsignal_t signalID) const override
Definition: ctimestampedvalue.h:109
omnetpp::SimTime
int64_t-based, base-10 fixed-point simulation time.
Definition: simtime.h:66
omnetpp::uintval_t
uint64_t uintval_t
Unsigned integer type which is guaranteed to be at least 64 bits wide. It is used throughout the libr...
Definition: simkerneldefs.h:109
omnetpp::cTimestampedValue::getTimestamp
virtual simtime_t_cref getTimestamp(simsignal_t signalID) const override
Definition: ctimestampedvalue.h:106
omnetpp::cITimestampedValue
Interface for emitting timestamped values as signals, primarily for result recording.
Definition: ctimestampedvalue.h:35
omnetpp::SimsignalType
SimsignalType
Signal data types.
Definition: clistener.h:47
omnetpp::intval_t
int64_t intval_t
Signed integer type which is guaranteed to be at least 64 bits wide. It is used throughout the librar...
Definition: simkerneldefs.h:101
omnetpp::cTimestampedValue
A straightforward implementation of cITimestampedValue.
Definition: ctimestampedvalue.h:66
omnetpp::cITimestampedValue::~cITimestampedValue
virtual ~cITimestampedValue()
Definition: ctimestampedvalue.h:39