-
Notifications
You must be signed in to change notification settings - Fork 0
/
ibus.hpp
48 lines (36 loc) · 1.07 KB
/
ibus.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#ifndef BRD_BUS_HPP
#define BRD_BUS_HPP
#include <stdexcept>
#include <boost/shared_ptr.hpp>
#include "bus_address.hpp"
namespace brd { namespace bus {
struct address;
struct bus_error : std::runtime_error {
bus_error(const std::string& what_arg) throw()
: std::runtime_error("bus: " + what_arg) {}
};
struct timeout_error : bus_error {
timeout_error(const std::string& what_arg) throw()
: bus_error("timeout " + what_arg) {}
};
struct ibus {
typedef uint32_t value_type;
virtual value_type read(const address&) = 0;
virtual void write(const address&, value_type) = 0;
virtual ~ibus() {};
template <typename Iterator>
void write(address addr, Iterator first, Iterator last) {
while (first != last) {
write(addr++, *first++);
}
}
template <typename Iterator>
void read(address addr, Iterator first, Iterator last) {
while (first != last) {
*first++ = read(addr++);
}
}
};
typedef boost::shared_ptr<ibus> bus_ptr;
}} //namespace brd::bus
#endif //BRD_BUS_HPP