Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
CurveRegistry.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
7#include <PhosphorAnimation/phosphoranimation_export.h>
8
9#include <QJsonObject>
10#include <QString>
11#include <QStringList>
12
13#include <functional>
14#include <memory>
15
16namespace PhosphorAnimation {
17
25class PHOSPHORANIMATION_EXPORT CurveRegistry
26{
27public:
29 using Factory = std::function<std::shared_ptr<const Curve>(const QString& typeId, const QString& params)>;
30
32 using JsonFactory = std::function<std::shared_ptr<const Curve>(const QJsonObject& parameters)>;
33
36
38 bool registerFactory(const QString& typeId, Factory factory);
39
41 bool registerFactory(const QString& typeId, Factory factory, const QString& ownerTag);
42
44 bool registerFactory(const QString& typeId, Factory stringFactory, JsonFactory jsonFactory,
45 const QString& ownerTag);
46
48 bool unregisterFactory(const QString& typeId);
49
51 int unregisterByOwner(const QString& ownerTag);
52
55 std::shared_ptr<const Curve> create(const QString& spec) const;
56
58 std::shared_ptr<const Curve> tryCreate(const QString& spec) const;
59
61 std::shared_ptr<const Curve> tryCreateFromJson(const QString& typeId, const QJsonObject& parameters) const;
62
65 QStringList knownTypes() const;
66
68 bool has(const QString& typeId) const;
69
72 static bool isBuiltinTypeId(const QString& typeId);
73
74 CurveRegistry(const CurveRegistry&) = delete;
78
79private:
80 class Impl;
81 std::unique_ptr<Impl> m_impl;
82};
83
84} // namespace PhosphorAnimation
String-id <-> curve factory registry.
Definition CurveRegistry.h:26
bool registerFactory(const QString &typeId, Factory factory, const QString &ownerTag)
Register a tagged factory. Tagged entries are bulk-removable via unregisterByOwner.
CurveRegistry(CurveRegistry &&)=delete
bool has(const QString &typeId) const
True if typeId has a registered factory.
static bool isBuiltinTypeId(const QString &typeId)
True if typeId names a built-in factory (auto-registered by constructor).
std::shared_ptr< const Curve > create(const QString &spec) const
Parse spec ("typeId:params" or "x1,y1,x2,y2") into a curve.
bool registerFactory(const QString &typeId, Factory stringFactory, JsonFactory jsonFactory, const QString &ownerTag)
Register both string-form and JSON-parameter factories.
bool registerFactory(const QString &typeId, Factory factory)
Register an untagged factory for typeId. Replaces prior registration.
QStringList knownTypes() const
All registered typeIds, sorted alphabetically (a stable, deterministic order for membership checks; n...
CurveRegistry & operator=(CurveRegistry &&)=delete
CurveRegistry & operator=(const CurveRegistry &)=delete
std::function< std::shared_ptr< const Curve >(const QString &typeId, const QString &params)> Factory
String-form factory: receives typeId + parameter substring after the colon.
Definition CurveRegistry.h:29
int unregisterByOwner(const QString &ownerTag)
Remove every factory matching ownerTag. Empty tag is rejected.
std::shared_ptr< const Curve > tryCreateFromJson(const QString &typeId, const QJsonObject &parameters) const
Build a curve from typeId + JSON parameters. Returns nullptr on failure.
std::function< std::shared_ptr< const Curve >(const QJsonObject &parameters)> JsonFactory
JSON factory: receives parameter fields, returns curve or nullptr on validation failure.
Definition CurveRegistry.h:32
std::shared_ptr< const Curve > tryCreate(const QString &spec) const
Like create() but returns nullptr on any failure.
bool unregisterFactory(const QString &typeId)
Remove a previously-registered factory. No-op if not registered.
CurveRegistry(const CurveRegistry &)=delete
Definition AnimatedValue.h:31