OpenASIP 2.2
Loading...
Searching...
No Matches
TPEFDataSectionReader.cc
Go to the documentation of this file.
1/*
2 Copyright (c) 2002-2009 Tampere University.
3
4 This file is part of TTA-Based Codesign Environment (TCE).
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23 */
24/**
25 * @file TPEFDataSectionReader.cc
26 *
27 * Definition of TPEFDataSectionReader class.
28 *
29 * @author Mikael Lepistö 2003 (tmlepist-no.spam-cs.tut.fi)
30 *
31 * @note rating: yellow
32 */
33
35#include "SectionReader.hh"
36#include "TPEFBaseType.hh"
37#include "SafePointer.hh"
38#include "BinaryStream.hh"
39#include "DataSection.hh"
40
41namespace TPEF {
42
43using ReferenceManager::SafePointer;
44using ReferenceManager::SectionIndexKey;
45using ReferenceManager::FileOffsetKey;
46using std::string;
47
48TPEFDataSectionReader TPEFDataSectionReader::proto_;
49
50/**
51 * Constructor.
52 *
53 * Registers itself to SectionReader.
54 */
59
60/**
61 * Destructor.
62 */
65
66/**
67 * Returns the type of section it is meant to read.
68 *
69 * @return The type of section it can read.
70 */
75
76/**
77 * Reads data section of TPEF binary file.
78 *
79 * @param stream Stream to be read from.
80 * @param section Section where the information is to be stored.
81 * @exception UnreachableStream If reading of section fails.
82 * @exception KeyAlreadyExists Key was in use when trying to register object.
83 * @exception EndOfFile If end of file were reached while it shouldn't.
84 * @exception OutOfRange Some of read values were out of range.
85 * @exception WrongSubclass Some class couldn't do what it was asked for.
86 * @exception UnexpectedValue If there was unexpected value when reading.
87 */
88void
90 // base classes implementation must be called with these.
91 TPEFSectionReader::readData(stream, section);
92
93 DataSection* dataSection = dynamic_cast<DataSection*>(section);
94 assert(dataSection != NULL);
95
96 // check that link section is defined properly
97 assert(header().linkId == 0);
98
99 if (!section->noBits()) {
100 while (stream.readPosition() <
101 header().bodyOffset + header().bodyLength) {
102 dataSection->addByte(stream.readByte());
103 }
104
105 dynamic_cast<TPEFReader*>(
106 parent())->addSectionSize(section, header().bodyLength);
107 }
108}
109}
#define assert(condition)
unsigned int readPosition()
virtual void addByte(Byte aByte)
static void registerSectionReader(const SectionReader *sReader)
@ ST_DATA
Initialized data section.
Definition Section.hh:80
bool noBits() const
virtual Section::SectionType type() const
virtual void readData(BinaryStream &stream, Section *section) const
static TPEFDataSectionReader proto_
Prototype instance of TPEFDataSectionReader to be registered to SectionReader.
virtual BinaryReader * parent() const
virtual void readData(BinaryStream &stream, Section *section) const
static const Header & header()