AsyncFunCalls.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 #ifndef SQUID_SRC_BASE_ASYNCFUNCALLS_H
10 #define SQUID_SRC_BASE_ASYNCFUNCALLS_H
11 
12 #include "base/AsyncCall.h"
13 
14 #include <iostream>
15 
18 {
19 public:
20  using Handler = void ();
21 
22  explicit NullaryFunDialer(Handler * const aHandler): handler(aHandler) {}
23 
24  /* CallDialer API */
25  bool canDial(AsyncCall &) { return bool(handler); }
26  void dial(AsyncCall &) { handler(); }
27  void print(std::ostream &os) const override { os << "()"; }
28 
29 private:
31 };
32 
34 template <typename Argument1>
36 {
37 public:
39  using Handler = void (Argument1);
40 
41  UnaryFunDialer(Handler * const aHandler, Argument1 anArg1):
42  handler(aHandler),
43  arg1(anArg1)
44  {}
45  ~UnaryFunDialer() override = default;
46 
47  /* CallDialer API */
48  bool canDial(AsyncCall &) { return bool(handler); }
49  void dial(AsyncCall &) { handler(std::move(arg1)); }
50  void print(std::ostream &os) const final { os << '(' << arg1 << ')'; }
51 
52 private:
55 };
56 
58 template <typename Argument1>
60 callDialer(void (*handler)(Argument1), Argument1 arg1)
61 {
62  return UnaryFunDialer<Argument1>(handler, arg1);
63 }
64 
65 #endif /* SQUID_SRC_BASE_ASYNCFUNCALLS_H */
66 
bool canDial(AsyncCall &)
Definition: AsyncFunCalls.h:25
Calls a function without arguments. See also: NullaryMemFunT.
Definition: AsyncFunCalls.h:17
void dial(AsyncCall &)
Definition: AsyncFunCalls.h:49
Handler * handler
the function to call
Definition: AsyncFunCalls.h:53
Handler * handler
the function to call (or nil)
Definition: AsyncFunCalls.h:30
~UnaryFunDialer() override=default
UnaryFunDialer(Handler *const aHandler, Argument1 anArg1)
Definition: AsyncFunCalls.h:41
void(Argument1) Handler
a stand-alone function that receives the parameter given to us
Definition: AsyncFunCalls.h:39
UnaryFunDialer< Argument1 > callDialer(void(*handler)(Argument1), Argument1 arg1)
helper function to simplify UnaryFunDialer creation
Definition: AsyncFunCalls.h:60
Argument1 arg1
actual call parameter
Definition: AsyncFunCalls.h:54
bool canDial(AsyncCall &)
Definition: AsyncFunCalls.h:48
NullaryFunDialer(Handler *const aHandler)
Definition: AsyncFunCalls.h:22
void dial(AsyncCall &)
Definition: AsyncFunCalls.h:26
void print(std::ostream &os) const final
Definition: AsyncFunCalls.h:50
CallDialer for single-parameter stand-alone functions.
Definition: AsyncFunCalls.h:35
void print(std::ostream &os) const override
Definition: AsyncFunCalls.h:27

 

Introduction

Documentation

Support

Miscellaneous