OpenASIP  2.0
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Private Types | Private Member Functions | Static Private Attributes | List of all members
TPEF::SectionReader Class Referenceabstract

#include <SectionReader.hh>

Inheritance diagram for TPEF::SectionReader:
Inheritance graph
Collaboration diagram for TPEF::SectionReader:
Collaboration graph

Public Types

typedef BinaryReader::Length Length
 

Public Member Functions

virtual ~SectionReader ()
 

Static Public Member Functions

static void readSection (BinaryStream &stream, Section *section, BinaryReader *reader)
 
static void finalizeBinary (Binary *binaryToFinalize, BinaryReader *reader)
 

Protected Member Functions

 SectionReader ()
 
virtual void readData (BinaryStream &stream, Section *section) const =0
 Does actual reading part for constructing section. More...
 
virtual BinaryReaderparent () const =0
 Returns binary reader whose sections actual section reader reads. More...
 
virtual Section::SectionType type () const =0
 Returns type (TPEF) section which actual section reader reads. More...
 
virtual void finalize (Section *section) const
 

Static Protected Member Functions

static const SectionReaderfindSectionReader (const Section::SectionType type, const BinaryReader *bReader)
 
static void registerSectionReader (const SectionReader *sReader)
 

Private Types

typedef std::pair< const Section::SectionType, const BinaryReader * > MapKey
 Key type for finding values in map of section readers. More...
 
typedef std::map< MapKey, const SectionReader * > MapType
 Map type that contains instances of registered section readers. More...
 

Private Member Functions

 SectionReader (const SectionReader &)
 Copying is not allowed. More...
 

Static Private Attributes

static MapTypeprototypes_ = NULL
 Contains section readers for all kinds of sections and all kinds of binary formats that are supported. More...
 

Detailed Description

Abstract base class for SectionReaders.

Implements user friendly interface for registration and finding concrete SectionReader instances. Defines also interface for reading sections so there is no need to know interface or even type of concrete SectionReaders.

Definition at line 56 of file SectionReader.hh.

Member Typedef Documentation

◆ Length

Definition at line 58 of file SectionReader.hh.

◆ MapKey

typedef std::pair<const Section::SectionType, const BinaryReader*> TPEF::SectionReader::MapKey
private

Key type for finding values in map of section readers.

Definition at line 94 of file SectionReader.hh.

◆ MapType

typedef std::map<MapKey, const SectionReader*> TPEF::SectionReader::MapType
private

Map type that contains instances of registered section readers.

Definition at line 97 of file SectionReader.hh.

Constructor & Destructor Documentation

◆ ~SectionReader()

TPEF::SectionReader::~SectionReader ( )
virtual

Destructor

Definition at line 63 of file SectionReader.cc.

63  {
64 }

◆ SectionReader() [1/2]

TPEF::SectionReader::SectionReader ( )
protected

Constructor

Definition at line 57 of file SectionReader.cc.

57  {
58 }

◆ SectionReader() [2/2]

TPEF::SectionReader::SectionReader ( const SectionReader )
private

Copying is not allowed.

Member Function Documentation

◆ finalize()

void TPEF::SectionReader::finalize ( Section section) const
protectedvirtual

Default finalizer method all sections.

Does nothing. This method is runned for every read section after body of every section is read and references are resolved once.

Parameters
sectionSection to finalize.

Reimplemented in TPEF::AOutSymbolSectionReader, TPEF::AOutRelocationSectionReader, and TPEF::TPEFRelocSectionReader.

Definition at line 169 of file SectionReader.cc.

169  {
170 }

Referenced by finalizeBinary().

◆ finalizeBinary()

void TPEF::SectionReader::finalizeBinary ( Binary bin,
BinaryReader reader 
)
static

Finalizes binary whose all data is read and resolved.

Parameters
binBinary to resolve.
readerReader which was used for reading.

Definition at line 99 of file SectionReader.cc.

99  {
100 
101  for (Word i = 0; i < bin->sectionCount(); i++) {
102  // get section and finalize it
103  Section* sect = bin->section(i);
104 
105  try {
106  const SectionReader* sectionReader =
107  findSectionReader(sect->type(), reader);
108  sectionReader->finalize(sect);
109 
110  } catch (const InstanceNotFound &e) {
111  // there is not always reader for every created section
112  // and it's ok.
113  }
114  }
115 }

References finalize(), findSectionReader(), TPEF::Binary::section(), TPEF::Binary::sectionCount(), and TPEF::Section::type().

Referenced by TPEF::BinaryReader::readBinary().

Here is the call graph for this function:

◆ findSectionReader()

const SectionReader * TPEF::SectionReader::findSectionReader ( const Section::SectionType  type,
const BinaryReader reader 
)
staticprotected

Finds SectionReader instance by SectionType and BinaryReader*.

Parameters
typeType of section to find.
readerBinaryReader which requested finding section.
Returns
Instance which can read section.
Exceptions
InstanceNotFoundReader instance was not found.

Definition at line 126 of file SectionReader.cc.

127  {
128  MapKey key(type, reader);
129 
130  if (prototypes_ == NULL ||
132  throw InstanceNotFound(__FILE__, __LINE__,
133  "SectionReader::findSectionReader");
134  }
135 
136  return (*prototypes_)[key];
137 }

References MapTools::containsKey(), prototypes_, and type().

Referenced by finalizeBinary(), and readSection().

Here is the call graph for this function:

◆ parent()

virtual BinaryReader* TPEF::SectionReader::parent ( ) const
protectedpure virtual

Returns binary reader whose sections actual section reader reads.

Implemented in TPEF::TPEFSectionReader, and TPEF::AOutSectionReader.

Referenced by registerSectionReader().

◆ readData()

virtual void TPEF::SectionReader::readData ( BinaryStream stream,
Section section 
) const
protectedpure virtual

◆ readSection()

void TPEF::SectionReader::readSection ( BinaryStream stream,
Section section,
BinaryReader reader 
)
static

Reads a section from BinaryStream.

Finds correct concrete SectionReader object for reading section and uses it for reading.

Parameters
streamStream from which section's data is read.
sectionSection instance where section elements are stored.
readerBinaryReader* of file type that we try to read.
Exceptions
InstanceNotFoundThere is no prototype registred for reading.
UnreachableStreamIf reading of section fails.
KeyAlreadyExistsKey was in use when trying to register object.
EndOfFileIf end of file were reached while it shouldn't.
OutOfRangeSome of read values were out of range.
WrongSubclassSome class couldn't do what it was asked for.
UnexpectedValueIf there was unexpected value when reading.

Definition at line 84 of file SectionReader.cc.

85  {
86  const SectionReader* sectionReader =
87  findSectionReader(section->type(), reader);
88 
89  sectionReader->readData(stream, section);
90 }

References findSectionReader(), readData(), and TPEF::Section::type().

Referenced by TPEF::TPEFReader::readData().

Here is the call graph for this function:

◆ registerSectionReader()

void TPEF::SectionReader::registerSectionReader ( const SectionReader reader)
staticprotected

Registers SectionReader instance for reading specific section type.

Parameters
readerInstance to register for reading.

Definition at line 145 of file SectionReader.cc.

145  {
146 
147  MapKey key(reader->type(), reader->parent());
148 
149  // We can't define a static prototypes_ map, because we cannot guarantee
150  // that it is initialized before this method is called.
151  if (prototypes_ == NULL) {
152  prototypes_ = new MapType();
153  }
154 
156 
157  (*prototypes_)[key] = reader;
158 }

References assert, MapTools::containsKey(), parent(), prototypes_, and type().

Referenced by TPEF::AOutDataSectionReader::AOutDataSectionReader(), TPEF::AOutRelocationSectionReader::AOutRelocationSectionReader(), TPEF::AOutStringSectionReader::AOutStringSectionReader(), TPEF::AOutSymbolSectionReader::AOutSymbolSectionReader(), TPEF::AOutTextSectionReader::AOutTextSectionReader(), TPEF::TPEFASpaceSectionReader::TPEFASpaceSectionReader(), TPEF::TPEFCodeSectionReader::TPEFCodeSectionReader(), TPEF::TPEFDataSectionReader::TPEFDataSectionReader(), TPEF::TPEFDebugSectionReader::TPEFDebugSectionReader(), TPEF::TPEFLEDataSectionReader::TPEFLEDataSectionReader(), TPEF::TPEFLineNumSectionReader::TPEFLineNumSectionReader(), TPEF::TPEFNullSectionReader::TPEFNullSectionReader(), TPEF::TPEFRelocSectionReader::TPEFRelocSectionReader(), TPEF::TPEFResourceSectionReader::TPEFResourceSectionReader(), TPEF::TPEFStringSectionReader::TPEFStringSectionReader(), TPEF::TPEFSymbolSectionReader::TPEFSymbolSectionReader(), and TPEF::TPEFUDataSectionReader::TPEFUDataSectionReader().

Here is the call graph for this function:

◆ type()

virtual Section::SectionType TPEF::SectionReader::type ( ) const
protectedpure virtual

Member Data Documentation

◆ prototypes_

SectionReader::MapType * TPEF::SectionReader::prototypes_ = NULL
staticprivate

Contains section readers for all kinds of sections and all kinds of binary formats that are supported.

Definition at line 101 of file SectionReader.hh.

Referenced by findSectionReader(), and registerSectionReader().


The documentation for this class was generated from the following files:
TPEF::SectionReader::SectionReader
SectionReader()
Definition: SectionReader.cc:57
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
assert
#define assert(condition)
Definition: Application.hh:86
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
MapTools::containsKey
static bool containsKey(const MapType &aMap, const KeyType &aKey)
TPEF::SectionReader::MapType
std::map< MapKey, const SectionReader * > MapType
Map type that contains instances of registered section readers.
Definition: SectionReader.hh:97
InstanceNotFound
Definition: Exception.hh:304