OpenVPN 3 Core Library
Loading...
Searching...
No Matches
autoreset.hpp
Go to the documentation of this file.
1// OpenVPN -- An application to securely tunnel IP networks
2// over a single port, with support for SSL/TLS-based
3// session authentication and key exchange,
4// packet encryption, packet authentication, and
5// packet compression.
6//
7// Copyright (C) 2012- OpenVPN Inc.
8//
9// SPDX-License-Identifier: MPL-2.0 OR AGPL-3.0-only WITH openvpn3-openssl-exception
10//
11
12// Automatically reset a target object when
13// AutoReset goes out of scope.
14
15#ifndef OPENVPN_COMMON_AUTORESET_H
16#define OPENVPN_COMMON_AUTORESET_H
17
18namespace openvpn {
19
20template <typename T>
22{
23 public:
24 AutoReset(T &obj)
25 : obj_(&obj)
26 {
27 }
28
30 {
31 if (obj_)
32 obj_->reset();
33 }
34
35 void disarm()
36 {
37 obj_ = nullptr;
38 }
39
40 private:
41 T *obj_;
42};
43
44} // namespace openvpn
45
46#endif