Network System 0.1.1
High-performance modular networking library for scalable client-server applications
Loading...
Searching...
No Matches
network_concepts.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2024, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
5#pragma once
6
21#include <concepts>
22#include <cstdint>
23#include <functional>
24#include <memory>
25#include <string>
26#include <system_error>
27#include <type_traits>
28#include <vector>
29
30// Note: common_system concepts are included via the parent concepts.h header
31// to avoid forward declaration conflicts. Do not include concepts.h here directly.
32
34
35// ============================================================================
36// Data Buffer Concepts
37// ============================================================================
38
55template <typename T>
56concept ByteBuffer = requires(const T t) {
57 { t.data() } -> std::convertible_to<const void*>;
58 { t.size() } -> std::convertible_to<std::size_t>;
59};
60
74template <typename T>
75concept MutableByteBuffer = ByteBuffer<T> && requires(T t, std::size_t n) {
76 { t.resize(n) };
77 { t.data() } -> std::convertible_to<void*>;
78};
79
80// ============================================================================
81// Callback Concepts
82// ============================================================================
83
99template <typename F>
101 std::invocable<F, const std::vector<uint8_t>&>;
102
115template <typename F>
116concept ErrorHandler = std::invocable<F, std::error_code>;
117
130template <typename F>
131concept ConnectionHandler = std::invocable<F>;
132
145template <typename F, typename Session>
146concept SessionHandler = std::invocable<F, std::shared_ptr<Session>>;
147
160template <typename F, typename Session>
162 std::invocable<F, std::shared_ptr<Session>, const std::vector<uint8_t>&>;
163
176template <typename F, typename Session>
178 std::invocable<F, std::shared_ptr<Session>, std::error_code>;
179
192template <typename F>
193concept DisconnectionHandler = std::invocable<F, const std::string&>;
194
207template <typename F>
208concept RetryCallback = std::invocable<F, std::size_t>;
209
210// ============================================================================
211// Network Component Concepts
212// ============================================================================
213
232template <typename T>
233concept NetworkClient = requires(T t, std::vector<uint8_t> data) {
234 { t.is_connected() } -> std::convertible_to<bool>;
235 { t.send_packet(std::move(data)) };
236 { t.stop_client() };
237};
238
256template <typename T>
257concept NetworkServer = requires(T t, unsigned short port) {
258 { t.start_server(port) };
259 { t.stop_server() };
260};
261
275template <typename T>
276concept NetworkSession = requires(T t) {
277 { t.get_session_id() } -> std::convertible_to<std::string>;
278 { t.start_session() };
279 { t.stop_session() };
280};
281
282// ============================================================================
283// Pipeline Concepts
284// ============================================================================
285
301template <typename T>
302concept DataTransformer = requires(T t, std::vector<uint8_t>& data) {
303 { t.transform(data) } -> std::convertible_to<bool>;
304};
305
319template <typename T>
321 DataTransformer<T> && requires(T t, std::vector<uint8_t>& data) {
322 { t.reverse_transform(data) } -> std::convertible_to<bool>;
323 };
324
325// ============================================================================
326// Duration Concepts
327// ============================================================================
328
342template <typename T>
343concept Duration = requires {
344 typename T::rep;
345 typename T::period;
346} && std::is_arithmetic_v<typename T::rep>;
347
348// ============================================================================
349// Integration with common_system concepts (when available)
350// ============================================================================
351// Note: Additional common_system integration concepts are defined in the
352// parent concepts.h header after proper include order is established.
353
354} // namespace kcenon::network::concepts
A type that can serve as a network data buffer.
A callback type for handling connection state changes.
A callback type for handling received data.
A type that can transform data (e.g., compression, encryption).
A callback type for handling disconnection events with session ID.
A type that represents a time duration.
A callback type for handling network errors.
A mutable byte buffer that can be resized.
A type that satisfies basic network client requirements.
A type that satisfies basic network server requirements.
A type that represents a network session.
A callback type for reconnection attempt notifications.
A transformer that supports both forward and reverse operations.
A callback type for handling data received on a specific session.
A callback type for handling errors on a specific session.
A callback type for handling session events with a session pointer.
C++20 concepts for compile-time type validation in network_system.