workflows: Fix typo in pr-subscriber
[llvm-project.git] / llvm / tools / llvm-remarkutil / RemarkUtilRegistry.cpp
blob244a16d51805b615bc61b9ea80f44990ab344b6c
1 //===- RemarkUtilRegistry.cpp: Implement a command registry. --------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Implement a simple subcommand registry.
11 //===----------------------------------------------------------------------===//
12 #include "RemarkUtilRegistry.h"
13 #include <unordered_map>
15 namespace llvm {
16 namespace remarkutil {
18 using HandlerType = std::function<Error()>;
20 static std::unordered_map<cl::SubCommand *, HandlerType> &getCommands() {
21 static std::unordered_map<cl::SubCommand *, HandlerType> Commands;
22 return Commands;
25 CommandRegistration::CommandRegistration(cl::SubCommand *SC,
26 HandlerType Command) {
27 assert(getCommands().count(SC) == 0 &&
28 "Attempting to overwrite a command handler");
29 assert(Command && "Attempting to register an empty std::function<Error()>");
30 getCommands()[SC] = Command;
33 HandlerType dispatch(cl::SubCommand *SC) {
34 auto It = getCommands().find(SC);
35 assert(It != getCommands().end() &&
36 "Attempting to dispatch on un-registered SubCommand.");
37 return It->second;
40 } // namespace remarkutil
41 } // namespace llvm