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
21class PHOSPHORANIMATION_EXPORT CurveRegistry
22{
23public:
25 using Factory = std::function<std::shared_ptr<const Curve>(const QString& typeId, const QString& params)>;
26
28 using JsonFactory = std::function<std::shared_ptr<const Curve>(const QJsonObject& parameters)>;
29
32
34 bool registerFactory(const QString& typeId, Factory factory);
35
37 bool registerFactory(const QString& typeId, Factory factory, const QString& ownerTag);
38
40 bool registerFactory(const QString& typeId, Factory stringFactory, JsonFactory jsonFactory,
41 const QString& ownerTag);
42
44 bool unregisterFactory(const QString& typeId);
45
47 int unregisterByOwner(const QString& ownerTag);
48
51 std::shared_ptr<const Curve> create(const QString& spec) const;
52
54 std::shared_ptr<const Curve> tryCreate(const QString& spec) const;
55
57 std::shared_ptr<const Curve> tryCreateFromJson(const QString& typeId, const QJsonObject& parameters) const;
58
60 QStringList knownTypes() const;
61
63 bool has(const QString& typeId) const;
64
67 static bool isBuiltinTypeId(const QString& typeId);
68
69 CurveRegistry(const CurveRegistry&) = delete;
73
74private:
75 class Impl;
76 std::unique_ptr<Impl> m_impl;
77};
78
79} // namespace PhosphorAnimation
String-id <-> curve factory registry.
Definition CurveRegistry.h:22
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 in insertion order.
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:25
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:28
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