• 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

45.45
/src/DataManager/IO/CapnProto/CapnProtoFormatLoader.cpp
1
#include "CapnProtoFormatLoader.hpp"
2

3
#include "Line_Data_Binary.hpp"
4
#include "Lines/Line_Data.hpp"
5

6
#include <iostream>
7

8
LoadResult CapnProtoFormatLoader::load(std::string const& filepath, 
1✔
9
                                      IODataType dataType, 
10
                                      nlohmann::json const& config, 
11
                                      DataFactory* factory) const {
12
    if (!factory) {
1✔
13
        return LoadResult("DataFactory is null");
×
14
    }
15

16
    switch (dataType) {
1✔
17
        case IODataType::Line:
1✔
18
            return loadLineDataCapnProto(filepath, config, factory);
1✔
19
            
20
        default:
×
21
            return LoadResult("CapnProto loader does not support data type: " + std::to_string(static_cast<int>(dataType)));
×
22
    }
23
}
24

25
bool CapnProtoFormatLoader::supportsFormat(std::string const& format, IODataType dataType) const {
21✔
26
    // Support capnp and binary formats for LineData
27
    if ((format == "capnp" || format == "binary") && dataType == IODataType::Line) {
21✔
28
        return true;
4✔
29
    }
30
    
31
    // Could add support for other data types in the future
32
    return false;
17✔
33
}
34

35
LoadResult CapnProtoFormatLoader::save(std::string const& filepath, 
×
36
                                       IODataType dataType, 
37
                                       nlohmann::json const& config, 
38
                                       void const* data) const {
39
    if (dataType != IODataType::Line) {
×
40
        return LoadResult("CapnProtoFormatLoader only supports saving LineData");
×
41
    }
42
    
43
    if (!data) {
×
44
        return LoadResult("Data pointer is null");
×
45
    }
46
    
47
    try {
48
        // Cast void pointer back to LineData
49
        auto const* line_data = static_cast<LineData const*>(data);
×
50
        
51
        // Convert JSON config to BinaryLineSaverOptions
52
        BinaryLineSaverOptions save_opts;
×
53
        save_opts.parent_dir = config.value("parent_dir", ".");
×
54
        save_opts.filename = config.value("filename", "line_data.capnp");
×
55
        
56
        // Call the existing save function
57
        if (::save(*line_data, save_opts)) {
×
NEW
58
            LoadResult result;
×
NEW
59
            result.success = true;
×
NEW
60
            return result;
×
61
        } else {
×
62
            return LoadResult("CapnProto save operation failed");
×
63
        }
64
        
UNCOV
65
    } catch (std::exception const& e) {
×
UNCOV
66
        return LoadResult("CapnProtoFormatLoader save failed: " + std::string(e.what()));
×
67
    }
×
68
}
69

70
std::string CapnProtoFormatLoader::getLoaderName() const {
92✔
71
    return "CapnProtoLoader";
276✔
72
}
73

74
LoadResult CapnProtoFormatLoader::loadLineDataCapnProto(std::string const& filepath, 
1✔
75
                                                       nlohmann::json const& config, 
76
                                                       DataFactory* factory) const {
77
    try {
78
        // Use existing CapnProto loading functionality
79
        BinaryLineLoaderOptions opts;
1✔
80
        opts.file_path = filepath;
1✔
81
        
82
        auto loaded_line_data = ::load(opts);
1✔
83
        if (!loaded_line_data) {
1✔
UNCOV
84
            return LoadResult("Failed to load CapnProto LineData from: " + filepath);
×
85
        }
86
        
87
        // Convert to factory-created object
88
        // First extract the data map from the loaded LineData
89
        std::map<TimeFrameIndex, std::vector<Line2D>> line_map;
1✔
90
        for (auto const& time : loaded_line_data->getTimesWithData()) {
3✔
91
            line_map[time] = loaded_line_data->getAtTime(time);
2✔
92
        }
93
        
94
        // Create new LineData using factory
95
        auto line_data_variant = factory->createLineData(line_map);
1✔
96
        
97
        // Apply image size from the loaded data
98
        ImageSize image_size = loaded_line_data->getImageSize();
1✔
99
        if (image_size.width > 0 && image_size.height > 0) {
1✔
UNCOV
100
            factory->setLineDataImageSize(line_data_variant, 
×
UNCOV
101
                                         static_cast<int>(image_size.width), 
×
102
                                         static_cast<int>(image_size.height));
×
103
        }
104
        
105
        // Apply image size override from config if specified
106
        if (config.contains("image_width") && config.contains("image_height")) {
1✔
UNCOV
107
            int width = config["image_width"];
×
UNCOV
108
            int height = config["image_height"];
×
109
            factory->setLineDataImageSize(line_data_variant, width, height);
×
110
        }
111
        
112
        return LoadResult(std::move(line_data_variant));
1✔
113
        
114
    } catch (std::exception const& e) {
1✔
UNCOV
115
        return LoadResult("CapnProto loading failed: " + std::string(e.what()));
×
UNCOV
116
    }
×
117
}
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