srecord: output.h Source File

srecord 1.65.0

Loading...
Searching...
No Matches
output.h
Go to the documentation of this file.
1//
2// srecord - manipulate eprom load files
3// Copyright (C) 1998, 1999, 2001-2003, 2006-2011 Peter Miller
4//
5// This program is free software; you can redistribute it and/or modify it
6// under the terms of the GNU Lesser General Public License as published by
7// the Free Software Foundation; either version 3 of the License, or (at your
8// option) any later version.
9//
10// This program is distributed in the hope that it will be useful, but WITHOUT
11// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13// for more details.
14//
15// You should have received a copy of the GNU Lesser General Public License
16// along with this program. If not, see <http://www.gnu.org/licenses/>.
17//
18
19#ifndef SRECORD_OUTPUT_H
20#define SRECORD_OUTPUT_H
21
22#include <cstdarg>
23#include <string>
24#include <memory>
25
26#include <srecord/format_printf.h>
27
28namespace srecord {
29
30class arglex_tool; // forward
31class record; // forward
32
33/**
34 * The srecord::output class is used to represent an abstract output vector.
35 * It could be a file, it could be a filter first, before it reaches
36 * a file.
37 */
38 class output
39{
40public:
41 typedef std::shared_ptr<output> pointer;
42
43 /**
44 * The destructor.
45 */
46 virtual ~output();
47
48 /**
49 * The write method is used to write a recordonto an output.
50 * Derived classes must implement this method.
51 *
52 * @param rec
53 * The record to be written.
54 */
55 virtual void write(const record &rec) = 0;
56
57 /**
58 * The write_header method is used to write a header record
59 * to the output. If no record is specified, a default
60 * record will be supplied. The write method will be called.
61 */
62 virtual void write_header(const record * = 0);
63
64 /**
65 * The write_data method is used to write data to the output.
66 * A suitable data record wil be produced. The #write method
67 * will be called.
68 */
69 virtual void write_data(unsigned long, const void *, size_t);
70
71 /**
72 * The write_execution_start_address method is used to write an
73 * execution start address record to the output. If no record is
74 * specified, a default record will be supplied. The #write method
75 * will be called.
76 */
77 virtual void write_execution_start_address(const record * = 0);
78
79 /**
80 * The set_line_length method is used to set the maximum
81 * length of an output line, for those formats for which
82 * this is a meaningful concept, and the line length is at
83 * all controllable. Derived classes must implement this method.
84 *
85 * @param cols
86 * The page width in fixed width text columns.
87 */
88 virtual void line_length_set(int cols) = 0;
89
90 /**
91 * The address_length_set method is used to set the minimum
92 * number of bytes to be written for addresses in the output,
93 * for those formats for which this is a meaningful concept, and
94 * the address length is at all controllable. Derived classes
95 * must implement this method.
96 *
97 * @param nbytes
98 * The number of byte to use for the address (2..4).
99 */
100 virtual void address_length_set(int nbytes) = 0;
101
102 /**
103 * The preferred_block_size_get method is used to get the
104 * proferred block size of the output fformat. Often, but not
105 * always, influenced by the line_lebgth_set method. Derived
106 * classes must implement this method.
107 */
108 virtual int preferred_block_size_get(void) const = 0;
109
110 /**
111 * The preferred_block_size_set method is is to set a precific
112 * number of bytes for the preferred block size.
113 *
114 * @param nbytes
115 * The exact number of bytes to be returned by the
116 * #preferred_block_size_get method.
117 * @returns
118 * There are format-specific limitations on block sizes, this
119 * method will return true if the setting was acceptable, false
120 * if the format is incapable of using the specified block
121 * size.
122 */
123 virtual bool preferred_block_size_set(int nbytes) = 0;
124
125 /**
126 * The fatal_error method is used to report fatal errors.
127 * The 'fmt' string is in the same style a standard C printf
128 * function. It calls the fatal_error_v method. This method
129 * does not return.
130 */
131 virtual void fatal_error(const char *fmt, ...) const
132 FORMAT_PRINTF(2, 3);
133 /**
134 * The fatal_error_v method is used to report fatal errors.
135 * The 'fmt' string is in the same style a standard C vprintf
136 * function. It calls global exit. This method does not return.
137 */
138 virtual void fatal_error_v(const char *fmt, va_list ap) const;
139
140 /**
141 * The fatal_error_errno method is used to report fatal errors,
142 * and append the string equivalent of errno. The 'fmt' string
143 * is in the same style a standard C printf function. It calls
144 * global exit(). This method does not return.
145 */
146 virtual void fatal_error_errno(const char *fmt, ...) const
147 FORMAT_PRINTF(2, 3);
148 /**
149 * The fatal_error_errno_v method is used to report fatal
150 * errors. The 'fmt' string is in the same style a standard C
151 * vprintf function. It calls the global exit function.
152 * This method does not return.
153 */
154 virtual void fatal_error_errno_v(const char *fmt, va_list ap) const;
155
156 /**
157 * The warning method is used to likely but non-fatal errors.
158 * The 'fmt' string is in the same style a standard C printf
159 * function. It calls the #warning_v method.
160 */
161 virtual void warning(const char *fmt, ...) const
162 FORMAT_PRINTF(2, 3);
163 /**
164 * The warning_v method is used to report likely but non-fatal
165 * errors. The 'fmt' string is in the same style a standard
166 * C vprintf function.
167 */
168 virtual void warning_v(const char *fmt, va_list ap) const;
169
170 /**
171 * The filename method is used to determine the name of the
172 * output file. It is used for the various error messages.
173 * Derived classes must implement this method.
174 */
175 virtual const std::string filename(void) const = 0;
176
177 /**
178 * The format_name method is used to obtain the name of this output
179 * format.
180 */
181 virtual const char *format_name(void) const = 0;
182
183 /**
184 * The notify_upper_bound method is used to notify the output class
185 * of the upper bound (highest address plus one) of the output
186 * to come. Shall be called before the head or any data records
187 * are written.
188 *
189 * @param addr
190 * One past the highest used memory byte.
191 */
192 virtual void notify_upper_bound(unsigned long addr);
193
194 /**
195 * The command_line method is used by arglex_srec::get_output when
196 * parsing the command line, to give the format an opportunity
197 * to grab extra arguments off the command line. The default
198 * implementation does nothing.
199 *
200 * @param cmdln
201 * Where to obtain information about the curreent parse stat of
202 * the command line.
203 */
204 virtual void command_line(arglex_tool *cmdln);
205
206protected:
207 /**
208 * The default constructor. Only derived classes may use.
209 */
210 output();
211
212private:
213 /**
214 * The copy constructor. Do not use.
215 */
216 output(const output &);
217
218 /**
219 * The assignment operator. Do not use.
220 */
221 output &operator=(const output &);
222};
223
224};
225
226#endif // SRECORD_OUTPUT_H
srecord::arglex_tool
The srecord::arglex_tool is used to parse command line with srec-specific arguments.
Definition tool.h:41
srecord::output::warning_v
virtual void virtual void warning_v(const char *fmt, va_list ap) const
The warning_v method is used to report likely but non-fatal errors.
srecord::output::write_data
virtual void write_data(unsigned long, const void *, size_t)
The write_data method is used to write data to the output.
srecord::output::format_name
virtual const char * format_name(void) const =0
The format_name method is used to obtain the name of this output format.
srecord::output::~output
virtual ~output()
The destructor.
srecord::output::write_header
virtual void write_header(const record *=0)
The write_header method is used to write a header record to the output.
srecord::output::fatal_error_errno
virtual void fatal_error_errno(const char *fmt,...) const FORMAT_PRINTF(2
The fatal_error_errno method is used to report fatal errors, and append the string equivalent of errn...
srecord::output::filename
virtual const std::string filename(void) const =0
The filename method is used to determine the name of the output file.
srecord::output::fatal_error_v
virtual void virtual void fatal_error_v(const char *fmt, va_list ap) const
The fatal_error_v method is used to report fatal errors.
srecord::output::command_line
virtual void command_line(arglex_tool *cmdln)
The command_line method is used by arglex_srec::get_output when parsing the command line,...
srecord::output::fatal_error
virtual void fatal_error(const char *fmt,...) const FORMAT_PRINTF(2
The fatal_error method is used to report fatal errors.
srecord::output::preferred_block_size_get
virtual int preferred_block_size_get(void) const =0
The preferred_block_size_get method is used to get the proferred block size of the output fformat.
srecord::output::warning
virtual void warning(const char *fmt,...) const FORMAT_PRINTF(2
The warning method is used to likely but non-fatal errors.
srecord::output::line_length_set
virtual void line_length_set(int cols)=0
The set_line_length method is used to set the maximum length of an output line, for those formats for...
srecord::output::output
output()
The default constructor.
srecord::output::pointer
std::shared_ptr< output > pointer
Definition output.h:41
srecord::output::write
virtual void write(const record &rec)=0
The write method is used to write a recordonto an output.
srecord::output::fatal_error_errno_v
virtual void virtual void fatal_error_errno_v(const char *fmt, va_list ap) const
The fatal_error_errno_v method is used to report fatal errors.
srecord::output::preferred_block_size_set
virtual bool preferred_block_size_set(int nbytes)=0
The preferred_block_size_set method is is to set a precific number of bytes for the preferred block s...
srecord::output::address_length_set
virtual void address_length_set(int nbytes)=0
The address_length_set method is used to set the minimum number of bytes to be written for addresses ...
srecord::output::notify_upper_bound
virtual void notify_upper_bound(unsigned long addr)
The notify_upper_bound method is used to notify the output class of the upper bound (highest address ...
srecord::output::write_execution_start_address
virtual void write_execution_start_address(const record *=0)
The write_execution_start_address method is used to write an execution start address record to the ou...
srecord::record
The srecord::record class is used to represent a data record read from a file.
Definition record.h:35
format_printf.h
FORMAT_PRINTF
#define FORMAT_PRINTF(x, y)
Definition format_printf.h:28
srecord
Definition adler16.h:25