|
| 1 | +/** |
| 2 | + * @file |
| 3 | + * @author Michal Sedlak <[email protected]> |
| 4 | + * @brief Aggregate view |
| 5 | + * |
| 6 | + * Copyright: (C) 2024 CESNET, z.s.p.o. |
| 7 | + * SPDX-License-Identifier: BSD-3-Clause |
| 8 | + */ |
| 9 | + |
| 10 | +#include <aggregator/value.hpp> |
| 11 | +#include <aggregator/view.hpp> |
| 12 | + |
| 13 | +namespace fdsdump { |
| 14 | +namespace aggregator { |
| 15 | + |
| 16 | +View::IterSpan |
| 17 | +View::iter_keys(uint8_t *ptr) const |
| 18 | +{ |
| 19 | + return IterSpan(m_fields.begin(), m_fields.begin() + m_key_count, ptr); |
| 20 | +} |
| 21 | + |
| 22 | +View::IterSpanPairs |
| 23 | +View::iter_keys(uint8_t *ptr1, uint8_t *ptr2) const |
| 24 | +{ |
| 25 | + return IterSpanPairs(m_fields.begin(), m_fields.begin() + m_key_count, ptr1, ptr2); |
| 26 | +} |
| 27 | + |
| 28 | +View::IterSpan |
| 29 | +View::iter_values(uint8_t *ptr) const |
| 30 | +{ |
| 31 | + return IterSpan(m_fields.begin() + m_key_count, m_fields.end(), ptr); |
| 32 | +} |
| 33 | + |
| 34 | +View::IterSpanPairs |
| 35 | +View::iter_values(uint8_t *ptr1, uint8_t *ptr2) const |
| 36 | +{ |
| 37 | + return IterSpanPairs(m_fields.begin() + m_key_count, m_fields.end(), ptr1, ptr2); |
| 38 | +} |
| 39 | + |
| 40 | +View::IterSpan |
| 41 | +View::iter_fields(uint8_t *ptr) const |
| 42 | +{ |
| 43 | + return IterSpan(m_fields.begin(), m_fields.end(), ptr); |
| 44 | +} |
| 45 | + |
| 46 | +View::IterSpanPairs |
| 47 | +View::iter_fields(uint8_t *ptr1, uint8_t *ptr2) const |
| 48 | +{ |
| 49 | + return IterSpanPairs(m_fields.begin(), m_fields.end(), ptr1, ptr2); |
| 50 | +} |
| 51 | + |
| 52 | +const Field * |
| 53 | +View::find_field(const std::string &name) |
| 54 | +{ |
| 55 | + for (const auto &field : fields()) { |
| 56 | + if (field->name() == name) { |
| 57 | + return field.get(); |
| 58 | + } |
| 59 | + } |
| 60 | + return nullptr; |
| 61 | +} |
| 62 | + |
| 63 | +Value & |
| 64 | +View::access_field(const Field &field, uint8_t *record_ptr) const |
| 65 | +{ |
| 66 | + return *reinterpret_cast<Value *>(record_ptr + field.offset()); |
| 67 | +} |
| 68 | + |
| 69 | +const Value & |
| 70 | +View::access_field(const Field &field, const uint8_t *record_ptr) const |
| 71 | +{ |
| 72 | + return *reinterpret_cast<const Value *>(record_ptr + field.offset()); |
| 73 | +} |
| 74 | + |
| 75 | +bool |
| 76 | +View::ordered_before(uint8_t *key1, uint8_t *key2) const |
| 77 | +{ |
| 78 | + assert(!m_order_fields.empty()); |
| 79 | + for (const auto &item : m_order_fields) { |
| 80 | + Value &value1 = *reinterpret_cast<Value *>(key1 + item.field->offset()); |
| 81 | + Value &value2 = *reinterpret_cast<Value *>(key2 + item.field->offset()); |
| 82 | + CmpResult res = item.field->compare(value1, value2); |
| 83 | + if (res != CmpResult::Eq) { |
| 84 | + return res == ( |
| 85 | + item.dir == OrderDirection::Ascending |
| 86 | + ? CmpResult::Lt : CmpResult::Gt); |
| 87 | + } |
| 88 | + } |
| 89 | + return false; |
| 90 | +} |
| 91 | + |
| 92 | +} // aggregator |
| 93 | +} // fdsdump |
0 commit comments