src/conditions.cpp
| 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 | #include <sqlon/conditions.h> | ||
| 19 | |||
| 20 | #include <utility> | ||
| 21 | |||
| 22 | namespace sqlon { | ||
| 23 | |||
| 24 | 9 | conditions::conditions(logic combination) | |
| 25 | 9 | : m_combination(combination) | |
| 26 | 9 | {} | |
| 27 | |||
| 28 | 11 | conditions& conditions::add(const expression<bool>& condition) | |
| 29 | { | ||
| 30 | 11 | m_values.push_back(condition); | |
| 31 | 11 | return *this; | |
| 32 | } | ||
| 33 | |||
| 34 | 3 | conditions& conditions::add(const conditions& group) | |
| 35 | { | ||
| 36 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | if (!group.empty()) |
| 37 |
7/9✓ Branch 1 taken 3 times.
✓ Branch 4 taken 3 times.
✓ Branch 7 taken 3 times.
✓ Branch 10 taken 3 times.
✓ Branch 13 taken 3 times.
✓ Branch 19 taken 3 times.
✓ Branch 20 taken 3 times.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
|
15 | m_values.push_back(detail::expression_access::make<bool>(detail::make_expression_node( |
| 38 | detail::expression_kind::unary, "group", {detail::conditions_access::node(group)}))); | ||
| 39 | |||
| 40 | 3 | return *this; | |
| 41 | 3 | } | |
| 42 | |||
| 43 | 8 | conditions& conditions::operator+=(const expression<bool>& condition) | |
| 44 | { | ||
| 45 | 8 | return add(condition); | |
| 46 | } | ||
| 47 | |||
| 48 | 2 | conditions& conditions::operator+=(const conditions& group) | |
| 49 | { | ||
| 50 | 2 | return add(group); | |
| 51 | } | ||
| 52 | |||
| 53 | 4 | bool conditions::empty() const noexcept | |
| 54 | { | ||
| 55 | 4 | return m_values.empty(); | |
| 56 | } | ||
| 57 | |||
| 58 | 2 | std::size_t conditions::size() const noexcept | |
| 59 | { | ||
| 60 | 2 | return m_values.size(); | |
| 61 | } | ||
| 62 | |||
| 63 | 10 | detail::expression_ptr conditions::node() const | |
| 64 | { | ||
| 65 |
2/2✓ Branch 1 taken 1 time.
✓ Branch 2 taken 9 times.
|
10 | if (m_values.empty()) return {}; |
| 66 | |||
| 67 | 9 | detail::expression_ptr result = detail::expression_access::node(m_values.front()); | |
| 68 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 3 times.
|
9 | const char* operation = m_combination == logic::and_ ? "and" : "or"; |
| 69 |
2/2✓ Branch 1 taken 6 times.
✓ Branch 2 taken 9 times.
|
15 | for (std::size_t index = 1; index < m_values.size(); ++index) |
| 70 |
2/2✓ Branch 6 taken 6 times.
✓ Branch 9 taken 6 times.
|
18 | result = detail::make_binary_node(operation, std::move(result), detail::expression_access::node(m_values[index])); |
| 71 | |||
| 72 | 9 | return result; | |
| 73 | 9 | } | |
| 74 | |||
| 75 | } // namespace sqlon | ||
| 76 |