Project

General

Profile

Statistics
| Branch: | Revision:

root / src / envir / fileoutvectormgr.h @ e26d3d25

History | View | Annotate | Download (3.85 KB)

1
//==========================================================================
2
//  FILEOUTPUTVECTORMGR.H - part of
3
//                     OMNeT++/OMNEST
4
//            Discrete System Simulation in C++
5
//
6
//  Author: Andras Varga
7
//
8
//==========================================================================
9

    
10
/*--------------------------------------------------------------*
11
  Copyright (C) 1992-2008 Andras Varga
12
  Copyright (C) 2006-2008 OpenSim Ltd.
13

14
  This file is distributed WITHOUT ANY WARRANTY. See the file
15
  `license' for details on this and other legal matters.
16
*--------------------------------------------------------------*/
17

    
18
#ifndef __FILEOUTPUTVECTORMGR_H
19
#define __FILEOUTPUTVECTORMGR_H
20

    
21
#include <stdio.h>
22
#include "envirdefs.h"
23
#include "envirext.h"
24
#include "simutil.h"
25
#include "runattributes.h"
26
#include "intervals.h"
27

    
28
NAMESPACE_BEGIN
29

    
30

    
31
/**
32
 * A cOutputVectorManager that uses a line-oriented text file as output.
33
 * The file consists of vector declarations lines and data lines.
34
 * Each data line contains a vector id, time, value triplet.
35
 *
36
 * @ingroup Envir
37
 */
38
class ENVIR_API cFileOutputVectorManager : public cOutputVectorManager
39
{
40
  protected:
41

    
42
    struct sVectorData { //XXX use stringPool for vectorname etc?
43
       int id;              // vector ID
44
       opp_string modulename; // module of cOutVector object
45
       opp_string vectorname; // cOutVector object name
46
       opp_string_map attributes; // vector attributes
47
       bool initialized;    // true if the vector declaration has been written out
48
       bool enabled;        // write to the output file can be enabled/disabled
49
       bool recordEventNumbers; // record the current event number for each sample
50
       Intervals intervals;
51

    
52
       const char *getColumns() { return recordEventNumbers ? "ETV" : "TV"; }
53
    };
54

    
55
    sRunData run;      // holds data of the current run
56
    int nextid;        // holds next free ID for output vectors
57
    opp_string fname;  // output file name
58
    FILE *f;           // file ptr of output file
59
    int prec;          // number of significant digits when writing doubles (time, value)
60

    
61
  protected:
62
    void openFile();
63
    void closeFile();
64
    virtual void initVector(sVectorData *vp);
65
    virtual sVectorData *createVectorData();
66
    virtual void writeRunData();
67

    
68
  public:
69
    /** @name Constructors, destructor */
70
    //@{
71

    
72
    /**
73
     * Constructor.
74
     */
75
    explicit cFileOutputVectorManager();
76

    
77
    /**
78
     * Destructor. Closes the output file if it is still open.
79
     */
80
    virtual ~cFileOutputVectorManager();
81
    //@}
82

    
83
    /**
84
     * Utility function for parsing the configuration of an output vector.
85
     */
86
    static void getOutVectorConfig(const char *modname, const char *vecname,
87
                                   bool& outEnabled, bool& outRecordEventNumbers, Intervals &outIntervals);
88

    
89
    /** @name Redefined cOutputVectorManager member functions. */
90
    //@{
91

    
92
    /**
93
     * Deletes output vector file if exists (left over from previous runs).
94
     * The file is not yet opened, it is done inside registerVector() on demand.
95
     */
96
    virtual void startRun();
97

    
98
    /**
99
     * Closes the output file.
100
     */
101
    virtual void endRun();
102

    
103
    /**
104
     * Registers a vector and returns a handle.
105
     */
106
    virtual void *registerVector(const char *modulename, const char *vectorname);
107

    
108
    /**
109
     * Deregisters the output vector.
110
     */
111
    virtual void deregisterVector(void *vechandle);
112

    
113
    /**
114
     * Sets an attribute of an output vector.
115
     */
116
    virtual void setVectorAttribute(void *vechandle, const char *name, const char *value);
117

    
118
    /**
119
     * Writes the (time, value) pair into the output file.
120
     */
121
    virtual bool record(void *vectorhandle, simtime_t t, double value);
122

    
123
    /**
124
     * Returns the file name.
125
     */
126
    const char *getFileName() const;
127

    
128
    /**
129
     * Calls fflush().
130
     */
131
    virtual void flush();
132
    //@}
133
};
134

    
135
NAMESPACE_END
136

    
137
#endif
138