• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

paulmthompson / WhiskerToolbox / 18685379784

21 Oct 2025 01:25PM UTC coverage: 72.522% (+0.1%) from 72.391%
18685379784

push

github

paulmthompson
fix failing tests

18 of 40 new or added lines in 1 file covered. (45.0%)

1765 existing lines in 32 files now uncovered.

53998 of 74457 relevant lines covered (72.52%)

46177.73 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.48
/src/StateEstimation/DataSource.hpp
1
#ifndef STATE_ESTIMATION_DATASOURCE_HPP
2
#define STATE_ESTIMATION_DATASOURCE_HPP
3

4
#include "Entity/EntityTypes.hpp"
5
#include "TimeFrame/TimeFrame.hpp"
6

7
#include <concepts>
8
#include <ranges>
9
#include <tuple>
10

11
namespace StateEstimation {
12

13
/**
14
 * @brief Concept for a single data item with entity and time information.
15
 * 
16
 * A DataItem can be either:
17
 * 1. Tuple-like: std::tuple<DataType, EntityId, TimeFrameIndex>
18
 * 2. Accessor-based: struct with getData(), getEntityId(), getTimeFrameIndex() methods
19
 * 
20
 * This dual support allows both legacy tuple-based sources and new adapter-based sources.
21
 */
22
template<typename T, typename DataType>
23
concept DataItem =
24
        // Option 1: Tuple-like access
25
        (requires(T item) {
26
            { std::get<0>(item) } -> std::convertible_to<DataType const &>;
27
            { std::get<1>(item) } -> std::convertible_to<EntityId>;
28
            { std::get<2>(item) } -> std::convertible_to<TimeFrameIndex>;
29
        }) ||
30
        // Option 2: Accessor methods
31
        (requires(T item) {
32
            { item.getData() } -> std::convertible_to<DataType const &>;
33
            { item.getEntityId() } -> std::convertible_to<EntityId>;
34
            { item.getTimeFrameIndex() } -> std::convertible_to<TimeFrameIndex>;
35
        });
36

37
/**
38
 * @brief Concept for a data source that provides a range of data items.
39
 * 
40
 * This concept allows zero-copy iteration over data with associated entity IDs
41
 * and time frame indices. It can be satisfied by:
42
 * - Tuple-based ranges: vector<tuple<DataType, EntityId, TimeFrameIndex>>
43
 * - Adapter-based ranges: FlattenedDataAdapter yielding DataItem structs
44
 * - LineData range views
45
 * - Custom generators
46
 * 
47
 * Note: Removes references from Source to handle forwarding references correctly.
48
 */
49
template<typename Source, typename DataType>
50
concept DataSource = std::ranges::input_range<std::remove_reference_t<Source>> &&
51
                     DataItem<std::ranges::range_value_t<std::remove_reference_t<Source>>, DataType>;
52

53
/**
54
 * @brief Helper to extract data from a DataItem (supports both tuple and accessor)
55
 */
56
template<typename Item>
57
inline auto const & getData(Item const & item) {
3,879✔
58
    if constexpr (requires { item.getData(); }) {
59
        return item.getData();
3,268✔
60
    } else {
61
        return std::get<0>(item);
611✔
62
    }
63
}
64

65
/**
66
 * @brief Helper to extract EntityId from a DataItem (supports both tuple and accessor)
67
 */
68
template<typename Item>
69
inline EntityId getEntityId(Item const & item) {
3,879✔
70
    if constexpr (requires { item.getEntityId(); }) {
71
        return item.getEntityId();
3,268✔
72
    } else {
73
        return std::get<1>(item);
611✔
74
    }
75
}
76

77
/**
78
 * @brief Helper to extract TimeFrameIndex from a DataItem (supports both tuple and accessor)
79
 */
80
template<typename Item>
81
inline TimeFrameIndex getTimeFrameIndex(Item const & item) {
4,211✔
82
    if constexpr (requires { item.getTimeFrameIndex(); }) {
83
        return item.getTimeFrameIndex();
3,600✔
84
    } else {
85
        return std::get<2>(item);
611✔
86
    }
87
}
88

89
template<typename DataType>
90
using FrameBucket = std::vector<std::tuple<DataType const *, EntityId, TimeFrameIndex>>;
91

92
template<typename DataType>
93
inline DataType const * findEntity(FrameBucket<DataType> const & bucket, EntityId id) {
1,743✔
94
    for (auto const & item: bucket) {
2,604✔
95
        if (std::get<1>(item) == id) return std::get<0>(item);
2,604✔
96
    }
UNCOV
97
    return nullptr;
×
98
}
99

100
template <typename Source, typename DataType>
101
    requires DataSource<Source, DataType>
102
inline std::map<TimeFrameIndex, FrameBucket<DataType>>
103
buildFrameLookup(Source && data_source, TimeFrameIndex start_frame, TimeFrameIndex end_frame) {
21✔
104
    std::map<TimeFrameIndex, FrameBucket<DataType>> lookup;
21✔
105
    for (auto const & item: data_source) {
7,475✔
106
        TimeFrameIndex t = getTimeFrameIndex(item);
3,836✔
107
        if (t >= start_frame && t <= end_frame) {
3,836✔
108
            lookup[t].emplace_back(&getData(item), getEntityId(item), t);
3,504✔
109
        }
110
    }
111
    return lookup;
21✔
UNCOV
112
}
×
113

114
}// namespace StateEstimation
115

116
#endif// STATE_ESTIMATION_DATASOURCE_HPP
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc