17 #ifndef ATTRIBUTE_RANGE_H 18 #define ATTRIBUTE_RANGE_H 31 using AttributeRangePtr = std::shared_ptr<AttributeRange>;
32 using AttributesScope = QHash<QString, AttributeRangePtr>;
120 static AttributeRangePtr
parse(
int attrId,
const QString&
attrName,
141 inline int id()
const;
145 inline const QString&
attrName()
const;
166 const QString m_attrName;
168 QString m_attrRangeStr;
183 static AttributeRangePtr setOfValues(QString
attrRangeStr,
const int id,
187 static AttributeRangePtr intervalOfValues(QString
attrRangeStr,
const int id,
248 std::function<Value(PRG*)> f_rand;
249 std::function<Value(const Value&)> f_next;
250 std::function<Value(const Value&)> f_prev;
279 inline const Values&
values()
const;
298 {
return m_attrName; }
301 {
return m_attrRangeStr; }
315 {
return prg->
bernoulli() ? m_max : m_min; }
326 {
return f_rand(prg); }
329 {
return f_next(val); }
332 {
return f_prev(val); }
337 if (m_values.empty())
return Value();
338 return m_values.at(prg->
uniform(m_values.size()-1));
345 #endif // ATTRIBUTE_RANGE_H Value prev(const Value &v) const override
Gets the value before v.
Definition: attributerange.h:331
A boolean.
Definition: attributerange.h:82
The IntervalOfValues class.
Definition: attributerange.h:225
A class for variant data types (tagged union).
Definition: value.h:56
T uniform(T min, T max)
Generates a random double/float [min, max).
Definition: prg.h:63
~SingleValue() override=default
Destructor.
A set of strings.
Definition: attributerange.h:86
A file path.
Definition: attributerange.h:91
A set of intergers.
Definition: attributerange.h:85
A range of real numbers.
Definition: attributerange.h:80
Type type() const
Gets the current attribute's range type.
Definition: attributerange.h:303
bool bernoulli(double p)
Bernoulli distribution.
Definition: prg.h:50
const Value & max() const
Gets the maximum value in the range.
Definition: attributerange.h:309
Value next(const Value &v) const override
Gets the value after v.
Definition: attributerange.h:317
Value rand(PRG *) const override
Gets a random value in the attribute range.
Definition: attributerange.h:314
virtual Value next(const Value &v) const =0
Gets the value after v.
~SetOfValues() override=default
Destructor.
A directory path.
Definition: attributerange.h:90
int id() const
Gets the attribute id.
Definition: attributerange.h:294
Value next(const Value &v) const override
Gets the value after v.
A common interface for the Attribute Range classes.
Definition: attributerange.h:38
const QString & attrRangeStr() const
Gets the original attribute's range string.
Definition: attributerange.h:300
virtual Value prev(const Value &v) const =0
Gets the value before v.
Value rand(PRG *prg) const override
Gets a random value in the attribute range.
Definition: attributerange.h:336
const Value & min() const
Gets the minimum value in the range.
Definition: attributerange.h:306
A string.
Definition: attributerange.h:88
The SingleValue class.
Definition: attributerange.h:198
virtual Value rand(PRG *prg) const =0
Gets a random value in the attribute range.
Value prev(const Value &v) const override
Gets the value before v.
Definition: attributerange.h:320
Value rand(PRG *prg) const override
Gets a random value in the attribute range.
Definition: attributerange.h:325
Invalid type.
Definition: attributerange.h:78
virtual ~AttributeRangeInterface()=default
Destructor.
The AttributeRange base class.
Definition: attributerange.h:71
bool isValid() const
Checks if this AttributeRange is valid.
Definition: attributerange.h:291
static AttributeRangePtr parse(int attrId, const QString &attrName, const QString &attrRangeStr)
Creates an AttributeRange object from a valid attrRangeStr string.
Value next(const Value &v) const override
Gets the value after v.
Definition: attributerange.h:328
const QString & attrName() const
Gets the attribute name.
Definition: attributerange.h:297
~AttributeRange() override=default
Destructor.
SetOfValues(int id, const QString &attrName, Type type, Values values)
Constructor.
The SetOfValues class.
Definition: attributerange.h:260
Type
An enum for the attribute range types.
Definition: attributerange.h:77
IntervalOfValues(int id, const QString &attrName, Type type, const Value &min, const Value &max)
Constructor.
A range of integers.
Definition: attributerange.h:81
Pseudo-random number generator.
Definition: prg.h:29
A set of real numbers.
Definition: attributerange.h:84
Value validate(const QString &valueStr) const
Checks if the valueStr belongs to this attribute range.
Value prev(const Value &v) const override
Gets the value before v.
~IntervalOfValues() override=default
Destructor.
const Values & values() const
Gets the vector of values.
Definition: attributerange.h:341
Definition: abstractgraph.h:29
AttributeRange(int id, const QString &attrName, Type type)
AttributeRange constructor.
A non-empty string.
Definition: attributerange.h:89