OpenASIP  2.0
SectionReader.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 SectionReader.hh
26  *
27  * Declaration of SectionReader class.
28  *
29  * @author Mikael Lepistö 2003 (tmlepist-no.spam-cs.tut.fi)
30  *
31  * @note rating: yellow
32  */
33 
34 #ifndef TTA_SECTIONREADER_HH
35 #define TTA_SECTIONREADER_HH
36 
37 #include <map>
38 #include <utility>
39 
40 #include "Section.hh"
41 #include "BinaryReader.hh"
42 #include "Exception.hh"
43 
44 namespace TPEF {
45 
46  class BinaryStream;
47 
48 /**
49  * Abstract base class for SectionReaders.
50  *
51  * Implements user friendly interface for registration and finding
52  * concrete SectionReader instances. Defines also interface for reading
53  * sections so there is no need to know interface or even type of concrete
54  * SectionReaders.
55  */
57 public:
59 
60  virtual ~SectionReader();
61 
62  static void readSection(
63  BinaryStream& stream, Section* section, BinaryReader* reader);
64 
65  static void finalizeBinary(
66  Binary *binaryToFinalize,
67  BinaryReader* reader);
68 
69 protected:
70  SectionReader();
71 
72  /// Does actual reading part for constructing section.
73  virtual void readData(BinaryStream& stream, Section* section) const = 0;
74 
75  /// Returns binary reader whose sections actual section reader reads.
76  virtual BinaryReader* parent() const = 0;
77 
78  /// Returns type (TPEF) section which actual section reader reads.
79  virtual Section::SectionType type() const = 0;
80 
81  virtual void finalize(Section* section) const;
82 
83  static const SectionReader* findSectionReader(
84  const Section::SectionType type, const BinaryReader* bReader);
85 
86  static void registerSectionReader(const SectionReader* sReader);
87 
88 private:
89  /// Copying is not allowed.
91 
92  /// Key type for finding values in map of section readers.
93  typedef
94  std::pair<const Section::SectionType, const BinaryReader*> MapKey;
95 
96  /// Map type that contains instances of registered section readers.
97  typedef std::map<MapKey, const SectionReader*> MapType;
98 
99  /// Contains section readers for all kinds of sections and all kinds of
100  /// binary formats that are supported.
102 };
103 }
104 
105 #endif
TPEF::SectionReader::Length
BinaryReader::Length Length
Definition: SectionReader.hh:58
TPEF::BinaryReader::Length
unsigned long Length
Definition: BinaryReader.hh:53
BinaryReader.hh
TPEF::SectionReader::SectionReader
SectionReader()
Definition: SectionReader.cc:57
Exception.hh
TPEF::SectionReader::prototypes_
static MapType * prototypes_
Contains section readers for all kinds of sections and all kinds of binary formats that are supported...
Definition: SectionReader.hh:101
TPEF::SectionReader::readData
virtual void readData(BinaryStream &stream, Section *section) const =0
Does actual reading part for constructing section.
TPEF::Binary
Definition: Binary.hh:49
TPEF::BinaryStream
Definition: BinaryStream.hh:59
TPEF::SectionReader::finalizeBinary
static void finalizeBinary(Binary *binaryToFinalize, BinaryReader *reader)
Definition: SectionReader.cc:99
TPEF::BinaryReader
Definition: BinaryReader.hh:51
TPEF::Section
Definition: Section.hh:64
TPEF::SectionReader::finalize
virtual void finalize(Section *section) const
Definition: SectionReader.cc:169
TPEF::SectionReader::parent
virtual BinaryReader * parent() const =0
Returns binary reader whose sections actual section reader reads.
TPEF::SectionReader
Definition: SectionReader.hh:56
TPEF::SectionReader::registerSectionReader
static void registerSectionReader(const SectionReader *sReader)
Definition: SectionReader.cc:145
TPEF::SectionReader::type
virtual Section::SectionType type() const =0
Returns type (TPEF) section which actual section reader reads.
TPEF::SectionReader::MapKey
std::pair< const Section::SectionType, const BinaryReader * > MapKey
Key type for finding values in map of section readers.
Definition: SectionReader.hh:94
TPEF::SectionReader::findSectionReader
static const SectionReader * findSectionReader(const Section::SectionType type, const BinaryReader *bReader)
Definition: SectionReader.cc:126
Section.hh
TPEF::SectionReader::MapType
std::map< MapKey, const SectionReader * > MapType
Map type that contains instances of registered section readers.
Definition: SectionReader.hh:97
TPEF::SectionReader::~SectionReader
virtual ~SectionReader()
Definition: SectionReader.cc:63
TPEF::Section::SectionType
SectionType
Definition: Section.hh:69
TPEF
Definition: Assembler.hh:43
TPEF::SectionReader::readSection
static void readSection(BinaryStream &stream, Section *section, BinaryReader *reader)
Definition: SectionReader.cc:84