Constructs a Binary object by reading data from the given binary stream.
Looks for the concrete binary reader class that can read the given binary stream. If found, that reader is used to read and construct a Binary object. This method cleans keytables of reference manager so after running this method reference manager contain keys of just read binary file.
- Parameters
-
stream | Stream to read binarys data from. |
- Returns
- Binary that was created from the given stream.
- Exceptions
-
Definition at line 88 of file BinaryReader.cc.
88 {
90
91 unsigned long startPos = stream.readPosition();
92
93 set<BinaryReader*>::iterator readers =
prototypes_->begin();
94
95
97
98 assert(stream.readPosition() == startPos);
99
100 if ((*readers)->isMyStreamType(stream)) {
101
102
103 assert(stream.readPosition() == startPos);
104
106
107 Binary *
readBinary = (*readers)->readData(stream);
108
109 try {
112 std::stringstream newErrorMsg;
113 newErrorMsg
114 << "Error was probably caused by a broken input file."
115 << std::endl
116 << "Unresolved references during reading: ";
117
121
122 error.setCause(e);
123 throw error;
124 }
125
127
128 try {
131 std::stringstream newErrorMsg;
132 newErrorMsg
133 << "Error was probably caused by a broken input file."
134 << std::endl
135 << "Unresolved references during finalization of "
136 << "reading: ";
137
141
142 error.setCause(e);
143 throw error;
144 }
145
146
148
150 }
151 readers++;
152 }
153 }
156 "Cannot find suitable reader implementation for file.");
157}
#define assert(condition)
std::string errorMessage() const
static std::set< BinaryReader * > * prototypes_
Contains instances of concrete BinaryReaders.
static Binary * readBinary(BinaryStream &stream)
static void cleanupKeyTables()
static void finalizeBinary(Binary *binaryToFinalize, BinaryReader *reader)
References __func__, assert, TPEF::ReferenceManager::SafePointer::cleanupKeyTables(), Exception::errorMessage(), TPEF::SectionReader::finalizeBinary(), prototypes_, readBinary(), TPEF::BinaryStream::readPosition(), TPEF::ReferenceManager::SafePointer::resolve(), and Exception::setCause().
Referenced by TTAProgram::Program::loadFromTPEF(), TTAProgram::Program::loadFromUnscheduledTPEF(), TTAProgram::Program::loadFromUnscheduledTPEF(), loadInputs(), SimulatorFrontend::loadProgram(), loadTPEF(), main(), and readBinary().