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

paulmthompson / WhiskerToolbox / 17270491352

27 Aug 2025 02:57PM UTC coverage: 65.333%. Remained the same
17270491352

push

github

paulmthompson
Merge branch 'main' of https://github.com/paulmthompson/WhiskerToolbox

352 of 628 new or added lines in 92 files covered. (56.05%)

357 existing lines in 24 files now uncovered.

26429 of 40453 relevant lines covered (65.33%)

1119.34 hits per line

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

20.83
/src/DataManager/utils/TableView/TableRegistry.cpp
1
#include "TableRegistry.hpp"
2

3
#include "DataManager.hpp"
4
#include "TableObserverBridge.hpp"
5
#include "utils/TableView/adapters/DataManagerExtension.h"
6
#include "utils/TableView/ComputerRegistry.hpp"
7

8
#include <iostream>
9

10
TableRegistry::TableRegistry(DataManager & data_manager)
191✔
11
    : _data_manager(data_manager),
191✔
12
      _data_manager_extension(std::make_shared<DataManagerExtension>(data_manager)),
191✔
13
      _computer_registry(std::make_unique<ComputerRegistry>()) {
191✔
14
    std::cout << "TableRegistry initialized" << std::endl;
191✔
15
}
191✔
16

17
TableRegistry::~TableRegistry() {
191✔
18
    std::cout << "TableRegistry destroyed" << std::endl;
191✔
19
}
191✔
20

21
bool TableRegistry::createTable(std::string const & table_id, std::string const & table_name, std::string const & table_description) {
22✔
22
    if (hasTable(table_id)) {
22✔
23
        std::cout << "Table with ID already exists: " << table_id << std::endl;
×
24
        return false;
×
25
    }
26
    TableInfo info(table_id, table_name, table_description);
22✔
27
    _table_info[table_id] = info;
22✔
28
    std::cout << "Created table: " << table_id << std::endl;
22✔
29
    notify(TableEventType::Created, table_id);
22✔
30
    return true;
22✔
31
}
22✔
32

33
bool TableRegistry::removeTable(std::string const & table_id) {
×
34
    if (!hasTable(table_id)) {
×
35
        return false;
×
36
    }
37
    _table_info.erase(table_id);
×
38
    _table_views.erase(table_id);
×
39
    std::cout << "Removed table: " << table_id << std::endl;
×
40
    notify(TableEventType::Removed, table_id);
×
41
    return true;
×
42
}
43

44
bool TableRegistry::hasTable(std::string const & table_id) const {
76✔
45
    return _table_info.find(table_id) != _table_info.end();
76✔
46
}
47

48
TableInfo TableRegistry::getTableInfo(std::string const & table_id) const {
×
49
    auto it = _table_info.find(table_id);
×
50
    if (it != _table_info.end()) {
×
51
        return it->second;
×
52
    }
53
    return TableInfo();
×
54
}
55

56
std::vector<std::string> TableRegistry::getTableIds() const {
×
57
    std::vector<std::string> ids;
×
58
    ids.reserve(_table_info.size());
×
59
    for (auto it = _table_info.begin(); it != _table_info.end(); ++it) {
×
60
        ids.push_back(it->first);
×
61
    }
62
    return ids;
×
63
}
×
64

65
std::vector<TableInfo> TableRegistry::getAllTableInfo() const {
×
66
    std::vector<TableInfo> infos;
×
67
    infos.reserve(_table_info.size());
×
68
    for (auto it = _table_info.begin(); it != _table_info.end(); ++it) {
×
69
        infos.push_back(it->second);
×
70
    }
71
    return infos;
×
72
}
×
73

74
bool TableRegistry::setTableView(std::string const & table_id, std::shared_ptr<TableView> table_view) {
×
75
    if (!hasTable(table_id)) {
×
76
        return false;
×
77
    }
78
    _table_views[table_id] = std::move(table_view);
×
79
    if (auto view = _table_views[table_id]) {
×
80
        auto column_names = view->getColumnNames();
×
81
        std::vector<std::string> qt_column_names;
×
82
        for (auto const & name : column_names) {
×
83
            qt_column_names.push_back(name);
×
84
        }
85
        _table_info[table_id].columnNames = qt_column_names;
×
86
    }
×
87
    std::cout << "Set TableView for table: " << table_id << std::endl;
×
88
    notify(TableEventType::DataChanged, table_id);
×
89
    return true;
×
90
}
91

92
bool TableRegistry::updateTableInfo(std::string const & table_id, std::string const & table_name, std::string const & table_description) {
×
93
    if (!hasTable(table_id)) {
×
94
        return false;
×
95
    }
96
    _table_info[table_id].name = table_name;
×
97
    _table_info[table_id].description = table_description;
×
98
    std::cout << "Updated table info for: " << table_id << std::endl;
×
99
    notify(TableEventType::InfoUpdated, table_id);
×
100
    return true;
×
101
}
102

103
bool TableRegistry::updateTableRowSource(std::string const & table_id, std::string const & row_source_name) {
×
104
    if (!hasTable(table_id)) {
×
105
        return false;
×
106
    }
107
    _table_info[table_id].rowSourceName = row_source_name;
×
108
    std::cout << "Updated row source for: " << table_id << std::endl;
×
109
    notify(TableEventType::InfoUpdated, table_id);
×
110
    return true;
×
111
}
112

113
bool TableRegistry::addTableColumn(std::string const & table_id, ColumnInfo const & column_info) {
×
114
    if (!hasTable(table_id)) {
×
115
        return false;
×
116
    }
117
    auto & table = _table_info[table_id];
×
118
    table.columns.push_back(column_info);
×
119
    table.columnNames.clear();
×
120
    for (auto const & column : table.columns) {
×
121
        table.columnNames.push_back(column.name);
×
122
    }
123
    std::cout << "Added column " << column_info.name << " to table " << table_id << std::endl;
×
124
    notify(TableEventType::InfoUpdated, table_id);
×
125
    return true;
×
126
}
127

NEW
128
bool TableRegistry::updateTableColumn(std::string const & table_id, size_t column_index, ColumnInfo const & column_info) {
×
129
    if (!hasTable(table_id)) {
×
130
        return false;
×
131
    }
132
    auto & table = _table_info[table_id];
×
NEW
133
    if (column_index >= table.columns.size()) {
×
134
        return false;
×
135
    }
136
    table.columns[column_index] = column_info;
×
137
    table.columnNames.clear();
×
138
    for (auto const & column : table.columns) {
×
139
        table.columnNames.push_back(column.name);
×
140
    }
141
    std::cout << "Updated column index " << column_index << " in table " << table_id << std::endl;
×
142
    notify(TableEventType::InfoUpdated, table_id);
×
143
    return true;
×
144
}
145

NEW
146
bool TableRegistry::removeTableColumn(std::string const & table_id, size_t column_index) {
×
147
    if (!hasTable(table_id)) {
×
148
        return false;
×
149
    }
150
    auto & table = _table_info[table_id];
×
NEW
151
    if (column_index >= table.columns.size()) {
×
152
        return false;
×
153
    }
154
    std::string removed = table.columns[column_index].name;
×
NEW
155
    table.columns.erase(table.columns.begin() + static_cast<long int>(column_index));
×
156
    table.columnNames.clear();
×
157
    for (auto const & column : table.columns) {
×
158
        table.columnNames.push_back(column.name);
×
159
    }
160
    std::cout << "Removed column " << removed << " from table " << table_id << std::endl;
×
161
    notify(TableEventType::InfoUpdated, table_id);
×
162
    return true;
×
163
}
×
164

NEW
165
ColumnInfo TableRegistry::getTableColumn(std::string const & table_id, size_t column_index) const {
×
166
    if (!hasTable(table_id)) {
×
167
        return ColumnInfo();
×
168
    }
169
    auto const & table = _table_info.at(table_id);
×
NEW
170
    if (column_index >= table.columns.size()) {
×
171
        return ColumnInfo();
×
172
    }
173
    return table.columns[column_index];
×
174
}
175

176
bool TableRegistry::storeBuiltTable(std::string const & table_id, TableView table_view) {
21✔
177
    if (!hasTable(table_id)) {
21✔
178
        return false;
×
179
    }
180
    _table_views[table_id] = std::make_shared<TableView>(std::move(table_view));
21✔
181
    if (auto view = _table_views[table_id]) {
21✔
182
        auto column_names = view->getColumnNames();
21✔
183
        std::vector<std::string> qt_column_names;
21✔
184
        for (auto const & name : column_names) {
102✔
185
            qt_column_names.push_back(name);
81✔
186
        }
187
        _table_info[table_id].columnNames = qt_column_names;
21✔
188
    }
42✔
189
    std::cout << "Stored built table for: " << table_id << std::endl;
21✔
190
    notify(TableEventType::DataChanged, table_id);
21✔
191
    return true;
21✔
192
}
193

194
std::shared_ptr<TableView> TableRegistry::getBuiltTable(std::string const & table_id) const {
21✔
195
    auto it = _table_views.find(table_id);
21✔
196
    if (it != _table_views.end()) {
21✔
197
        return it->second;
21✔
198
    }
199
    return nullptr;
×
200
}
201

202
std::string TableRegistry::generateUniqueTableId(std::string const & base_name) const {
×
203
    std::string candidate;
×
204
    while (true) {
205
        candidate = base_name + "_" + std::to_string(_next_table_counter);
×
206
        const_cast<TableRegistry*>(this)->_next_table_counter++;
×
207
        if (!hasTable(candidate)) {
×
208
            break;
×
209
        }
210
    }
211
    return candidate;
×
212
}
×
213

214
bool TableRegistry::addTableColumnWithTypeInfo(std::string const & table_id, ColumnInfo & column_info) {
×
215
    if (!hasTable(table_id)) {
×
216
        std::cout << "Table does not exist: " << table_id<< std::endl;
×
217
        return false;
×
218
    }
219
    auto computer_info = _computer_registry->findComputerInfo(column_info.computerName);
×
220
    if (!computer_info) {
×
221
        std::cout << "Computer not found in registry: " << column_info.computerName << std::endl;
×
222
        return false;
×
223
    }
224
    column_info.outputType = computer_info->outputType;
×
225
    column_info.outputTypeName = computer_info->outputTypeName;
×
226
    column_info.isVectorType = computer_info->isVectorType;
×
227
    column_info.elementType = computer_info->elementType;
×
228
    column_info.elementTypeName = computer_info->elementTypeName;
×
229
    return addTableColumn(table_id, column_info);
×
230
}
231

NEW
232
std::vector<std::string> TableRegistry::getAvailableComputersForDataSource(std::string const & /*row_selector_type*/, std::string const & /*data_source_name*/) const {
×
233
    std::vector<std::string> computers;
×
234
    auto all_computer_names = _computer_registry->getAllComputerNames();
×
235
    for (auto const & name : all_computer_names) {
×
236
        computers.push_back(name);
×
237
    }
238
    return computers;
×
239
}
×
240

241
std::tuple<std::string, bool, std::string> TableRegistry::getComputerTypeInfo(std::string const & computer_name) const {
×
242
    auto computer_info = _computer_registry->findComputerInfo(computer_name);
×
243
    if (!computer_info) {
×
244
        return std::make_tuple(std::string("unknown"), false, std::string("unknown"));
×
245
    }
246
    return std::make_tuple(
247
        computer_info->outputTypeName,
×
248
        computer_info->isVectorType,
×
249
        computer_info->elementTypeName
×
250
    );
×
251
}
252

253
ComputerInfo const * TableRegistry::getComputerInfo(std::string const & computer_name) const {
×
254
    return _computer_registry->findComputerInfo(computer_name);
×
255
}
256

257
std::vector<std::string> TableRegistry::getAvailableOutputTypes() const {
×
258
    auto type_names = _computer_registry->getOutputTypeNames();
×
259
    std::vector<std::string> result;
×
260
    for (auto const & [type_index, name] : type_names) {
×
261
        (void)type_index;
262
        result.push_back(name);
×
263
    }
264
    return result;
×
265
}
×
266

267
void TableRegistry::notify(TableEventType type, std::string const & table_id) const {
43✔
268
    TableEvent ev{type, table_id};
43✔
269
    DataManager__NotifyTableObservers(_data_manager, ev);
43✔
270
}
86✔
271

272

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