Loading...
Searching...
No Matches
types.h
Go to the documentation of this file.
/*******************************************************************************
* Copyright (c) 2015-2017 Frank Pagliughi <fpagliughi@mindspring.com>
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v2.0
* and Eclipse Distribution License v1.0 which accompany this distribution.
*
* The Eclipse Public License is available at
* http://www.eclipse.org/legal/epl-v20.html
* and the Eclipse Distribution License is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* Contributors:
* Frank Pagliughi - initial implementation and documentation
*******************************************************************************/
#ifndef __mqtt_types_h
#define __mqtt_types_h
#include <chrono>
#include <memory>
#include <string>
#include <vector>
// Pull in reason codes here for backward compatability with old version
#include "mqtt/reason_code.h"
namespace mqtt {
// Basic data types
using byte = uint8_t;
using string = std::string;
using binary = std::string;
using string_ptr = std::shared_ptr<const string>;
using binary_ptr = std::shared_ptr<const binary>;
// Time functions
template <class Rep, class Period>
std::chrono::seconds to_seconds(const std::chrono::duration<Rep, Period>& dur) {
return std::chrono::duration_cast<std::chrono::seconds>(dur);
}
template <class Rep, class Period>
long to_seconds_count(const std::chrono::duration<Rep, Period>& dur) {
return (long)to_seconds(dur).count();
}
template <class Rep, class Period>
std::chrono::milliseconds to_milliseconds(const std::chrono::duration<Rep, Period>& dur) {
return std::chrono::duration_cast<std::chrono::milliseconds>(dur);
}
template <class Rep, class Period>
long to_milliseconds_count(const std::chrono::duration<Rep, Period>& dur) {
return (long)to_milliseconds(dur).count();
}
// Misc
inline bool to_bool(int n) { return n != 0; }
inline int to_int(bool b) { return b ? (!0) : 0; }
inline string to_string(const char* cstr) { return cstr ? string(cstr) : string(); }
} // namespace mqtt
#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