Skip to content

File LineCurveVertexCache.hpp

File List > QAccelPlot > src > QAccelPlot > series > LineCurveVertexCache.hpp

Go to the documentation of this file

//
// SPDX-FileCopyrightText: 2026 Michal Grabarczyk
// SPDX-License-Identifier: GPL-3.0-only WITH Universal-FOSS-exception-1.0
//
// This file is also available under a separate commercial license.
// See COMMERCIAL-LICENSING.md for contact information.
//
#pragma once

#include <cstddef>
#include <functional>
#include <vector>

namespace QAccelPlot {

class LineCurveVertexCache final {
public:
    enum class Layout { None, Line, Points };

    using Writer = std::function<void(std::vector<char>& bytes, int firstPoint)>;

    void update(Layout layout, int pointCount, std::size_t bytesPerPoint, const Writer& writer);

    [[nodiscard]] bool isReusableForDataChange(Layout requiredLayout, int pointCount) const noexcept;

    void invalidate() noexcept;

    void clear() noexcept;

    [[nodiscard]] const std::vector<char>* data() const noexcept;

    [[nodiscard]] const std::vector<char>& bytes() const noexcept;

    [[nodiscard]] bool valid() const noexcept;

    [[nodiscard]] Layout layout() const noexcept;

    [[nodiscard]] int pointCount() const noexcept;

private:
    std::vector<char> bytes_;
    bool valid_{false};
    Layout layout_{Layout::None};
    int pointCount_{0};
    std::size_t bytesPerPoint_{0};
};

} // namespace QAccelPlot