aboutsummaryrefslogtreecommitdiff
path: root/include/ble
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2018-11-23 16:41:24 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2018-11-23 16:41:24 +0100
commitaf416f81b14a3bee682e300b165a6efdb9739d54 (patch)
tree20c4704d5d24ed18a78970f9331aec12c9522a41 /include/ble
parent2034b1bb10720a2f0e6cc97427346f2320c115bc (diff)
downloadble-toys-af416f81b14a3bee682e300b165a6efdb9739d54.tar.gz
ble-toys-af416f81b14a3bee682e300b165a6efdb9739d54.tar.bz2
ble-toys-af416f81b14a3bee682e300b165a6efdb9739d54.tar.xz
ble-toys-af416f81b14a3bee682e300b165a6efdb9739d54.zip
o Trying to improve compatibility with some feature checks.
o Misc nits.
Diffstat (limited to 'include/ble')
-rw-r--r--include/ble/Bluetooth.h4
-rw-r--r--include/ble/att.h6
-rw-r--r--include/ble/compiler-support.h62
-rw-r--r--include/ble/misc.h4
4 files changed, 68 insertions, 8 deletions
diff --git a/include/ble/Bluetooth.h b/include/ble/Bluetooth.h
index 5f7cd17..28e2794 100644
--- a/include/ble/Bluetooth.h
+++ b/include/ble/Bluetooth.h
@@ -1,7 +1,6 @@
#ifndef BLUETOOTH_H
#define BLUETOOTH_H
-#include <optional>
#include <iosfwd>
#include <iostream>
#include <stdexcept>
@@ -23,9 +22,6 @@ using std::vector;
using std::map;
using std::runtime_error;
-template<typename T>
-using o = std::optional<T>;
-
class BluetoothAdapter;
class BluetoothDevice;
class BluetoothGatt;
diff --git a/include/ble/att.h b/include/ble/att.h
index 152a779..7b77812 100644
--- a/include/ble/att.h
+++ b/include/ble/att.h
@@ -1,6 +1,5 @@
#pragma once
-#include <variant>
#include <vector>
#include "ble/ByteBuffer.h"
@@ -9,6 +8,9 @@
namespace trygvis {
namespace bluetooth {
+using ::trygvis::compiler::variant;
+using ::trygvis::compiler::monostate;
+
/**
* BLUETOOTH SPECIFICATION Version 4.0 [Vol 3] - Attribute Protocol (ATT) - 3.4.8 Attribute Opcode Summary
* Table 3.37
@@ -144,7 +146,7 @@ struct HandleValueIndication {
ByteBuffer data;
};
-using AttVariant = std::variant<std::monostate,
+using AttVariant = variant<monostate,
ErrorRes,
ExchangeMtuReq, ExchangeMtuRes,
FindInformationRes,
diff --git a/include/ble/compiler-support.h b/include/ble/compiler-support.h
new file mode 100644
index 0000000..1e7e185
--- /dev/null
+++ b/include/ble/compiler-support.h
@@ -0,0 +1,62 @@
+#ifndef COMPILER_SUPPORT_H
+
+#ifdef __has_include
+
+# if __has_include(<optional>)
+# include <optional>
+# define have_optional 1
+# elif __has_include(<experimental/optional>)
+# include <experimental/optional>
+# define have_optional 1
+# define have_experimental_optional 1
+# else
+# define have_optional 0
+# endif
+
+# if __has_include(<variant>)
+# include <variant>
+# define have_variant 1
+# elif __has_include(<experimental/variant>)
+# include <experimental/variant>
+# define have_variant 1
+# define have_experimental_variant 1
+# else
+# define have_variant 0
+# endif
+
+#endif
+
+namespace trygvis {
+namespace compiler {
+
+#if have_experimental_optional
+
+template<typename T>
+using o = std::experimental::optional<T>;
+
+#elif have_optional
+
+template<typename T>
+using o = std::optional<T>;
+
+#endif
+
+#if have_experimental_variant
+
+template<typename... T>
+using variant = std::experimental::variant<T>;
+using monostate = std::experimental::monostate;
+
+#elif have_variant
+
+template<typename... T>
+using variant = std::variant<T...>;
+using monostate = std::monostate;
+
+#endif
+
+} // namespace compiler
+} // namespace trygvis
+
+
+#endif
diff --git a/include/ble/misc.h b/include/ble/misc.h
index 563d039..aa0ba2e 100644
--- a/include/ble/misc.h
+++ b/include/ble/misc.h
@@ -1,5 +1,6 @@
#pragma once
+#include "ble/compiler-support.h"
#include "ByteBuffer.h"
#include <optional>
@@ -10,8 +11,7 @@
namespace trygvis {
namespace bluetooth {
-template<typename T>
-using o = std::optional<T>;
+using ::trygvis::compiler::o;
class BluetoothAdapter;
class BluetoothDevice;