OpenASIP  2.0
BinaryStream.cc
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 BinaryStream.cc
26  *
27  * Implementation of BinaryStream class.
28  *
29  * @author Ari Metsähalme 2003 (ari.metsahalme-no.spam-tut.fi)
30  * @author Mikael Lepistö 2005 (mikael.lepisto-no.spam-tut.fi)
31  * @note reviewed 7 August 2003 by pj, am, jn, ao, rl
32  *
33  * @note rating: yellow
34  */
35 
36 #include <string>
37 #include <fstream>
38 #include <cassert>
39 #include <boost/format.hpp>
40 
41 #include "BinaryStream.hh"
42 #include "Swapper.hh"
43 #include "BaseType.hh"
44 
45 using std::fstream;
46 using std::ios;
47 
48 namespace TPEF {
49 
50 BinaryStream::BinaryStream(std::ostream& stream, bool littleEndian):
51  fileName_(""), extOStream_(&stream), littleEndianStorage_(littleEndian),
52  tpefVersion_(TPEFHeaders::TPEF_V2) {
53 }
54 
55 /**
56  * Prepares the binary stream so that it can be read from / written to.
57  *
58  * The input string is used as the name of the file to open (if
59  * existing) or to create (if not existing).
60  *
61  * @param name is the name of the input file.
62  * @note The initial read and write positions of the stream are 0.
63  */
64 BinaryStream::BinaryStream(std::string name, bool littleEndian):
65  fileName_(name), extOStream_(NULL), littleEndianStorage_(littleEndian),
66  tpefVersion_(TPEFHeaders::TPEF_V1) {
67 }
68 
69 /**
70  * Returns true in case words should be swapped due to mismatch between
71  * the host and current target (TTA) endianness.
72  */
73 bool
75  return (littleEndianStorage_ && (HOST_BIGENDIAN == 1)) ||
77 }
78 
79 
80 /**
81  * Sets TPEF version to be used.
82  *
83  * @param version TPEF format version.
84  */
85 void
87  tpefVersion_ = version;
88 }
89 
90 /**
91  * Returns TPEF version being used.
92  *
93  */
96  return tpefVersion_;
97 }
98 
99 /**
100  * Closes the stream.
101  *
102  * No other cleanup or deallocation activity is required.
103  *
104  * @note Only way of closing and flushing the actual output stream can be done
105  * be calling the destructor (through deletion of the object).
106  */
108  close();
109 }
110 
111 
112 /**
113  * Reads one Byte from the binary stream.
114  *
115  * @return The next 8-bit byte from the stream.
116  * @exception UnreachableStream If reading from the stream fails.
117  * @exception EndOfFile If end of file were reached.
118  */
119 Byte
121  Byte value;
122 
123  try {
124  value = getByte();
125 
126  } catch (const EndOfFile& error) {
127  EndOfFile newException =
128  EndOfFile(__FILE__, __LINE__, __func__, fileName_);
129  newException.setCause(error);
130  throw newException;
131 
132  } catch (const UnreachableStream& error) {
133  UnreachableStream newException =
134  UnreachableStream(__FILE__, __LINE__, __func__, fileName_);
135  newException.setCause(error);
136  throw newException;
137  }
138 
139  return value;
140 }
141 
142 /**
143  * Reads one HalfWord from the binary stream.
144  *
145  * @return The next 16-bit word (half-word) from the stream.
146  * @exception UnreachableStream If reading from the stream fails.
147  * @exception EndOfFile If end of file were reached.
148  */
149 HalfWord
151  union {
152  Byte buffer[sizeof(HalfWord)];
153  HalfWord result;
154  } U;
155 
156  try {
157  readByteBlock(U.buffer, sizeof(HalfWord));
158 
159  } catch (const EndOfFile& error) {
160  EndOfFile newException =
161  EndOfFile(__FILE__, __LINE__, __func__, fileName_);
162  newException.setCause(error);
163  throw newException;
164 
165  } catch (const UnreachableStream& error) {
166  UnreachableStream newException =
167  UnreachableStream(__FILE__, __LINE__, __func__, fileName_);
168  newException.setCause(error);
169  throw newException;
170  }
171 
172  // convert half-word to host endianess
173  if (needsSwap())
174  Swapper::swap(U.buffer, (Byte*)&U.result, sizeof(U.result));
175 
176  return U.result;
177 }
178 
179 /**
180  * Reads one Word from the binary stream.
181  *
182  * @return The next 32-bit word from the stream.
183  * @exception UnreachableStream If reading from the stream fails.
184  * @exception EndOfFile If end of file were reached.
185  */
186 Word
188  union {
189  Byte buffer[sizeof(Word)];
190  Word result;
191  } U;
192 
193  try {
194  readByteBlock(U.buffer, sizeof(Word));
195 
196  } catch (const EndOfFile& error) {
197  EndOfFile newException =
198  EndOfFile(__FILE__, __LINE__, __func__, fileName_);
199  newException.setCause(error);
200  throw newException;
201 
202  } catch (const UnreachableStream& error) {
203  UnreachableStream newException =
204  UnreachableStream(__FILE__, __LINE__, __func__, fileName_);
205  newException.setCause(error);
206  throw newException;
207  }
208 
209  // convert word to host endianess
210  if (needsSwap())
211  Swapper::swap(U.buffer, (Byte*)&U.result, sizeof(U.result));
212 
213  return U.result;
214 }
215 
216 /**
217  * Reads a block of Bytes from the binary stream.
218  *
219  * @param buffer is where the bytes are returned.
220  * @param howmany is how many bytes are supposed to be read.
221  * @exception UnreachableStream If reading from the stream fails.
222  * @exception EndOfFile If end of file were reached.
223  */
224 void
225 BinaryStream::readByteBlock(Byte* buffer, unsigned int howmany) {
226  try {
227  for (unsigned int i = 0; i < howmany; i++) {
228  buffer[i] = getByte();
229  }
230 
231  } catch (const EndOfFile& error) {
232  EndOfFile newException =
233  EndOfFile(__FILE__, __LINE__, __func__, fileName_);
234  newException.setCause(error);
235  throw newException;
236 
237  } catch (const UnreachableStream& error) {
238  UnreachableStream newException =
239  UnreachableStream(__FILE__, __LINE__, __func__, fileName_);
240  newException.setCause(error);
241  throw newException;
242  }
243 }
244 
245 /**
246  * Reads a block of HalfWords from the binary stream.
247  *
248  * @param buffer is where the halfwords are returned.
249  * @param howmany is how many halfwords are supposed to be read.
250  * @exception UnreachableStream If reading from the stream fails.
251  * @exception EndOfFile If end of file were reached.
252  */
253 void
254 BinaryStream::readHalfWordBlock(HalfWord* buffer, unsigned int howmany) {
255  try {
256  for (unsigned int i = 0; i < howmany; i++) {
257  buffer[i] = readHalfWord();
258  }
259 
260  } catch (const EndOfFile& error) {
261  EndOfFile newException =
262  EndOfFile(__FILE__, __LINE__, __func__, fileName_);
263  newException.setCause(error);
264  throw newException;
265 
266  } catch (const UnreachableStream& error) {
267  UnreachableStream newException =
268  UnreachableStream(__FILE__, __LINE__, __func__, fileName_);
269  newException.setCause(error);
270  throw newException;
271  }
272 }
273 
274 /**
275  * Reads a block of Words from the binary stream.
276  *
277  * @param buffer is where the words are returned.
278  * @param howmany is how many words are supposed to be read.
279  * @exception UnreachableStream If reading from the stream fails.
280  * @exception EndOfFile If end of file were reached.
281  */
282 void
283 BinaryStream::readWordBlock(Word* buffer, unsigned int howmany) {
284  try {
285  for (unsigned int i = 0; i < howmany; i++) {
286  buffer[i] = readWord();
287  }
288  } catch (const EndOfFile& error) {
289  EndOfFile newException =
290  EndOfFile(__FILE__, __LINE__, __func__, fileName_);
291  newException.setCause(error);
292  throw newException;
293 
294  } catch (const UnreachableStream& error) {
295  UnreachableStream newException =
296  UnreachableStream(__FILE__, __LINE__, __func__, fileName_);
297  newException.setCause(error);
298  throw newException;
299  }
300 }
301 
302 /**
303  * Writes one Byte to the binary stream.
304  *
305  * @param byte The Byte to write to the stream.
306  * @exception UnreachableStream If writing to stream fails.
307  * @exception WritePastEOF If tried to write past end of file.
308  */
309 void
311  try {
312  putByte(byte);
313 
314  } catch (const WritePastEOF& error) {
315  WritePastEOF newException =
316  WritePastEOF(__FILE__, __LINE__, __func__, fileName_);
317  newException.setCause(error);
318  throw newException;
319 
320  } catch (const UnreachableStream& error) {
321  UnreachableStream newException =
322  UnreachableStream(__FILE__, __LINE__, __func__, fileName_);
323  newException.setCause(error);
324  throw newException;
325  }
326 }
327 
328 /**
329  * Writes one HalfWord to the binary stream.
330  *
331  * @param halfword The HalfWord to write to the stream.
332  * @exception UnreachableStream If writing to stream fails.
333  * @exception WritePastEOF If tried to write past end of file.
334  */
335 void
336 BinaryStream::writeHalfWord(HalfWord halfword) {
337  Byte buffer[sizeof(HalfWord)];
338 
339  // convert HalfWord to the target byte order.
340  if (needsSwap())
341  Swapper::swap((Byte*)&halfword, buffer, sizeof(HalfWord));
342 
343  try {
344  writeByteBlock(buffer, sizeof(HalfWord));
345 
346  } catch (const WritePastEOF& error) {
347  WritePastEOF newException =
348  WritePastEOF(__FILE__, __LINE__, __func__, fileName_);
349  newException.setCause(error);
350  throw newException;
351 
352  } catch (const UnreachableStream& error) {
353  UnreachableStream newException =
354  UnreachableStream(__FILE__, __LINE__, __func__, fileName_);
355  newException.setCause(error);
356  throw newException;
357  }
358 }
359 
360 /**
361  * Writes one Word to the binary stream.
362  *
363  * @param word The Word to write to the stream.
364  * @exception UnreachableStream If writing to stream fails.
365  * @exception WritePastEOF If tried to write past end of file.
366  */
367 void
369  Byte buffer[sizeof(Word)];
370 
371  // convert Word to the target byte order.
372  if (needsSwap())
373  Swapper::swap((Byte*)&word, buffer, sizeof(Word));
374 
375  try {
376  writeByteBlock(buffer, sizeof(Word));
377 
378  } catch (const WritePastEOF& error) {
379  WritePastEOF newException =
380  WritePastEOF(__FILE__, __LINE__, __func__, fileName_);
381  newException.setCause(error);
382  throw newException;
383 
384  } catch (const UnreachableStream& error) {
385  UnreachableStream newException =
386  UnreachableStream(__FILE__, __LINE__, __func__, fileName_);
387  newException.setCause(error);
388  throw newException;
389  }
390 }
391 
392 /**
393  * Writes a block of Bytes to the binary stream.
394  *
395  * @param bytes The block of Bytes to be written.
396  * @param howmany How many Bytes to write.
397  * @exception UnreachableStream If writing to stream fails.
398  * @exception WritePastEOF If tried to write past end of file.
399  */
400 void
401 BinaryStream::writeByteBlock(Byte* bytes, unsigned int howmany) {
402  try {
403  for (unsigned int i = 0; i < howmany; i++) {
404  putByte(bytes[i]);
405  }
406  } catch (const WritePastEOF& error) {
407  WritePastEOF newException =
408  WritePastEOF(__FILE__, __LINE__, __func__, fileName_);
409  newException.setCause(error);
410  throw newException;
411 
412  } catch (const UnreachableStream& error) {
413  UnreachableStream newException =
414  UnreachableStream(__FILE__, __LINE__, __func__, fileName_);
415  newException.setCause(error);
416  throw newException;
417  }
418 }
419 
420 /**
421  * Writes a block of HalfWords to the binary stream.
422  *
423  * @param halfwords The block of HalfWords to be written.
424  * @param howmany How many HalfWords to write.
425  * @exception UnreachableStream If writing to stream fails.
426  * @exception WritePastEOF If tried to write past end of file.
427  */
428 void
429 BinaryStream::writeHalfWordBlock(HalfWord* halfwords, unsigned int howmany) {
430  try {
431  for (unsigned int i = 0; i < howmany; i++) {
432  writeHalfWord(halfwords[i]);
433  }
434  } catch (const WritePastEOF& error) {
435  WritePastEOF newException =
436  WritePastEOF(__FILE__, __LINE__, __func__, fileName_);
437  newException.setCause(error);
438  throw newException;
439 
440  } catch (const UnreachableStream& error) {
441  UnreachableStream newException =
442  UnreachableStream(__FILE__, __LINE__, __func__, fileName_);
443  newException.setCause(error);
444  throw newException;
445  }
446 }
447 
448 /**
449  * Writes a block of Words to the binary stream.
450  *
451  * @param words The block of Words to be written.
452  * @param howmany How many Words to write.
453  * @exception UnreachableStream If writing to stream fails.
454  * @exception WritePastEOF If tried to write past end of file.
455  */
456 void
457 BinaryStream::writeWordBlock(Word* words, unsigned int howmany) {
458  try {
459  for (unsigned int i = 0; i < howmany; i++) {
460  writeWord(words[i]);
461  }
462  } catch (const WritePastEOF& error) {
463  WritePastEOF newException =
464  WritePastEOF(__FILE__, __LINE__, __func__, fileName_);
465  newException.setCause(error);
466  throw newException;
467 
468  } catch (const UnreachableStream& error) {
469  UnreachableStream newException =
470  UnreachableStream(__FILE__, __LINE__, __func__, fileName_);
471  newException.setCause(error);
472  throw newException;
473  }
474 }
475 
476 /**
477  * Opens the binary file for input.
478  *
479  * @param name Name of the input file.
480  * @exception UnreachableStream If file is not found or is unreadable.
481  * @note The initial read position is 0.
482  */
483 void
484 BinaryStream::openInput(std::string name) {
485  if (extOStream_ != NULL) {
486  throw UnreachableStream(
487  __FILE__, __LINE__, __func__, "External stream is write-only.");
488  }
489 
490  iStream_.open(name.c_str());
491 
492  if (!iStream_.is_open()) {
493  const std::string error = (boost::format(
494  "File '%s' could not be opened for input.") % name).str();
495  throw UnreachableStream(
496  __FILE__, __LINE__, __func__, error);
497  }
498  if (oStream_.is_open()) {
499  oStream_.flush();
500  }
501  iStream_.tie(&oStream_);
502 }
503 
504 /**
505  * Opens the binary file for output.
506  *
507  * If a file doesn't exist, a new empty file will be created.
508  *
509  * @param name Name of the output file.
510  * @exception UnreachableStream If file cannot be opened.
511  * @note The initial write position is 0.
512  */
513 void
514 BinaryStream::openOutput(std::string name) {
515  if (extOStream_ != NULL) {
516  throw UnreachableStream(
517  __FILE__, __LINE__, __func__,
518  "External stream should be always open.");
519  }
520 
521  oStream_.open(name.c_str(), fstream::out);
522 
523  // With some versions of STL a non-existing file is not
524  // automatically created when using only 'out'-flag. In that case,
525  // we have to open the stream in truncate mode to force the creating
526  // of the empty file.
527  if (!oStream_.is_open()) {
528  oStream_.clear();
529  oStream_.open(name.c_str(), fstream::out | fstream::trunc);
530  }
531 
532  if (!oStream_.is_open()) {
533  const std::string error = (boost::format(
534  "File '%s' could not be opened for output.") % fileName_).str();
535  throw UnreachableStream(
536  __FILE__, __LINE__, __func__, error);
537  }
538 }
539 
540 /**
541  * Closes the stream.
542  */
543 void
545  if (iStream_.is_open()) {
546  iStream_.close();
547  }
548  if (oStream_.is_open()) {
549  oStream_.close();
550  }
551 }
552 
553 
554 /**
555  * Returns the current position of the read cursor.
556  *
557  * @exception UnreachableStream If stream is bad or otherwise
558  * unreachable.
559  */
560 unsigned int
562  if (extOStream_ != NULL) {
563  throw UnreachableStream(
564  __FILE__, __LINE__, __func__, "External stream is write-only.");
565  }
566 
567  if (!iStream_.is_open()) {
568  try {
570  } catch (const UnreachableStream& error) {
571  UnreachableStream newException =
572  UnreachableStream(__FILE__, __LINE__, __func__, fileName_);
573  newException.setCause(error);
574  throw newException;
575  }
576  }
577 
578  if (iStream_.bad()) {
579  throw UnreachableStream(__FILE__, __LINE__,
580  "BinaryStream::readPosition", fileName_);
581  }
582  return iStream_.tellg();
583 }
584 
585 /**
586  * Returns the current position of the write cursor.
587  *
588  * @exception UnreachableStream If stream is bad or otherwise
589  * unreachable.
590  */
591 unsigned int
593  if (extOStream_ != NULL) {
594  return extOStream_->tellp();
595  }
596 
597  if (!oStream_.is_open()) {
598  try {
600 
601  } catch (const UnreachableStream& error) {
602  UnreachableStream newException =
603  UnreachableStream(__FILE__, __LINE__, __func__, fileName_);
604  newException.setCause(error);
605  throw newException;
606  }
607  }
608 
609  if (oStream_.bad()) {
610  throw UnreachableStream(
611  __FILE__, __LINE__, __func__, fileName_);
612  }
613  return oStream_.tellp();
614 }
615 
616 /**
617  * Sets the read cursor position in the stream.
618  *
619  * If the stream has reached end-of-file, and read position is then
620  * set before eof, eof-status is automatically cleared and reading is
621  * again possible. Setting position beyond eof doesn't immediately set
622  * eof-status, instead, it is only set after trying to read past eof.
623  *
624  * @param position New read cursor position.
625  * @exception UnreachableStream If stream is bad or otherwise
626  * unreachable.
627  */
628 void
629 BinaryStream::setReadPosition(unsigned int position) {
630  if (extOStream_ != NULL) {
631  throw UnreachableStream(
632  __FILE__, __LINE__, __func__, "External stream is write-only.");
633  }
634 
635  if (!iStream_.is_open()) {
636  try {
638 
639  } catch (const UnreachableStream& error) {
640  UnreachableStream newException =
641  UnreachableStream(__FILE__, __LINE__, __func__, fileName_);
642  newException.setCause(error);
643  throw newException;
644  }
645  }
646  if (iStream_.bad()) {
647  throw UnreachableStream(
648  __FILE__, __LINE__, __func__, fileName_);
649  }
650 
651  // if eof is already reached, the stream must be cleared to make it
652  // accessible again
653  bool eof = false;
654  if (iStream_.eof()) {
655  eof = true;
656  iStream_.clear();
657  }
658 
659  // possible eof-status is cleared if the position is set before eof
660  iStream_.seekg(0, ios::end);
661  unsigned int fileSize = iStream_.tellg();
662  if (position <= fileSize) {
663  iStream_.clear();
664  eof = false;
665  }
666 
667  iStream_.seekg(position);
668 
669  // return the eof status if it has been cleared earlier to access the
670  // stream and read position is not set before eof
671  if (eof) {
672  iStream_.setstate(ios::eofbit);
673  }
674 }
675 
676 /**
677  * Sets the write cursor position in the stream.
678  *
679  * If write position is located past the end of the file and writing
680  * to the stream is attempted, WritePastEOF exception will be
681  * thrown.
682  *
683  * @see putByte
684  * @param position New write cursor position.
685  * @exception UnreachableStream If stream is bad or otherwise
686  * unreachable.
687  */
688 void
689 BinaryStream::setWritePosition(unsigned int position) {
690  if (extOStream_ != NULL) {
691  extOStream_->seekp(position);
692  return;
693  }
694 
695  if (!oStream_.is_open()) {
696  try {
698 
699  } catch (const UnreachableStream& error) {
700  UnreachableStream newException =
701  UnreachableStream(__FILE__, __LINE__, __func__, fileName_);
702  newException.setCause(error);
703  throw newException;
704  }
705  }
706 
707  if (oStream_.bad()) {
708  throw UnreachableStream(
709  __FILE__, __LINE__, __func__, fileName_);
710  }
711 
712  oStream_.seekp(position);
713 }
714 
715 /**
716  * Returns true if read position is at the end of file.
717  *
718  * @exception UnreachableStream If stream is bad or otherwise
719  * unreachable.
720  */
721 bool
723  if (extOStream_ != NULL) {
724  throw UnreachableStream(
725  __FILE__, __LINE__, __func__, "External stream is write-only.");
726  }
727 
728  if (!iStream_.is_open()) {
729  try {
731 
732  } catch (const UnreachableStream& error) {
733  UnreachableStream newException =
734  UnreachableStream(__FILE__, __LINE__, __func__, fileName_);
735  newException.setCause(error);
736  throw newException;
737  }
738  }
739 
740  if (iStream_.bad()) {
741  throw UnreachableStream(
742  __FILE__, __LINE__, __func__, fileName_);
743  }
744 
745  return iStream_.eof();
746 }
747 
748 /**
749  * Checks the size of the file being handled.
750  *
751  * First tries to check the size from output stream, if it's not opened,
752  * tries to check from input stream.
753  *
754  * @exception UnreachableStream If stream is bad or file does not exist.
755  *
756  * @note UnreachableStream is also generated if file is existing with
757  * only write rights and it is not yet opened for writing. This is
758  * because of restricted file handling abilities of C++ standard
759  * library.
760  *
761  * @return The size of the file.
762  */
763 unsigned int
765  if (extOStream_ != NULL) {
766  unsigned int currentPos = extOStream_->tellp();
767  extOStream_->seekp(0, ios::end);
768  unsigned int fileSize = extOStream_->tellp();
769  extOStream_->seekp(currentPos, ios::end);
770  return fileSize;
771  }
772 
773  if (oStream_.is_open()) {
774  unsigned int currentPos = writePosition();
775  oStream_.seekp(0, ios::end);
776  unsigned int fileSize = oStream_.tellp();
777  setWritePosition(currentPos);
778  return fileSize;
779 
780  } else if (!iStream_.is_open()) {
781  try {
783 
784  } catch (const UnreachableStream& error) {
785  UnreachableStream newException =
786  UnreachableStream(__FILE__, __LINE__, __func__, fileName_);
787  newException.setCause(error);
788  throw newException;
789  }
790  }
791 
792  if (iStream_.bad()) {
793  throw UnreachableStream(
794  __FILE__, __LINE__, __func__, fileName_);
795  }
796 
797  unsigned int currentPos = readPosition();
798  iStream_.seekg(0, ios::end);
799  unsigned int fileSize = iStream_.tellg();
800  setReadPosition(currentPos);
801  return fileSize;
802 }
803 }
TPEF::BinaryStream::writeHalfWord
void writeHalfWord(HalfWord halfword)
Definition: BinaryStream.cc:336
TPEF::TPEFHeaders::TPEF_V2
@ TPEF_V2
Support for over 255 Buses, FUs, RFs.
Definition: TPEFHeaders.hh:58
BaseType.hh
TPEF::BinaryStream::readPosition
unsigned int readPosition()
Definition: BinaryStream.cc:561
UnreachableStream
Definition: Exception.hh:171
TPEF::BinaryStream::setReadPosition
void setReadPosition(unsigned int position)
Definition: BinaryStream.cc:629
TPEF::BinaryStream::writeWord
void writeWord(Word word)
Definition: BinaryStream.cc:368
TPEF::BinaryStream::fileName_
std::string fileName_
The name of the stream.
Definition: BinaryStream.hh:97
TPEF::BinaryStream::writeHalfWordBlock
void writeHalfWordBlock(HalfWord *hwords, unsigned int howmany)
Definition: BinaryStream.cc:429
TPEF::BinaryStream::writePosition
unsigned int writePosition()
Definition: BinaryStream.cc:592
Exception::setCause
void setCause(const Exception &cause)
Definition: Exception.cc:75
TPEF::BinaryStream::readWordBlock
void readWordBlock(Word *buffer, unsigned int howmany)
Definition: BinaryStream.cc:283
Byte
unsigned char Byte
Definition: BaseType.hh:116
TPEF::BinaryStream::putByte
void putByte(Byte byte)
TPEF::BinaryStream::setTPEFVersion
void setTPEFVersion(TPEFHeaders::TPEFVersion version)
Definition: BinaryStream.cc:86
TPEF::BinaryStream::writeByteBlock
void writeByteBlock(Byte *bytes, unsigned int howmany)
Definition: BinaryStream.cc:401
TPEF::BinaryStream::extOStream_
std::ostream * extOStream_
Externally given output stream.
Definition: BinaryStream.hh:100
TPEF::BinaryStream::~BinaryStream
virtual ~BinaryStream()
Definition: BinaryStream.cc:107
TPEF::BinaryStream::littleEndianStorage_
bool littleEndianStorage_
In case we want to store the words in little endian order, big endian otherwise.
Definition: BinaryStream.hh:104
TPEF::BinaryStream::readHalfWordBlock
void readHalfWordBlock(HalfWord *buffer, unsigned int howmany)
Definition: BinaryStream.cc:254
TPEF::TPEFHeaders::TPEFVersion
TPEFVersion
Definition: TPEFHeaders.hh:56
TPEF::BinaryStream::close
void close()
Definition: BinaryStream.cc:544
TPEF::BinaryStream::setWritePosition
void setWritePosition(unsigned int position)
Definition: BinaryStream.cc:689
TPEF::BinaryStream::iStream_
std::ifstream iStream_
The input stream.
Definition: BinaryStream.hh:93
TPEF::BinaryStream::writeWordBlock
void writeWordBlock(Word *words, unsigned int howmany)
Definition: BinaryStream.cc:457
WritePastEOF
Definition: Exception.hh:207
TPEF::BinaryStream::oStream_
std::ofstream oStream_
The output stream.
Definition: BinaryStream.hh:95
__func__
#define __func__
Definition: Application.hh:67
TPEF::BinaryStream::getByte
Byte getByte()
TPEF::TPEFHeaders::TPEF_V1
@ TPEF_V1
Initial TPEF version.
Definition: TPEFHeaders.hh:57
TPEF::Swapper::swap
static void swap(const Byte *src, Byte *dst, int size)
TPEF::BinaryStream::readHalfWord
HalfWord readHalfWord()
Definition: BinaryStream.cc:150
TPEF::BinaryStream::writeByte
void writeByte(Byte byte)
Definition: BinaryStream.cc:310
TPEF::BinaryStream::readByte
Byte readByte()
Definition: BinaryStream.cc:120
TPEF::BinaryStream::endOfFile
bool endOfFile()
Definition: BinaryStream.cc:722
Swapper.hh
TPEF::BinaryStream::needsSwap
bool needsSwap() const
Definition: BinaryStream.cc:74
TPEF::BinaryStream::BinaryStream
BinaryStream(std::ostream &stream, bool littleEndian=false)
Definition: BinaryStream.cc:50
TPEF::BinaryStream::openInput
void openInput(std::string name)
Definition: BinaryStream.cc:484
BinaryStream.hh
TPEF::BinaryStream::TPEFVersion
TPEFHeaders::TPEFVersion TPEFVersion() const
Definition: BinaryStream.cc:95
EndOfFile
Definition: Exception.hh:189
TPEF::BinaryStream::sizeOfFile
unsigned int sizeOfFile()
Definition: BinaryStream.cc:764
TPEF::BinaryStream::readByteBlock
void readByteBlock(Byte *buffer, unsigned int howmany)
Definition: BinaryStream.cc:225
TPEF::BinaryStream::tpefVersion_
TPEFHeaders::TPEFVersion tpefVersion_
Indicates TPEF format version used.
Definition: BinaryStream.hh:107
TPEF::BinaryStream::readWord
Word readWord()
Definition: BinaryStream.cc:187
HOST_BIGENDIAN
#define HOST_BIGENDIAN
Definition: BaseType.hh:123
TPEF::BinaryStream::openOutput
void openOutput(std::string name)
Definition: BinaryStream.cc:514
TPEF
Definition: Assembler.hh:43