|
1 | 1 | #ifndef YSTDLIB_IO_INTERFACE_WRITERINTERFACE_HPP |
2 | 2 | #define YSTDLIB_IO_INTERFACE_WRITERINTERFACE_HPP |
3 | | -// NOLINTBEGIN |
4 | 3 |
|
5 | 4 | // TODO: https://github.com/y-scope/ystdlib-cpp/issues/50 |
6 | 5 | // NOLINTNEXTLINE(misc-include-cleaner) |
@@ -30,28 +29,32 @@ class WriterInterface { |
30 | 29 |
|
31 | 30 | // Methods |
32 | 31 | /** |
33 | | - * Writes the given data to the underlying medium |
| 32 | + * Writes the given data to the underlying medium. |
34 | 33 | * @param data |
35 | 34 | * @param data_length |
36 | 35 | */ |
37 | | - virtual void write(char const* data, size_t data_length) = 0; |
38 | | - virtual void flush() = 0; |
| 36 | + [[nodiscard]] virtual auto write(char const* data, size_t data_length) -> ErrorCode = 0; |
39 | 37 |
|
40 | 38 | /** |
41 | | - * Writes a numeric value |
42 | | - * @param val Value to write |
| 39 | + * Forces any buffered output data to be available at the underlying medium. |
| 40 | + */ |
| 41 | + [[nodiscard]] virtual auto flush() -> ErrorCode = 0; |
| 42 | + |
| 43 | + /** |
| 44 | + * Writes a numeric value to the underlying medium. |
| 45 | + * @param val |
43 | 46 | */ |
44 | 47 | template <typename ValueType> |
45 | | - void write_numeric_value(ValueType value); |
| 48 | + [[nodiscard]] auto write_numeric_value(ValueType value) -> ErrorCode; |
46 | 49 |
|
47 | 50 | /** |
48 | | - * Writes the given character to the underlying medium. |
| 51 | + * Writes a character to the underlying medium. |
49 | 52 | * @param c |
50 | 53 | */ |
51 | 54 | [[nodiscard]] virtual auto write_char(char c) -> ErrorCode { return write(&c, 1); } |
52 | 55 |
|
53 | 56 | /** |
54 | | - * Writes the given string to the underlying medium. |
| 57 | + * Writes a string to the underlying medium. |
55 | 58 | * @param str |
56 | 59 | */ |
57 | 60 | [[nodiscard]] virtual auto write_string(std::string const& str) -> ErrorCode { |
@@ -79,10 +82,9 @@ class WriterInterface { |
79 | 82 | }; |
80 | 83 |
|
81 | 84 | template <typename ValueType> |
82 | | -void WriterInterface::write_numeric_value(ValueType val) { |
83 | | - write(reinterpret_cast<char*>(&val), sizeof(val)); |
| 85 | +auto WriterInterface::write_numeric_value(ValueType val) -> ErrorCode { |
| 86 | + return write(static_cast<char const*>(&val), sizeof(ValueType)); |
84 | 87 | } |
85 | 88 | } // namespace ystdlib::io_interface |
86 | 89 |
|
87 | | -// NOLINTEND |
88 | 90 | #endif // YSTDLIB_IO_INTERFACE_WRITERINTERFACE_HPP |
0 commit comments