OMNeT++ Simulation Library  5.6.1
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 long longValue(simsignal_t signalID) const = 0;
51  virtual unsigned long unsignedLongValue(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;
57 };
58 
64 class SIM_API cTimestampedValue : public cITimestampedValue, public cObject
65 {
66  public:
67  simtime_t timestamp;
68  SimsignalType type; // selector for the union
69  union {
70  bool b;
71  long l;
72  unsigned long ul;
73  double d;
74  const char *s;
75  cObject *obj;
76  };
77  SimTime t; // cannot go into the union because it has a ctor
78 
79  public:
82  cTimestampedValue() {type=SIMSIGNAL_UNDEF;}
83  cTimestampedValue(simtime_t timestamp, bool b) {set(timestamp,b);}
84  cTimestampedValue(simtime_t timestamp, long l) {set(timestamp,l);}
85  cTimestampedValue(simtime_t timestamp, unsigned long ul) {set(timestamp,ul);}
86  cTimestampedValue(simtime_t timestamp, double d) {set(timestamp,d);}
87  cTimestampedValue(simtime_t timestamp, const SimTime& t) {set(timestamp,t);}
88  cTimestampedValue(simtime_t timestamp, const char *s) {set(timestamp,s);}
89  cTimestampedValue(simtime_t timestamp, cObject *obj) {set(timestamp,obj);}
91 
94  void set(simtime_t timestamp, bool b) {this->timestamp=timestamp; type=SIMSIGNAL_BOOL; this->b=b;}
95  void set(simtime_t timestamp, long l) {this->timestamp=timestamp; type=SIMSIGNAL_LONG; this->l=l;}
96  void set(simtime_t timestamp, unsigned long ul) {this->timestamp=timestamp; type=SIMSIGNAL_ULONG; this->ul=ul;}
97  void set(simtime_t timestamp, double d) {this->timestamp=timestamp; type=SIMSIGNAL_DOUBLE; this->d=d;}
98  void set(simtime_t timestamp, const SimTime& t) {this->timestamp=timestamp; type=SIMSIGNAL_SIMTIME; this->t=t;}
99  void set(simtime_t timestamp, const char *s) {this->timestamp=timestamp; type=SIMSIGNAL_STRING; this->s=s;}
100  void set(simtime_t timestamp, cObject *obj) {this->timestamp=timestamp; type=SIMSIGNAL_OBJECT; this->obj=obj;}
102 
104  virtual simtime_t_cref getTimestamp(simsignal_t signalID) const override {return timestamp;}
105 
107  virtual SimsignalType getValueType(simsignal_t signalID) const override {return type;}
108 
111  virtual bool boolValue(simsignal_t signalID) const override {return b;}
112  virtual long longValue(simsignal_t signalID) const override {return l;}
113  virtual unsigned long unsignedLongValue(simsignal_t signalID) const override {return ul;}
114  virtual double doubleValue(simsignal_t signalID) const override {return d;}
115  virtual SimTime simtimeValue(simsignal_t signalID) const override {return t;}
116  virtual const char *stringValue(simsignal_t signalID) const override {return s;}
117  virtual cObject *objectValue(simsignal_t signalID) const override {return obj;}
119 };
120 
121 } // namespace omnetpp
122 
123 #endif
124 
Root of the OMNeT++ class hierarchy. cObject is a lightweight class without any data members...
Definition: cobject.h:58
int64_t-based, base-10 fixed-point simulation time.
Definition: simtime.h:66
virtual SimsignalType getValueType(simsignal_t signalID) const override
Definition: ctimestampedvalue.h:107
A straightforward implementation of cITimestampedValue.
Definition: ctimestampedvalue.h:64
Interface for emitting timestamped values as signals, primarily for result recording.
Definition: ctimestampedvalue.h:35
Definition: cabstracthistogram.h:21
SimsignalType
Signal data types.
Definition: clistener.h:44
virtual ~cITimestampedValue()
Definition: ctimestampedvalue.h:39
virtual simtime_t_cref getTimestamp(simsignal_t signalID) const override
Definition: ctimestampedvalue.h:104
int simsignal_t
Signal handle.
Definition: clistener.h:24