srecord 1.65.0
 
Loading...
Searching...
No Matches
chunk.h
Go to the documentation of this file.
1//
2// srecord - manipulate eprom load files
3// Copyright (C) 1998-2000, 2002, 2003, 2006-2008, 2010 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_MEMORY_CHUNK_H
20#define SRECORD_MEMORY_CHUNK_H
21
22#include <stddef.h>
23
25
26namespace srecord {
27
28/**
29 * The srecord::memory_chunk class is used to represent portion of memory.
30 * Not all bytes are actually set, so there is a bit map of which bytes
31 * actually contain data.
32 */
34{
35public:
36 enum {
37 /**
38 * The size value is the size, in bytes, of each memory chunk.
39 *
40 * @note
41 * Code that uses this value <b>shall not</b> assume that
42 * it is, or will ever be, a power of 2. The compiler will
43 * optimize for you, don't do premature optimizations like bit
44 * masks and bit shifts.
45 * @note
46 * If you change this value, you will have to change tests
47 * test/01/t0199a.sh and test/02/t0200a.sh to match,
48 * otherwise it will fail. Make sure that interactions with
49 * srecord::output_filter_reblock are what you intended, too.
50 */
51 size = 7 * 256 };
52
53 /**
54 * The constructor.
55 */
56 memory_chunk(unsigned long address);
57
58 /**
59 * The copy constructor.
60 */
62
63 /**
64 * The assignment operator.
65 */
67
68 /**
69 * The destructor.
70 */
72
73 /**
74 * The set method is used to set the byte at the given offset within
75 * the chunk.
76 */
77 void set(unsigned long offset, int value);
78
79 /**
80 * The get method is used to get the value at the given offset
81 * within the chunk.
82 */
83 int get(unsigned long offset);
84
85 /**
86 * The get_p method is used to determine whether the byte at the
87 * given offset within the chunk contains valid data.
88 */
89 bool set_p(unsigned long) const;
90
91 /**
92 * The walk method is used to iterate across all of the bytes which
93 * are set within the chunk, calling the walker's observe method.
94 */
96
97 /**
98 * The get_address method is used to get the address of the memory
99 * chunk. This is NOT the address of the first byte, it is the
100 * chunk number. To calculate the byte address, multiply by size.
101 */
102 unsigned long get_address() const { return address; }
103
104 /**
105 * The equal class method is used to determine wherther two memory
106 * chunks are equal. The must have the same address, the same bit
107 * mask, and the same byte values on the valid bytes.
108 */
109 static bool equal(const memory_chunk &, const memory_chunk &);
110
111 /**
112 * The find_next_data method is used when iteratinbg across all of
113 * the bytes set within the chunk.
114 */
115 bool find_next_data(unsigned long &, void *, size_t &) const;
116
117 /**
118 * The get_upper_bound method is used to determine the upper bound
119 * (offset of last byte with valid data, plus one) of the chunk.
120 * It returns a memory byte address, NOT the chunk offset.
121 */
122 unsigned long get_upper_bound() const;
123
124 /**
125 * The get_lower_bound method is used to determine the lower bound
126 * (offset of first byte with valid data) of the chunk.
127 * It returns a memory byte address, NOT the chunk offset.
128 */
129 unsigned long get_lower_bound() const;
130
131private:
132 /**
133 * The address of the memory chunk. This is NOT the address of
134 * the first byte, it is the chunk number. To calculate the byte
135 * address, multiply by size.
136 */
137 unsigned long address;
138
139 /**
140 * The data array is used to remember the valus of valid data bytes.
141 */
142 unsigned char data[size];
143
144 /**
145 * The mask array is used to remember which values in the data
146 * array contain valid values.
147 */
148 unsigned char mask[(size + 7) / 8];
149
150 /**
151 * The default constructor. Do not use.
152 */
153 memory_chunk();
154};
155
158
159};
160
161// vim: set ts=8 sw=4 et :
162#endif // SRECORD_MEMORY_CHUNK_H
The srecord::memory_chunk class is used to represent portion of memory.
Definition chunk.h:34
unsigned long get_address() const
The get_address method is used to get the address of the memory chunk.
Definition chunk.h:102
bool set_p(unsigned long) const
The get_p method is used to determine whether the byte at the given offset within the chunk contains ...
unsigned long get_upper_bound() const
The get_upper_bound method is used to determine the upper bound (offset of last byte with valid data,...
static bool equal(const memory_chunk &, const memory_chunk &)
The equal class method is used to determine wherther two memory chunks are equal.
memory_chunk(unsigned long address)
The constructor.
~memory_chunk()
The destructor.
void set(unsigned long offset, int value)
The set method is used to set the byte at the given offset within the chunk.
memory_chunk & operator=(const memory_chunk &)
The assignment operator.
memory_chunk(const memory_chunk &)
The copy constructor.
bool find_next_data(unsigned long &, void *, size_t &) const
The find_next_data method is used when iteratinbg across all of the bytes set within the chunk.
@ size
The size value is the size, in bytes, of each memory chunk.
Definition chunk.h:51
int get(unsigned long offset)
The get method is used to get the value at the given offset within the chunk.
unsigned long get_lower_bound() const
The get_lower_bound method is used to determine the lower bound (offset of first byte with valid data...
void walk(memory_walker::pointer) const
The walk method is used to iterate across all of the bytes which are set within the chunk,...
std::shared_ptr< memory_walker > pointer
Definition walker.h:36
bool operator==(const interval &lhs, const interval &rhs)
The equality operator is used to determine if two intervals are the same.
Definition interval.h:265
bool operator!=(const interval &lhs, const interval &rhs)
The inequality operator is used to determine if two intervals are different.
Definition interval.h:275