Paho C++  1.0
The Paho MQTT C++ Client Library
 All Classes Files Functions Variables Typedefs Friends
types.h
Go to the documentation of this file.
1 
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 v1.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-v10.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 <string>
27 #include <vector>
28 #include <memory>
29 #include <chrono>
30 
31 namespace mqtt {
32 
34 // Basic data types
35 
37 using byte = uint8_t;
38 
40 using string = std::string;
42 using binary = std::string; //std::basic_string<byte>;
43 
45 using string_ptr = std::shared_ptr<const string>;
47 using binary_ptr = std::shared_ptr<const binary>;
48 
50 // Time functions
51 
58 template <class Rep, class Period>
59 std::chrono::seconds to_seconds(const std::chrono::duration<Rep, Period>& dur) {
60  return std::chrono::duration_cast<std::chrono::seconds>(dur);
61 }
62 
69 template <class Rep, class Period>
70 long to_seconds_count(const std::chrono::duration<Rep, Period>& dur) {
71  return (long) to_seconds(dur).count();
72 }
73 
80 template <class Rep, class Period>
81 std::chrono::milliseconds to_milliseconds(const std::chrono::duration<Rep, Period>& dur) {
82  return std::chrono::duration_cast<std::chrono::milliseconds>(dur);
83 }
84 
91 template <class Rep, class Period>
92 long to_milliseconds_count(const std::chrono::duration<Rep, Period>& dur) {
93  return (long) to_milliseconds(dur).count();
94 }
95 
97 // Misc
98 
104 inline bool to_bool(int n) { return n != 0; }
110 inline int to_int(bool b) { return b ? (!0) : 0; }
111 
113 // end namespace mqtt
114 }
115 
116 #endif // __mqtt_types_h
117