Skip to main content

Neuralyzer::Reflection

Neuralyzer::Reflection

Functions

Name
template <typename T >
rfl::Result< T >
parseJson(nlohmann::json const & json)
Convert nlohmann::json to reflect-cpp compatible format.
template <typename T >
nlohmann::json
toJson(T const & obj)
Convert reflected object to nlohmann::json.
template <typename T >
void
printFieldInfo()
Print reflection field information for debugging.
template <typename T >
std::string
generateSchema()
Generate JSON schema for a reflected type.
template <typename T >
std::optional< T >
tryParseWithErrors(nlohmann::json const & json, std::string const & context_name =““)
Try to parse JSON with reflected type, with detailed error reporting.

Functions Documentation

function parseJson

template <typename T >
rfl::Result< T > parseJson(
    nlohmann::json const & json
)

Convert nlohmann::json to reflect-cpp compatible format.

Parameters:

  • json The nlohmann::json object to parse

Template Parameters:

  • T The reflected type to parse into

Return: rfl::Result containing either the parsed object or an error

This helper bridges the gap between our existing nlohmann::json usage and reflect-cpp’s JSON parsing. It converts the JSON to a string and uses reflect-cpp’s parser to deserialize into a reflected type.

function toJson

template <typename T >
nlohmann::json toJson(
    T const & obj
)

Convert reflected object to nlohmann::json.

Parameters:

  • obj The object to serialize

Template Parameters:

  • T The reflected type to serialize

Return: nlohmann::json representation of the object

Useful for maintaining compatibility with existing code that expects nlohmann::json objects.

function printFieldInfo

template <typename T >
void printFieldInfo()

Print reflection field information for debugging.

Template Parameters:

  • T The reflected type to inspect

Useful for understanding what fields a reflected type has. Note: Field introspection is done at compile time in reflect-cpp. This is a placeholder for debugging output.

function generateSchema

template <typename T >
std::string generateSchema()

Generate JSON schema for a reflected type.

Template Parameters:

  • T The reflected type to generate schema for

Return: std::string JSON schema as a formatted string

This is extremely useful for:

  • Documentation generation
  • Validation
  • UI generation
  • Fuzz testing corpus generation

function tryParseWithErrors

template <typename T >
std::optional< T > tryParseWithErrors(
    nlohmann::json const & json,
    std::string const & context_name =""
)

Try to parse JSON with reflected type, with detailed error reporting.

Parameters:

  • json The nlohmann::json object to parse
  • context_name Optional context for error messages (e.g., “BinaryAnalogLoader”)

Template Parameters:

  • T The reflected type to parse into

Return: std::optional containing the parsed object if successful

This variant provides more user-friendly error messages by catching and formatting validation errors.


Updated on 2026-11-13 at 20:25:41 +0000