Project

General

Profile

Statistics
| Branch: | Revision:

root / src / scave / indexedvectorfilereader2.h @ a3be1d55

History | View | Annotate | Download (2.37 KB)

1 01873262 Georg Kunz
//=========================================================================
2
//  INDEXEDVECTORFILEREADER2.H - part of
3
//                  OMNeT++/OMNEST
4
//           Discrete System Simulation in C++
5
//
6
//  Author: Tamas Borbely
7
//
8
//=========================================================================
9
10
/*--------------------------------------------------------------*
11
  Copyright (C) 2006-2008 OpenSim Ltd.
12

13
  This file is distributed WITHOUT ANY WARRANTY. See the file
14
  `license' for details on this and other legal matters.
15
*--------------------------------------------------------------*/
16
17
#ifndef _INDEXEDVECTORFILEREADER2_H_
18
#define _INDEXEDVECTORFILEREADER2_H_
19
20
#include <map>
21
#include <string>
22
#include "node.h"
23
#include "nodetype.h"
24
#include "commonnodes.h"
25
#include "filereader.h"
26
#include "linetokenizer.h"
27
#include "indexfile.h"
28
#include "resultfilemanager.h"
29
30
NAMESPACE_BEGIN
31
32
// read in 64K chunks (apparently it doesn't matter much if we use a bigger buffer)
33
#define VECFILEREADER_BUFSIZE  (64*1024)
34
35
36
/**
37
 * Producer node which reads an output vector file.
38
 */
39
class SCAVE_API IndexedVectorFileReaderNode2 : public ReaderNode
40
{
41
    typedef std::vector<Port> PortVector;
42
43
    struct PortData {
44
        VectorData *vector;
45
        int currentBlockIndex;
46
        PortVector ports;
47
48
        PortData() : vector(NULL), currentBlockIndex(0) {}
49
    };
50
51
    typedef std::map<int,PortData> PortMap;
52
53
    private:
54
        PortMap ports;
55
        VectorFileIndex *index;
56
        LineTokenizer tokenizer;
57
        bool fFinished;
58
59
    public:
60
        IndexedVectorFileReaderNode2(const char *filename, size_t bufferSize = VECFILEREADER_BUFSIZE);
61
        virtual ~IndexedVectorFileReaderNode2();
62
63
        Port *addVector(const VectorResult &vector);
64
65
        virtual bool isReady() const;
66
        virtual void process();
67
        virtual bool isFinished() const;
68
69
    private:
70
        void readIndexFile();
71
        bool readNextBlock(PortData& portData);
72
};
73
74
75
class SCAVE_API IndexedVectorFileReaderNode2Type : public ReaderNodeType
76
{
77
    public:
78
        virtual const char *getName() const {return "indexedvectorfilereader2";}
79
        virtual const char *getDescription() const;
80
        virtual void getAttributes(StringMap& attrs) const;
81
        virtual Node *create(DataflowManager *mgr, StringMap& attrs) const;
82
        virtual Port *getPort(Node *node, const char *portname) const;
83
};
84
85
86
NAMESPACE_END
87
88
89
#endif
90