srecord: input.h Source File

srecord 1.65.0

Loading...
Searching...
No Matches
input.h
Go to the documentation of this file.
1//
2// srecord - manipulate eprom load files
3// Copyright (C) 1998-2000, 2002, 2003, 2005-2008, 2010, 2013 Peter Miller
4//
5// This program is free software; you can redistribute it and/or modify
6// it under the terms of the GNU Lesser General Public License as
7// published by the Free Software Foundation; either version 3 of the
8// License, or (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13// Lesser General Public License 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_INPUT_H
20#define SRECORD_INPUT_H
21
22#include <string>
23#include <stdarg.h>
24#include <memory>
25
26#include <srecord/format_printf.h>
27
28namespace srecord {
29
30class arglex_tool; // forward
31class quit; // forward
32
33/**
34 * The srecord::input class is used to represent an abstract EPROM load
35 * file source. It could be one of many file formats, or a chain of
36 * filters applied to an input file.
37 */
38 class input
39{
40public:
41 typedef std::shared_ptr<input> pointer;
42
43 /**
44 * The destructor.
45 */
46 virtual ~input();
47
48 /**
49 * The read method is used to read one record from the input.
50 * It returns 0 at the end of the input, and 1 if a record is
51 * read successfully.
52 *
53 * See the srecord::record documentation (header file) for details
54 * of the various record types.
55 *
56 * Note: there is no guarantee that a header record will appear
57 * first, or that a execution start address record will appear last.
58 *
59 * @param rec
60 * Where to put the returned data.
61 * @returns
62 * bool; true if data was read, false if at end-of-file
63 */
64 virtual bool read(class record &rec) = 0;
65
66 /**
67 * The fatal_error method is used to report problems parsing
68 * the file. Do not put a newline at the end of the message.
69 * Usually called from within derived class methods. This method
70 * does not return.
71 *
72 * The file name and line number are automatically included
73 * in the message. The filename_and_line method is called to
74 * determine them.
75 */
76 virtual void fatal_error(const char *, ...) const
77 FORMAT_PRINTF(2, 3);
78 /**
79 * The fatal_error_errno method is used to report problems
80 * reading the input file. Do not put a newline at the end
81 * of the message. The string equivalent of errno is appended
82 * to the error message. This method does not return.
83 *
84 * The file name and line number are automatically included
85 * in the message. The filename_and_line method is called to
86 * determine them.
87 */
88 virtual void fatal_error_errno(const char *, ...) const
89 FORMAT_PRINTF(2, 3);
90 /**
91 * The warning method is used to report potential (but non-fatal)
92 * problems parsing the file. Do not put a newline at the
93 * end of the message. Usually called from within derived
94 * class methods.
95 *
96 * The file name and line number are automatically included
97 * in the message. The filename_and_line method is called to
98 * determine them.
99 */
100 virtual void warning(const char *, ...) const
101 FORMAT_PRINTF(2, 3);
102 /**
103 * The filename method is used to get the name of the input file
104 * being processed. Derived classes must supply this method.
105 */
106 virtual std::string filename(void) const = 0;
107
108 /**
109 * The filename_and_line method is used to get the name
110 * and current line number within the file. The default
111 * implementation simply calls the filename method and returns
112 * that. Text formats should be cleverer.
113 */
114 virtual std::string filename_and_line(void) const;
115
116 /**
117 * The get_file_format_name method is used to find out the name
118 * of the file format being read. Derived classes must supply
119 * this method.
120 */
121 virtual const char *get_file_format_name(void) const = 0;
122
123 /**
124 * The set_quit method is used to set the disposition of the
125 * error messages, and the "exit" implementation. The default
126 * is to write error messages on the standard error, and to
127 * exit using the standard C exit function.
128 */
129 void set_quit(quit &);
130
131 /**
132 * The reset_quit method is used to cause the disposition of
133 * the error messages, and the "exit" back to the default.
134 */
135 void reset_quit(void);
136
137 /**
138 * The disable_checksum_validation method is used to have this
139 * input stream ignore checksum errors.
140 */
141 virtual void disable_checksum_validation(void) = 0;
142
143 /**
144 * The command_line method is used by arglex_srec::get_input
145 * when parsing the command line, to give a format or filter an
146 * opportunity to grab extra arguments off the command line. The
147 * default implementation does nothing.
148 *
149 * @param cmdln
150 * Where to obtain information about the curreent parse state
151 * of the command line.
152 */
153 virtual void command_line(srecord::arglex_tool *cmdln);
154
155private:
156 /**
157 * The quitter instance variable is used to remember how to quit.
158 * It is set by the set_quit and reset_quit. It is used by
159 * the fatal_error, fatal_error_with_errno and warning methods.
160 */
161 quit *quitter;
162
163protected:
164 /**
165 * The default constructor. Only derived classes may call.
166 */
167 input();
168
169private:
170 /**
171 * The copy constructor. Do not use.
172 */
173 input(const input &);
174
175 /**
176 * The assignment operator. Do not use.
177 */
178 input &operator=(const input &);
179};
180
181};
182
183// vim: set ts=8 sw=4 et :
184#endif // SRECORD_INPUT_H
srecord::arglex_tool
The srecord::arglex_tool is used to parse command line with srec-specific arguments.
Definition tool.h:41
srecord::input::disable_checksum_validation
virtual void disable_checksum_validation(void)=0
The disable_checksum_validation method is used to have this input stream ignore checksum errors.
srecord::input::filename
virtual void virtual void virtual void virtual std::string filename(void) const =0
The filename method is used to get the name of the input file being processed.
srecord::input::fatal_error_errno
virtual void virtual void fatal_error_errno(const char *,...) const FORMAT_PRINTF(2
The fatal_error_errno method is used to report problems reading the input file.
srecord::input::warning
virtual void virtual void virtual void warning(const char *,...) const FORMAT_PRINTF(2
The warning method is used to report potential (but non-fatal) problems parsing the file.
srecord::input::get_file_format_name
virtual const char * get_file_format_name(void) const =0
The get_file_format_name method is used to find out the name of the file format being read.
srecord::input::fatal_error
virtual void fatal_error(const char *,...) const FORMAT_PRINTF(2
The fatal_error method is used to report problems parsing the file.
srecord::input::filename_and_line
virtual std::string filename_and_line(void) const
The filename_and_line method is used to get the name and current line number within the file.
srecord::input::input
input()
The default constructor.
srecord::input::command_line
virtual void command_line(srecord::arglex_tool *cmdln)
The command_line method is used by arglex_srec::get_input when parsing the command line,...
srecord::input::reset_quit
void reset_quit(void)
The reset_quit method is used to cause the disposition of the error messages, and the "exit" back to ...
srecord::input::pointer
std::shared_ptr< input > pointer
Definition input.h:41
srecord::input::set_quit
void set_quit(quit &)
The set_quit method is used to set the disposition of the error messages, and the "exit" implementati...
srecord::input::read
virtual bool read(class record &rec)=0
The read method is used to read one record from the input.
srecord::input::~input
virtual ~input()
The destructor.
srecord::quit
The quit class is an abstract class for reporting error messages, both fatal and non-fatal.
Definition quit.h:33
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