srecord 1.65.0
 
Loading...
Searching...
No Matches
reblock.h
Go to the documentation of this file.
1//
2// srecord - Manipulate EPROM load files
3// Copyright (C) 2010, 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 General Public License for
13// 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_FILTER_REBLOCK_H
20#define SRECORD_OUTPUT_FILTER_REBLOCK_H
21
23
24namespace srecord {
25
26/**
27 * The output_filter_reblock class is used to represent a filter that
28 * repacks output records so that they exactly align with the output
29 * format's preferred block size.
30 *
31 * This can also be used to remove artifacts of whatever the SRecord
32 * internal memory chunk size happens to be.
33 */
34class output_filter_reblock:
35 public output_filter
36{
37public:
38 typedef std::shared_ptr<output_filter_reblock> pointer;
39
40 /**
41 * The destructor.
42 */
44
45 /**
46 * The create class method is used to create new dynamically
47 * allocated instanced of this class.
48 *
49 * @param deeper
50 * Where to send our filtered output.
51 * @param align
52 * Whether or not to align data records on block boundaries
53 * (that is, to use non-optimal short writes after holes to force
54 * alignment).
55 */
56 static pointer create(const output::pointer &deeper, bool align = false);
57
58protected:
59 // See base class for documentation.
60 void write(const record &r);
61
62 // See base class for documentation.
63 void line_length_set(int);
64
65 // See base class for documentation.
67
68 // See base class for documentation.
69 int preferred_block_size_get(void) const;
70
71 // See base class for documentation.
72 bool preferred_block_size_set(int nbytes);
73
74private:
75 /**
76 * The constructor.
77 * It is private on purpose, use the #create class method instead.
78 *
79 * @param deeper
80 * Where to send our filtered output.
81 * @param align
82 * Whether or not to align data records on block boundaries
83 * (that is, to use non-optimal short writes after holes to force
84 * alignment).
85 */
86 output_filter_reblock(const output::pointer &deeper, bool align);
87
88 /**
89 * The align instance variable is used to remember whether or
90 * not to use shoirt writes after holds to force records to be
91 * on block_size boundaries, rather than as tightly packed as
92 * pissible.
93 */
94 bool align;
95
96 /**
97 * The block_size instance variable is used to remember the
98 * block size (in bytes) we are packing to. It is cache of the
99 * deeper->preferred_block_size_get() value, the cahce is updated
100 * at strategic times, by calling the #track_block_size method.
101 */
102 unsigned block_size;
103
104 /**
105 * The buffer_address instance variable is used to remember the
106 * byte address of the first byte of the output buffer. Not
107 * meaningful if #buffer_pos is zero.
108 */
109 unsigned long buffer_address;
110
111 /**
112 * The buffer instance variable is used to remember the base
113 * address of a buffer allocated from dynamic memory. The
114 * allocatred size may be found in the #buffer_max instance
115 * variable.
116 *
117 * assert(!buffer == !buffer_max);
118 */
119 unsigned char *buffer;
120
121 /**
122 * The buffer_pos instance variable is used to remember how many
123 * bytes of the #buffer have been used to date.
124 *
125 * assert(buffer_pos < buffer_max);
126 */
127 size_t buffer_pos;
128
129 /**
130 * The buffer_max instance variable is used to remember how many
131 * data bytes were allocated when the #buffer was created.
132 */
133 size_t buffer_max;
134
135 /**
136 * The track_block_size method is used to re-cache the
137 * deeper->preferred_bock_size_get whenever that value could have
138 * changed.
139 */
140 void track_block_size(void);
141
142 /**
143 * The flush_buffer method is used to write the accumulkated
144 * contents of the #buffer to the deeper output.
145 *
146 * @param partial
147 * Whether or not to write a partial record at the end. True
148 * for partial record, false for no short record (which could
149 * leave some residual bytes in the #buffer).
150 */
151 void flush_buffer(bool partial);
152
153 /**
154 * The default constructor. Do not use.
155 */
156 output_filter_reblock();
157
158 /**
159 * The copy constructor. Do not use.
160 */
161 output_filter_reblock(const output_filter_reblock &);
162
163 /**
164 * The assignment operator. Do not use.
165 */
166 output_filter_reblock &operator=(const output_filter_reblock &);
167};
168
169};
170
171// vim: set ts=8 sw=4 et :
172#endif // SRECORD_OUTPUT_FILTER_REBLOCK_H
void write(const record &r)
The write method is used to write a recordonto an output.
virtual ~output_filter_reblock()
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 ...
std::shared_ptr< output_filter_reblock > pointer
Definition reblock.h:38
static pointer create(const output::pointer &deeper, bool align=false)
The create class method is used to create new dynamically allocated instanced of this class.
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 line_length_set(int)
The set_line_length method is used to set the maximum length of an output line, for those formats for...
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...
output_filter(const output::pointer &deeper)
The constructor.
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