PahoMqttCpp
MQTT C++ Client for POSIX and Windows
Toggle main menu visibility
Loading...
Searching...
No Matches
types.h
Go to the documentation of this file.
1
6
7
/*******************************************************************************
8
* Copyright (c) 2015-2017 Frank Pagliughi <fpagliughi@mindspring.com>
9
*
10
* All rights reserved. This program and the accompanying materials
11
* are made available under the terms of the Eclipse Public License v2.0
12
* and Eclipse Distribution License v1.0 which accompany this distribution.
13
*
14
* The Eclipse Public License is available at
15
* http://www.eclipse.org/legal/epl-v20.html
16
* and the Eclipse Distribution License is available at
17
* http://www.eclipse.org/org/documents/edl-v10.php.
18
*
19
* Contributors:
20
* Frank Pagliughi - initial implementation and documentation
21
*******************************************************************************/
22
23
#ifndef __mqtt_types_h
24
#define __mqtt_types_h
25
26
#include <chrono>
27
#include <memory>
28
#include <string>
29
#include <vector>
30
31
// Pull in reason codes here for backward compatability with old version
32
#include "
mqtt/reason_code.h
"
33
34
namespace
mqtt
{
35
37
// Basic data types
38
40
using
byte
= uint8_t;
41
43
using
string
= std::string;
45
using
binary
= std::string;
46
48
using
string_ptr
= std::shared_ptr<const string>;
50
using
binary_ptr
= std::shared_ptr<const binary>;
51
53
// Time functions
54
61
template
<
class
Rep,
class
Period>
62
std::chrono::seconds
to_seconds
(
const
std::chrono::duration<Rep, Period>& dur) {
63
return
std::chrono::duration_cast<std::chrono::seconds>(dur);
64
}
65
72
template
<
class
Rep,
class
Period>
73
long
to_seconds_count
(
const
std::chrono::duration<Rep, Period>& dur) {
74
return
(
long
)
to_seconds
(dur).count();
75
}
76
83
template
<
class
Rep,
class
Period>
84
std::chrono::milliseconds
to_milliseconds
(
const
std::chrono::duration<Rep, Period>& dur) {
85
return
std::chrono::duration_cast<std::chrono::milliseconds>(dur);
86
}
87
94
template
<
class
Rep,
class
Period>
95
long
to_milliseconds_count
(
const
std::chrono::duration<Rep, Period>& dur) {
96
return
(
long
)
to_milliseconds
(dur).count();
97
}
98
100
// Misc
101
107
inline
bool
to_bool
(
int
n) {
return
n != 0; }
113
inline
int
to_int
(
bool
b) {
return
b ? (!0) : 0; }
114
122
inline
string
to_string
(
const
char
* cstr) {
return
cstr ?
string
(cstr) :
string
(); }
123
125
}
// namespace mqtt
126
127
#endif
// __mqtt_types_h
mqtt
Definition
async_client.h:60
mqtt::to_seconds_count
long to_seconds_count(const std::chrono::duration< Rep, Period > &dur)
Definition
types.h:73
mqtt::to_bool
bool to_bool(int n)
Definition
types.h:107
mqtt::string_ptr
std::shared_ptr< const string > string_ptr
Definition
types.h:48
mqtt::binary
std::string binary
Definition
types.h:45
mqtt::to_milliseconds
std::chrono::milliseconds to_milliseconds(const std::chrono::duration< Rep, Period > &dur)
Definition
types.h:84
mqtt::to_seconds
std::chrono::seconds to_seconds(const std::chrono::duration< Rep, Period > &dur)
Definition
types.h:62
mqtt::byte
uint8_t byte
Definition
types.h:40
mqtt::string
std::string string
Definition
types.h:43
mqtt::binary_ptr
std::shared_ptr< const binary > binary_ptr
Definition
types.h:50
mqtt::to_string
std::string to_string(ReasonCode reasonCode)
mqtt::to_int
int to_int(bool b)
Definition
types.h:113
mqtt::to_milliseconds_count
long to_milliseconds_count(const std::chrono::duration< Rep, Period > &dur)
Definition
types.h:95
reason_code.h
Generated on
for PahoMqttCpp by
1.17.0