Project

General

Profile

Statistics
| Branch: | Revision:

root / src / scave / indexedvectorfilereader.h @ a3be1d55

History | View | Annotate | Download (2.8 KB)

1 01873262 Georg Kunz
//=========================================================================
2
//  INDEXEDVECTORFILEREADER.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 _INDEXEDVECTORFILEREADER_H_
18
#define _INDEXEDVECTORFILEREADER_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 IndexedVectorFileReaderNode : public ReaderNode
40
{
41
    typedef std::vector<Port> PortVector;
42
43
    struct PortData
44
    {
45
        VectorData *vector;
46
        PortVector ports;
47
48
        PortData() : vector(NULL) {}
49
    };
50
51
    struct BlockAndPortData
52
    {
53
        Block *blockPtr;
54
        PortData *portDataPtr;
55
56
        BlockAndPortData(Block *blockPtr, PortData *portDataPtr)
57
            : blockPtr(blockPtr), portDataPtr(portDataPtr) {}
58
59
        bool operator<(const BlockAndPortData& other) const
60
        {
61
            return this->blockPtr->startOffset < other.blockPtr->startOffset;
62
        }
63
    };
64
65
    typedef std::map<int,PortData> VectorIdToPortMap;
66
67
    private:
68
        VectorIdToPortMap ports;
69
        VectorFileIndex *index;
70
        std::vector<BlockAndPortData> blocksToRead;
71
        unsigned int currentBlockIndex;
72
        LineTokenizer tokenizer;
73
74
    public:
75
        IndexedVectorFileReaderNode(const char *filename, size_t bufferSize = VECFILEREADER_BUFSIZE);
76
        virtual ~IndexedVectorFileReaderNode();
77
78
        Port *addVector(const VectorResult &vector);
79
80
        virtual bool isReady() const;
81
        virtual void process();
82
        virtual bool isFinished() const;
83
84
    private:
85
        void readIndexFile();
86
        long readBlock(const Block *blockPtr, const PortData *portDataPtr);
87
};
88
89
90
class SCAVE_API IndexedVectorFileReaderNodeType : public ReaderNodeType
91
{
92
    public:
93
        virtual const char *getName() const {return "indexedvectorfilereader";}
94
        virtual const char *getDescription() const;
95
        virtual void getAttributes(StringMap& attrs) const;
96
        virtual Node *create(DataflowManager *mgr, StringMap& attrs) const;
97
        virtual Port *getPort(Node *node, const char *portname) const;
98
};
99
100
101
NAMESPACE_END
102
103
104
#endif
105