// Copyright (c) FIRST and other WPILib contributors. // Open Source Software; you can modify and/or share it under the terms of // the WPILib BSD license file in the root directory of this project. #pragma once #include #include #include #include "Handle.h" namespace nt { // Utility wrapper class for our UidVectors template class HandleMap : public wpi::UidVector, Size> { public: template T* Add(int inst, Args&&... args) { auto i = this->emplace_back(); auto& it = (*this)[i]; it = std::make_unique(Handle(inst, i, T::kType), std::forward(args)...); return it.get(); } std::unique_ptr Remove(NT_Handle handle) { Handle h{handle}; if (!h.IsType(T::kType)) { return {}; } unsigned int i = h.GetIndex(); if (i >= this->size()) { return {}; } return this->erase(i); } T* Get(NT_Handle handle) { Handle h{handle}; if (!h.IsType(T::kType)) { return {}; } unsigned int i = h.GetIndex(); if (i >= this->size()) { return {}; } return (*this)[i].get(); } }; } // namespace nt