KSeExpr  4.0.4.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 
16 namespace KSeExpr
17 {
20 {
21 public:
22  ControlSpec(const ExprNode &node)
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 
34 protected:
36  std::string _name;
38  int _start;
40  int _end;
41 };
42 
45 {
46 public:
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 
55 private:
57  double _min, _max;
59  double _val;
60 };
61 
64 {
65 public:
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 
74 private:
76  double _min, _max;
79 };
80 
82 template<class T> class ExprCurveAssignSpec : public ControlSpec
83 {
84 public:
86  std::string toString() const override;
87  static const ExprCurveAssignSpec *match(const ExprNode *node);
88 
89 private:
91  std::string _lookupText;
93  std::vector<typename Curve<T>::CV> _vec;
94 };
95 
96 class ExprStrSpec : public ControlSpec
97 {
98  enum Type { STRING, FILE, DIRECTORY };
99 
100 public:
102  ExprStrSpec(const ExprStrNode &node, const char *name, Type type)
103  : ControlSpec(node)
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 
113 private:
114  std::string _str;
116 };
117 
119 class SpecExaminer : public Examiner<true>
120 {
121 public:
122  SpecExaminer() = default;
123  ~SpecExaminer();
124  SpecExaminer &operator=(const SpecExaminer &) = default;
126  SpecExaminer(const SpecExaminer &) = default;
127  SpecExaminer(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 
146 private:
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=(ControlSpec &&)=default
ControlSpec & operator=(const ControlSpec &)=default
virtual ~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
ExprCurveAssignSpec(const ExprAssignNode &node)
Variable equals scalar control specification.
Definition: ControlSpec.h:45
static const ExprScalarAssignSpec * match(const ExprNode *node)
ExprScalarAssignSpec(const ExprAssignNode &node)
Definition: ControlSpec.cpp:78
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!
Definition: ControlSpec.h:102
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
ExprVectorAssignSpec(const ExprAssignNode &node)
Vec3d _val
Current Value.
Definition: ControlSpec.h:78
Examiner that builds a list of specs potentially used in widgets (for qdgui)
Definition: ControlSpec.h:120
SpecExaminer & operator=(SpecExaminer &&)=default
SpecExaminer(SpecExaminer &&)=default
void reset() override
Definition: ControlSpec.h:131
bool examine(const ExprNode *examinee) override
Definition: ControlSpec.cpp:21
std::vector< const ControlSpec * >::const_iterator end() const
Definition: ControlSpec.cpp:48
SpecExaminer & operator=(const SpecExaminer &)=default
SpecExaminer(const SpecExaminer &)=default
void post(const ExprNode *) override
Definition: ControlSpec.h:130
std::vector< const ControlSpec * > _specList
Definition: ControlSpec.h:147
const ControlSpec * spec(int i) const
Definition: ControlSpec.h:139
std::vector< const ControlSpec * >::const_iterator begin() const
Definition: ControlSpec.cpp:43