More implementation of the C standard library.

This commit is contained in:
2024-02-04 02:01:08 +01:00
parent 2a612d2d83
commit b965486de3
21 changed files with 658 additions and 68 deletions

View File

@@ -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)

View File

@@ -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;
}
};
}