OpenASIP 2.2
Loading...
Searching...
No Matches
BinaryStream.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 BinaryStream.hh
26 *
27 * Declaration of BinaryStream class.
28 *
29 * @author Ari Metsähalme 2003 (ari.metsahalme-no.spam-tut.fi)
30 * @note reviewed 7 August 2003 by pj, am, jn, ao, rl
31 *
32 * @note rating: yellow
33 */
34
35#ifndef TTA_BINARYSTREAM_HH
36#define TTA_BINARYSTREAM_HH
37
38#include <fstream>
39#include <string>
40#include "TPEFBaseType.hh"
41#include "Exception.hh"
42#include "TPEFHeaders.hh"
43
44namespace TPEF {
45
46/**
47 * Abstracts the input/output binary stream used to read and write TTA
48 * programs.
49 *
50 * It takes care of opening and closing the streams automatically, and
51 * hides possible byte order mismatch.
52 *
53 * The bits read from the stream are converted to the byte order of
54 * the host machine. Conversely, the bits written into the stream will
55 * be converted to the standard byte order of TTA Program Exchange
56 * Format files which adheres to the byte order of the ADF the TPEF
57 * is associated with (by default big endian).
58 */
60public:
61 BinaryStream(std::ostream &stream, bool littleEndian=false);
62 BinaryStream(std::string name, bool littleEndian=false);
63 virtual ~BinaryStream();
64
65 Byte readByte();
66 HalfWord readHalfWord();
67 Word readWord();
68
69 void readByteBlock(Byte* buffer, unsigned int howmany);
70 void readHalfWordBlock(HalfWord* buffer, unsigned int howmany);
71 void readWordBlock(Word* buffer, unsigned int howmany);
72
73 void writeByte(Byte byte);
74 void writeHalfWord(HalfWord halfword);
75 void writeWord(Word word);
76
77 void writeByteBlock(Byte* bytes, unsigned int howmany);
78 void writeHalfWordBlock(HalfWord* hwords, unsigned int howmany);
79 void writeWordBlock(Word* words, unsigned int howmany);
80
81 unsigned int readPosition();
82 unsigned int writePosition();
83 void setReadPosition(unsigned int position);
84 void setWritePosition(unsigned int position);
85 bool endOfFile();
86 unsigned int sizeOfFile();
87
90
91private:
92 /// The input stream.
93 std::ifstream iStream_;
94 /// The output stream.
95 std::ofstream oStream_;
96 /// The name of the stream.
97 std::string fileName_;
98
99 /// Externally given output stream.
100 std::ostream* extOStream_;
101
102 /// In case we want to store the words in little endian order,
103 /// big endian otherwise.
105
106 /// Indicates TPEF format version used.
108
109 /// Assignment not allowed.
111 /// Copying not allowed.
113
114 void openInput(std::string name);
115 void openOutput(std::string name);
116 void close();
118 void putByte(Byte byte);
119
120 bool needsSwap() const;
121};
122}
123
124#include "BinaryStream.icc"
125
126#endif
unsigned char Byte
Definition BaseType.hh:116
void writeByte(Byte byte)
void openInput(std::string name)
void setReadPosition(unsigned int position)
void writeHalfWordBlock(HalfWord *hwords, unsigned int howmany)
void readWordBlock(Word *buffer, unsigned int howmany)
std::string fileName_
The name of the stream.
void writeHalfWord(HalfWord halfword)
std::ifstream iStream_
The input stream.
BinaryStream & operator=(BinaryStream &old)
Assignment not allowed.
void openOutput(std::string name)
unsigned int readPosition()
BinaryStream(BinaryStream &old)
Copying not allowed.
void writeWordBlock(Word *words, unsigned int howmany)
unsigned int sizeOfFile()
unsigned int writePosition()
std::ofstream oStream_
The output stream.
std::ostream * extOStream_
Externally given output stream.
TPEFHeaders::TPEFVersion TPEFVersion() const
bool needsSwap() const
void setTPEFVersion(TPEFHeaders::TPEFVersion version)
void putByte(Byte byte)
void setWritePosition(unsigned int position)
void writeWord(Word word)
void readByteBlock(Byte *buffer, unsigned int howmany)
TPEFHeaders::TPEFVersion tpefVersion_
Indicates TPEF format version used.
HalfWord readHalfWord()
void readHalfWordBlock(HalfWord *buffer, unsigned int howmany)
void writeByteBlock(Byte *bytes, unsigned int howmany)
bool littleEndianStorage_
In case we want to store the words in little endian order, big endian otherwise.