ForestHub SDK 0.1.0
C++14 LLM SDK for PC and embedded platforms
Loading...
Searching...
No Matches
console.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: AGPL-3.0-only
2// Copyright (c) 2026 ForestHub. All rights reserved.
3// For commercial licensing, visit https://github.com/ForestHubAI/fh-sdk
4
5#ifndef FORESTHUB_PLATFORM_CONSOLE_HPP
6#define FORESTHUB_PLATFORM_CONSOLE_HPP
7
10
11#include <cstdarg>
12#include <string>
13
15
16namespace foresthub {
17namespace platform {
18
24public:
25 virtual ~ConsoleInterface() = default;
26
29 virtual void Begin() = 0;
30
33 virtual bool Available() const noexcept = 0;
34
38 virtual char Read() = 0;
39
45 virtual std::string ReadLine(size_t max_length = 256, unsigned long timeout_ms = 0, bool echo = true) = 0;
46
52 virtual Optional<std::string> TryReadLine(size_t max_length = 256, bool echo = true) = 0;
53
55 virtual void ClearLineBuffer() = 0;
56
58 virtual void Write(const std::string& data) = 0;
59
63#if defined(__GNUC__) || defined(__clang__)
64 // GCC/Clang: Enable compile-time format string checking.
65 // Argument indices: 2 = format string (1 is implicit 'this'), 3 = first vararg
66 virtual void Printf(const char* format, ...) __attribute__((format(printf, 2, 3))) = 0;
67#else
68 virtual void Printf(const char* format, ...) = 0;
69#endif
70
72 virtual void Flush() noexcept = 0;
73};
74
75} // namespace platform
76} // namespace foresthub
77
78#endif // FORESTHUB_PLATFORM_CONSOLE_HPP
Abstract interface for console I/O.
Definition console.hpp:23
virtual Optional< std::string > TryReadLine(size_t max_length=256, bool echo=true)=0
Try to read a line without blocking.
virtual bool Available() const noexcept=0
Check if input data is available for reading.
virtual void Write(const std::string &data)=0
Write a string to the console.
virtual void Begin()=0
Initialize the console for I/O operations.
virtual char Read()=0
Read a single character.
virtual void Printf(const char *format,...)=0
Formatted output (printf-style).
virtual std::string ReadLine(size_t max_length=256, unsigned long timeout_ms=0, bool echo=true)=0
Read a line of input with optional timeout.
virtual void Flush() noexcept=0
Flush the output buffer (ensure all pending output is transmitted).
virtual void ClearLineBuffer()=0
Clear the internal line buffer, discarding any partially typed input.
Hardware abstraction layer: network, console, time, crypto, and GPIO interfaces.
Top-level namespace for the ForestHub SDK.
Minimal Optional<T> polyfill for C++14 compatibility.
Minimal Optional<T> polyfill for C++14 compatibility.
Definition optional.hpp:21