OpenASIP  2.0
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 
44 namespace 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  */
59 public:
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 
75 protected:
76  SectionWriter();
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 
101 private:
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
TPEF::SectionId
HalfWord SectionId
Type for storing binary file section ids.
Definition: TPEFBaseType.hh:43
TPEF::SectionWriter::writeData
static void writeData(BinaryStream &stream, const Section *sect, const BinaryWriter *writer)
Definition: SectionWriter.cc:79
TPEF::SectionWriter::actualWriteData
virtual void actualWriteData(BinaryStream &stream, const Section *sect) const =0
Does actual writing of sections data.
Exception.hh
TPEF::Binary
Definition: Binary.hh:49
TPEF::SectionWriter::finalize
virtual void finalize(BinaryStream &stream, Section *section) const
Definition: SectionWriter.cc:192
TPEF::SectionWriter::type
virtual Section::SectionType type() const =0
Returns SectionType that actual reader or writer instance can handle.
TPEF::BinaryStream
Definition: BinaryStream.hh:59
TPEF::SectionWriter::~SectionWriter
virtual ~SectionWriter()
Definition: SectionWriter.cc:50
TPEF::Section
Definition: Section.hh:64
TPEF::SectionWriter::actualWriteHeader
virtual void actualWriteHeader(BinaryStream &stream, const Section *sect) const =0
Does actual writing of sections header.
TPEF::SectionWriter::registerSectionWriter
static void registerSectionWriter(const SectionWriter *sWriter)
Definition: SectionWriter.cc:148
TPEF::SectionWriter::writeHeader
static void writeHeader(BinaryStream &stream, const Section *sect, const BinaryWriter *writer)
Definition: SectionWriter.cc:62
TPEF::SectionWriter::findSectionWriter
static const SectionWriter * findSectionWriter(const Section::SectionType type, const BinaryWriter *bWriter)
Definition: SectionWriter.cc:129
TPEF::SectionWriter
Definition: SectionWriter.hh:58
Section.hh
TPEF::SectionWriter::MapKey
std::pair< const Section::SectionType, const BinaryWriter * > MapKey
Key type for finding values in map of section writers.
Definition: SectionWriter.hh:104
TPEF::SectionWriter::SectionWriter
SectionWriter()
Definition: SectionWriter.cc:44
TPEF::Section::SectionType
SectionType
Definition: Section.hh:69
TPEF::SectionWriter::parent
virtual const BinaryWriter & parent() const =0
Gets parent of instance which for SectionWriter is created.
TPEFBaseType.hh
TPEF::SectionWriter::finalizeBinary
static void finalizeBinary(BinaryStream &stream, const Binary *binaryToFinalize, const BinaryWriter *writer)
Definition: SectionWriter.cc:99
TPEF::SectionWriter::prototypes_
static MapType * prototypes_
Contains section writers for all kinds of sections and all kinds of binrary fromats that are supporte...
Definition: SectionWriter.hh:116
TPEF::SectionWriter::getUniqueSectionId
static SectionId getUniqueSectionId()
Definition: SectionWriter.cc:172
TPEF::SectionWriter::MapType
std::map< MapKey, const SectionWriter * > MapType
Map type that contains instances of registered section writers.
Definition: SectionWriter.hh:107
TPEF::BinaryWriter
Definition: BinaryWriter.hh:50
TPEF
Definition: Assembler.hh:43