Project

General

Profile

Statistics
| Branch: | Revision:

root / include / ctimestampedvalue.h @ e1750c09

History | View | Annotate | Download (4.55 KB)

1 01873262 Georg Kunz
//==========================================================================
2
//  CTIMESTAMPEDVALUE.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 __CTIMESTAMPEDVALUE_H
17
#define __CTIMESTAMPEDVALUE_H
18
19
#include "clistener.h"  // simsignal_t
20
#include "simtime_t.h"
21
#include "cobject.h"
22
23
NAMESPACE_BEGIN
24
25
26
/**
27
 * Interface for emitting timestamped values as signals, primarily for
28
 * result recording.
29
 *
30
 * Note: The signalID argument is present in the methods to allow the same
31
 * object to support multiple signals.
32
 *
33
 * @ingroup Signals
34
 */
35
class SIM_API cITimestampedValue
36
{
37
    public:
38
        enum Type {UNDEF, LONG, ULONG, DOUBLE, SIMTIME, STRING, OBJECT};
39
40
    public:
41
        /** Virtual destructor */
42
        virtual ~cITimestampedValue() {}
43
44
        /** Returns the timestamp for the given signal. */
45
        virtual simtime_t_cref getTimestamp(simsignal_t signalID) const = 0;
46
47
        /** Returns the value's data type for the given signal. */
48
        virtual Type getValueType(simsignal_t signalID) const = 0;
49
50
        /** @name Returns the value for the given signal. */
51
        //@{
52
        virtual long longValue(simsignal_t signalID) const = 0;
53
        virtual unsigned long unsignedLongValue(simsignal_t signalID) const = 0;
54
        virtual double doubleValue(simsignal_t signalID) const = 0;
55
        virtual SimTime simtimeValue(simsignal_t signalID) const = 0;
56
        virtual const char *stringValue(simsignal_t signalID) const = 0;
57
        virtual cObject *objectValue(simsignal_t signalID) const = 0;
58
        //@}
59
};
60
61
/**
62
 * A straightforward implementation of cITimestampedValue.
63
 *
64
 * @ingroup Signals
65
 */
66
class SIM_API cTimestampedValue : public cITimestampedValue, public cObject
67
{
68
    public:
69
        simtime_t timestamp;
70
        Type type; // selector for the union
71
        union {
72
            long l;
73
            unsigned long ul;
74
            double d;
75
            const char *s;
76
            cObject *obj;
77
        };
78
        SimTime t;  // cannot go into the union because it has a ctor
79
80
    public:
81
        /** @name Constructors */
82
        //@{
83
        cTimestampedValue() {type=UNDEF;}
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);}
90
        //@}
91
92
        /** @name Setters */
93
        //@{
94
        void set(simtime_t timestamp, long l) {this->timestamp=timestamp; type=LONG; this->l=l;}
95
        void set(simtime_t timestamp, unsigned long ul) {this->timestamp=timestamp; type=ULONG; this->ul=ul;}
96
        void set(simtime_t timestamp, double d) {this->timestamp=timestamp; type=DOUBLE; this->d=d;}
97
        void set(simtime_t timestamp, const SimTime& t) {this->timestamp=timestamp; type=SIMTIME; this->t=t;}
98
        void set(simtime_t timestamp, const char *s) {this->timestamp=timestamp; type=STRING; this->s=s;}
99
        void set(simtime_t timestamp, cObject *obj) {this->timestamp=timestamp; type=OBJECT; this->obj=obj;}
100
        //@}
101
102
        /** Returns the stored timestamp. */
103
        virtual simtime_t_cref getTimestamp(simsignal_t signalID) const {return timestamp;}
104
105
        /** Returns the data type of the stored value. */
106
        virtual Type getValueType(simsignal_t signalID) const {return type;}
107
108
        /** @name Getters. Call the one that corresponds to the stored type. */
109
        //@{
110
        virtual long longValue(simsignal_t signalID) const {return l;}
111
        virtual unsigned long unsignedLongValue(simsignal_t signalID) const {return ul;}
112
        virtual double doubleValue(simsignal_t signalID) const {return d;}
113
        virtual SimTime simtimeValue(simsignal_t signalID) const {return t;}
114
        virtual const char *stringValue(simsignal_t signalID) const {return s;}
115
        virtual cObject *objectValue(simsignal_t signalID) const {return obj;}
116
        //@}
117
};
118
119
NAMESPACE_END
120
121
#endif