OpenASIP 2.2
Loading...
Searching...
No Matches
SectionWriter.hh
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 SectionWriter.hh
26 *
27 * Declaration of SectionWriter class.
28 *
29 * @author Mikael Lepistö 2003 (tmlepist-no.spam-cs.tut.fi)
30 *
31 * @note rating: yellow
32 */
33
34#ifndef TTA_SECTION_WRITER_HH
35#define TTA_SECTION_WRITER_HH
36
37#include <map>
38#include <utility>
39
40#include "Section.hh"
41#include "Exception.hh"
42#include "TPEFBaseType.hh"
43
44namespace TPEF {
45
46 class BinaryWriter;
47 class BinaryStream;
48 class Binary;
49
50/**
51 * Abstract base class for actual section writer classes.
52 *
53 * SectionWriter base class stores instances of all registed section
54 * writer classes and serve registeration methods for actual SectionWriter
55 * instances. Actual section writer classes needs also static instance()
56 * method to work correctly.
57 */
59public:
60 static void writeHeader(
61 BinaryStream& stream,
62 const Section* sect,
63 const BinaryWriter* writer);
64
65 static void writeData(
66 BinaryStream& stream,
67 const Section* sect,
68 const BinaryWriter* writer);
69
70 static void finalizeBinary(
71 BinaryStream& stream,
72 const Binary* binaryToFinalize,
73 const BinaryWriter* writer);
74
75protected:
77 virtual ~SectionWriter();
78
79 /// Gets parent of instance which for SectionWriter is created.
80 virtual const BinaryWriter& parent() const = 0;
81
82 /// Returns SectionType that actual reader or writer instance can handle.
83 virtual Section::SectionType type() const = 0;
84
85 virtual void finalize(BinaryStream& stream, Section* section) const;
86
87 /// Does actual writing of sections header.
88 virtual void actualWriteHeader(
89 BinaryStream& stream,
90 const Section* sect) const = 0;
91
92 /// Does actual writing of sections data.
93 virtual void actualWriteData(
94 BinaryStream& stream,
95 const Section* sect) const = 0;
96
97 static void registerSectionWriter(const SectionWriter* sWriter);
98
100
101private:
102 /// Key type for finding values in map of section writers.
103 typedef
104 std::pair<const Section::SectionType, const BinaryWriter*> MapKey;
105
106 /// Map type that contains instances of registered section writers.
107 typedef std::map<MapKey, const SectionWriter*> MapType;
108
110
111 static const SectionWriter* findSectionWriter(
112 const Section::SectionType type, const BinaryWriter* bWriter);
113
114 /// Contains section writers for all kinds of sections and all kinds of
115 /// binrary fromats that are supported.
117};
118}
119
120#endif
static void finalizeBinary(BinaryStream &stream, const Binary *binaryToFinalize, const BinaryWriter *writer)
static void writeHeader(BinaryStream &stream, const Section *sect, const BinaryWriter *writer)
static void writeData(BinaryStream &stream, const Section *sect, const BinaryWriter *writer)
SectionWriter(const SectionWriter &)
virtual const BinaryWriter & parent() const =0
Gets parent of instance which for SectionWriter is created.
virtual Section::SectionType type() const =0
Returns SectionType that actual reader or writer instance can handle.
virtual void actualWriteData(BinaryStream &stream, const Section *sect) const =0
Does actual writing of sections data.
virtual void finalize(BinaryStream &stream, Section *section) const
std::pair< const Section::SectionType, const BinaryWriter * > MapKey
Key type for finding values in map of section writers.
static SectionId getUniqueSectionId()
virtual void actualWriteHeader(BinaryStream &stream, const Section *sect) const =0
Does actual writing of sections header.
std::map< MapKey, const SectionWriter * > MapType
Map type that contains instances of registered section writers.
static void registerSectionWriter(const SectionWriter *sWriter)
static MapType * prototypes_
Contains section writers for all kinds of sections and all kinds of binrary fromats that are supporte...
static const SectionWriter * findSectionWriter(const Section::SectionType type, const BinaryWriter *bWriter)
HalfWord SectionId
Type for storing binary file section ids.