OMNeT++ Simulation Library  6.0.3
coutvector.h
1 //==========================================================================
2 // COUTVECTOR.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_COUTVECTOR_H
17 #define __OMNETPP_COUTVECTOR_H
18 
19 #include <cstdio>
20 #include "cownedobject.h"
21 #include "simtime_t.h"
22 
23 namespace omnetpp {
24 
25 
31 typedef void (*RecordFunc)(void *, simtime_t, double);
32 
33 class cEnum;
34 
35 
44 class SIM_API cOutVector : public cNoncopyableOwnedObject
45 {
46  protected:
47  enum {
48  FL_ENABLED = 4, // flag: when false, record() method will do nothing
49  FL_RECORDWARMUP = 8, // flag: when set, object records data during warmup period as well
50  };
51 
52  void *handle = nullptr; // identifies output vector for the output vector manager
53  simtime_t lastTimestamp; // last timestamp written, needed to ensure increasing timestamp order
54  long numReceived = 0; // total number of values passed to the output vector object
55  long numStored = 0; // number of values actually stored
56 
57  // the following members will be used directly by inspectors
58  RecordFunc recordInInspector = nullptr; // to notify inspector about file writes
59  void *dataForInspector;
60 
61  public:
62  // internal: called from behind cEnvir
63  void setCallback(RecordFunc f, void *d) {recordInInspector=f; dataForInspector=d;}
64 
65  public:
66  enum Type { TYPE_INT, TYPE_DOUBLE, TYPE_ENUM };
67  enum InterpolationMode { NONE, SAMPLE_HOLD, BACKWARD_SAMPLE_HOLD, LINEAR };
68 
69  public:
75  explicit cOutVector(const char *name=nullptr);
76 
80  virtual ~cOutVector();
82 
85 
90  virtual void setName(const char *name) override;
91 
96  virtual std::string str() const override;
98 
108  virtual void setEnum(const char *registeredEnumName);
109 
117  virtual void setEnum(cEnum *enumDecl);
118 
124  virtual void setUnit(const char *unit);
125 
132  virtual void setType(Type type);
133 
139  virtual void setInterpolationMode(InterpolationMode mode);
140 
147  virtual void setMin(double minValue);
148 
155  virtual void setMax(double maxValue);
157 
166  virtual bool record(double value);
167 
171  virtual bool record(SimTime value) {return record(value.dbl());}
172 
182  virtual bool recordWithTimestamp(simtime_t t, double value);
183 
187  virtual bool recordWithTimestamp(simtime_t t, SimTime value) {return recordWithTimestamp(t, value.dbl());}
188 
192  virtual void enable() {setFlag(FL_ENABLED,true);}
193 
198  virtual void disable() {setFlag(FL_ENABLED,false);}
199 
204  virtual void setEnabled(bool b) {setFlag(FL_ENABLED,b);}
205 
209  virtual bool isEnabled() const {return flags&FL_ENABLED;}
210 
218  virtual void setRecordDuringWarmupPeriod(bool b) {setFlag(FL_RECORDWARMUP,b);}
219 
224  virtual bool getRecordDuringWarmupPeriod() const {return flags&FL_RECORDWARMUP;}
225 
231  long getValuesReceived() const {return numReceived;}
232 
238  long getValuesStored() const {return numStored;}
240 };
241 
242 } // namespace omnetpp
243 
244 
245 #endif
246 
247 
omnetpp::cOutVector::setEnabled
virtual void setEnabled(bool b)
Definition: coutvector.h:204
omnetpp::cOutVector::enable
virtual void enable()
Definition: coutvector.h:192
omnetpp::cOutVector
Responsible for recording vector simulation results (an output vector).
Definition: coutvector.h:44
omnetpp::cOutVector::getValuesReceived
long getValuesReceived() const
Definition: coutvector.h:231
omnetpp::cOutVector::getRecordDuringWarmupPeriod
virtual bool getRecordDuringWarmupPeriod() const
Definition: coutvector.h:224
omnetpp::cOutVector::isEnabled
virtual bool isEnabled() const
Definition: coutvector.h:209
omnetpp::cOutVector::getValuesStored
long getValuesStored() const
Definition: coutvector.h:238
omnetpp::SimTime
int64_t-based, base-10 fixed-point simulation time.
Definition: simtime.h:66
omnetpp::cEnum
Provides string representation for enums.
Definition: cenum.h:32
omnetpp::simtime_t
SimTime simtime_t
Represents simulation time.
Definition: simtime_t.h:40
omnetpp::cOutVector::recordWithTimestamp
virtual bool recordWithTimestamp(simtime_t t, SimTime value)
Definition: coutvector.h:187
omnetpp::cOutVector::record
virtual bool record(SimTime value)
Definition: coutvector.h:171
omnetpp::SimTime::dbl
double dbl() const
Definition: simtime.h:307
omnetpp::cOutVector::disable
virtual void disable()
Definition: coutvector.h:198
omnetpp::RecordFunc
void(* RecordFunc)(void *, simtime_t, double)
Prototype for callback functions that are used to notify graphical user interfaces when values are re...
Definition: coutvector.h:31
omnetpp::cNoncopyableOwnedObject
Base class for cOwnedObject-based classes that do not wish to support assignment and duplication.
Definition: cownedobject.h:242
omnetpp::cOutVector::setRecordDuringWarmupPeriod
virtual void setRecordDuringWarmupPeriod(bool b)
Definition: coutvector.h:218