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