libepaper 2.0.0
A C++23 library for controlling Waveshare e-paper displays on Raspberry Pi, featuring transparent sleep/wake management and a fluent builder API.
Loading...
Searching...
No Matches
Namespaces | Concepts
driver_concepts.hpp File Reference

C++20 concept defining the Driver interface contract. More...

#include "epaper/core/errors.hpp"
#include "epaper/drivers/driver.hpp"
#include <concepts>
#include <cstddef>
#include <expected>
#include <span>
Include dependency graph for driver_concepts.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

namespace  epaper
 

Concepts

concept  epaper::Driver
 

Detailed Description

C++20 concept defining the Driver interface contract.

Uses modern C++ concepts to specify the required interface for display drivers. Provides compile-time validation that driver implementations satisfy the contract.

Design Philosophy:

Concept-Based Polymorphism (C++20)
├─ Compile-Time Validation: Errors caught at instantiation, not runtime
├─ Zero Overhead: No vtables, no dynamic dispatch
├─ Duck Typing: If it walks like a driver and quacks like a driver...
└─ Template Constraints: Display<Driver> only compiles for valid drivers

Benefits Over Virtual Interfaces:

Required Driver Interface:

class MyDriver {
public:
// Lifecycle (returns std::expected<void, Error>)
auto init(DisplayMode mode) -> std::expected<void, Error>;
auto sleep() -> std::expected<void, Error>;
auto wake() -> std::expected<void, Error>;
// Drawing (returns std::expected<void, Error>)
auto clear() -> std::expected<void, Error>;
auto display(std::span<const std::byte> buffer) -> std::expected<void, Error>;
// Dimensions (const or static, returns size_t or convertible)
auto width() const -> std::size_t;
auto height() const -> std::size_t;
};

Movability Requirement:

Validation Example:

// Compile-time check
static_assert(Driver<EPD27>); // OK - EPD27 satisfies concept
static_assert(Driver<MockDriver>); // OK - MockDriver satisfies concept
// static_assert(Driver<int>); // ERROR - int doesn't satisfy Driver
// Use in template constraints
template <Driver D>
class Display { ... }; // Only accepts types satisfying Driver concept
See also
Display, driver_traits, EPD27, MockDriver