More implementation of the C standard library.
This commit is contained in:
@@ -55,4 +55,15 @@ inline void serialWriteString(std::uint16_t port, const char* str) noexcept
|
||||
}
|
||||
}
|
||||
|
||||
inline void serialWriteString(std::uint16_t port, const char* str, size_t count) noexcept
|
||||
{
|
||||
for (size_t pos = 0; pos < count; ++pos)
|
||||
{
|
||||
if (str[pos] == '\n') {
|
||||
serialWrite(port, '\r');
|
||||
}
|
||||
serialWrite(port, str[pos]);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // !defined(BAD_APPLE_OS_SERIAL_HPP_INCLUDED)
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <span>
|
||||
|
||||
namespace baos
|
||||
{
|
||||
@@ -47,6 +48,33 @@ public:
|
||||
--mBufferedElements;
|
||||
return true;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool isDataContinuous() const noexcept
|
||||
{
|
||||
return mBufferedElements <= mPosition;
|
||||
}
|
||||
|
||||
void normalize() noexcept
|
||||
{
|
||||
std::array<T, SIZE> tempElements;
|
||||
auto it = tempElements.begin();
|
||||
while (next(*it)) { ++it; }
|
||||
mBufferedElements = it - tempElements.begin();
|
||||
mElements = std::move(tempElements);
|
||||
mPosition = mBufferedElements;
|
||||
}
|
||||
|
||||
std::span<T> getAll(bool reset = true) noexcept
|
||||
{
|
||||
if (!isDataContinuous()) {
|
||||
normalize();
|
||||
}
|
||||
std::span<T> result = {mElements.data() + mPosition - mBufferedElements, mBufferedElements};
|
||||
if (reset) {
|
||||
mBufferedElements = 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user