mirror of
https://github.com/ETLCPP/etl.git
synced 2026-10-28 18:07:10 +08:00
Fix callbacks for Boolean byte-stream writes (#1615)
* Add docs and tutorial for etl::intrusive_avl_tree (#1608) * Add docs and tutorial for etl::intrusive_avl_tree Documents the intrusive AVL tree added in PR #1425: a full API reference page under Containers/Trees, and a tutorial demonstrating ordered access to intrusively-linked objects with unpredictable lifetimes, including move support and destructor-driven automatic removal from the tree. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * Add complexity shortcode and document its usage Introduces a {{< complexity >}} Hugo shortcode (with light/dark styling for constant/logarithmic/linear/linearithmic/polynomial/exponential classes) for rendering Big-O complexity inline, applies it throughout the intrusive_avl_tree API reference in place of raw "O(...)" text, and documents the Description/Complexity structure and supported classes in DOCUMENTATION.md. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * Fix issues found by @CodeRabbit * Put complexity notes on their own lines in intrusive_avl_tree docs Move the complexity shortcode from the inline "**Complexity:**" label to its own line under a "**Complexity**" label. Notes that give several alternatives (e.g. amortized vs. worst-case) now show each one on a separate line. Update the guideline in DOCUMENTATION.md to match. * Update complexity examples in DOCUMENTATION.md Add the hard line break after the "**Complexity**" label in the example, and rewrite the list of supported complexity classes in the new two-line format, including an example with several alternatives. * Add logarithmic complexity example to DOCUMENTATION.md --------- Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com> Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com> * Updated sponsors pages * Refactor the documentation css to group styles for light and dark themes * Update Codacy badge in README.md Updated Codacy badge link to reflect new project status. * Fix Codacy badge display * Fix callbacks for Boolean byte-stream writes Advance Boolean writes through the existing callback path and test checked and unchecked writes, including rejected writes at full capacity. --------- Co-authored-by: Sergei <sergej.shirokov@gmail.com> Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com> Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com> Co-authored-by: John Wellbelove <john.wellbelove@etlcpp.com>
This commit is contained in:
parent
c98000a41a
commit
41bfe65dda
@ -92,6 +92,7 @@ bool write(bool value)
|
||||
**Description**
|
||||
Write a boolean value to the stream.
|
||||
Returns `true` if successful, otherwise `false`.
|
||||
If a callback is set, it receives the one-byte boolean value after a successful write.
|
||||
|
||||
---
|
||||
|
||||
|
||||
@ -126,7 +126,8 @@ namespace etl
|
||||
//***************************************************************************
|
||||
void write_unchecked(bool value)
|
||||
{
|
||||
*pcurrent++ = value ? 1 : 0;
|
||||
*pcurrent = value ? 1 : 0;
|
||||
step(1U);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
|
||||
@ -1374,6 +1374,61 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(write_bool_callback)
|
||||
{
|
||||
std::array<char, 3> storage = {};
|
||||
std::vector<char> received;
|
||||
std::vector<size_t> lengths;
|
||||
std::vector<char*> positions;
|
||||
auto lambda = [&](etl::byte_stream_writer::callback_parameter_type sp)
|
||||
{
|
||||
received.insert(received.end(), sp.begin(), sp.end());
|
||||
lengths.push_back(sp.size());
|
||||
positions.push_back(sp.data());
|
||||
};
|
||||
etl::byte_stream_writer::callback_type callback(lambda);
|
||||
etl::byte_stream_writer writer(storage.data(), storage.size(), etl::endian::big, callback);
|
||||
|
||||
CHECK_TRUE(writer.write(char(7)));
|
||||
CHECK_TRUE(writer.write(true));
|
||||
CHECK_TRUE(writer.write(false));
|
||||
CHECK_TRUE(writer.full());
|
||||
CHECK_EQUAL(size_t(3), writer.size_bytes());
|
||||
CHECK_EQUAL(size_t(3), received.size());
|
||||
CHECK(received == std::vector<char>({char(7), char(1), char(0)}));
|
||||
CHECK(lengths == std::vector<size_t>({1U, 1U, 1U}));
|
||||
CHECK(positions == std::vector<char*>({storage.data(), storage.data() + 1, storage.data() + 2}));
|
||||
CHECK_ARRAY_EQUAL(storage.data(), received.data(), received.size());
|
||||
|
||||
CHECK_FALSE(writer.write(true));
|
||||
CHECK_EQUAL(size_t(3), received.size());
|
||||
CHECK_EQUAL(size_t(3), writer.size_bytes());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(write_bool_unchecked_callback)
|
||||
{
|
||||
std::array<char, 2> storage = {};
|
||||
std::vector<char> received;
|
||||
auto lambda = [&](etl::byte_stream_writer::callback_parameter_type sp)
|
||||
{
|
||||
CHECK_EQUAL(size_t(1), sp.size());
|
||||
received.insert(received.end(), sp.begin(), sp.end());
|
||||
};
|
||||
etl::byte_stream_writer::callback_type callback(lambda);
|
||||
etl::byte_stream_writer writer(storage.data(), storage.size(), etl::endian::little);
|
||||
writer.set_callback(callback);
|
||||
|
||||
writer.write_unchecked(false);
|
||||
etl::write_unchecked(writer, true);
|
||||
CHECK_TRUE(writer.full());
|
||||
CHECK_EQUAL(size_t(2), writer.size_bytes());
|
||||
CHECK(received == std::vector<char>({char(0), char(1)}));
|
||||
CHECK_EQUAL(char(0), storage[0]);
|
||||
CHECK_EQUAL(char(1), storage[1]);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(write_byte_stream_callback)
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user