srecord  1.65.0
hexdump.h
Go to the documentation of this file.
1 //
2 // srecord - The "srecord" program.
3 // Copyright (C) 2007, 2008, 2010, 2011 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 published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (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
13 // GNU 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
17 // <http://www.gnu.org/licenses/>.
18 //
19 
20 #ifndef SRECORD_OUTPUT_FILE_HEXDUMP_H
21 #define SRECORD_OUTPUT_FILE_HEXDUMP_H
22 
23 #include <srecord/output/file.h>
24 
25 namespace srecord
26 {
27 
28 /**
29  * The srecord::output_file_hexdump class is used to represent an output
30  * file which emits a hexadecimal dump (including ASCII) of the data.
31  */
33  public output_file
34 {
35 public:
36  /**
37  * The destructor.
38  */
40 
41 private:
42  /**
43  * The constructor. It is private on purpose, use the #create
44  * class method instead.
45  *
46  * @param file_name
47  * The name of the file to be written. The special name "-"
48  * indicates the standard output is to be used.
49  */
50  output_file_hexdump(const std::string &file_name);
51 
52 public:
53  /**
54  * The create class method is used to create new dynamically
55  * allocated instances of this class.
56  *
57  * @param file_name
58  * The name of the file to be written.
59  */
60  static pointer create(const std::string &file_name);
61 
62 protected:
63  // See base class for documentation.
64  void write(const record &);
65 
66  // See base class for documentation.
67  void line_length_set(int);
68 
69  // See base class for documentation.
70  void address_length_set(int);
71 
72  // See base class for documentation.
73  int preferred_block_size_get(void) const;
74 
75  // See base class for documentation.
76  bool preferred_block_size_set(int nbytes);
77 
78  // See base class for documentation.
79  void command_line(arglex_tool *cmdln);
80 
81  // See base class for documentation.
82  const char *format_name(void) const;
83 
84 private:
85  /**
86  * The number_of_columns instance variable is used to remember how
87  * many columns of hex bytes to display on a single line. It is
88  * always a power of two.
89  */
90  int number_of_columns;
91 
92  /**
93  * The row_cache_address instance variable is used to remember
94  * where we are up to in printing our rows of data. It is the
95  * address of the beginning of the row, NOT the current byte.
96  * The lower "number_of_columns" bits are always zero.
97  */
98  unsigned long row_cache_address;
99 
100  /**
101  * The row_cache_address_mask instance variable is used to remember
102  * the mask to calculate the column within the output line, give a
103  * byte address.
104  */
105  unsigned long row_cache_address_mask;
106 
107  /**
108  * The row_cache_size instance variable is used to remember the
109  * number of printing columns wide the output is.
110  */
111  size_t row_cache_size;
112 
113  /**
114  * The row_cache instance variable is used to remember the text of
115  * the line to be printed. It contains ASCII hex representations
116  * of the bytes "written" to this output.
117  */
118  char *row_cache;
119 
120  /**
121  * The address_length instance variable is used to remember how
122  * many bytes to emit when emitting addresses.
123  */
124  int address_length;
125 
126  /**
127  * The emit_byte method is used to emit a single byte. It uses
128  * column to track the position, so as not to exceed line_length.
129  */
130  void emit_byte(unsigned long address, unsigned char data);
131 
132  /**
133  * The row_cache_print method is used to print the row cache to the
134  * file and then erase the cache in preparation for another row.
135  */
136  void row_cache_print(void);
137 
138  /**
139  * The columns_to_line_length method is used to
140  */
141  int columns_to_line_length(int cols);
142 
143  /**
144  * The default constructor. Do not use.
145  */
147 
148  /**
149  * The copy constructor. Do not use.
150  */
152 
153  /**
154  * The assignment operator. Do not use.
155  */
156  output_file_hexdump &operator=(const output_file_hexdump &);
157 };
158 
159 };
160 
161 // vim: set ts=8 sw=4 et :
162 #endif // SRECORD_OUTPUT_FILE_HEXDUMP_H
The srecord::arglex_tool is used to parse command line with srec-specific arguments.
Definition: tool.h:41
The srecord::output_file_hexdump class is used to represent an output file which emits a hexadecimal ...
Definition: hexdump.h:34
int preferred_block_size_get(void) const
The preferred_block_size_get method is used to get the proferred block size of the output fformat.
void write(const record &)
The write method is used to write a recordonto an output.
void line_length_set(int)
The set_line_length method is used to set the maximum length of an output line, for those formats for...
void command_line(arglex_tool *cmdln)
The command_line method is used by arglex_srec::get_output when parsing the command line,...
virtual ~output_file_hexdump()
The destructor.
void address_length_set(int)
The address_length_set method is used to set the minimum number of bytes to be written for addresses ...
bool preferred_block_size_set(int nbytes)
The preferred_block_size_set method is is to set a precific number of bytes for the preferred block s...
const char * format_name(void) const
The format_name method is used to obtain the name of this output format.
static pointer create(const std::string &file_name)
The create class method is used to create new dynamically allocated instances of this class.
The srecord::output_file class is used to represent a generic output file.
Definition: file.h:35
std::shared_ptr< output > pointer
Definition: output.h:41
The srecord::record class is used to represent a data record read from a file.
Definition: record.h:35