OpenVPN 3 Core Library
Loading...
Searching...
No Matches
stringtempl.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
13
// Sometimes you want to accept a <typename STRING> in a
14
// method, without knowing whether it's a const char *,
15
// const std::string&, or nullptr. These methods help with
16
// basic type-independent string operations.
17
18
#ifndef OPENVPN_COMMON_STRINGTEMPL_H
19
#define OPENVPN_COMMON_STRINGTEMPL_H
20
21
#include <string>
22
#include <cstddef>
// for std::nullptr_t
23
#include <utility>
24
25
namespace
openvpn::StringTempl
{
26
27
// empty
28
29
inline
bool
empty
(std::nullptr_t)
30
{
31
return
true
;
32
}
33
34
inline
bool
empty
(
const
char
*
str
)
35
{
36
return
!
str
||
str
[0] ==
'\0'
;
37
}
38
39
inline
bool
empty
(
const
std::string &
str
)
40
{
41
return
str
.empty();
42
}
43
44
// to_string
45
46
inline
std::string to_string(std::nullptr_t)
47
{
48
return
std::string();
49
}
50
51
inline
std::string to_string(
const
char
*
str
)
52
{
53
if
(
str
)
54
return
std::string(
str
);
55
else
56
return
to_string(
nullptr
);
57
}
58
59
inline
std::string to_string(std::string &&
str
)
60
{
61
return
std::move(
str
);
62
}
63
64
inline
const
std::string &to_string(
const
std::string &
str
)
65
{
66
return
str
;
67
}
68
69
// to_cstring
70
71
inline
const
char
*
to_cstring
(
const
std::string &
str
)
72
{
73
return
str
.c_str();
74
}
75
76
inline
const
char
*
to_cstring
(
const
char
*
str
)
77
{
78
return
str
;
79
}
80
}
// namespace openvpn::StringTempl
81
82
#endif
openvpn::StringTempl
Definition
stringtempl.hpp:25
openvpn::StringTempl::empty
bool empty(std::nullptr_t)
Definition
stringtempl.hpp:29
openvpn::StringTempl::to_cstring
const char * to_cstring(const std::string &str)
Definition
stringtempl.hpp:71
str
os<< "Session Name: "<< tbc-> session_name<< '\n';os<< "Layer: "<< tbc-> layer str()<< '\n'
openvpn
common
stringtempl.hpp
Generated by
1.9.8