include/sqlon/conditions.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /****************************************************************************** | ||
| 2 | ** | ||
| 3 | ** Copyright (C) 2026 Ivan Pinezhaninov <ivan.pinezhaninov@gmail.com> | ||
| 4 | ** | ||
| 5 | ** This file is part of the SQLon - which can be found at | ||
| 6 | ** https://github.com/IvanPinezhaninov/sqlon/. | ||
| 7 | ** | ||
| 8 | ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 9 | ** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| 10 | ** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
| 11 | ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | ||
| 12 | ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
| 13 | ** OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR | ||
| 14 | ** THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 15 | ** | ||
| 16 | ******************************************************************************/ | ||
| 17 | |||
| 18 | #ifndef SQLON_CONDITIONS_H | ||
| 19 | #define SQLON_CONDITIONS_H | ||
| 20 | |||
| 21 | #include <sqlon/export.h> | ||
| 22 | #include <sqlon/expression.h> | ||
| 23 | |||
| 24 | #include <cstdint> | ||
| 25 | #include <vector> | ||
| 26 | |||
| 27 | namespace sqlon { | ||
| 28 | |||
| 29 | namespace detail { | ||
| 30 | struct conditions_access; | ||
| 31 | } | ||
| 32 | |||
| 33 | /** @brief Logical operation used to combine a condition group. */ | ||
| 34 | enum class logic : std::uint8_t { | ||
| 35 | and_, ///< Combine conditions with logical AND. | ||
| 36 | or_ ///< Combine conditions with logical OR. | ||
| 37 | }; | ||
| 38 | |||
| 39 | /** @brief Mutable group of dynamically accumulated predicates. */ | ||
| 40 | class conditions final { | ||
| 41 | public: | ||
| 42 | /** @brief Creates an empty condition group with the requested combination logic. */ | ||
| 43 | SQLON_API explicit conditions(logic combination = logic::and_); | ||
| 44 | |||
| 45 | /** @brief Appends a predicate to the group. */ | ||
| 46 | SQLON_API conditions& add(const expression<bool>& condition); | ||
| 47 | |||
| 48 | /** @brief Appends a nested condition group. */ | ||
| 49 | SQLON_API conditions& add(const conditions& group); | ||
| 50 | |||
| 51 | /** @brief Appends a predicate to the group. */ | ||
| 52 | SQLON_API conditions& operator+=(const expression<bool>& condition); | ||
| 53 | |||
| 54 | /** @brief Appends a nested condition group. */ | ||
| 55 | SQLON_API conditions& operator+=(const conditions& group); | ||
| 56 | |||
| 57 | /** @brief Returns whether the group contains no predicates. */ | ||
| 58 | SQLON_API bool empty() const noexcept; | ||
| 59 | |||
| 60 | /** @brief Returns the number of predicates and nested groups. */ | ||
| 61 | SQLON_API std::size_t size() const noexcept; | ||
| 62 | |||
| 63 | private: | ||
| 64 | friend struct detail::conditions_access; | ||
| 65 | |||
| 66 | SQLON_API detail::expression_ptr node() const; | ||
| 67 | |||
| 68 | logic m_combination; | ||
| 69 | std::vector<expression<bool>> m_values; | ||
| 70 | }; | ||
| 71 | |||
| 72 | namespace detail { | ||
| 73 | |||
| 74 | struct conditions_access final { | ||
| 75 | 10 | static expression_ptr node(const conditions& value) | |
| 76 | { | ||
| 77 | 10 | return value.node(); | |
| 78 | } | ||
| 79 | }; | ||
| 80 | |||
| 81 | } // namespace detail | ||
| 82 | |||
| 83 | } // namespace sqlon | ||
| 84 | |||
| 85 | #endif // SQLON_CONDITIONS_H | ||
| 86 |