NMEA: make nmeatool available with/without ENABLE_IO
[marnav.git] / include / marnav / io / device.hpp
blob1562b6c0930ddc7012fe84dc1194385ae8e61472
1 #ifndef MARNAV_IO_DEVICE_HPP
2 #define MARNAV_IO_DEVICE_HPP
4 #include <cstdint>
6 namespace marnav
8 namespace io
10 /// This is the base class for devices needed to perform IO operations.
11 /// It is simply an interface, no data members.
12 class device
14 public:
15 virtual ~device() {}
17 /// Opens the device.
18 ///
19 /// @exception std::runtime_error Error on opening the device.
20 virtual void open() = 0;
22 /// Closes the device.
23 virtual void close() = 0;
25 /// Reads data from the opened device into the buffer of the specified size.
26 ///
27 /// @param[out] buffer The buffer to contain all read data.
28 /// @param[in] size The size of the buffer.
29 /// @return The number of bytes read into the buffer.
30 /// @exception std::invalid_argument Parameter errors (buffer is nullptr, size is zero, ...)
31 /// @exception std::runtime_error Probably a read error. This does not include EOF.
32 virtual int read(char * buffer, uint32_t size) = 0;
34 /// Writes to the opened device.
35 ///
36 /// @param[in] buffer Data to write.
37 /// @param[in] size Number of bytes to write to the device.
38 /// @return The number of bytes written to the device.
39 /// @exception std::invalid_argument Parameter errors (buffer is nullptr, size is zero, ...)
40 /// @exception std::runtime_error Probably a read error. This does not include EOF.
41 virtual int write(const char * buffer, uint32_t size) = 0;
46 #endif