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

#include <BinaryWriter.hh>

Inheritance diagram for TPEF::BinaryWriter:
Inheritance graph
Collaboration diagram for TPEF::BinaryWriter:
Collaboration graph

Public Member Functions

virtual ~BinaryWriter ()
 
void writeBinary (BinaryStream &stream, const Binary *bin) const
 

Protected Member Functions

 BinaryWriter ()
 
virtual void actualWriteBinary (BinaryStream &stream, const Binary *bin) const =0
 Does real writing of binary. More...
 
void setWriter (const BinaryWriter *writer)
 

Private Attributes

const BinaryWriterwriterToUse_
 Contains concrete writer instance that is used for writing binary. More...
 

Detailed Description

Interface for actual binary writer classes and for clients to write binary object representation.

Provides a way for calling the concrete writers with better error checking.

Definition at line 50 of file BinaryWriter.hh.

Constructor & Destructor Documentation

◆ ~BinaryWriter()

TPEF::BinaryWriter::~BinaryWriter ( )
virtual

Destructor.

Definition at line 54 of file BinaryWriter.cc.

54  {
55 }

◆ BinaryWriter()

TPEF::BinaryWriter::BinaryWriter ( )
protected

Constructor.

Definition at line 48 of file BinaryWriter.cc.

48  {
49 }

Member Function Documentation

◆ actualWriteBinary()

virtual void TPEF::BinaryWriter::actualWriteBinary ( BinaryStream stream,
const Binary bin 
) const
protectedpure virtual

Does real writing of binary.

Implemented in TPEF::TPEFWriter.

Referenced by writeBinary().

◆ setWriter()

void TPEF::BinaryWriter::setWriter ( const BinaryWriter writer)
protected

Sets the concrete binary writer to be used for writing binary program representations to a binary stream.

Parameters
writerWriter instance that we use for writing binary.

Definition at line 131 of file BinaryWriter.cc.

131  {
132  writerToUse_ = writer;
133 }

References writerToUse_.

Referenced by TPEF::TPEFWriter::TPEFWriter().

◆ writeBinary()

void TPEF::BinaryWriter::writeBinary ( BinaryStream stream,
const Binary bin 
) const

Stores a binary program representation to given binary stream.

Parameters
streamStream where to write the program representation.
binBinary class hierarchy to write.

Definition at line 64 of file BinaryWriter.cc.

64  {
65 
66  assert(writerToUse_ != NULL);
67 
68  // init referencemanager and replacers
72 
73  try {
74  writerToUse_->actualWriteBinary(stream, bin);
75  } catch (Exception& e) {
76  std::cerr << "Failed to write binary. Maybe the disk is full?" << std::endl << std::endl;;
77  exit(-1);
78  }
79 
80  // try catch blocks are just for debug use right now
81  try {
83  } catch(const MissingKeys &e) {
84  std::cerr << "Missing keys during writing binary file! : \n"
85  << e.procedureName() << std::endl
86  << e.errorMessage() << std::endl
87  << std::endl;
88 
89  assert(false);
90  } catch( ... ) {
91  std::cerr << "Problems with stream during writing binary file"
92  << std::endl;
93  assert(false);
94  }
95 
96  // finalize was called successfully so init must be run again
98 
99  try {
101  } catch (Exception& e) {
102  std::cerr << "Failed to finalize binary." << std::endl;
103  exit(-1);
104  }
105 
106  // try catch blocks are just for debug use right now
107  try {
109  } catch(const MissingKeys &e) {
110  std::cerr << "Missing keys during finalization of writing! \n"
111  << e.procedureName() << std::endl
112  << e.errorMessage() << std::endl
113  << std::endl;
114  assert(false);
115  } catch( ... ) {
116  std::cerr << "Problems with stream during finalization of writing"
117  << std::endl;
118  assert(false);
119  }
120 
122 }

References actualWriteBinary(), assert, TPEF::ReferenceManager::SafePointer::cleanupKeyTables(), TPEF::SectionSizeReplacer::clear(), Exception::errorMessage(), TPEF::ValueReplacer::finalize(), TPEF::SectionWriter::finalizeBinary(), TPEF::ValueReplacer::initialize(), Exception::procedureName(), and writerToUse_.

Referenced by TTAProgram::Program::writeToTPEF().

Here is the call graph for this function:

Member Data Documentation

◆ writerToUse_

const BinaryWriter* TPEF::BinaryWriter::writerToUse_
private

Contains concrete writer instance that is used for writing binary.

Definition at line 68 of file BinaryWriter.hh.

Referenced by setWriter(), and writeBinary().


The documentation for this class was generated from the following files:
MissingKeys
Definition: Exception.hh:405
Exception::procedureName
std::string procedureName() const
TPEF::BinaryWriter::actualWriteBinary
virtual void actualWriteBinary(BinaryStream &stream, const Binary *bin) const =0
Does real writing of binary.
TPEF::ValueReplacer::initialize
static void initialize(BinaryStream &stream)
Definition: ValueReplacer.cc:105
assert
#define assert(condition)
Definition: Application.hh:86
TPEF::ReferenceManager::SafePointer::cleanupKeyTables
static void cleanupKeyTables()
Definition: SafePointer.cc:644
TPEF::SectionSizeReplacer::clear
static void clear()
Definition: SectionSizeReplacer.cc:109
Exception
Definition: Exception.hh:54
Exception::errorMessage
std::string errorMessage() const
Definition: Exception.cc:123
TPEF::ValueReplacer::finalize
static void finalize()
Definition: ValueReplacer.cc:127
TPEF::SectionWriter::finalizeBinary
static void finalizeBinary(BinaryStream &stream, const Binary *binaryToFinalize, const BinaryWriter *writer)
Definition: SectionWriter.cc:99
TPEF::BinaryWriter::writerToUse_
const BinaryWriter * writerToUse_
Contains concrete writer instance that is used for writing binary.
Definition: BinaryWriter.hh:68