From 305c039d8392b135deb085516682d6527505e505 Mon Sep 17 00:00:00 2001 From: Christian Seiler Date: Wed, 13 May 2026 19:50:50 +0200 Subject: [PATCH] C++: create all stub methods for structured analysis --- cpp/src/monoformat_structured.cpp | 592 +++++++++++++++++++++++++++++- cpp/src/monoformat_structured.hpp | 21 +- 2 files changed, 603 insertions(+), 10 deletions(-) diff --git a/cpp/src/monoformat_structured.cpp b/cpp/src/monoformat_structured.cpp index 99bd689..940d435 100644 --- a/cpp/src/monoformat_structured.cpp +++ b/cpp/src/monoformat_structured.cpp @@ -141,7 +141,7 @@ AnimationElement::AnimationElement(std::uint16_t x, std::uint16_t y, std::uint16 , m_numberOfFrames{numberOfFrames} , m_updateInterval{updateInterval} { - std::size_t const imageBufferSize = (m_width * m_height + 8 - 1) / 8;\ + std::size_t const imageBufferSize = (m_width * m_height + 8 - 1) / 8; m_buffer.resize(imageBufferSize * numberOfFrames); } @@ -220,4 +220,594 @@ std::expected, ParseError> AnimationElement::p // FIXME: implement this } +HScrollImageElement::HScrollImageElement(std::uint16_t x, std::uint16_t y, std::uint16_t width, std::uint16_t height, std::uint16_t contentWidth, std::uint8_t flags, std::uint8_t scrollSpeed) + : m_x{x} + , m_y{y} + , m_width{width} + , m_height{height} + , m_contentWidth{contentWidth} + , m_flags{flags} + , m_scrollSpeed{scrollSpeed} +{ + std::size_t const imageBufferSize = (m_contentWidth * m_height + 8 - 1) / 8; + m_buffer.resize(imageBufferSize); +} + +std::uint16_t HScrollImageElement::x() const noexcept { + return m_x; +} + +std::uint16_t HScrollImageElement::y() const noexcept { + return m_y; +} + +std::uint16_t HScrollImageElement::width() const noexcept { + return m_width; +} + +std::uint16_t HScrollImageElement::height() const noexcept { + return m_height; +} + +std::uint16_t HScrollImageElement::contentWidth() const noexcept { + return m_contentWidth; +} + +std::uint8_t HScrollImageElement::flags() const noexcept { + return m_flags; +} + +std::uint8_t HScrollImageElement::scrollSpeed() const noexcept { + return m_scrollSpeed; +} + +std::span HScrollImageElement::buffer() noexcept { + return std::span{m_buffer}; +} + +std::span HScrollImageElement::buffer() const noexcept { + return std::span{m_buffer}; +} + +MemoryOneBitBuffer HScrollImageElement::image() noexcept { + return MemoryOneBitBuffer{m_buffer, m_contentWidth, m_height}; +} + +ConstMemoryOneBitBuffer HScrollImageElement::image() const noexcept { + return ConstMemoryOneBitBuffer{m_buffer, m_contentWidth, m_height}; +} + +HScrollImageElement::~HScrollImageElement() { +} + +ElementType HScrollImageElement::elementType() const { + return ElementType::HScrollImage; +} + +std::size_t HScrollImageElement::serializeTo(std::span target) const { + // FIXME Serialize +} + +void HScrollImageElement::drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp) { + // FIXME draw +} + +std::expected, ParseError> HScrollImageElement::parse(std::span& buffer) { + // FIXME parse +} + +VScrollImageElement::VScrollImageElement(std::uint16_t x, std::uint16_t y, std::uint16_t width, std::uint16_t height, std::uint16_t contentHeight, std::uint8_t flags, std::uint8_t scrollSpeed) + : m_x{x} + , m_y{y} + , m_width{width} + , m_height{height} + , m_contentHeight{contentHeight} + , m_flags{flags} + , m_scrollSpeed{scrollSpeed} +{ + std::size_t const imageBufferSize = (m_width * m_contentHeight + 8 - 1) / 8; + m_buffer.resize(imageBufferSize); +} + +std::uint16_t VScrollImageElement::x() const noexcept { + return m_x; +} + +std::uint16_t VScrollImageElement::y() const noexcept { + return m_y; +} + +std::uint16_t VScrollImageElement::width() const noexcept { + return m_width; +} + +std::uint16_t VScrollImageElement::height() const noexcept { + return m_height; +} + +std::uint16_t VScrollImageElement::contentHeight() const noexcept { + return m_contentHeight; +} + +std::uint8_t VScrollImageElement::flags() const noexcept { + return m_flags; +} + +std::uint8_t VScrollImageElement::scrollSpeed() const noexcept { + return m_scrollSpeed; +} + +std::span VScrollImageElement::buffer() noexcept { + return std::span{m_buffer}; +} + +std::span VScrollImageElement::buffer() const noexcept { + return std::span{m_buffer}; +} + +MemoryOneBitBuffer VScrollImageElement::image() noexcept { + return MemoryOneBitBuffer{m_buffer, m_width, m_contentHeight}; +} + +ConstMemoryOneBitBuffer VScrollImageElement::image() const noexcept { + return ConstMemoryOneBitBuffer{m_buffer, m_width, m_contentHeight}; +} + +VScrollImageElement::~VScrollImageElement() { +} + +ElementType VScrollImageElement::elementType() const { + return ElementType::VScrollImage; +} + +std::size_t VScrollImageElement::serializeTo(std::span target) const { + // FIXME Serialize +} + +void VScrollImageElement::drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp) { + // FIXME draw +} + +std::expected, ParseError> VScrollImageElement::parse(std::span& buffer) { + // FIXME parse +} + + +LineElement::LineElement(std::uint16_t originX, std::uint16_t originY, std::uint16_t targetX, std::uint16_t targetY, LineStyle lineStyle, std::uint8_t flags) + : m_originX{originX} + , m_originY{originY} + , m_targetX{targetX} + , m_targetY{targetY} + , m_lineStyle{lineStyle} + , m_flags{flags} +{ +} + +std::uint16_t LineElement::originX() const noexcept { + return m_originX; +} + +std::uint16_t LineElement::originY() const noexcept { + return m_originY; +} + +std::uint16_t LineElement::targetX() const noexcept { + return m_targetX; +} + +std::uint16_t LineElement::targetY() const noexcept { + return m_targetY; +} + +LineStyle LineElement::lineStyle() const noexcept { + return m_lineStyle; +} + +std::uint8_t LineElement::flags() const noexcept { + return m_flags; +} + +LineElement::~LineElement() { +} + +ElementType LineElement::elementType() const { + return ElementType::Line; +} + +std::size_t LineElement::serializeTo(std::span target) const { + // FIXME: serialize +} + +void LineElement::drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp) { + // FIXME: draw +} + +std::expected, ParseError> LineElement::parse(std::span& buffer) { + // FIXME: parse +} + +ClippedTextElement::ClippedTextElement(std::uint16_t x, std::uint16_t y, std::uint16_t width, std::uint16_t height, std::uint16_t fontIndex, std::string text) + : m_x{x} + , m_y{y} + , m_width{width} + , m_height{height} + , m_fontIndex{fontIndex} + , m_text{std::move(text)} +{ +} + +std::uint16_t ClippedTextElement::x() const noexcept { + return m_x; +} + +std::uint16_t ClippedTextElement::y() const noexcept { + return m_y; +} + +std::uint16_t ClippedTextElement::width() const noexcept { + return m_width; +} + +std::uint16_t ClippedTextElement::height() const noexcept { + return m_height; +} + +std::uint16_t ClippedTextElement::fontIndex() const noexcept { + return m_fontIndex; +} + +std::string ClippedTextElement::text() const { + return m_text; +} + +ClippedTextElement::~ClippedTextElement() { +} + +ElementType ClippedTextElement::elementType() const { + return ElementType::ClippedText; +} + +std::size_t ClippedTextElement::serializeTo(std::span target) const { + // FIXME: serialize +} + +void ClippedTextElement::drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp) { + // FIXME: draw +} + +std::expected, ParseError> ClippedTextElement::parse(std::span& buffer) { + // FIXME: parse +} + +HScrollTextElement::HScrollTextElement(std::uint16_t x, std::uint16_t y, std::uint16_t width, std::uint16_t height, std::uint8_t flags, std::uint8_t scrollSpeed, std::uint16_t fontIndex, std::string text) + : m_x{x} + , m_y{y} + , m_width{width} + , m_height{height} + , m_flags{flags} + , m_scrollSpeed{scrollSpeed} + , m_fontIndex{fontIndex} + , m_text{std::move(text)} +{ +} + +std::uint16_t HScrollTextElement::x() const noexcept { + return m_x; +} + +std::uint16_t HScrollTextElement::y() const noexcept { + return m_y; +} + +std::uint16_t HScrollTextElement::width() const noexcept { + return m_width; +} + +std::uint16_t HScrollTextElement::height() const noexcept { + return m_height; +} + +std::uint8_t HScrollTextElement::flags() const noexcept { + return m_flags; +} + +std::uint8_t HScrollTextElement::scrollSpeed() const noexcept { + return m_scrollSpeed; +} + +std::uint16_t HScrollTextElement::fontIndex() const noexcept { + return m_fontIndex; +} + +std::string HScrollTextElement::text() const { + return m_text; +} + +HScrollTextElement::~HScrollTextElement() { +} + +ElementType HScrollTextElement::elementType() const { + return ElementType::HScrollText; +} + +std::size_t HScrollTextElement::serializeTo(std::span target) const { + // FIXME serialize +} + +void HScrollTextElement::drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp) { + // FIXME: draw +} + +std::expected, ParseError> HScrollTextElement::parse(std::span& buffer) { + // FIXME: parse +} + +CurrentTimeElement::CurrentTimeElement(std::uint16_t x, std::uint16_t y, std::uint16_t width, std::uint16_t height, std::uint16_t fontIndex, std::uint16_t utcOffset, std::uint16_t flags) + : m_x{x} + , m_y{y} + , m_width{width} + , m_height{height} + , m_fontIndex{fontIndex} + , m_utcOffset{utcOffset} + , m_flags{flags} +{ +} + +std::uint16_t CurrentTimeElement::x() const noexcept { + return m_x; +} + +std::uint16_t CurrentTimeElement::y() const noexcept { + return m_y; +} + +std::uint16_t CurrentTimeElement::width() const noexcept { + return m_width; +} + +std::uint16_t CurrentTimeElement::height() const noexcept { + return m_height; +} + +std::uint16_t CurrentTimeElement::fontIndex() const noexcept { + return m_fontIndex; +} + +std::uint16_t CurrentTimeElement::utcOffset() const noexcept { + return m_utcOffset; +} + +std::uint16_t CurrentTimeElement::flags() const noexcept { + return m_flags; +} + +CurrentTimeElement::~CurrentTimeElement() { +} + +ElementType CurrentTimeElement::elementType() const { + return ElementType::CurrentTime; +} + +std::size_t CurrentTimeElement::serializeTo(std::span target) const { + // FIXME: serialize +} + +void CurrentTimeElement::drawTo(OneBitBufferInterface* imageBuffer, std::size_t animationTick, std::int64_t currentTimestamp) { + // FIXME: draw +} + +std::expected, ParseError> CurrentTimeElement::parse(std::span& buffer) { + // FIXME: current time +} + +AlwaysDrawnSection::~AlwaysDrawnSection() { +} + +bool AlwaysDrawnSection::doesDrawOnFront() const noexcept { + return m_drawOnFront; +} + +bool AlwaysDrawnSection::doesDrawOnBack() const noexcept { + return m_drawOnBack; +} + +bool AlwaysDrawnSection::doesClearBeforeDrawing() const noexcept { + return m_clearBeforeDrawing; +} + +void AlwaysDrawnSection::setDrawOnFront(bool value) noexcept { + m_drawOnFront = value; +} + +void AlwaysDrawnSection::setDrawOnBack(bool value) noexcept { + m_drawOnBack = value; +} + +void AlwaysDrawnSection::setClearBeforeDrawing(bool value) noexcept { + m_clearBeforeDrawing = value; +} + +std::size_t AlwaysDrawnSection::elementCount() const noexcept { + return m_elements.size(); +} + +Element* AlwaysDrawnSection::elementAt(std::size_t index) const { + if (index < m_elements.size()) { + return m_elements[index].get(); + } else { + return nullptr; + } +} + +void AlwaysDrawnSection::appendElement(std::unique_ptr element) { + m_elements.push_back(std::move(element)); +} + +void AlwaysDrawnSection::insertElement(std::size_t index, std::unique_ptr element) { + if (index < m_elements.size()) { + m_elements.insert(m_elements.begin() + index, std::move(element)); + } else { + m_elements.push_back(std::move(element)); + } +} + +std::unique_ptr AlwaysDrawnSection::replaceElement(std::size_t index, std::unique_ptr element) { + std::unique_ptr result; + if (index < m_elements.size()) { + result = std::move(m_elements[index]); + m_elements[index] = std::move(element); + } + return result; +} + +std::unique_ptr AlwaysDrawnSection::eraseElement(std::size_t index) { + std::unique_ptr result; + if (index < m_elements.size()) { + result = std::move(m_elements[index]); + m_elements.erase(m_elements.begin() + index); + } + return result; +} + +SectionType AlwaysDrawnSection::sectionType() const { + return SectionType::AlwaysDrawn; +} + +std::size_t AlwaysDrawnSection::serializeTo(std::span target) const { + // FIXME: serialize +} + +std::expected, ParseError> AlwaysDrawnSection::parse(std::span& buffer) { + // FIXME: parse +} + +TimeBasedDrawnSection::~TimeBasedDrawnSection() { +} + +bool TimeBasedDrawnSection::doesDrawOnFront() const noexcept { + return m_drawOnFront; +} + +bool TimeBasedDrawnSection::doesDrawOnBack() const noexcept { + return m_drawOnBack; +} + +bool TimeBasedDrawnSection::doesClearBeforeDrawing() const noexcept { + return m_clearBeforeDrawing; +} + +void TimeBasedDrawnSection::setDrawOnFront(bool value) noexcept { + m_drawOnFront = value; +} + +void TimeBasedDrawnSection::setDrawOnBack(bool value) noexcept { + m_drawOnBack = value; +} + +void TimeBasedDrawnSection::setClearBeforeDrawing(bool value) noexcept { + m_clearBeforeDrawing = value; +} + +std::size_t TimeBasedDrawnSection::elementCount() const noexcept { + return m_elements.size(); +} + +Element* TimeBasedDrawnSection::elementAt(std::size_t index) const { + if (index < m_elements.size()) { + return m_elements[index].get(); + } else { + return nullptr; + } +} + +void TimeBasedDrawnSection::appendElement(std::unique_ptr element) { + m_elements.push_back(std::move(element)); +} + +void TimeBasedDrawnSection::insertElement(std::size_t index, std::unique_ptr element) { + if (index < m_elements.size()) { + m_elements.insert(m_elements.begin() + index, std::move(element)); + } else { + m_elements.push_back(std::move(element)); + } +} + +std::unique_ptr TimeBasedDrawnSection::replaceElement(std::size_t index, std::unique_ptr element) { + std::unique_ptr result; + if (index < m_elements.size()) { + result = std::move(m_elements[index]); + m_elements[index] = std::move(element); + } + return result; +} + +std::unique_ptr TimeBasedDrawnSection::eraseElement(std::size_t index) { + std::unique_ptr result; + if (index < m_elements.size()) { + result = std::move(m_elements[index]); + m_elements.erase(m_elements.begin() + index); + } + return result; +} + +std::int64_t TimeBasedDrawnSection::startTimestamp() const noexcept { + return m_startTimestamp; +} + +std::int64_t TimeBasedDrawnSection::endTimestamp() const noexcept { + return m_endTimestamp; +} + +void TimeBasedDrawnSection::setStartTimestamp(std::int64_t value) { + m_startTimestamp = value; +} + +void TimeBasedDrawnSection::setEndTimestamp(std::int64_t value) { + m_endTimestamp = value; +} + +SectionType TimeBasedDrawnSection::sectionType() const { + return SectionType::TimeBasedDrawn; +} + +std::size_t TimeBasedDrawnSection::serializeTo(std::span target) const { + // FIXME: serialize +} + +std::expected, ParseError> TimeBasedDrawnSection::parse(std::span& buffer) { + // FIXME: parse +} + +CustomFontSection::~CustomFontSection() { +} + +std::span CustomFontSection::fontData() const { + return std::span{m_fontData}; +} + +void CustomFontSection::setFontData(std::span fontData) { + m_fontData.resize(fontData.size()); + std::copy(fontData.begin(), fontData.end(), m_fontData.begin()); +} + +SectionType CustomFontSection::sectionType() const { + return SectionType::CustomFont; +} + +std::size_t CustomFontSection::serializeTo(std::span target) const { + // FIXME: serailize +} + +std::expected, ParseError> CustomFontSection::parse(std::span& buffer) { + // FIXME: parse +} + +std::size_t serializeFile(std::span& buffer, File const& file) { + // FIXME: serialize +} + +std::expected parseFile(std::span data) { + // FIXME: parse +} + } // namespace monoformat diff --git a/cpp/src/monoformat_structured.hpp b/cpp/src/monoformat_structured.hpp index 400ea43..e3a6436 100644 --- a/cpp/src/monoformat_structured.hpp +++ b/cpp/src/monoformat_structured.hpp @@ -331,7 +331,7 @@ struct AlwaysDrawnSection : public Section { void setClearBeforeDrawing(bool value) noexcept; std::size_t elementCount() const noexcept; - std::unique_ptr elementAt(std::size_t index) const; + Element* elementAt(std::size_t index) const; void appendElement(std::unique_ptr element); void insertElement(std::size_t index, std::unique_ptr element); @@ -363,17 +363,17 @@ struct TimeBasedDrawnSection : public Section { void setClearBeforeDrawing(bool value) noexcept; std::size_t elementCount() const noexcept; - std::unique_ptr elementAt(std::size_t index) const; + Element* elementAt(std::size_t index) const; void appendElement(std::unique_ptr element); void insertElement(std::size_t index, std::unique_ptr element); std::unique_ptr replaceElement(std::size_t index, std::unique_ptr element); std::unique_ptr eraseElement(std::size_t index); - std::uint64_t startTimestamp() const noexcept; - std::uint64_t endTimestamp() const noexcept; - void setStartTimestamp(std::uint64_t value); - void setEndTimestamp(std::uint64_t value); + std::int64_t startTimestamp() const noexcept; + std::int64_t endTimestamp() const noexcept; + void setStartTimestamp(std::int64_t value); + void setEndTimestamp(std::int64_t value); virtual SectionType sectionType() const override; virtual std::size_t serializeTo(std::span target) const override; @@ -382,8 +382,8 @@ struct TimeBasedDrawnSection : public Section { private: std::vector> m_elements; - std::uint64_t m_startTimestamp{}; - std::uint64_t m_endTimestamp{}; + std::int64_t m_startTimestamp{}; + std::int64_t m_endTimestamp{}; bool m_drawOnFront{true}; bool m_drawOnBack{true}; bool m_clearBeforeDrawing{true}; @@ -393,6 +393,9 @@ struct CustomFontSection : public Section { CustomFontSection() = default; virtual ~CustomFontSection() override; + std::span fontData() const; + void setFontData(std::span fontData); + virtual SectionType sectionType() const override; virtual std::size_t serializeTo(std::span target) const override; @@ -406,8 +409,8 @@ struct File { std::vector> sections; }; +extern std::size_t serializeFile(std::span& buffer, File const& file); extern std::expected parseFile(std::span data); -extern std::size_t serializeFile(std::span buffer); } // namespace monoformat