ngscopeclient 0.1-dev+51fbda87c
FilterParameter.h
Go to the documentation of this file.
1/***********************************************************************************************************************
2* *
3* libscopehal *
4* *
5* Copyright (c) 2012-2024 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) const;
109
113 bool GetBoolVal() const
114 { return (m_intval != 0); }
115
119 int64_t GetIntVal() const
120 { return m_intval; }
121
125 float GetFloatVal() const
126 { return m_floatval; }
127
131 std::vector<T8B10BSymbol> Get8B10BPattern()
132 { return m_8b10bPattern; }
133
137 std::string GetFileName() const
138 { return m_string; }
139
140 void SetBoolVal(bool b);
141 void SetIntVal(int64_t i);
142 void SetFloatVal(float f);
143 void SetStringVal(const std::string& f);
144 void SetFileName(const std::string& f);
145 void Set8B10BPattern(const std::vector<T8B10BSymbol>& pattern);
146
151 { return m_type; }
152
156 Unit GetUnit() const
157 { return m_unit; }
158
162 void SetUnit(Unit u)
163 { m_unit = u; }
164
165 //File filters for TYPE_FILENAME (otherwise ignored)
166 std::string m_fileFilterMask;
167 std::string m_fileFilterName;
168
169 //Specifies TYPE_FILENAME is an output
170 bool m_fileIsOutput;
171
175 void AddEnumValue(const std::string& name, int value)
176 {
177 m_forwardEnumMap[name] = value;
178 m_reverseEnumMap[value] = name;
179 m_enumSignal.emit();
180 }
181
185 void GetEnumValues(std::vector<std::string>& values)
186 {
187 for(auto it : m_forwardEnumMap)
188 values.push_back(it.first);
189 }
190
195 {
196 m_forwardEnumMap.clear();
197 m_reverseEnumMap.clear();
198 m_enumSignal.emit();
199 }
200
201 void Reinterpret();
202
206 sigc::signal<void()> signal_changed()
207 { return m_changeSignal; }
208
212 sigc::signal<void()> signal_enums_changed()
213 { return m_enumSignal; }
214
223 { m_hidden = true; }
224
228 bool IsHidden()
229 { return m_hidden; }
230
238 { m_readOnly = true; }
239
244 { return m_readOnly; }
245
246protected:
247 ParameterTypes m_type;
248
249 sigc::signal<void()> m_changeSignal;
250 sigc::signal<void()> m_enumSignal;
251
252 Unit m_unit;
253
254 std::map<std::string, int> m_forwardEnumMap;
255 std::map<int, std::string> m_reverseEnumMap;
256
257 std::vector<T8B10BSymbol> m_8b10bPattern;
258
259 int64_t m_intval;
260 float m_floatval;
261 std::string m_string;
262
263 bool m_hidden;
264 bool m_readOnly;
265};
266
267#endif
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:212
void MarkReadOnly()
Marks this parameter as read-only in the GUI.
Definition: FilterParameter.h:237
bool GetBoolVal() const
Returns the value of the parameter interpreted as a boolean.
Definition: FilterParameter.h:113
void MarkHidden()
Marks this parameter to be hidden from the GUI.
Definition: FilterParameter.h:222
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:243
bool IsHidden()
Checks if this parameter should be hidden in the GUI.
Definition: FilterParameter.h:228
ParameterTypes GetType() const
Returns the type of the parameter.
Definition: FilterParameter.h:150
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
void AddEnumValue(const std::string &name, int value)
Adds a (name, value) pair to a TYPE_ENUM parameter.
Definition: FilterParameter.h:175
void ClearEnumValues()
Clears the list of enumerated values for a TYPE_ENUM parameter.
Definition: FilterParameter.h:194
sigc::signal< void()> signal_changed()
Signal emitted every time the parameter's value changes.
Definition: FilterParameter.h:206
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:185
void SetFileName(const std::string &f)
Sets the parameter to a file path.
Definition: FilterParameter.cpp:344
std::vector< T8B10BSymbol > Get8B10BPattern()
Access to the underlying pattern.
Definition: FilterParameter.h:131
std::string GetFileName() const
Returns the value of the parameter interpreted as a file path.
Definition: FilterParameter.h:137
std::string ToString(bool useDisplayLocale=true) const
Returns a pretty-printed representation of the parameter's value.
Definition: FilterParameter.cpp:225
float GetFloatVal() const
Returns the value of the parameter interpreted as a floating point number.
Definition: FilterParameter.h:125
void SetUnit(Unit u)
Change the units of the parameter.
Definition: FilterParameter.h:162
FilterParameter(ParameterTypes type=FilterParameter::TYPE_FLOAT, Unit unit=Unit(Unit::UNIT_FS))
Creates a parameter.
Definition: FilterParameter.cpp:51
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:156
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:57