ngscopeclient v0.2
Loading...
Searching...
No Matches
InputConstraint.h
Go to the documentation of this file.
1/***********************************************************************************************************************
2* *
3* libscopehal *
4* *
5* Copyright (c) 2012-2026 Andrew D. Zonenberg and contributors *
6* All rights reserved. *
7* *
8* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
9* following conditions are met: *
10* *
11* * Redistributions of source code must retain the above copyright notice, this list of conditions, and the *
12* following disclaimer. *
13* *
14* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the *
15* following disclaimer in the documentation and/or other materials provided with the distribution. *
16* *
17* * Neither the name of the author nor the names of any contributors may be used to endorse or promote products *
18* derived from this software without specific prior written permission. *
19* *
20* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
21* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
22* THE AUTHORS BE HELD LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
23* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
24* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
25* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
26* POSSIBILITY OF SUCH DAMAGE. *
27* *
28***********************************************************************************************************************/
29
36#ifndef InputConstraint_h
37#define InputConstraint_h
38
39#include <type_traits>
40
41#ifdef __GNUC__
42#include <cxxabi.h>
43#endif
44
51{
52public:
54 virtual ~InputConstraint();
55
57 virtual bool Check(StreamDescriptor source) =0;
58
60 virtual std::string ToString() =0;
61
62protected:
63 FlowGraphNode* m_sink;
64
65 std::string StreamTypeToString(Stream::StreamType type);
66};
67
69
76{
77public:
78 InputConstraintAND(FlowGraphNode* sink, std::initializer_list<std::shared_ptr<InputConstraint> > constraints)
80 , m_constraints(constraints)
81 {}
82
83 //Match if all children are satisfied
84 virtual bool Check(StreamDescriptor source) override
85 {
86 for(auto p : m_constraints)
87 {
88 if(!p->Check(source))
89 return false;
90 }
91 return true;
92 }
93
94 virtual std::string ToString() override
95 {
96 std::string ret = "";
97 for(auto p : m_constraints)
98 {
99 if(!ret.empty())
100 ret += "\n";
101 ret += std::string("• ") + p->ToString();
102 }
103 return ret;
104 }
105
106protected:
107 std::vector< std::shared_ptr<InputConstraint> > m_constraints;
108};
109
111
118{
119public:
122 , m_type(stype)
123 {}
124
125 virtual bool Check(StreamDescriptor source) override
126 { return (m_type == source.GetType() ); }
127
128 virtual std::string ToString() override
129 { return std::string("Stream type is ") + StreamTypeToString(m_type); }
130
131protected:
132 Stream::StreamType m_type;
133};
134
136
143{
144public:
147 {}
148
149 virtual bool Check(StreamDescriptor source) override
150 {
151 //Input must be non-null and sparse
152 auto pdata = dynamic_cast<SparseWaveformBase*>(source.GetData());
153 if(!pdata)
154 return false;
155
156 return (m_type == source.GetType() );
157 }
158
159 virtual std::string ToString() override
160 { return std::string("Stream type is sparse ") + StreamTypeToString(m_type); }
161};
162
164
170template<class T>
172{
173public:
176 {}
177
178 virtual bool Check(StreamDescriptor source) override
179 {
180 //Waveform type must be a waveform
181 static_assert(std::is_base_of<WaveformBase, T>::value == true);
182
183 //Input must be non-null
184 auto pdata = source.GetData();
185 if(!pdata)
186 return false;
187
188 //Make sure it matches what we expect
189 return ( typeid(*pdata) == typeid(T) );
190 }
191
192 virtual std::string ToString() override
193 {
194 std::string stype;
195
196 //separate path here needed since GCC returns mangled name
197 #ifdef __GNUC__
198 int status;
199 auto tmp = abi::__cxa_demangle(typeid(T).name(), nullptr, nullptr, &status);
200 stype = std::string(tmp);
201 free(tmp);
202 #else
203 stype = typeid(T).name();
204 #endif
205
206 return std::string("Stream type is ") + stype;
207 }
208};
209
211
217template<class T>
219{
220public:
223 {}
224
225 virtual bool Check(StreamDescriptor source) override
226 {
227 //Node type must be a graph node
228 static_assert(std::is_base_of<FlowGraphNode, T>::value == true);
229
230 //Input must be non-null
231 auto chan = source.m_channel;
232 if(!chan)
233 return false;
234
235 //Make sure it matches what we expect
236 return ( typeid(*chan) == typeid(T) );
237 }
238
239 virtual std::string ToString() override
240 {
241 std::string stype;
242
243 //separate path here needed since GCC returns mangled name
244 #ifdef __GNUC__
245 int status;
246 auto tmp = abi::__cxa_demangle(typeid(T).name(), nullptr, nullptr, &status);
247 stype = std::string(tmp);
248 free(tmp);
249 #else
250 stype = typeid(T).name();
251 #endif
252
253 return std::string("Source block type is ") + stype;
254 }
255};
256
258
265{
266public:
267 InputConstraintStreamTypes(FlowGraphNode* sink, std::initializer_list<Stream::StreamType> stypes)
269 , m_types(stypes)
270 {}
271
272 virtual bool Check(StreamDescriptor source) override
273 {
274 for(auto t : m_types)
275 {
276 if(t == source.GetType())
277 return true;
278 }
279 return false;
280 }
281
282 virtual std::string ToString() override;
283
284protected:
285 std::vector<Stream::StreamType> m_types;
286};
287
289
298{
299public:
302 , m_width(width)
303 {}
304
305 virtual bool Check(StreamDescriptor source) override
306 { return (m_width == source.GetDigitalWidth() ); }
307
308 virtual std::string ToString() override
309 { return std::string("Digital signal width is ") + std::to_string(m_width); }
310
311protected:
312 size_t m_width;
313};
314
316
323{
324public:
327 , m_unit(unit)
328 {}
329
330 virtual bool Check(StreamDescriptor source) override
331 { return (m_unit == source.GetXAxisUnits() ); }
332
333 virtual std::string ToString() override
334 { return std::string("X axis unit is ") + m_unit.ToStringLong(); }
335
336protected:
337 Unit m_unit;
338};
339
341
348{
349public:
352 , m_unit(unit)
353 {}
354
355 virtual bool Check(StreamDescriptor source) override
356 { return (m_unit == source.GetYAxisUnits() ); }
357
358 virtual std::string ToString() override
359 { return std::string("Y axis unit is ") + m_unit.ToStringLong(); }
360
361protected:
362 Unit m_unit;
363};
364
365#endif
Definition AcceleratorBuffer.h:204
Abstract base class for a node in the signal flow graph.
Definition FlowGraphNode.h:81
A set of constraints, all of which must be satisfied for the group to match.
Definition InputConstraint.h:76
virtual std::string ToString() override
Convert this constraint to a string.
Definition InputConstraint.h:94
virtual bool Check(StreamDescriptor source) override
Checks if the given input satisfies the constraint.
Definition InputConstraint.h:84
Match if the input filter is of the correct class type.
Definition InputConstraint.h:219
virtual bool Check(StreamDescriptor source) override
Checks if the given input satisfies the constraint.
Definition InputConstraint.h:225
virtual std::string ToString() override
Convert this constraint to a string.
Definition InputConstraint.h:239
Match if the input's digital width matches the requested value.
Definition InputConstraint.h:298
virtual std::string ToString() override
Convert this constraint to a string.
Definition InputConstraint.h:308
virtual bool Check(StreamDescriptor source) override
Checks if the given input satisfies the constraint.
Definition InputConstraint.h:305
Match if the input is of the correct stream type, and sparse.
Definition InputConstraint.h:143
virtual bool Check(StreamDescriptor source) override
Checks if the given input satisfies the constraint.
Definition InputConstraint.h:149
virtual std::string ToString() override
Convert this constraint to a string.
Definition InputConstraint.h:159
Match if the input is of the correct stream type.
Definition InputConstraint.h:118
virtual bool Check(StreamDescriptor source) override
Checks if the given input satisfies the constraint.
Definition InputConstraint.h:125
virtual std::string ToString() override
Convert this constraint to a string.
Definition InputConstraint.h:128
Match if the input is one of a list of stream types.
Definition InputConstraint.h:265
virtual std::string ToString() override
Convert this constraint to a string.
Definition InputConstraint.cpp:75
virtual bool Check(StreamDescriptor source) override
Checks if the given input satisfies the constraint.
Definition InputConstraint.h:272
Match if the input is of the correct class type.
Definition InputConstraint.h:172
virtual bool Check(StreamDescriptor source) override
Checks if the given input satisfies the constraint.
Definition InputConstraint.h:178
virtual std::string ToString() override
Convert this constraint to a string.
Definition InputConstraint.h:192
Match if the input's X axis unit is a specific value.
Definition InputConstraint.h:323
virtual std::string ToString() override
Convert this constraint to a string.
Definition InputConstraint.h:333
virtual bool Check(StreamDescriptor source) override
Checks if the given input satisfies the constraint.
Definition InputConstraint.h:330
Match if the input's Y axis unit is a specific value.
Definition InputConstraint.h:348
virtual std::string ToString() override
Convert this constraint to a string.
Definition InputConstraint.h:358
virtual bool Check(StreamDescriptor source) override
Checks if the given input satisfies the constraint.
Definition InputConstraint.h:355
Base class for constraints on inputs.
Definition InputConstraint.h:51
virtual bool Check(StreamDescriptor source)=0
Checks if the given input satisfies the constraint.
virtual std::string ToString()=0
Convert this constraint to a string.
Base class for waveforms with nonuniform sample rate.
Definition Waveform.h:293
Descriptor for a single stream coming off a channel.
Definition StreamDescriptor.h:47
StreamType
General data type stored in a stream.
Definition Stream.h:57
A unit of measurement, plus conversion to pretty-printed output.
Definition Unit.h:59
std::string ToStringLong() const
Converts this unit to a string in long format.
Definition Unit.cpp:142