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{
14 {
15 public:
16 enum class Type
17 {
18 Equal,
19 Different,
20 Inferior,
21 Superior,
25 GeoWithin,
30 Contains,
32 In,
33 NotIn
34 };
36 {
37 Value value;
38 Type type;
39 bool operator==(const Constraint& _rhs) const {
40 return value == _rhs.value and type == _rhs.type;
41 }
42 bool operator!=(const Constraint& _rhs) const {
43 return not(*this == _rhs);
44 }
45 };
46 public:
49 ConstrainedValue& operator=(const ConstrainedValue& _rhs);
51
52 bool operator==(const ConstrainedValue& _value) const;
53
57 bool hasConstraints() const;
58 QList<Constraint> constraints() const;
59 knowCore::ReturnValue<bool> check(const Value& _value);
64 template<typename _T_>
65 knowCore::ReturnValue<bool> check(const _T_& _value);
70 ConstrainedValue& apply(const Constraint& _constraint);
75 ConstrainedValue& apply(const Value& _value, Type _type);
76 template<typename _T_>
77 knowCore::ReturnVoid apply(const _T_& _value, Type _type);
78 private:
79 struct Private;
80 QSharedDataPointer<Private> d;
81 };
82 template<typename _T_>
83 knowCore::ReturnValue<bool> ConstrainedValue::check(const _T_& _value)
84 {
85 return check(Value::fromValue(_value));
86 }
87 template<typename _T_>
88 knowCore::ReturnVoid ConstrainedValue::apply(const _T_& _value, Type _type)
89 {
90 apply(Value::fromValue(_value), _type);
91 return kCrvSuccess();
92 }
93}
94
95#include <knowCore/Formatter.h>
96
97KNOWCORE_CORE_DECLARE_FORMATTER_ENUM(knowCore::ConstrainedValue::Type, Equal, Different, Inferior, Superior, InferiorEqual, SuperiorEqual, GeoOverlaps, GeoWithin, GeoContains, GeoIntersects, Contains, In);
98
99KNOWCORE_CORE_DECLARE_FORMATTER(knowCore::ConstrainedValue::Constraint)
100{
101 return format_to(ctx.out(), "{} {}", p.type, p.value);
102}
103
104KNOWCORE_CORE_DECLARE_FORMATTER(knowCore::ConstrainedValue)
105{
106 return format_to(ctx.out(), "{}", fmt::join(p.constraints(), " and "));
107}
Definition Forward.h:12
Definition ConstrainedValue.h:14
knowCore::ReturnValue< ValueRange > update(const ValueRange &_range)
Definition ConstrainedValue.cpp:117
ConstrainedValue & apply(const Constraint &_constraint)
Definition ConstrainedValue.cpp:105
Type
Definition ConstrainedValue.h:17
@ GeoOverlaps
such as value overlaps with constraint.value (but they cannot share a boundary)
@ 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:95
Definition Range.h:65
Definition ReturnValue.h:85
Definition ReturnValue.h:29
Definition Value.h:13
static Value fromValue(const _T_ &_value)
Definition Value.h:184
Definition ConstrainedValue.cpp:8
Definition ConstrainedValue.h:36