XPlor/libs/dsl/dslkeys.h

81 lines
2.7 KiB
C
Raw Normal View History

#ifndef DSLKEYS_H
#define DSLKEYS_H
#include <QString>
#include <QVariantMap>
// Internal keys used by the DSL runtime.
// These are set by the interpreter and consumed by the application.
// XScript authors interact with these via functions like set_name(), set_display(), etc.
enum class DslKey {
Type, // "_type" - parsed type name
Name, // "_name" - display name for tree
Display, // "_display" - category display override
Path, // "_path" - source file path
Ext, // "_ext" - file extension (lowercase)
Basename, // "_basename" - filename without extension
Preview, // "_preview" - preview data for viewers
Viewer, // "_viewer" - viewer type override
Hidden // "$hidden" - hide from tree
};
// Prefix for skip_tree markers: "$skip_tree_<varname>"
constexpr const char* kSkipTreePrefix = "$skip_tree_";
namespace DslKeys {
// Convert enum to string key
inline QString toString(DslKey key) {
switch (key) {
case DslKey::Type: return QStringLiteral("_type");
case DslKey::Name: return QStringLiteral("_name");
case DslKey::Display: return QStringLiteral("_display");
case DslKey::Path: return QStringLiteral("_path");
case DslKey::Ext: return QStringLiteral("_ext");
case DslKey::Basename: return QStringLiteral("_basename");
case DslKey::Preview: return QStringLiteral("_preview");
case DslKey::Viewer: return QStringLiteral("_viewer");
case DslKey::Hidden: return QStringLiteral("$hidden");
}
return QString();
}
// Helper to get value from QVariantMap
inline QVariant get(const QVariantMap& vars, DslKey key) {
return vars.value(toString(key));
}
// Helper to get string value
inline QString getString(const QVariantMap& vars, DslKey key) {
return vars.value(toString(key)).toString();
}
// Helper to check if key exists
inline bool contains(const QVariantMap& vars, DslKey key) {
return vars.contains(toString(key));
}
// Helper to set value
inline void set(QVariantMap& vars, DslKey key, const QVariant& value) {
vars[toString(key)] = value;
}
// Helper to check if a variable should be skipped in tree
inline bool hasSkipTree(const QVariantMap& vars, const QString& varName) {
return vars.contains(QString(kSkipTreePrefix) + varName);
}
// Helper to set skip_tree marker
inline void setSkipTree(QVariantMap& vars, const QString& varName) {
vars[QString(kSkipTreePrefix) + varName] = true;
}
// Check if this is an internal key (starts with _ or $)
inline bool isInternalKey(const QString& key) {
return key.startsWith('_') || key.startsWith('$');
}
} // namespace DslKeys
#endif // DSLKEYS_H