PahoMqttCpp
MQTT C++ Client for POSIX and Windows
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
34namespace mqtt {
35
37// Basic data types
38
40using byte = uint8_t;
41
43using string = std::string;
45using binary = std::string;
46
48using string_ptr = std::shared_ptr<const string>;
50using binary_ptr = std::shared_ptr<const binary>;
51
53// Time functions
54
61template <class Rep, class Period>
62std::chrono::seconds to_seconds(const std::chrono::duration<Rep, Period>& dur) {
63 return std::chrono::duration_cast<std::chrono::seconds>(dur);
64}
65
72template <class Rep, class Period>
73long to_seconds_count(const std::chrono::duration<Rep, Period>& dur) {
74 return (long)to_seconds(dur).count();
75}
76
83template <class Rep, class Period>
84std::chrono::milliseconds to_milliseconds(const std::chrono::duration<Rep, Period>& dur) {
85 return std::chrono::duration_cast<std::chrono::milliseconds>(dur);
86}
87
94template <class Rep, class Period>
95long to_milliseconds_count(const std::chrono::duration<Rep, Period>& dur) {
96 return (long)to_milliseconds(dur).count();
97}
98
100// Misc
101
107inline bool to_bool(int n) { return n != 0; }
113inline int to_int(bool b) { return b ? (!0) : 0; }
114
122inline string to_string(const char* cstr) { return cstr ? string(cstr) : string(); }
123
125} // namespace mqtt
126
127#endif // __mqtt_types_h
Definition async_client.h:60
long to_seconds_count(const std::chrono::duration< Rep, Period > &dur)
Definition types.h:73
bool to_bool(int n)
Definition types.h:107
std::shared_ptr< const string > string_ptr
Definition types.h:48
std::string binary
Definition types.h:45
std::chrono::milliseconds to_milliseconds(const std::chrono::duration< Rep, Period > &dur)
Definition types.h:84
std::chrono::seconds to_seconds(const std::chrono::duration< Rep, Period > &dur)
Definition types.h:62
uint8_t byte
Definition types.h:40
std::string string
Definition types.h:43
std::shared_ptr< const binary > binary_ptr
Definition types.h:50
std::string to_string(ReasonCode reasonCode)
int to_int(bool b)
Definition types.h:113
long to_milliseconds_count(const std::chrono::duration< Rep, Period > &dur)
Definition types.h:95