knowL: Knowledge Libraries
Loading...
Searching...
No Matches
ConstrainedValue.h
1#pragma once
2
3#include <QSharedDataPointer>
4
5#include "Value.h"
6
7namespace knowCore
8{
15 {
16 public:
17 enum class Type
18 {
19 Equal,
20 Different,
21 Inferior,
22 Superior,
27 GeoWithin,
32 Contains,
34 In,
35 NotIn
36 };
38 {
39 Value value;
40 Type type;
41 bool operator==(const Constraint& _rhs) const
42 {
43 return value == _rhs.value and type == _rhs.type;
44 }
45 bool operator!=(const Constraint& _rhs) const { return not(*this == _rhs); }
46 };
47 public:
50 ConstrainedValue& operator=(const ConstrainedValue& _rhs);
52
53 bool operator==(const ConstrainedValue& _value) const;
54
58 bool hasConstraints() const;
59 QList<Constraint> constraints() const;
60 cres_qresult<bool> check(const Value& _value);
64 cres_qresult<ValueRange> update(const ValueRange& _range);
65 template<typename _T_>
66 cres_qresult<bool> check(const _T_& _value);
71 ConstrainedValue& apply(const Constraint& _constraint);
76 ConstrainedValue& apply(const Value& _value, Type _type);
77 template<typename _T_>
78 ConstrainedValue& apply(const _T_& _value, Type _type);
79 private:
80 struct Private;
81 QSharedDataPointer<Private> d;
82 };
83 template<typename _T_>
84 cres_qresult<bool> ConstrainedValue::check(const _T_& _value)
85 {
86 return check(Value::fromValue(_value));
87 }
88 template<typename _T_>
89 ConstrainedValue& ConstrainedValue::apply(const _T_& _value, Type _type)
90 {
91 return apply(Value::fromValue(_value), _type);
92 }
93} // namespace knowCore
94
95#include <knowCore/Formatter.h>
96
97clog_format_declare_enum_formatter(knowCore::ConstrainedValue::Type, Equal, Different, Inferior,
98 Superior, InferiorEqual, SuperiorEqual, GeoOverlaps, GeoWithin,
99 GeoContains, GeoIntersects, Contains, In, NotIn, GeoTouches,
100 GeoDisjoint, NotContains);
101
102clog_format_declare_formatter(knowCore::ConstrainedValue::Constraint)
103{
104 return format_to(ctx.out(), "{} {}", p.type, p.value);
105}
106
107clog_format_declare_formatter(knowCore::ConstrainedValue)
108{
109 return format_to(ctx.out(), "{:s' and '}", p.constraints());
110}
Definition Forward.h:14
Definition ConstrainedValue.h:15
cres_qresult< ValueRange > update(const ValueRange &_range)
Definition ConstrainedValue.cpp:108
ConstrainedValue & apply(const Constraint &_constraint)
Definition ConstrainedValue.cpp:96
Type
Definition ConstrainedValue.h:18
@ Superior
such as constraint.value < value
@ GeoWithin
such as value is within the constraint.value
@ NotContains
such as list does not contains a value
@ GeoDisjoint
such as value disjoint with constraint.value,
@ InferiorEqual
such as value <= constraint.value
@ GeoTouches
such as value touches with constraint.value,
@ Contains
such as list contains a value
@ Inferior
such as value < constraint.value
@ NotIn
such as one value is not part of a list
@ SuperiorEqual
such as constraint.value <= value
@ GeoIntersects
such as value intersects with constraint.value,
@ GeoContains
such as constraint.value is within the value
@ In
such as one value is part of a list
bool hasConstraints() const
Definition ConstrainedValue.cpp:92
Definition Range.h:66
Definition Value.h:21
static Value fromValue(const _T_ &_value)
Definition Value.h:241
Definition ConstrainedValue.cpp:8
Definition ConstrainedValue.h:38