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

paulmthompson / WhiskerToolbox / 17920603410

22 Sep 2025 03:39PM UTC coverage: 71.97% (-0.05%) from 72.02%
17920603410

push

github

paulmthompson
all tests pass

277 of 288 new or added lines in 8 files covered. (96.18%)

520 existing lines in 35 files now uncovered.

40275 of 55961 relevant lines covered (71.97%)

1225.8 hits per line

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

86.36
/src/DataManager/utils/TableView/core/TableViewBuilder.h
1
#ifndef TABLE_VIEW_BUILDER_H
2
#define TABLE_VIEW_BUILDER_H
3

4
#include "TableView.h"
5

6
#include "utils/TableView/columns/Column.h"
7
#include "utils/TableView/columns/IColumn.h"
8
#include "utils/TableView/interfaces/MultiComputerOutputView.hpp"
9

10
#include <memory>
11
#include <string>
12
#include <vector>
13

14
class DataManagerExtension;
15
template<typename T>
16
class IColumnComputer;
17
template<typename T>
18
class IMultiColumnComputer;
19
class IRowSelector;
20

21
/**
22
 * @brief Builder class for constructing TableView objects with a fluent API.
23
 * 
24
 * The TableViewBuilder provides a step-by-step, fluent API for constructing
25
 * TableView objects, simplifying the setup of complex configurations.
26
 */
27
class TableViewBuilder {
28
public:
29
    /**
30
     * @brief Constructs a TableViewBuilder with the given data manager.
31
     * @param dataManager Shared pointer to the data manager extension.
32
     */
33
    explicit TableViewBuilder(std::shared_ptr<DataManagerExtension> dataManager);
34

35
    ~TableViewBuilder();
36

37
    /**
38
     * @brief Sets the row selector that defines the table rows.
39
     * @param rowSelector Unique pointer to the row selector.
40
     * @return Reference to this builder for method chaining.
41
     */
42
    auto setRowSelector(std::unique_ptr<IRowSelector> rowSelector) -> TableViewBuilder &;
43

44
    /**
45
     * @brief Adds a column to the table being built.
46
     * @param name The name of the column.
47
     * @param computer Unique pointer to the column computer.
48
     * @return Reference to this builder for method chaining.
49
     */
50
    auto addColumn(std::string const & name, std::unique_ptr<IColumnComputer<double>> computer) -> TableViewBuilder &;
51

52
    /**
53
     * @brief Adds a templated column to the table being built.
54
     * @tparam T The type of the column data.
55
     * @param name The name of the column.
56
     * @param computer Unique pointer to the templated column computer.
57
     * @return Reference to this builder for method chaining.
58
     */
59
    template<typename T>
60
    auto addColumn(std::string const & name, std::unique_ptr<IColumnComputer<T>> computer) -> TableViewBuilder &;
61

62
    /**
63
     * @brief Adds multiple columns backed by a single multi-output computer.
64
     * @tparam T Element type of the outputs.
65
     * @param baseName Base name for the columns; per-output suffixes are provided by the computer.
66
     * @param computer Unique pointer to the multi-output computer.
67
     * @return Reference to this builder for method chaining.
68
     */
69
    template<typename T>
70
    auto addColumns(std::string const & baseName, std::unique_ptr<IMultiColumnComputer<T>> computer) -> TableViewBuilder &;
71

72
    /**
73
     * @brief Builds the final TableView object.
74
     * 
75
     * This method validates the configuration and constructs the TableView.
76
     * After calling build(), the builder is in an invalid state and should
77
     * not be used further.
78
     * 
79
     * @return The constructed TableView object.
80
     * @throws std::runtime_error if the configuration is invalid.
81
     */
82
    [[nodiscard]] auto build() -> TableView;
83

84
private:
85
    /**
86
     * @brief Validates that at most one multi-sample source is used.
87
     * 
88
     * This method checks all columns for dependencies on multi-sample line sources.
89
     * If more than one multi-sample source is found, it throws an exception with
90
     * detailed information about the conflicting sources.
91
     * 
92
     * @throws std::runtime_error if multiple multi-sample sources are detected.
93
     */
94
    void validateMultiSampleSources();
95

96
private:
97
    std::shared_ptr<DataManagerExtension> m_dataManager;
98
    std::unique_ptr<IRowSelector> m_rowSelector;
99
    std::vector<std::shared_ptr<IColumn>> m_columns;
100
};
101

102
// Template method implementation
103
template<typename T>
104
auto TableViewBuilder::addColumn(std::string const & name, std::unique_ptr<IColumnComputer<T>> computer) -> TableViewBuilder & {
187✔
105
    if (!computer) {
187✔
106
        throw std::invalid_argument("Column computer cannot be null");
×
107
    }
108

109
    // Create the templated column
110
    auto column = std::shared_ptr<IColumn>(new Column<T>(name, std::move(computer)));
187✔
111
    m_columns.push_back(std::move(column));
187✔
112

113
    return *this;
187✔
114
}
187✔
115

116

117
template<typename T>
118
auto TableViewBuilder::addColumns(std::string const & baseName, std::unique_ptr<IMultiColumnComputer<T>> computer) -> TableViewBuilder & {
36✔
119
    if (!computer) {
36✔
UNCOV
120
        throw std::invalid_argument("Multi-column computer cannot be null");
×
121
    }
122

123
    auto suffixes = computer->getOutputNames();
36✔
124
    if (suffixes.empty()) {
36✔
UNCOV
125
        throw std::invalid_argument("Multi-column computer returned no outputs");
×
126
    }
127

128
    // wrap in shared_ptr so each per-output view can reference the same instance
129
    auto sharedComputer = std::shared_ptr<IMultiColumnComputer<T>>(std::move(computer));
36✔
130
    auto sharedCache = std::make_shared<typename MultiComputerOutputView<T>::SharedBatchCache>();
36✔
131

132
    for (size_t i = 0; i < suffixes.size(); ++i) {
416✔
133
        std::string colName = baseName + suffixes[i];
190✔
134
        auto view = std::make_unique<MultiComputerOutputView<T>>(sharedComputer, sharedCache, i);
190✔
135
        auto column = std::shared_ptr<IColumn>(new Column<T>(colName, std::move(view)));
190✔
136
        m_columns.push_back(std::move(column));
190✔
137
    }
138

139
    return *this;
36✔
140
}
36✔
141

142

143
#endif// TABLE_VIEW_BUILDER_H
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