ldc2: Cosmetic fixes and support for compiler orverride
[h316.git] / pc-tools / ldc2 / src / tape_block.hh
CommitLineData
4741aa72 1/******************************************************************************
2 *
3 * LDC2 source code
4 *
8dc281af 5 * $Date: 2007/12/23 15:25:11 $
4741aa72 6 * $Author: hachti $
7 *
8 * $Log: tape_block.hh,v $
8dc281af 9 * Revision 2.1 2007/12/23 15:25:11 hachti
10 * *** empty log message ***
11 *
12 * Revision 2.0 2007-03-26 01:00:40 hachti
4741aa72 13 * *** empty log message ***
14 *
15 *
16 ******************************************************************************/
17
7880ae2d 18#ifndef TAPE_BLOCK_HH
19#define TAPE_BLOCK_HH
6c06db96 20
21using namespace std;
22
97b26985 23/*!
0ec6e042 24 *\brief Tape data block base class.
97b26985 25 *
26 * This class represents a Honeywell paper tape block.
27 * That may be some kind of data block or a end of tape mark.
28 */
29class tape_block{
7880ae2d 30
97b26985 31public: // types
7880ae2d 32
97b26985 33 /*!
0ec6e042 34 * Tape block types.
97b26985 35 */
36 typedef enum {
37 TBT_DATA=0x10, //!< Data block
38 TBT_EOT, //!< End of tape block
7880ae2d 39 TBT_BROKEN, //!< A broken block
97b26985 40 } tb_type_t;
7880ae2d 41
42 /*!
43 *\brief Local base class for exceptions.
44 */
45 class exception {
46 protected:
47 exception();
48 public:
49 virtual ~exception();
50 tape_block * get_block();
51 protected:
52 tape_block * m_broken_block;
53 };
54
55 /*!
56 *\brief Checksum error exception.
57 */
58 class checksum_error_exception
59 : public exception {
60 public:
61 checksum_error_exception(tape_block * block);
62 };
63
64 /*!
65 *\brief EOF while reading block exception.
66 */
67 class eof_illegal_exception
68 : public exception {
69 public:
70 eof_illegal_exception(tape_block * block);
71 };
72
73 /*!
74 *\brief EOF after reading block exception.
75 */
76 class eof_legal_exception
77 : public exception {
78 public:
79 eof_legal_exception(int bytes_consumed);
80 int get_consumed();
81 private:
82 int bytes_consumed;
83 tape_block * get_block();
84 };
85
86 /*!
87 *\brief IO error exception.
88 */
89 class io_error_exception
90 : exception {
91 public:
92 io_error_exception();
93 private:
94 tape_block * get_block();
95 };
96
97b26985 97public: // methods
97b26985 98 virtual ~tape_block();
6c06db96 99
100 tape_block(tape_block &);
101 void operator=(tape_block &);
7880ae2d 102
97b26985 103 virtual int get_type();
97b26985 104 virtual int get_subtype();
6c06db96 105 virtual vector<string> get_description();
106 int get_raw_size();
fed2c751 107 int get_discarded_bytes();
6c06db96 108 unsigned char * get_raw_data();
874a2bd8 109 virtual int dump_to_fd(int fd);
110 virtual bool is_endblock();
111 virtual vector<string> get_exported_symbols();
112 virtual vector<string> get_called_symbols();
8dc281af 113 virtual vector<string> dump_contents();
874a2bd8 114 virtual bool has_known_type();
115
6c06db96 116 static tape_block * gen_from_fd(int fd,
117 void(*input_start)(void *)=0,
118 void (*input_stop)(void *)=0,
119 void * start_stop_arg=0
120 );
7880ae2d 121
09cb0f4f 122protected: // methods
0ec6e042 123 tape_block();
09cb0f4f 124 string get_typestring();
7880ae2d 125
09cb0f4f 126private: // methods
0ec6e042 127 tape_block (int fd_p,
128 void(*input_start)(void *)=0,
129 void (*input_stop)(void *)=0,
130 void * start_stop_arg=0
131 );
6c06db96 132
97b26985 133 int init_words(void);
97b26985 134 int test_checksum();
7880ae2d 135
97b26985 136protected: // members
0ec6e042 137 int block_type; //!< Type of this block.
874a2bd8 138 bool m_has_known_type; //!< Block is of a documented type.
fed2c751 139 int discarded_bytes; //!< Amount of bytes discarded before beginning.
0ec6e042 140 unsigned char * raw_data; //!< Raw block data in bytes.
141 int raw_size; //!< Size of the raw data.
142 unsigned short * word_data; //!< Data organized in machine words.
143 int word_size; //!< Size of the blocks in machine words.
fed2c751 144 int poolsize; //!< Amount of data malloc'ed
6c06db96 145}; // class tape_block
97b26985 146
97b26985 147#endif