RADLib
RADical C++ application framework
RADCore.h File Reference

Core RADLib primitives: events, event loops, timers, IO, JSON, settings, filesystem helpers, processes, threads, and value types. More...

#include <RADCore/RADLicenseGate.h>
#include <iostream>
#include <array>
#include <vector>
#include <functional>
#include <queue>
#include <mutex>
#include <map>
#include <chrono>
#include <thread>
#include <atomic>
#include <memory>
#include <algorithm>
#include <cstdint>
#include <sstream>
#include <shared_mutex>
#include <future>
#include <type_traits>
#include <optional>
#include <string>
#include <filesystem>
#include <variant>
#include <condition_variable>
#include <deque>
#include <unordered_map>
#include <exception>
#include <sys/types.h>
+ Include dependency graph for RADCore.h:

Go to the source code of this file.

Classes

class  RADCore::RADError
 Structured error object returned by RADResult and newer APIs. More...
 
class  RADCore::RADResult< T >
 Success-or-error return value for APIs that should not throw. More...
 
class  RADCore::RADResult< void >
 Void specialization for success-or-error operations. More...
 
class  RADCore::RADSpan< T >
 Non-owning contiguous view over T values. More...
 
class  RADCore::RADElapsedTimer
 Monotonic elapsed timer based on std::chrono::steady_clock. More...
 
class  RADCore::RADDeadlineTimer
 Deadline helper for timeout loops and cancellation-aware waits. More...
 
class  RADCore::RADCancellationToken
 Shared cancellation token passed to long-running tasks. More...
 
class  RADCore::RADCancellationSource
 Owner object used to request cancellation on associated tokens. More...
 
class  RADCore::RADVariant
 Small value container used by models, futures, settings, and database rows. More...
 
class  RADCore::RADDateTime
 UTC millisecond timestamp helper. More...
 
class  RADCore::RADUuid
 128-bit UUID helper. More...
 
class  RADCore::RADUrl
 Lightweight URL parser for scheme, host, port, path, query, and fragment. More...
 
class  RADCore::RADJsonValue
 JSON value supporting null, bool, number, string, array, and object. More...
 
class  RADCore::RADJsonDocument
 JSON document wrapper around a root RADJsonValue. More...
 
class  RADCore::RADSettings
 JSON-file-backed key/value settings helper. More...
 
struct  RADCore::FileSystem::DirectoryEntry
 Directory listing entry with basic metadata. More...
 
class  RADCore::RADTemporaryDirectory
 RAII temporary directory with optional auto-remove. More...
 
class  RADCore::RADTemporaryFile
 RAII temporary file with optional auto-remove. More...
 
class  RADCore::RADLockFile
 Advisory filesystem lock file. More...
 
struct  RADCore::ThreadAffinity
 Thread affinity snapshot for RADObject event delivery. More...
 
struct  RADCore::Internal::ExtractArgs< Ret(*)(Args...)>
 
struct  RADCore::ConnectionRecord
 Connection record tracked by RADObject for automatic receiver cleanup. More...
 
class  RADCore::Connection
 Explicit event connection handle. More...
 
struct  RADCore::Connection::State
 Shared connection state used by Event and Connection. More...
 
class  RADCore::RADObject
 Base class for event receivers, senders, and thread-affinity aware objects. More...
 
class  RADCore::EventLoop
 RADCore task event loop with locked and low-latency scheduling strategies. More...
 
class  RADCore::EventLoopHandle
 Weak posting handle for EventLoop tasks that may outlive the loop object. More...
 
class  RADCore::EventBackend
 Low-level raw handler collection used internally by typed Event. More...
 
class  RADCore::Event< void(Args...)>
 Typed event dispatcher. Use Event<void(Args...)> through RAD_EVENT. More...
 
struct  RADCore::Event< void(Args...)>::LiveHandler
 Live connected handler record. More...
 
class  RADCore::RADIODevice
 Abstract byte-oriented IO device similar to QIODevice. More...
 
class  RADCore::RADBuffer
 In-memory RADIODevice backed by a byte vector. More...
 
class  RADCore::RADFile
 File-backed RADIODevice. More...
 
class  RADCore::RADDataStream
 Binary serialization stream for RADIODevice. More...
 
class  RADCore::RADFileSystemWatcher
 inotify-backed filesystem watcher that emits on a RADCore EventLoop. More...
 
class  RADCore::RADFuture
 Shared future wrapper returning RADVariant results. More...
 
class  RADCore::RADFutureT< T >
 Typed shared future with optional continuation support. More...
 
class  RADCore::RADFutureT< void >
 Void typed future specialization. More...
 
class  RADCore::RADPromise< T >
 Typed promise that creates RADFutureT. More...
 
class  RADCore::RADPromise< void >
 Void promise specialization. More...
 
class  RADCore::RADThreadPool
 Simple worker thread pool that reports completion through RADFuture. More...
 
class  RADCore::RADAbstractItemModel
 Minimal abstract item model for UI/model integrations. More...
 
class  RADCore::RADStringListModel
 One-column string list implementation of RADAbstractItemModel. More...
 
class  RADCore::RADProcess
 Child process helper for stdout/stderr capture. More...
 
class  RADCore::RADPtyProcess
 PTY-backed process helper for terminal applications. More...
 
class  RADCore::Timer
 High-precision timer that emits timeout through a RADCore EventLoop. More...
 
class  RADCore::RADThread
 Thread object with an owned RADCore EventLoop. More...
 
struct  RADCore::Internal::EventBinder< Args >
 
struct  RADCore::Internal::TriggerHelper
 
class  RADCore::Internal::LogStream
 Streaming log proxy used by RADInfo() and RADDebug(). More...
 

Namespaces

 RADCore
 
 RADCore::FileSystem
 Filesystem helper namespace for paths, standard locations, MIME guesses, and text files.
 
 RADCore::Internal
 

Macros

#define RADEvents   public
 Marks a public event declaration block in RADObject-derived classes. More...
 
#define RADHandlers   public
 Marks a public handler declaration block in RADObject-derived classes. More...
 
#define RADInfo()   RADCore::Internal::LogStream(RADCore::LogLevel::INFO)
 Starts an INFO log stream; use like RADInfo() << "message". More...
 
#define RADDebug()   RADCore::Internal::LogStream(RADCore::LogLevel::DEBUG)
 Starts a DEBUG log stream; use like RADDebug() << "message". More...
 
#define RAD_EVENT(Name, Signature)   RADCore::Event<void Signature> Name
 Declares a typed RADCore event; example: RAD_EVENT(done, (int)). More...
 
#define RADCONNECT(Sender, RadEvent, Receiver, Class, RadEventHandler)    (Sender).RadEvent.connect(Receiver, &Class::RadEventHandler)
 Connects an event to a receiver handler using the receiver's thread affinity. More...
 
#define RADCONNECT_QUEUED(Sender, RadEvent, Loop, Receiver, Class, RadEventHandler)    (Sender).RadEvent.connect_queued(Loop, Receiver, &Class::RadEventHandler)
 Connects an event to a receiver handler by posting through an explicit event loop. More...
 
#define radtrig(RadEvent, ...)   RadEvent.raise(__VA_ARGS__)
 Raises an event with optional arguments. More...
 
#define rtrig   RADCore::Internal::TriggerHelper() <<
 Stream-style event trigger helper used as rtrig << event(args...). More...
 

Typedefs

using RADCore::RADByteSpan = RADSpan< uint8_t >
 Mutable byte span. More...
 
using RADCore::RADConstByteSpan = RADSpan< const uint8_t >
 Const byte span. More...
 

Enumerations

enum class  RADCore::OpenMode : uint32_t {
  RADCore::NotOpen = 0 , RADCore::ReadOnly = 1 << 0 , RADCore::WriteOnly = 1 << 1 , RADCore::ReadWrite = (1 << 0) | (1 << 1) ,
  RADCore::Append = 1 << 2 , RADCore::Truncate = 1 << 3 , RADCore::Text = 1 << 4
}
 Open mode flags shared by RADIODevice, RADFile, and RADBuffer. More...
 
enum class  RADCore::ByteOrder { RADCore::LittleEndian , RADCore::BigEndian }
 Byte order used by RADDataStream. More...
 
enum class  RADCore::DataStreamStatus { RADCore::Ok , RADCore::ReadPastEnd , RADCore::WriteFailed , RADCore::ReadFailed }
 Read/write status for RADDataStream. More...
 
enum class  RADCore::VariantType {
  RADCore::Invalid , RADCore::Bool , RADCore::Int64 , RADCore::Double ,
  RADCore::String , RADCore::ByteArray
}
 Runtime type tag for RADVariant. More...
 
enum class  RADCore::JsonType {
  RADCore::Null , RADCore::Bool , RADCore::Number , RADCore::String ,
  RADCore::Array , RADCore::Object
}
 JSON value type tag. More...
 
enum class  RADCore::FileSystem::StandardPath {
  RADCore::FileSystem::Home , RADCore::FileSystem::Desktop , RADCore::FileSystem::Documents , RADCore::FileSystem::Downloads ,
  RADCore::FileSystem::Config , RADCore::FileSystem::Data , RADCore::FileSystem::Cache , RADCore::FileSystem::Temp ,
  RADCore::FileSystem::Executable , RADCore::FileSystem::Current
}
 Standard platform path categories. More...
 
enum class  RADCore::FileSystem::DirectoryEntryType { RADCore::FileSystem::Unknown , RADCore::FileSystem::File , RADCore::FileSystem::Directory , RADCore::FileSystem::Symlink }
 Directory entry type. More...
 
enum class  RADCore::ProcessState { RADCore::NotRunning , RADCore::Running , RADCore::Finished , RADCore::FailedToStart }
 Process lifecycle state. More...
 
enum class  RADCore::LoopStrategy { RADCore::RADEVENT_LOCK , RADCore::RADEVENT_NOLOCK }
 Event loop scheduling backend. More...
 
enum class  RADCore::Priority : int { RADCore::LOW = 0 , RADCore::NORMAL = 1 , RADCore::HIGH = 2 }
 Event loop task priority. More...
 
enum class  RADCore::FileSystemEvent {
  RADCore::Created , RADCore::Modified , RADCore::Removed , RADCore::Moved ,
  RADCore::Overflow , RADCore::WatchLost , RADCore::Unknown
}
 File watcher event type. More...
 
enum class  RADCore::LogLevel { RADCore::INFO , RADCore::DEBUG }
 Logger severity level. More...
 

Functions

const char * RADCore::runtimeEdition ()
 Returns the edition used to build the loaded RADCore runtime library. More...
 
bool RADCore::runtimeRequiresLicenseKey ()
 Returns true when the loaded RADCore runtime expects a paid license key. More...
 
const char * RADCore::runtimeAuditStamp ()
 Returns a stable runtime audit stamp suitable for diagnostics. More...
 
constexpr OpenMode RADCore::operator| (OpenMode lhs, OpenMode rhs)
 Combines OpenMode flags. More...
 
constexpr OpenMode RADCore::operator& (OpenMode lhs, OpenMode rhs)
 Intersects OpenMode flags. More...
 
constexpr bool RADCore::hasOpenMode (OpenMode mode, OpenMode flag)
 Returns true when mode includes flag. More...
 
bool RADCore::FileSystem::exists (const std::string &path)
 Returns true when path exists. More...
 
bool RADCore::FileSystem::isFile (const std::string &path)
 Returns true when path is a regular file. More...
 
bool RADCore::FileSystem::isDirectory (const std::string &path)
 Returns true when path is a directory. More...
 
bool RADCore::FileSystem::createDirectories (const std::string &path)
 Creates path and missing parents. More...
 
bool RADCore::FileSystem::remove (const std::string &path)
 Removes file or directory path. More...
 
bool RADCore::FileSystem::copyFile (const std::string &source, const std::string &destination, bool overwrite=true)
 Copies a file from source to destination. More...
 
std::string RADCore::FileSystem::currentPath ()
 Returns current working directory. More...
 
std::string RADCore::FileSystem::tempDirectoryPath ()
 Returns system temporary directory. More...
 
std::string RADCore::FileSystem::standardPath (StandardPath path)
 Returns a standard platform path. More...
 
std::string RADCore::FileSystem::fileName (const std::string &path)
 Returns filename component of path. More...
 
std::string RADCore::FileSystem::extension (const std::string &path)
 Returns extension component of path. More...
 
std::string RADCore::FileSystem::parentPath (const std::string &path)
 Returns parent directory path. More...
 
std::vector< DirectoryEntry > RADCore::FileSystem::listEntries (const std::string &path, bool recursive=false)
 Lists directory entries, recursively when requested. More...
 
std::vector< std::string > RADCore::FileSystem::listDirectory (const std::string &path)
 Lists child paths in a directory. More...
 
std::string RADCore::FileSystem::mimeTypeForFile (const std::string &path)
 Guesses MIME type from file contents or extension. More...
 
std::optional< std::string > RADCore::FileSystem::readTextFile (const std::string &path)
 Reads a UTF-8/text file into a string. More...
 
bool RADCore::FileSystem::writeTextFile (const std::string &path, const std::string &text)
 Writes text to a file. More...
 
void RADCore::singleShot (int intervalMs, EventLoop &targetLoop, EventLoop::Task task)
 Posts task to targetLoop after intervalMs milliseconds. More...
 
template<typename F >
void RADCore::invoke (EventLoop &loop, F &&task)
 Posts task to loop. More...
 
template<typename F >
auto RADCore::invokeBlocking (EventLoop &loop, F &&task) -> std::invoke_result_t< F >
 Posts task to loop and blocks until the result is available. More...
 
void RADCore::initLogger ()
 Starts the background logging engine. More...
 
void RADCore::shutdownLogger ()
 Stops the background logging engine. More...
 

Variables

constexpr int RADCore::VersionMajor = 0
 Compile-time RADCore major version. More...
 
constexpr int RADCore::VersionMinor = 1
 Compile-time RADCore minor version. More...
 
constexpr LoopStrategy RADCore::RADEVENT_LOCK = LoopStrategy::RADEVENT_LOCK
 Mutex/condition-variable event loop backend. More...
 
constexpr LoopStrategy RADCore::RADEVENT_NOLOCK = LoopStrategy::RADEVENT_NOLOCK
 Low-latency bounded ring event loop backend. More...
 

Detailed Description

Core RADLib primitives: events, event loops, timers, IO, JSON, settings, filesystem helpers, processes, threads, and value types.

Macro Definition Documentation

◆ RAD_EVENT

#define RAD_EVENT (   Name,
  Signature 
)    RADCore::Event<void Signature> Name

Declares a typed RADCore event; example: RAD_EVENT(done, (int)).

◆ RADCONNECT

#define RADCONNECT (   Sender,
  RadEvent,
  Receiver,
  Class,
  RadEventHandler 
)     (Sender).RadEvent.connect(Receiver, &Class::RadEventHandler)

Connects an event to a receiver handler using the receiver's thread affinity.

◆ RADCONNECT_QUEUED

#define RADCONNECT_QUEUED (   Sender,
  RadEvent,
  Loop,
  Receiver,
  Class,
  RadEventHandler 
)     (Sender).RadEvent.connect_queued(Loop, Receiver, &Class::RadEventHandler)

Connects an event to a receiver handler by posting through an explicit event loop.

◆ RADDebug

Starts a DEBUG log stream; use like RADDebug() << "message".

◆ RADEvents

#define RADEvents   public

Marks a public event declaration block in RADObject-derived classes.

◆ RADHandlers

#define RADHandlers   public

Marks a public handler declaration block in RADObject-derived classes.

◆ RADInfo

Starts an INFO log stream; use like RADInfo() << "message".

◆ radtrig

#define radtrig (   RadEvent,
  ... 
)    RadEvent.raise(__VA_ARGS__)

Raises an event with optional arguments.

◆ rtrig

#define rtrig   RADCore::Internal::TriggerHelper() <<

Stream-style event trigger helper used as rtrig << event(args...).