My Project
common.h
1 /*
2  * uuid-common - Microcontroller common utilities
3  * Copyright 2019,2022 Simon Arlott
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef UUID_COMMON_H_
20 #define UUID_COMMON_H_
21 
22 #include <Arduino.h>
23 
24 #if __has_include(<mutex>)
25 # include <mutex>
26 #endif
27 #include <string>
28 #include <vector>
29 
30 #ifndef UUID_COMMON_STD_MUTEX_AVAILABLE
31 # if __has_include(<mutex>) && (!defined(_GLIBCXX_MUTEX) || defined(_GLIBCXX_HAS_GTHREADS))
32 # define UUID_COMMON_STD_MUTEX_AVAILABLE 1
33 # else
34 # define UUID_COMMON_STD_MUTEX_AVAILABLE 0
35 # endif
36 #endif
37 
38 #if defined(DOXYGEN) || defined(ARDUINO_ARCH_ESP32) || UUID_COMMON_STD_MUTEX_AVAILABLE
39 # define UUID_COMMON_THREAD_SAFE 1
40 #else
41 # define UUID_COMMON_THREAD_SAFE 0
42 #endif
43 
50 namespace uuid {
51 
57 #if UUID_COMMON_THREAD_SAFE
58 static constexpr bool thread_safe = true;
59 #else
60 static constexpr bool thread_safe = false;
61 #endif
62 
73 std::string read_flash_string(const __FlashStringHelper *flash_str);
74 
83 size_t print_to_string(const Printable &printable, std::string &output);
84 
92 std::string printable_to_string(const Printable &printable);
93 
99 using flash_string_vector = std::vector<const __FlashStringHelper*>;
100 
107 void loop();
108 
115 uint64_t get_uptime_ms();
116 
117 } // namespace uuid
118 
119 #endif
uuid::print_to_string
size_t print_to_string(const Printable &printable, std::string &output)
Append to a std::string by printing a Printable object.
Definition: printable_to_string.cpp:49
uuid::loop
void loop()
Loop function that must be called regularly to detect a 32-bit uptime overflow.
Definition: loop.cpp:25
uuid::get_uptime_ms
uint64_t get_uptime_ms()
Get the current uptime as a 64-bit milliseconds value.
Definition: get_uptime_ms.cpp:30
uuid::flash_string_vector
std::vector< const __FlashStringHelper * > flash_string_vector
Type definition for a std::vector of flash strings.
Definition: common.h:99
uuid::printable_to_string
std::string printable_to_string(const Printable &printable)
Create a std::string from a Printable object.
Definition: printable_to_string.cpp:55
uuid::read_flash_string
std::string read_flash_string(const __FlashStringHelper *flash_str)
Read a string from flash and convert it to a std::string.
Definition: read_flash_string.cpp:27
uuid
Common utilities.
Definition: get_uptime_ms.cpp:28
uuid::thread_safe
static constexpr bool thread_safe
Thread-safe status of the library.
Definition: common.h:58