Sonde v1.1.0
Embeddable Model Context Protocol server for Qt applications
Loading...
Searching...
No Matches
Sonde::ObjectTree::anonymous_namespace{objecttree.cpp} Namespace Reference

Classes

struct  Registry
 Registered providers, in registration order. More...
struct  Segment
 One parsed segment of an object spec. More...

Functions

Registry & registry ()
 The process-wide provider registry.
template<typename List, typename Value>
void upsert (List &list, const QString &key, Value value)
 Replaces the entry for key, or appends one.
QLatin1StringView withoutQmlSuffix (QLatin1StringView name)
 name without the _QMLTYPE_<n> or _QML_<n> suffix Qt gives a QML type's class.
std::optional< Segment > parseSegment (const QString &text, QString *error)
 Parses one spec segment ("Class#name[prop=value]" and its parts).
bool matches (const QObject *o, const Segment &s)
 Whether o matches s (ignoring mnemonic ampersands in property values).
std::optional< QMetaEnum > metaEnumFor (QMetaType type)
 Finds the QMetaEnum for an enum or QFlags meta type.
QObject * findObject (const QString &spec, QString *errorMessage)
 find(), writing why nothing matched to errorMessage.
QJsonValue placeholderFor (QMetaType type)
 A placeholder for a value that can't be converted: "<TypeName>".
QJsonValue toJson (const QVariant &v, int depth)
 variantToJson() with the depth of nesting so far.
QJsonObject gadgetToJson (const QVariant &v, const QMetaObject *mo, int depth)
 The readable properties of a gadget, by name (values converted with toJson()).
std::optional< QJsonValue > geometryToJson (const QVariant &v)
 Geometry types as {x, y} / {width, height} / {x, y, width, height}; std::nullopt for other types.
auto metaEnumValue (int value)
 value as QMetaEnum takes it: quint64 since Qt 6.9, int before.
QJsonValue enumToJson (const QVariant &v)
 An enum or flags value as its key name(s), or its number if it has no key.
std::optional< QJsonValue > compositeToJson (const QVariant &v, int depth)
 A map, list or gadget converted element by element; std::nullopt for other types.
bool convertJson (const QJsonValue &json, QMetaType type, QVariant *out, QString *error)
 jsonToVariant(), writing the value to out and why it failed to error.
bool jsonToGadget (const QJsonObject &json, QMetaType type, QVariant *out, QString *error)
 jsonToVariant() for a gadget: a default-constructed type with each key of json written to the property of that name.
bool fail (QString *error, const QString &message)
 Stores message in error (which may be null) and returns false.
bool intField (const QJsonObject &o, const char *key, int *out, QString *error)
 Reads the number key of o as an int.
template<std::size_t N>
bool intFields (const QJsonObject &o, const std::array< const char *, N > &keys, std::array< int, N > *out, QString *error)
 Reads the int fields keys of o into out, in order.
std::optional< bool > jsonToGeometry (const QJsonObject &o, QMetaType type, QVariant *out, QString *error)
 jsonToVariant() for the geometry types; std::nullopt if type isn't one.
std::optional< bool > jsonToEnum (const QJsonValue &json, QMetaType type, QVariant *out, QString *error)
 jsonToVariant() for an enum or flags type given key name(s); std::nullopt if not applicable.
bool jsonToObjectPointer (const QJsonValue &json, QMetaType type, QVariant *out, QString *error)
 jsonToVariant() for a QObject pointer type, given an object spec or null.

Variables

constexpr int kMaxSearchNodes = 200000
 Safety limit on the number of objects one search visits.
constexpr int kMaxJsonDepth = 16
 How deep variantToJson() descends into lists, maps and gadgets; deeper values become "<TypeName>".

Function Documentation

◆ compositeToJson()

std::optional< QJsonValue > Sonde::ObjectTree::anonymous_namespace{objecttree.cpp}::compositeToJson ( const QVariant & v,
int depth )

A map, list or gadget converted element by element; std::nullopt for other types.

Elements are converted as they would be on their own (a list of gadgets, say), rather than to null. Any registered container converts to a QVariantMap or QVariantList.

◆ intField()

bool Sonde::ObjectTree::anonymous_namespace{objecttree.cpp}::intField ( const QJsonObject & o,
const char * key,
int * out,
QString * error )

Reads the number key of o as an int.

Returns
False, with error set, if it is outside int's range (converting it would be undefined behaviour).

◆ jsonToGadget()

bool Sonde::ObjectTree::anonymous_namespace{objecttree.cpp}::jsonToGadget ( const QJsonObject & json,
QMetaType type,
QVariant * out,
QString * error )

jsonToVariant() for a gadget: a default-constructed type with each key of json written to the property of that name.

Read-only properties are skipped, so what variantToJson() gives can be passed back; a key that names no property is an error.

◆ metaEnumFor()

std::optional< QMetaEnum > Sonde::ObjectTree::anonymous_namespace{objecttree.cpp}::metaEnumFor ( QMetaType type)

Finds the QMetaEnum for an enum or QFlags meta type.

Handles enums of classes and of Q_NAMESPACEs, and flags whose enumerator is registered under the flags name (Q_FLAG(Options) for enum Option).

◆ metaEnumValue()

auto Sonde::ObjectTree::anonymous_namespace{objecttree.cpp}::metaEnumValue ( int value)

value as QMetaEnum takes it: quint64 since Qt 6.9, int before.

Converting a negative value to quint64 sign-extends it, which Qt 6.9 expects.