1 | //===----------------------------------------------------------------------===// |
---|---|
2 | // DuckDB |
3 | // |
4 | // duckdb/planner/bound_constraint.hpp |
5 | // |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #pragma once |
10 | |
11 | #include "duckdb/common/common.hpp" |
12 | #include "duckdb/parser/constraint.hpp" |
13 | #include "duckdb/common/serializer.hpp" |
14 | #include "duckdb/common/exception.hpp" |
15 | |
16 | namespace duckdb { |
17 | //! Bound equivalent of Constraint |
18 | class BoundConstraint { |
19 | public: |
20 | explicit BoundConstraint(ConstraintType type) : type(type) {}; |
21 | virtual ~BoundConstraint() { |
22 | } |
23 | |
24 | void Serialize(Serializer &serializer) const { |
25 | serializer.Write(element: type); |
26 | } |
27 | |
28 | static unique_ptr<BoundConstraint> Deserialize(Deserializer &source) { |
29 | return make_uniq<BoundConstraint>(args: source.Read<ConstraintType>()); |
30 | } |
31 | |
32 | ConstraintType type; |
33 | |
34 | public: |
35 | template <class TARGET> |
36 | TARGET &Cast() { |
37 | if (type != TARGET::TYPE) { |
38 | throw InternalException("Failed to cast constraint to type - bound constraint type mismatch"); |
39 | } |
40 | return reinterpret_cast<TARGET &>(*this); |
41 | } |
42 | |
43 | template <class TARGET> |
44 | const TARGET &Cast() const { |
45 | if (type != TARGET::TYPE) { |
46 | throw InternalException("Failed to cast constraint to type - bound constraint type mismatch"); |
47 | } |
48 | return reinterpret_cast<const TARGET &>(*this); |
49 | } |
50 | }; |
51 | } // namespace duckdb |
52 |