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