ForestHub SDK 0.1.0
C++14 LLM SDK for PC and embedded platforms
Loading...
Searching...
No Matches
foresthub::util Namespace Reference

Utility types: Optional polyfill, JSON Schema normalization, Ticker. More...

Classes

class  Ticker
 Unified timing class for periodic, one-shot, and calendar-aligned scheduling. More...

Functions

json NormalizeSchema (json schema)
 Wraps a minimal properties-only JSON object into a full JSON Schema.
std::string StrPrintf (const char *fmt,...)
 Builds a std::string using printf-style formatting.

Detailed Description

Utility types: Optional polyfill, JSON Schema normalization, Ticker.

Function Documentation

◆ NormalizeSchema()

json foresthub::util::NormalizeSchema ( json schema)

Wraps a minimal properties-only JSON object into a full JSON Schema.

Handles four input formats:

  • Empty/null → returns empty object.
  • Already has "type" → returned unchanged.
  • Has "properties" but no "type" → adds "type": "object".
  • Otherwise → treated as a bare property map, wrapped into {"type":"object","properties":...}.
    Parameters
    schemaRaw JSON schema in any of the supported formats.
    Returns
    Normalized JSON Schema object.

◆ StrPrintf()

std::string foresthub::util::StrPrintf ( const char * fmt,
... )
inline

Builds a std::string using printf-style formatting.

Uses a two-pass vsnprintf approach: first measures the exact output size, then allocates once and writes. This avoids heap fragmentation from repeated std::string concatenation on memory-constrained embedded devices.

Warning
The format string must not contain untrusted user input. Pass user data as arguments, never as the format string.
Parameters
fmtprintf-style format string
...arguments matching the format specifiers
Returns
formatted std::string (empty on encoding error)