.. _program_listing_file_src_tap_control_command_mapping.cpp: Program Listing for File command_mapping.cpp ============================================ |exhale_lsh| :ref:`Return to documentation for file ` (``src/tap/control/command_mapping.cpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp /* * Copyright (c) 2020-2021 Advanced Robotics at the University of Washington * * This file is part of Taproot. * * Taproot is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Taproot is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Taproot. If not, see . */ #include "command_mapping.hpp" #include #include "tap/drivers.hpp" namespace tap { namespace control { CommandMapping::CommandMapping( Drivers *drivers, const std::vector cmds, const RemoteMapState &rms) : mapState(rms), mappedCommands(cmds), drivers(drivers) { std::remove_if( mappedCommands.begin(), mappedCommands.end(), [](Command *c) { return c == nullptr; }); } bool operator==(const CommandMapping &cm1, const CommandMapping &cm2) { return (cm1.mapState == cm2.mapState) && (cm1.mappedCommands == cm2.mappedCommands); } bool mapStateEqual(const CommandMapping &cm1, const CommandMapping &cm2) { return cm1.mapState == cm2.mapState; } bool CommandMapping::mappingSubset(const RemoteMapState &mapState) { return this->mapState.stateSubsetOf(mapState); } void CommandMapping::addCommands() { std::for_each( mappedCommands.begin(), mappedCommands.end(), [this](auto cmd) { drivers->commandScheduler.addCommand(cmd); }); } void CommandMapping::removeCommands() { std::for_each( mappedCommands.begin(), mappedCommands.end(), [this](auto cmd) { drivers->commandScheduler.removeCommand(cmd, false); }); } bool CommandMapping::noCommandsScheduled() const { for (auto cmd : mappedCommands) { if (drivers->commandScheduler.isCommandScheduled(cmd)) { return false; } } return true; } } // namespace control } // namespace tap