ctimestampedvalue.h

00001 //==========================================================================
00002 //  CTIMESTAMPEDVALUE.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 __CTIMESTAMPEDVALUE_H
00017 #define __CTIMESTAMPEDVALUE_H
00018 
00019 #include "clistener.h"  // simsignal_t
00020 #include "simtime_t.h"
00021 #include "cobject.h"
00022 
00023 NAMESPACE_BEGIN
00024 
00025 
00035 class SIM_API cITimestampedValue
00036 {
00037     public:
00039         virtual ~cITimestampedValue() {}
00040 
00042         virtual simtime_t_cref getTimestamp(simsignal_t signalID) const = 0;
00043 
00045         virtual SimsignalType getValueType(simsignal_t signalID) const = 0;
00046 
00049         virtual bool boolValue(simsignal_t signalID) const = 0;
00050         virtual long longValue(simsignal_t signalID) const = 0;
00051         virtual unsigned long unsignedLongValue(simsignal_t signalID) const = 0;
00052         virtual double doubleValue(simsignal_t signalID) const = 0;
00053         virtual SimTime simtimeValue(simsignal_t signalID) const = 0;
00054         virtual const char *stringValue(simsignal_t signalID) const = 0;
00055         virtual cObject *objectValue(simsignal_t signalID) const = 0;
00057 };
00058 
00064 class SIM_API cTimestampedValue : public cITimestampedValue, public cObject
00065 {
00066     public:
00067         simtime_t timestamp;
00068         SimsignalType type; // selector for the union
00069         union {
00070             bool b;
00071             long l;
00072             unsigned long ul;
00073             double d;
00074             const char *s;
00075             cObject *obj;
00076         };
00077         SimTime t;  // cannot go into the union because it has a ctor
00078 
00079     public:
00082         cTimestampedValue() {type=SIMSIGNAL_UNDEF;}
00083         cTimestampedValue(simtime_t timestamp, bool b) {set(timestamp,b);}
00084         cTimestampedValue(simtime_t timestamp, long l) {set(timestamp,l);}
00085         cTimestampedValue(simtime_t timestamp, unsigned long ul) {set(timestamp,ul);}
00086         cTimestampedValue(simtime_t timestamp, double d) {set(timestamp,d);}
00087         cTimestampedValue(simtime_t timestamp, const SimTime& t) {set(timestamp,t);}
00088         cTimestampedValue(simtime_t timestamp, const char *s) {set(timestamp,s);}
00089         cTimestampedValue(simtime_t timestamp, cObject *obj) {set(timestamp,obj);}
00091 
00094         void set(simtime_t timestamp, bool b) {this->timestamp=timestamp; type=SIMSIGNAL_BOOL; this->b=b;}
00095         void set(simtime_t timestamp, long l) {this->timestamp=timestamp; type=SIMSIGNAL_LONG; this->l=l;}
00096         void set(simtime_t timestamp, unsigned long ul) {this->timestamp=timestamp; type=SIMSIGNAL_ULONG; this->ul=ul;}
00097         void set(simtime_t timestamp, double d) {this->timestamp=timestamp; type=SIMSIGNAL_DOUBLE; this->d=d;}
00098         void set(simtime_t timestamp, const SimTime& t) {this->timestamp=timestamp; type=SIMSIGNAL_SIMTIME; this->t=t;}
00099         void set(simtime_t timestamp, const char *s) {this->timestamp=timestamp; type=SIMSIGNAL_STRING; this->s=s;}
00100         void set(simtime_t timestamp, cObject *obj) {this->timestamp=timestamp; type=SIMSIGNAL_OBJECT; this->obj=obj;}
00102 
00104         virtual simtime_t_cref getTimestamp(simsignal_t signalID) const {return timestamp;}
00105 
00107         virtual SimsignalType getValueType(simsignal_t signalID) const {return type;}
00108 
00111         virtual bool boolValue(simsignal_t signalID) const {return b;}
00112         virtual long longValue(simsignal_t signalID) const {return l;}
00113         virtual unsigned long unsignedLongValue(simsignal_t signalID) const {return ul;}
00114         virtual double doubleValue(simsignal_t signalID) const {return d;}
00115         virtual SimTime simtimeValue(simsignal_t signalID) const {return t;}
00116         virtual const char *stringValue(simsignal_t signalID) const {return s;}
00117         virtual cObject *objectValue(simsignal_t signalID) const {return obj;}
00119 };
00120 
00121 NAMESPACE_END
00122 
00123 #endif
00124 
Generated on Tue Dec 2 11:16:27 2014 for OMNeT++ Simulation Library by  doxygen 1.6.3