libdrmconf 0.12.1
A library to program DMR radios.
Loading...
Searching...
No Matches
addressmap.hh
1#ifndef ADDRESSMAP_HH
2#define ADDRESSMAP_HH
3
4#include <cinttypes>
5#include <vector>
6
14{
15public:
17 AddressMap();
19 AddressMap(const AddressMap &other);
20
22 AddressMap &operator=(const AddressMap &other);
23
25 void clear();
27 bool add(uint32_t addr, uint32_t len, int idx=-1);
29 bool rem(uint32_t idx);
31 bool contains(uint32_t addr) const;
34 int find(uint32_t addr) const;
35
36protected:
39 struct AddrMapItem {
40 uint32_t address;
41 uint32_t length;
42 uint32_t index;
43
45 inline AddrMapItem(uint32_t addr, uint32_t len, uint32_t idx)
46 : address(addr), length(len), index(idx) {
47 // pass...
48 }
50 inline bool operator<(const AddrMapItem &other) const {
51 return address < other.address;
52 }
54 inline bool operator<(uint32_t addr) const {
55 return address < addr;
56 }
58 inline bool contains(uint32_t addr) const {
59 return (address <= addr) && ((address+length) > addr);
60 }
61 };
62
63protected:
65 std::vector<AddrMapItem> _items;
66};
67
68#endif // ADDRESSMAP_HH
This class represents a memory map.
Definition addressmap.hh:14
bool add(uint32_t addr, uint32_t len, int idx=-1)
Adds an item to the address map.
Definition addressmap.cc:29
void clear()
Clears the address map.
Definition addressmap.cc:24
AddressMap & operator=(const AddressMap &other)
Copy assignment.
Definition addressmap.cc:17
bool contains(uint32_t addr) const
Returns true if the given address is contained in any of the memory regions.
Definition addressmap.cc:56
int find(uint32_t addr) const
Finds the index of the memory region containing the given address.
Definition addressmap.cc:61
bool rem(uint32_t idx)
Removes an item from the address map associated with the given index.
Definition addressmap.cc:43
std::vector< AddrMapItem > _items
Holds the vector of memory items, the order of these items is maintained.
Definition addressmap.hh:65
AddressMap()
Empty constructor.
Definition addressmap.cc:4
Memory map item.
Definition addressmap.hh:39
AddrMapItem(uint32_t addr, uint32_t len, uint32_t idx)
Constructor.
Definition addressmap.hh:45
bool operator<(const AddrMapItem &other) const
Comparison operator.
Definition addressmap.hh:50
uint32_t length
The size/length of the memory item.
Definition addressmap.hh:41
bool contains(uint32_t addr) const
Returns true if the given address is contained within this memory region.
Definition addressmap.hh:58
uint32_t address
The start address of the item.
Definition addressmap.hh:40
bool operator<(uint32_t addr) const
Comparison operator.
Definition addressmap.hh:54
uint32_t index
The associated (element) index.
Definition addressmap.hh:42