ngscopeclient v0.2.1
Loading...
Searching...
No Matches
FilterParameter.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
37#ifndef FilterParameter_h
38#define FilterParameter_h
39
45{
46public:
47
48 enum disparity_t
49 {
50 POSITIVE,
51 NEGATIVE,
52 ANY
53 } disparity;
54
55 enum type_t
56 {
57 KSYMBOL,
58 DSYMBOL,
59 DONTCARE
60 } ktype;
61
63 : disparity(ANY)
64 , ktype(DONTCARE)
65 , value(0)
66 {}
67
68 T8B10BSymbol(T8B10BSymbol::disparity_t d, T8B10BSymbol::type_t t, uint8_t v)
69 : disparity(d)
70 , ktype(t)
71 , value(v)
72 {}
73
74 uint8_t value;
75};
76
86{
87public:
88
93 {
94 TYPE_FLOAT, //32-bit floating point number
95 TYPE_INT, //64-bit integer
96 TYPE_BOOL, //boolean value
97 TYPE_FILENAME, //file path
98 TYPE_ENUM, //enumerated constant
99 TYPE_STRING, //arbitrary string
100 TYPE_8B10B_PATTERN //8B/10B pattern
101 };
102
103 FilterParameter(ParameterTypes type = FilterParameter::TYPE_FLOAT, Unit unit = Unit(Unit::UNIT_FS));
104
106
107 void ParseString(const std::string& str, bool useDisplayLocale = true);
108 std::string ToString(bool useDisplayLocale = true, int sigfigs = -1) const;
109
113 bool GetBoolVal() const
114 { return (m_intval != 0); }
115
120 { return m_intval; }
121
125 template<class T>
126 T GetEnumVal() const
127 {
128 //Make sure it's a valid enum member
129 //If not, return the first valid value
130 if(m_reverseEnumMap.find(m_intval) == m_reverseEnumMap.end())
131 {
132 LogWarning("Attempted to convert value %" PRIi64 " to a %s but it is not a legal enum member\n",
133 m_intval,
134 typeid(T).name());
135 return static_cast<T>(m_reverseEnumMap.begin()->first);
136 }
137
138 return static_cast<T>(m_intval);
139 }
140
144 float GetFloatVal() const
145 { return m_floatval; }
146
150 const std::vector<T8B10BSymbol>& Get8B10BPattern()
151 { return m_8b10bPattern; }
152
156 const std::string& GetFileName() const
157 { return m_string; }
158
159 void SetBoolVal(bool b);
160 void SetIntVal(int64_t i);
161 void SetFloatVal(float f);
162 void SetStringVal(const std::string& f);
163 void SetFileName(const std::string& f);
164 void Set8B10BPattern(const std::vector<T8B10BSymbol>& pattern);
165
170 { return m_type; }
171
175 Unit GetUnit() const
176 { return m_unit; }
177
182 { m_unit = u; }
183
184 //File filters for TYPE_FILENAME (otherwise ignored)
185 std::string m_fileFilterMask;
186 std::string m_fileFilterName;
187
188 //Specifies TYPE_FILENAME is an output
189 bool m_fileIsOutput;
190
194 void AddEnumValue(const std::string& name, int value)
195 {
196 m_forwardEnumMap[name] = value;
197 m_reverseEnumMap[value] = name;
198 m_enumSignal.emit();
199 }
200
204 void GetEnumValues(std::vector<std::string>& values)
205 {
206 for(auto it : m_forwardEnumMap)
207 values.push_back(it.first);
208 }
209
214 {
215 m_forwardEnumMap.clear();
216 m_reverseEnumMap.clear();
217 m_enumSignal.emit();
218 }
219
220 void Reinterpret();
221
225 sigc::signal<void()> signal_changed()
226 { return m_changeSignal; }
227
231 sigc::signal<void()> signal_enums_changed()
232 { return m_enumSignal; }
233
241 void MarkHidden(bool hidden = true)
242 { m_hidden = hidden; }
243
247 bool IsHidden()
248 { return m_hidden; }
249
257 { m_readOnly = true; }
258
263 { return m_readOnly; }
264
265protected:
266 ParameterTypes m_type;
267
268 sigc::signal<void()> m_changeSignal;
269 sigc::signal<void()> m_enumSignal;
270
271 Unit m_unit;
272
273 std::map<std::string, int> m_forwardEnumMap;
274 std::map<int, std::string> m_reverseEnumMap;
275
276 std::vector<T8B10BSymbol> m_8b10bPattern;
277
278 int64_t m_intval;
279 float m_floatval;
280 std::string m_string;
281
282 bool m_hidden;
283 bool m_readOnly;
284};
285
286#endif
Definition AcceleratorBuffer.h:204
A parameter to a filter.
Definition FilterParameter.h:86
sigc::signal< void()> signal_enums_changed()
Signal emitted every time the list of enumeration values changes.
Definition FilterParameter.h:231
void MarkReadOnly()
Marks this parameter as read-only in the GUI.
Definition FilterParameter.h:256
bool GetBoolVal() const
Returns the value of the parameter interpreted as a boolean.
Definition FilterParameter.h:113
const std::vector< T8B10BSymbol > & Get8B10BPattern()
Access to the underlying pattern.
Definition FilterParameter.h:150
void SetIntVal(int64_t i)
Sets the parameter to an integer value.
Definition FilterParameter.cpp:307
bool IsReadOnly()
Checks if this parameter should be read-only in the GUI.
Definition FilterParameter.h:262
bool IsHidden()
Checks if this parameter should be hidden in the GUI.
Definition FilterParameter.h:247
ParameterTypes GetType() const
Returns the type of the parameter.
Definition FilterParameter.h:169
int64_t GetIntVal() const
Returns the value of the parameter interpreted as an integer.
Definition FilterParameter.h:119
ParameterTypes
Types of data a parameter can store.
Definition FilterParameter.h:93
T GetEnumVal() const
Returns the value of the parameter interpreted as an enum.
Definition FilterParameter.h:126
const std::string & GetFileName() const
Returns the value of the parameter interpreted as a file path.
Definition FilterParameter.h:156
void AddEnumValue(const std::string &name, int value)
Adds a (name, value) pair to a TYPE_ENUM parameter.
Definition FilterParameter.h:194
void ClearEnumValues()
Clears the list of enumerated values for a TYPE_ENUM parameter.
Definition FilterParameter.h:213
sigc::signal< void()> signal_changed()
Signal emitted every time the parameter's value changes.
Definition FilterParameter.h:225
void SetFloatVal(float f)
Sets the parameter to a floating point value.
Definition FilterParameter.cpp:323
void SetStringVal(const std::string &f)
Sets the parameter to a string.
Definition FilterParameter.cpp:336
void SetBoolVal(bool b)
Sets the parameter to a boolean value.
Definition FilterParameter.cpp:294
void GetEnumValues(std::vector< std::string > &values)
Gets a list of valid enumerated parameter names for a TYPE_ENUM parameter.
Definition FilterParameter.h:204
void MarkHidden(bool hidden=true)
Marks this parameter to be hidden from the GUI.
Definition FilterParameter.h:241
void SetFileName(const std::string &f)
Sets the parameter to a file path.
Definition FilterParameter.cpp:344
float GetFloatVal() const
Returns the value of the parameter interpreted as a floating point number.
Definition FilterParameter.h:144
void SetUnit(Unit u)
Change the units of the parameter.
Definition FilterParameter.h:181
static FilterParameter UnitSelector()
Constructs a FilterParameter object for choosing from available units.
Definition FilterParameter.cpp:67
Unit GetUnit() const
Returns the units of the parameter.
Definition FilterParameter.h:175
std::string ToString(bool useDisplayLocale=true, int sigfigs=-1) const
Returns a pretty-printed representation of the parameter's value.
Definition FilterParameter.cpp:225
void Reinterpret()
Reinterprets our string representation (in case our type or enums changed)
Definition FilterParameter.cpp:100
void ParseString(const std::string &str, bool useDisplayLocale=true)
Sets the parameter to a value represented as a string.
Definition FilterParameter.cpp:110
An 8B/10B symbol within a pattern, used for trigger matching.
Definition FilterParameter.h:45
A unit of measurement, plus conversion to pretty-printed output.
Definition Unit.h:59