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

paulmthompson / WhiskerToolbox / 14795857731

02 May 2025 01:10PM UTC coverage: 17.527% (-0.4%) from 17.972%
14795857731

push

github

paulmthompson
fix const error in tests

319 of 1820 relevant lines covered (17.53%)

1.75 hits per line

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

0.0
/src/WhiskerToolbox/DataManager/transforms/TransformRegistry.cpp
1

2
#include <iostream>// For init messages
3
#include <map>
4
#include <memory>// unique_ptr
5
#include <string>
6
#include <typeindex>
7
#include <variant>// Needed for the public interface
8
#include <vector>
9

10
#include "TransformRegistry.hpp"
11

12
#include "transforms/Masks/mask_area.hpp"
13
#include "transforms/AnalogTimeSeries/analog_event_threshold.hpp"
14

15

16
TransformRegistry::TransformRegistry() {
×
17

18
    std::cout << "Initializing Operation Registry..." << std::endl;
×
19

20
    // --- 1. Register Operations---
21
    _registerOperation(std::make_unique<MaskAreaOperation>());
×
22
    _registerOperation(std::make_unique<EventThresholdOperation>());
×
23

24
    _computeApplicableOperations();
×
25
    std::cout << "Operation Registry Initialized." << std::endl;
×
26
}
×
27

28
std::vector<std::string> TransformRegistry::getOperationNamesForVariant(DataTypeVariant const & dataVariant) const {
×
29
    // Get the type_index of the type currently stored in the variant.
30
    // Note: std::variant::type() returns the type_index of the *alternative*,
31
    // which in our case IS the std::shared_ptr<T>. This matches what
32
    // getTargetInputTypeIndex() should return.
33
    auto current_type_index = std::visit([](auto & v) -> std::type_index { return typeid(v); }, dataVariant);
×
34

35
    // Look up the type index in the pre-computed map
36
    auto it = type_index_to_op_names_.find(current_type_index);
×
37
    if (it != type_index_to_op_names_.end()) {
×
38
        return it->second;// Return the pre-computed list of names
×
39
    } else {
40
        // No registered operation targets this specific type_index.
41
        // This is normal if a data type has no operations defined for it.
42
        return {};// Return empty vector
×
43
    }
44
}
45

46
TransformOperation * TransformRegistry::findOperationByName(std::string const & operation_name) const {
×
47
    auto it = name_to_operation_.find(operation_name);
×
48
    if (it != name_to_operation_.end()) {
×
49
        return it->second;
×
50
    } else {
51
        // std::cerr << "Warning: Requested operation name not found: '" << operation_name << "'" << std::endl;
52
        return nullptr;
×
53
    }
54
}
55

56
void TransformRegistry::_registerOperation(std::unique_ptr<TransformOperation> op) {
×
57
    if (!op) return;
×
58
    std::string op_name = op->getName();
×
59
    if (name_to_operation_.count(op_name)) {
×
60
        std::cerr << "Warning: Operation with name '" << op_name << "' already registered." << std::endl;
×
61
        return;
×
62
    }
63
    std::cout << "Registering operation: " << op_name
64
              << " (Targets type index: " << op->getTargetInputTypeIndex().name() << ")"// Debug info
×
65
              << std::endl;
×
66
    name_to_operation_[op_name] = op.get();
×
67
    all_operations_.push_back(std::move(op));
×
68
}
×
69

70
void TransformRegistry::_computeApplicableOperations() {
×
71
    std::cout << "Computing applicable operations based on registered operations..." << std::endl;
×
72
    type_index_to_op_names_.clear();// Start fresh
×
73

74
    for (auto const & op_ptr: all_operations_) {
×
75
        if (!op_ptr) continue;
×
76
        // Get the type index this operation says it targets
77
        std::type_index target_type_index = op_ptr->getTargetInputTypeIndex();
×
78
        // Get the user-facing name of the operation
79
        std::string op_name = op_ptr->getName();
×
80

81
        // Add this operation's name to the list for its target type index
82
        type_index_to_op_names_[target_type_index].push_back(op_name);
×
83
    }
×
84

85
    std::cout << "Finished computing applicable operations." << std::endl;
×
86
// Debug print (optional): shows mangled names for type_index keys internally
87
#ifndef NDEBUG// Example: Only print in debug builds
88
    for (auto const & pair: type_index_to_op_names_) {
×
89
        std::cout << "  TypeIndex Hash(" << pair.first.hash_code()
×
90
                  << ", Name=" << pair.first.name() << ") supports: ";
×
91
        for (auto const & name: pair.second) std::cout << "'" << name << "' ";
×
92
        std::cout << std::endl;
×
93
    }
94
#endif
95
}
×
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