Soldered 125kHz RFID board Arduino library 1.0.0
Library for Soldered 125kHz RFID board.
Loading...
Searching...
No Matches
ghostl.h
Go to the documentation of this file.
1/*
2ghostl.h - Implementation of a bare-bones, mostly no-op, C++ STL shell
3 that allows building some Arduino ESP8266/ESP32
4 libraries on Aruduino AVR.
5Copyright (c) 2019 Dirk O. Kaar. All rights reserved.
6
7This library is free software; you can redistribute it and/or
8modify it under the terms of the GNU Lesser General Public
9License as published by the Free Software Foundation; either
10version 2.1 of the License, or (at your option) any later version.
11
12This library is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public
18License along with this library; if not, write to the Free Software
19Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20*/
21
22#ifndef __ghostl_h
23#define __ghostl_h
24
25#if defined(ARDUINO_ARCH_SAMD)
26#include <atomic>
27#endif
28
29using size_t = decltype(sizeof(char));
30
31namespace std
32{
33#if !defined(ARDUINO_ARCH_SAMD)
40 template< typename T > class atomic {
41 private:
43 public:
44 atomic() {}
45 atomic(T desired) { value = desired; }
46 void store(T desired, std::memory_order = std::memory_order_seq_cst) volatile noexcept { value = desired; }
47 T load(std::memory_order = std::memory_order_seq_cst) const volatile noexcept { return value; }
48 };
49 inline void atomic_thread_fence(std::memory_order order) noexcept {}
50 template< typename T > T&& move(T& t) noexcept { return static_cast<T&&>(t); }
51#endif
52
53 template< typename T, size_t long N > struct array
54 {
56 decltype(sizeof(0)) size() const { return N; }
57 T& operator[](decltype(sizeof(0)) i) { return _M_elems[i]; }
58 const T& operator[](decltype(sizeof(0)) i) const { return _M_elems[i]; }
59 };
60
61 template< typename T > class unique_ptr
62 {
63 public:
64 using pointer = T*;
65 unique_ptr() noexcept : ptr(nullptr) {}
67 pointer operator->() const noexcept { return ptr; }
68 T& operator[](decltype(sizeof(0)) i) const { return ptr[i]; }
69 void reset(pointer p = pointer()) noexcept
70 {
71 delete ptr;
72 ptr = p;
73 }
74 T& operator*() const { return *ptr; }
75 private:
77 };
78
79 template< typename T > using function = T*;
80 using nullptr_t = decltype(nullptr);
81
82 template<typename T>
83 struct identity {
84 typedef T type;
85 };
86
87 template <typename T>
88 inline T&& forward(typename identity<T>::type& t) noexcept
89 {
90 return static_cast<typename identity<T>::type&&>(t);
91 }
92}
93
94#endif // __ghostl_h
Definition ghostl.h:40
T load(std::memory_order=std::memory_order_seq_cst) const volatile noexcept
Definition ghostl.h:47
void store(T desired, std::memory_order=std::memory_order_seq_cst) volatile noexcept
Definition ghostl.h:46
atomic(T desired)
Definition ghostl.h:45
atomic()
Definition ghostl.h:44
T value
Definition ghostl.h:42
Definition ghostl.h:62
T & operator*() const
Definition ghostl.h:74
T & operator[](decltype(sizeof(0)) i) const
Definition ghostl.h:68
unique_ptr(pointer p)
Definition ghostl.h:66
pointer operator->() const noexcept
Definition ghostl.h:67
void reset(pointer p=pointer()) noexcept
Definition ghostl.h:69
pointer ptr
Definition ghostl.h:76
T * pointer
Definition ghostl.h:64
unique_ptr() noexcept
Definition ghostl.h:65
decltype(sizeof(char)) size_t
Definition ghostl.h:29
Definition ghostl.h:32
void atomic_thread_fence(std::memory_order order) noexcept
Definition ghostl.h:49
T && move(T &t) noexcept
Definition ghostl.h:50
decltype(nullptr) nullptr_t
Definition ghostl.h:80
memory_order
Definition ghostl.h:34
@ memory_order_relaxed
Definition ghostl.h:35
@ memory_order_release
Definition ghostl.h:37
@ memory_order_acquire
Definition ghostl.h:36
@ memory_order_seq_cst
Definition ghostl.h:38
T && forward(typename identity< T >::type &t) noexcept
Definition ghostl.h:88
T * function
Definition ghostl.h:79
Definition ghostl.h:54
decltype(sizeof(0)) size() const
Definition ghostl.h:56
T & operator[](decltype(sizeof(0)) i)
Definition ghostl.h:57
const T & operator[](decltype(sizeof(0)) i) const
Definition ghostl.h:58
T _M_elems[N]
Definition ghostl.h:55
Definition ghostl.h:83
T type
Definition ghostl.h:84