Path: blob/main/contrib/llvm-project/llvm/tools/llvm-remarkutil/RemarkUtilRegistry.cpp
35231 views
//===- RemarkUtilRegistry.cpp: Implement a command registry. --------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// Implement a simple subcommand registry.9//10//===----------------------------------------------------------------------===//11#include "RemarkUtilRegistry.h"12#include <unordered_map>1314namespace llvm {15namespace remarkutil {1617using HandlerType = std::function<Error()>;1819static std::unordered_map<cl::SubCommand *, HandlerType> &getCommands() {20static std::unordered_map<cl::SubCommand *, HandlerType> Commands;21return Commands;22}2324CommandRegistration::CommandRegistration(cl::SubCommand *SC,25HandlerType Command) {26assert(getCommands().count(SC) == 0 &&27"Attempting to overwrite a command handler");28assert(Command && "Attempting to register an empty std::function<Error()>");29getCommands()[SC] = Command;30}3132HandlerType dispatch(cl::SubCommand *SC) {33auto It = getCommands().find(SC);34assert(It != getCommands().end() &&35"Attempting to dispatch on un-registered SubCommand.");36return It->second;37}3839} // namespace remarkutil40} // namespace llvm414243