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
return
to_string(
nullptr
);
56
}
57
58
inline
std::string to_string(std::string &&
str
)
59
{
60
return
std::move(
str
);
61
}
62
63
inline
const
std::string &to_string(
const
std::string &
str
)
64
{
65
return
str
;
66
}
67
68
// to_cstring
69
70
inline
const
char
*
to_cstring
(
const
std::string &
str
)
71
{
72
return
str
.c_str();
73
}
74
75
inline
const
char
*
to_cstring
(
const
char
*
str
)
76
{
77
return
str
;
78
}
79
}
// namespace openvpn::StringTempl
80
81
#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:70
str
os<< "Session Name: "<< tbc-> session_name<< '\n';os<< "Layer: "<< tbc-> layer str()<< '\n'
openvpn
common
stringtempl.hpp
Generated by
1.9.8