From a7fb95ce818454307f2cd521db7d5b330fcf2b04 Mon Sep 17 00:00:00 2001 From: Hideaki Tai Date: Tue, 29 Sep 2020 20:57:21 +0900 Subject: [PATCH] update ArxContainer to v0.3.9 --- README.md | 2 +- util/ArxContainer/ArxContainer.h | 46 ++++++++----------- util/ArxContainer/ArxContainer/has_include.h | 29 ++++++++++++ .../ArxContainer/has_libstdcplusplus.h | 25 ++++++++++ .../ArxContainer/initializer_list.h | 30 ++++++++++++ .../ArxContainer/replace_minmax_macros.h | 33 +++++++++++++ util/ArxContainer/README.md | 16 +++---- util/ArxContainer/library.json | 8 ++-- util/ArxContainer/library.properties | 4 +- 9 files changed, 149 insertions(+), 44 deletions(-) create mode 100644 util/ArxContainer/ArxContainer/has_include.h create mode 100644 util/ArxContainer/ArxContainer/has_libstdcplusplus.h create mode 100644 util/ArxContainer/ArxContainer/initializer_list.h create mode 100644 util/ArxContainer/ArxContainer/replace_minmax_macros.h diff --git a/README.md b/README.md index 402d0eb..e09fad3 100644 --- a/README.md +++ b/README.md @@ -251,7 +251,7 @@ Please use only sender OR receiver. ## Embedded Libraries -- [ArxContainer v0.3.8](https://github.com/hideakitai/ArxContainer) +- [ArxContainer v0.3.9](https://github.com/hideakitai/ArxContainer) - [TeensyDirtySTLErrorSolution v0.1.0](https://github.com/hideakitai/TeensyDirtySTLErrorSolution) diff --git a/util/ArxContainer/ArxContainer.h b/util/ArxContainer/ArxContainer.h index 0d1f9ec..f7bacf6 100644 --- a/util/ArxContainer/ArxContainer.h +++ b/util/ArxContainer/ArxContainer.h @@ -3,17 +3,26 @@ #ifndef ARX_RINGBUFFER_H #define ARX_RINGBUFFER_H +#if __cplusplus < 201103L + #error "C++11 must be enabled in the compiler for this library to work, please check your compiler flags" +#endif + +#include "ArxContainer/has_include.h" +#include "ArxContainer/has_libstdcplusplus.h" + #include -#if defined(ARDUINO_ARCH_AVR)\ - || defined(ARDUINO_ARCH_MEGAAVR)\ - || defined(ARDUINO_ARCH_SAM)\ - || defined(ARDUINO_ARCH_SAMD)\ - || defined(ARDUINO_spresense_ast) - #define ARX_CONTAINER_DISABLED -#endif +#include "ArxContainer/replace_minmax_macros.h" +#include "ArxContainer/initializer_list.h" + +#if ARX_HAVE_LIBSTDCPLUSPLUS >= 201103L // Have libstdc++11 + +#include +#include +#include + +#else // Do not have libstdc++11 -#ifdef ARX_CONTAINER_DISABLED #ifndef ARX_VECTOR_DEFAULT_SIZE #define ARX_VECTOR_DEFAULT_SIZE 16 @@ -27,25 +36,6 @@ #define ARX_MAP_DEFAULT_SIZE 16 #endif // ARX_MAP_DEFAULT_SIZE -#ifndef ARX_TYPE_TRAITS_INITIALIZER_LIST_DEFINED -#define ARX_TYPE_TRAITS_INITIALIZER_LIST_DEFINED -namespace std -{ - template - class initializer_list - { - private: - const T* array; - size_t len; - initializer_list(const T* a, size_t l) : array(a), len(l) {} - public: - initializer_list() : array(nullptr), len(0) {} - size_t size() const { return len; } - const T *begin() const { return array; } - const T *end() const { return array + len; } - }; -} -#endif // ARX_TYPE_TRAITS_INITIALIZER_LIST_DEFINED namespace arx { @@ -560,5 +550,5 @@ template using ArxRingBuffer = arx::RingBuffer; -#endif // ARX_CONTAINER_DISABLED +#endif // Do not have libstdc++11 #endif // ARX_RINGBUFFER_H diff --git a/util/ArxContainer/ArxContainer/has_include.h b/util/ArxContainer/ArxContainer/has_include.h new file mode 100644 index 0000000..76b39a9 --- /dev/null +++ b/util/ArxContainer/ArxContainer/has_include.h @@ -0,0 +1,29 @@ +#pragma once + +#ifndef ARX_TYPE_TRAITS_HAS_INCLUDE_H +#define ARX_TYPE_TRAITS_HAS_INCLUDE_H + + // Check whether __has_include is available, but also check the GCC + // version (__has_include was introduced in gcc 5) to catch + // environments (such as ESP8266) where gcc is old, but some system + // header provides a fake __has_include. We also need to check + // against __clang__ here, since clang pretends to be GCC + // 4.something and would otherwise be detected incorrectly here... + #if !defined(__has_include) || defined(__GNUC__) && __GNUC__ < 5 && !defined(__clang__) + #if defined(ARDUINO_ARCH_ESP8266) + // ESP8266 does not have a working __has_include, but we + // know it does have a working libstdc++ with all the + // headers we care about, so provide a fake has_include + #define ARX_SYSTEM_HAS_INCLUDE(x) 1 + #elif defined(ARDUINO_SAM_DUE) + // Arduino DUE's GCC version is 4.8.3 (GCC < 5.0). + // And it has not libstdc++ + #define ARX_SYSTEM_HAS_INCLUDE(x) 0 + #else + #error "Compiler does not support __has_include, please report a bug against the ArxTypeTraits library about this." + #endif + #else + #define ARX_SYSTEM_HAS_INCLUDE(x) __has_include(x) + #endif + +#endif // ARX_TYPE_TRAITS_HAS_INCLUDE_H diff --git a/util/ArxContainer/ArxContainer/has_libstdcplusplus.h b/util/ArxContainer/ArxContainer/has_libstdcplusplus.h new file mode 100644 index 0000000..77d77be --- /dev/null +++ b/util/ArxContainer/ArxContainer/has_libstdcplusplus.h @@ -0,0 +1,25 @@ +#pragma once + +#ifndef ARX_TYPE_TRAITS_HAS_LIBSTDCPLUSPLUS_H +#define ARX_TYPE_TRAITS_HAS_LIBSTDCPLUSPLUS_H + +#if !defined(ARX_HAVE_LIBSTDCPLUSPLUS) + #if ARX_SYSTEM_HAS_INCLUDE() + #include + #if defined(__GLIBCXX__) || defined(_LIBCPP_VERSION) + // For gcc's libstdc++ and clang's libc++, assume that + // __cplusplus tells us what the standard includes support + #define ARX_HAVE_LIBSTDCPLUSPLUS __cplusplus + #elif defined(__UCLIBCXX_MAJOR__) + // For uclibc++, assume C++98 support only. + #define ARX_HAVE_LIBSTDCPLUSPLUS 199711L + #else + #error "Unknown C++ library found, please report a bug against the ArxTypeTraits library about this." + #endif + #else + // Assume no standard library is available at all (e.g. on AVR) + #define ARX_HAVE_LIBSTDCPLUSPLUS 0 + #endif +#endif + +#endif // ARX_TYPE_TRAITS_HAS_LIBSTDCPLUSPLUS_H diff --git a/util/ArxContainer/ArxContainer/initializer_list.h b/util/ArxContainer/ArxContainer/initializer_list.h new file mode 100644 index 0000000..cdd1e5d --- /dev/null +++ b/util/ArxContainer/ArxContainer/initializer_list.h @@ -0,0 +1,30 @@ +#pragma once + +#ifndef ARX_TYPE_TRAITS_INITIALIZER_H +#define ARX_TYPE_TRAITS_INITIALIZER_H + +// Initializer_list *must* be defined in std, so take extra care to only +// define it when is really not available (e.g. +// ArduinoSTL is C++98 but *does* define ) and not +// already defined (e.g. by ArxContainer). +#if __has_include() +#include +#else +namespace std { + template + class initializer_list + { + private: + const T* array; + size_t len; + initializer_list(const T* a, size_t l) : array(a), len(l) {} + public: + initializer_list() : array(nullptr), len(0) {} + size_t size() const { return len; } + const T *begin() const { return array; } + const T *end() const { return array + len; } + }; +} // namespace std +#endif + +#endif // ARX_TYPE_TRAITS_INITIALIZER_LIST_H diff --git a/util/ArxContainer/ArxContainer/replace_minmax_macros.h b/util/ArxContainer/ArxContainer/replace_minmax_macros.h new file mode 100644 index 0000000..9668ccc --- /dev/null +++ b/util/ArxContainer/ArxContainer/replace_minmax_macros.h @@ -0,0 +1,33 @@ +#pragma once + +#ifndef ARX_TYPE_TRAITS_REPLACE_MINMAX_MACROS_H +#define ARX_TYPE_TRAITS_REPLACE_MINMAX_MACROS_H + +// Make sure Arduino.h is actually included, since otherwise it might be +// included later and break *uses* of the min/max methods, rather than +// the declarations of it. +#include + +// These macros are defined by Arduino.h on some platforms, and conflict +// with min/max methods defined or included by ArxTypeTraits, so replace +// them with macros here. +#ifdef max + #undef max + template + constexpr auto max(T1 x, T2 y) + -> decltype(x + y) + { + return (x > y) ? x : y; + } +#endif +#ifdef min + #undef min + template + constexpr auto min(T1 x, T2 y) + -> decltype(x + y) + { + return (x < y) ? x : y; + } +#endif + +#endif // ARX_TYPE_TRAITS_REPLACE_MINMAX_MACROS_H diff --git a/util/ArxContainer/README.md b/util/ArxContainer/README.md index 86d7684..4a90558 100644 --- a/util/ArxContainer/README.md +++ b/util/ArxContainer/README.md @@ -1,12 +1,14 @@ # ArxContainer -C++ container-like classes (vector, map, etc.) for Arduino which cannot use STL +C++ container-like classes (`vector`, `deque`, `map` etc.) for Arduino which cannot use STL ## Note -`ArxContainer` is C++ container-__like__ classes for Arduino. -All of the functions is not supported currently. -Detail of these containers are described in Detail section. +- `ArxContainer` is C++ container-__like__ classes for Arduino + - Containers in this library is defined inside namespace `arx` instad of `std` (e.g. `arx::vector`) + - All of the functions is not supported currently +- If standard libraries are available, automatically use `std` version instead of `arx` version + ## Supported Container Types @@ -17,14 +19,12 @@ Detail of these containers are described in Detail section. ## Supported Boards -This library is currently enabled only if you use following architecture. -Please use C++ Standard Template Library for other boards. +`arx` version of containers are enabled only if you use following architecture. +In other borads, `arx` version is disabled and standard libraries (`std` version) will be imported (because they can use them). - AVR (Uno, Nano, Mega, etc.) - MEGAAVR (Uno WiFi, Nano Ecery, etc.) - SAM (Due) -- SAMD (Zero, MKR, M0, etc.) -- SPRESENSE ## Usage diff --git a/util/ArxContainer/library.json b/util/ArxContainer/library.json index 83d940c..2c746d7 100644 --- a/util/ArxContainer/library.json +++ b/util/ArxContainer/library.json @@ -2,18 +2,16 @@ "name": "ArxContainer", "keywords": "ringbuffer, vector, deque, map", "description": "C++ container-like classes (vector, map, etc.) for Arduino which cannot use STL", - "repository": - { + "repository": { "type": "git", "url": "https://github.com/hideakitai/ArxContainer.git" }, - "authors": - { + "authors": { "name": "Hideaki Tai", "url": "https://github.com/hideakitai", "maintainer": true }, - "version": "0.3.8", + "version": "0.3.9", "license": "MIT", "frameworks": "arduino", "platforms": "*" diff --git a/util/ArxContainer/library.properties b/util/ArxContainer/library.properties index 1d0fe4d..a1b55ec 100644 --- a/util/ArxContainer/library.properties +++ b/util/ArxContainer/library.properties @@ -1,9 +1,9 @@ name=ArxContainer -version=0.3.8 +version=0.3.9 author=hideakitai maintainer=hideakitai sentence=C++ container-like classes (vector, map, etc.) for Arduino which cannot use STL paragraph=C++ container-like classes (vector, map, etc.) for Arduino which cannot use STL category=Data Storage -url=https://github.com/hideakitai +url=https://github.com/hideakitai/ArxContainer architectures=*