Program Listing for File MovementDetector.hpp

Return to documentation for file (src/navtk/inertial/MovementDetector.hpp)

#pragma once

#include <memory>
#include <string>
#include <unordered_map>

#include <navtk/inertial/MovementDetectorPlugin.hpp>
#include <navtk/inertial/MovementStatus.hpp>
#include <navtk/not_null.hpp>

namespace navtk {
namespace inertial {

struct MovementDetectorPluginStat {
    double weight = 0.0;

    double stale_time = 0.0;
};

class MovementDetector {

public:
    void add_plugin(const std::string& id,
                    not_null<std::shared_ptr<MovementDetectorPlugin>> plugin,
                    const double weight     = 1.0,
                    const double stale_time = 1.0);

    void remove_plugin(const std::string& id);

    // Formatting breaks in-docs link to other function version
    // clang-format off
    // clang-format on
    void process(not_null<std::shared_ptr<aspn_xtensor::AspnBase>> data);

    void process(const std::vector<std::string>& ids,
                 not_null<std::shared_ptr<aspn_xtensor::AspnBase>> data);

    MovementStatus get_status();

    std::unordered_map<std::string, MovementDetectorPluginStat> plugin_info() const;

private:
    // Container for storing plugin and assorted info
    struct FullPluginStat {
        MovementDetectorPluginStat stats;
        std::shared_ptr<MovementDetectorPlugin> plugin;
    };

    // Storage for plugins and related data.
    std::unordered_map<std::string, FullPluginStat> mp;

    // Extracted keys from plugin map to support no-id process() function
    std::vector<std::string> keys;
};

}  // namespace inertial
}  // namespace navtk