OMNeT++ API 6.1
Discrete Event Simulation Library
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 #include "opp_string.h"
23 
24 namespace omnetpp {
25 
26 
32 typedef void (*RecordFunc)(void *, simtime_t, double);
33 
34 class cEnum;
35 
36 
58 class SIM_API cOutVector : public cNoncopyableOwnedObject
59 {
60  protected:
61  enum {
62  FL_ENABLED = 4, // flag: when false, record() method will do nothing
63  FL_RECORDWARMUP = 8, // flag: when set, object records data during warmup period as well
64  };
65 
66  opp_string_map attributes; // collects vector attributes until registration
67  void *handle = nullptr; // identifies output vector for the output vector manager
68  simtime_t lastTimestamp; // last timestamp written, needed to ensure increasing timestamp order
69  long numReceived = 0; // total number of values passed to the output vector object
70  long numStored = 0; // number of values actually stored
71 
72  // the following members will be used directly by inspectors
73  RecordFunc recordInInspector = nullptr; // to notify inspector about file writes
74  void *dataForInspector;
75 
76  public:
77  // internal: called from behind cEnvir
78  void setCallback(RecordFunc f, void *d) {recordInInspector=f; dataForInspector=d;}
79 
80  public:
81  enum Type { TYPE_INT, TYPE_DOUBLE, TYPE_ENUM };
82  enum InterpolationMode { NONE, SAMPLE_HOLD, BACKWARD_SAMPLE_HOLD, LINEAR };
83 
84  protected:
85  virtual void ensureRegistered();
86 
87  public:
95  explicit cOutVector(const char *name=nullptr);
96 
100  explicit cOutVector(const char *name, const opp_string_map& attributes);
101 
105  virtual ~cOutVector();
107 
110 
115  virtual void setName(const char *name) override;
116 
121  virtual std::string str() const override;
123 
126 
130  virtual void setAttributes(const opp_string_map& attributes);
131 
137  virtual void setAttribute(const char *name, const char *value);
138 
146  virtual void registerVector();
147 
154  virtual void setEnum(const char *registeredEnumName);
155 
162  virtual void setEnum(cEnum *enumDecl);
163 
168  virtual void setUnit(const char *unit);
169 
175  virtual void setType(Type type);
176 
182  virtual void setInterpolationMode(InterpolationMode mode);
183 
189  virtual void setMin(double minValue);
190 
196  virtual void setMax(double maxValue);
198 
207  virtual bool record(double value);
208 
212  virtual bool record(SimTime value) {return record(value.dbl());}
213 
223  virtual bool recordWithTimestamp(simtime_t t, double value);
224 
228  virtual bool recordWithTimestamp(simtime_t t, SimTime value) {return recordWithTimestamp(t, value.dbl());}
229 
233  virtual void enable() {setFlag(FL_ENABLED,true);}
234 
239  virtual void disable() {setFlag(FL_ENABLED,false);}
240 
245  virtual void setEnabled(bool b) {setFlag(FL_ENABLED,b);}
246 
250  virtual bool isEnabled() const {return flags&FL_ENABLED;}
251 
259  virtual void setRecordDuringWarmupPeriod(bool b) {setFlag(FL_RECORDWARMUP,b);}
260 
265  virtual bool getRecordDuringWarmupPeriod() const {return flags&FL_RECORDWARMUP;}
266 
272  long getValuesReceived() const {return numReceived;}
273 
279  long getValuesStored() const {return numStored;}
281 };
282 
283 } // namespace omnetpp
284 
285 
286 #endif
287 
288 
omnetpp::cOutVector::setEnabled
virtual void setEnabled(bool b)
Definition: coutvector.h:245
omnetpp::cOutVector::enable
virtual void enable()
Definition: coutvector.h:233
omnetpp::cOutVector
Responsible for recording an "output vector" into the simulation results file. An output vector is a ...
Definition: coutvector.h:58
omnetpp::cOutVector::getValuesReceived
long getValuesReceived() const
Definition: coutvector.h:272
omnetpp::cOutVector::getRecordDuringWarmupPeriod
virtual bool getRecordDuringWarmupPeriod() const
Definition: coutvector.h:265
omnetpp::cOutVector::isEnabled
virtual bool isEnabled() const
Definition: coutvector.h:250
omnetpp::opp_string_map
Lightweight string-to-string map, used internally in some parts of OMNeT++.
Definition: opp_string.h:219
omnetpp::cOutVector::getValuesStored
long getValuesStored() const
Definition: coutvector.h:279
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:33
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:228
omnetpp::cOutVector::record
virtual bool record(SimTime value)
Definition: coutvector.h:212
omnetpp::SimTime::dbl
double dbl() const
Definition: simtime.h:346
omnetpp::cOutVector::disable
virtual void disable()
Definition: coutvector.h:239
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:32
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:259