KSeExpr 6.0.0.0
ControlSpec.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2011-2019 Disney Enterprises, Inc.
2// SPDX-License-Identifier: LicenseRef-Apache-2.0
3// SPDX-FileCopyrightText: 2020 L. E. Segovia <amy@amyspark.me>
4// SPDX-License-Identifier: GPL-3.0-or-later
5
6#pragma once
7
8#include <cstdio>
9#include <string>
10#include <vector>
11
12#include <KSeExpr/Curve.h>
13#include <KSeExpr/ExprNode.h>
14#include <KSeExpr/ExprWalker.h>
15
16namespace KSeExpr
17{
20{
21public:
23 : _start(node.startPos())
24 , _end(node.endPos()) {};
25 virtual ~ControlSpec() = default;
26 ControlSpec &operator=(const ControlSpec &) = default;
28 ControlSpec(const ControlSpec &) = default;
29 ControlSpec(ControlSpec &&) = default;
30
32 virtual std::string toString() const = 0;
33
34protected:
36 std::string _name;
38 int _start;
40 int _end;
41};
42
45{
46public:
48 std::string toString() const override;
49 inline double value() const
50 {
51 return _val;
52 };
53 static const ExprScalarAssignSpec *match(const ExprNode *node);
54
55private:
57 double _min, _max;
59 double _val;
60};
61
64{
65public:
67 std::string toString() const override;
68 inline const Vec3d &value() const
69 {
70 return _val;
71 };
72 static const ExprVectorAssignSpec *match(const ExprNode *node);
73
74private:
76 double _min, _max;
79};
80
82template<class T> class ExprCurveAssignSpec : public ControlSpec
83{
84public:
86 std::string toString() const override;
87 static const ExprCurveAssignSpec *match(const ExprNode *node);
88
89private:
91 std::string _lookupText;
93 std::vector<typename Curve<T>::CV> _vec;
94};
95
97{
99
100public:
102 ExprStrSpec(const ExprStrNode &node, const char *name, Type type)
104 , _str(node.str())
105 , _type(type)
106 {
107 _name = name;
108 }
109
110 std::string toString() const override;
111 static const ExprStrSpec *match(const ExprNode *node);
112
113private:
114 std::string _str;
116};
117
119class SpecExaminer : public Examiner<true>
120{
121public:
122 SpecExaminer() = default;
126 SpecExaminer(const SpecExaminer &) = default;
128
129 bool examine(const ExprNode *examinee) override;
130 void post(const ExprNode *) override {};
131 void reset() override
132 {
133 _specList.clear();
134 };
135 inline int length() const
136 {
137 return _specList.size();
138 };
139 inline const ControlSpec *spec(int i) const
140 {
141 return _specList[i];
142 };
143 inline std::vector<const ControlSpec *>::const_iterator begin() const;
144 inline std::vector<const ControlSpec *>::const_iterator end() const;
145
146private:
147 std::vector<const ControlSpec *> _specList;
148};
149} // namespace KSeExpr
Generic Expression control specification.
Definition ControlSpec.h:20
std::string _name
Name of control.
Definition ControlSpec.h:36
int _start
Start position of text in original source.
Definition ControlSpec.h:38
ControlSpec & operator=(const ControlSpec &)=default
virtual ~ControlSpec()=default
ControlSpec & operator=(ControlSpec &&)=default
virtual std::string toString() const =0
Generates a replacement string based on changes to the spec.
int _end
End position of text in original source.
Definition ControlSpec.h:40
ControlSpec(const ExprNode &node)
Definition ControlSpec.h:22
ControlSpec(const ControlSpec &)=default
ControlSpec(ControlSpec &&)=default
Node that compute a local variable assignment.
Definition ExprNode.h:414
Curve assignment expression. Assignment of curve to a variable.
Definition ControlSpec.h:83
std::string toString() const override
Generates a replacement string based on changes to the spec.
static const ExprCurveAssignSpec * match(const ExprNode *node)
std::string _lookupText
Lookup subexpression text.
Definition ControlSpec.h:91
std::vector< typename Curve< T >::CV > _vec
Control points of curve spline.
Definition ControlSpec.h:93
Variable equals scalar control specification.
Definition ControlSpec.h:45
static const ExprScalarAssignSpec * match(const ExprNode *node)
double _min
Range of values.
Definition ControlSpec.h:57
std::string toString() const override
Generates a replacement string based on changes to the spec.
double _val
Current Value.
Definition ControlSpec.h:59
Node that stores a string.
Definition ExprNode.h:632
static const ExprStrSpec * match(const ExprNode *node)
ExprStrSpec(const ExprStrNode &node, const char *name, Type type)
Takes name and type comments and takes ownership of them!
std::string toString() const override
Generates a replacement string based on changes to the spec.
Variable equals vector control specification.
Definition ControlSpec.h:64
std::string toString() const override
Generates a replacement string based on changes to the spec.
static const ExprVectorAssignSpec * match(const ExprNode *node)
double _min
Range of values.
Definition ControlSpec.h:76
const Vec3d & value() const
Definition ControlSpec.h:68
Vec3d _val
Current Value.
Definition ControlSpec.h:78
Examiner that builds a list of specs potentially used in widgets (for qdgui)
SpecExaminer & operator=(const SpecExaminer &)=default
std::vector< constControlSpec * >::const_iterator begin() const
SpecExaminer(SpecExaminer &&)=default
const ControlSpec * spec(int i) const
void reset() override
bool examine(const ExprNode *examinee) override
std::vector< constControlSpec * >::const_iterator end() const
SpecExaminer(const SpecExaminer &)=default
void post(const ExprNode *) override
std::vector< const ControlSpec * > _specList
SpecExaminer & operator=(SpecExaminer &&)=default