OpenASIP 2.2
Loading...
Searching...
No Matches
AOutStringSectionReader.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 AOutStringSectionReader.cc
26 *
27 * Definition of AOutStringSectionReader class.
28 *
29 * @author Ari Metsähalme (ari.metsahalme-no.spam-tut.fi)
30 * @author Mikael Lepistö 2004 (tmlepist-no.spam-cs.tut.fi)
31 * @note reviewed 17 October 2003 by kl, pj, am, rm
32 *
33 * @note rating: yellow
34 */
35
36#include "Section.hh"
37#include "SafePointer.hh"
38#include "ReferenceKey.hh"
39#include "StringSection.hh"
42
43namespace TPEF {
44
45using std::string;
46using ReferenceManager::SectionKey;
47using ReferenceManager::SafePointer;
48
49AOutStringSectionReader AOutStringSectionReader::proto_;
50
51/**
52 * Constructor.
53 *
54 * Registers to SectionReader.
55 */
59
60/**
61 * Destructor.
62 */
65
66/**
67 * Returns the type of section that this class can read.
68 *
69 * @return Type of section to read.
70 */
75
76/**
77 * Reads string section from a.out binary file.
78 *
79 * Reads section from stream and makes sure that section starts withs
80 * zero.
81 *
82 * @param stream Stream to be read from.
83 * @param section Section where to the information is stored.
84 * @exception UnreachableStream If reading of section fails.
85 * @exception KeyAlreadyExists Key was in use when trying to register object.
86 * @exception EndOfFile If end of file were reached while it shouldn't.
87 * @exception OutOfRange Some of read values were out of range.
88 * @exception WrongSubclass Some class couldn't do what it was asked for.
89 * @exception UnexpectedValue If there was unexpected value when reading.
90 */
91void
93 BinaryStream& stream, Section* section) const {
94 AOutReader* aOutReader = dynamic_cast<AOutReader*>(parent());
95
96 StringSection* strSect = dynamic_cast<StringSection*>(section);
97 assert(strSect != NULL);
98
99 for (unsigned int i = 0;
100 i < aOutReader->header().sectionSizeString(); i++) {
101 strSect->addByte(stream.readByte());
102 }
103
104 // add zero byte if no data
105 if (strSect->length() == 0) {
106 strSect->addByte(0);
107 }
108
109 // section must start with zero.
110 assert(strSect->byte(strSect->chunk(0)) == 0);
111}
112}
#define assert(condition)
static const Header & header()
virtual BinaryReader * parent() const
static AOutStringSectionReader proto_
Static attribute enables registering to SectionReader before main function is executed.
virtual void readData(BinaryStream &stream, Section *section) const
virtual Section::SectionType type() const
virtual Word length() const
virtual Byte byte(const Chunk *chunk) const
virtual void addByte(Byte aByte)
virtual Chunk * chunk(SectionOffset offset) const
Definition Section.cc:212
static void registerSectionReader(const SectionReader *sReader)
@ ST_STRTAB
String table.
Definition Section.hh:71