Formatted source files

This commit is contained in:
John Wellbelove 2026-04-02 14:11:45 +01:00
parent c7571660bd
commit aeb8e4f734
767 changed files with 68663 additions and 64413 deletions

View File

@ -2,79 +2,79 @@
#ifndef ETL_EMBEDDED_TEMPLATE_LIBRARY_INCLUDED #ifndef ETL_EMBEDDED_TEMPLATE_LIBRARY_INCLUDED
#define ETL_EMBEDDED_TEMPLATE_LIBRARY_INCLUDED #define ETL_EMBEDDED_TEMPLATE_LIBRARY_INCLUDED
#if defined(TEENSYDUINO) #if defined(TEENSYDUINO)
#if defined(__AVR_ATmega32U4__) #if defined(__AVR_ATmega32U4__)
#define ARDUINO_BOARD "Teensy 2.0" #define ARDUINO_BOARD "Teensy 2.0"
#elif defined(__AVR_AT90USB1286__) #elif defined(__AVR_AT90USB1286__)
#define ARDUINO_BOARD "Teensy++ 2.0" #define ARDUINO_BOARD "Teensy++ 2.0"
#elif defined(__MK20DX128__) #elif defined(__MK20DX128__)
#define ARDUINO_BOARD "Teensy 3.0" #define ARDUINO_BOARD "Teensy 3.0"
#elif defined(__MK20DX256__) #elif defined(__MK20DX256__)
#define ARDUINO_BOARD "Teensy 3.2" // and Teensy 3.1 #define ARDUINO_BOARD "Teensy 3.2" // and Teensy 3.1
#elif defined(__MKL26Z64__) #elif defined(__MKL26Z64__)
#define ARDUINO_BOARD "Teensy LC" #define ARDUINO_BOARD "Teensy LC"
#elif defined(__MK64FX512__) #elif defined(__MK64FX512__)
#define ARDUINO_BOARD "Teensy 3.5" #define ARDUINO_BOARD "Teensy 3.5"
#elif defined(__MK66FX1M0__) #elif defined(__MK66FX1M0__)
#define ARDUINO_BOARD "Teensy 3.6" #define ARDUINO_BOARD "Teensy 3.6"
#else #else
#define ARDUINO_BOARD "Unknown" #define ARDUINO_BOARD "Unknown"
#endif #endif
#else // --------------- Arduino ------------------ #else // --------------- Arduino ------------------
#if defined(ARDUINO_AVR_ADK) #if defined(ARDUINO_AVR_ADK)
#define ARDUINO_BOARD "Mega Adk" #define ARDUINO_BOARD "Mega Adk"
#elif defined(ARDUINO_AVR_BT) #elif defined(ARDUINO_AVR_BT)
#define ARDUINO_BOARD "Bt" #define ARDUINO_BOARD "Bt"
#elif defined(ARDUINO_AVR_DUEMILANOVE) #elif defined(ARDUINO_AVR_DUEMILANOVE)
#define ARDUINO_BOARD "Duemilanove" #define ARDUINO_BOARD "Duemilanove"
#elif defined(ARDUINO_AVR_ESPLORA) #elif defined(ARDUINO_AVR_ESPLORA)
#define ARDUINO_BOARD "Esplora" #define ARDUINO_BOARD "Esplora"
#elif defined(ARDUINO_AVR_ETHERNET) #elif defined(ARDUINO_AVR_ETHERNET)
#define ARDUINO_BOARD "Ethernet" #define ARDUINO_BOARD "Ethernet"
#elif defined(ARDUINO_AVR_FIO) #elif defined(ARDUINO_AVR_FIO)
#define ARDUINO_BOARD "Fio" #define ARDUINO_BOARD "Fio"
#elif defined(ARDUINO_AVR_GEMMA) #elif defined(ARDUINO_AVR_GEMMA)
#define ARDUINO_BOARD "Gemma" #define ARDUINO_BOARD "Gemma"
#elif defined(ARDUINO_AVR_LEONARDO) #elif defined(ARDUINO_AVR_LEONARDO)
#define ARDUINO_BOARD "Leonardo" #define ARDUINO_BOARD "Leonardo"
#elif defined(ARDUINO_AVR_LILYPAD) #elif defined(ARDUINO_AVR_LILYPAD)
#define ARDUINO_BOARD "Lilypad" #define ARDUINO_BOARD "Lilypad"
#elif defined(ARDUINO_AVR_LILYPAD_USB) #elif defined(ARDUINO_AVR_LILYPAD_USB)
#define ARDUINO_BOARD "Lilypad Usb" #define ARDUINO_BOARD "Lilypad Usb"
#elif defined(ARDUINO_AVR_MEGA) #elif defined(ARDUINO_AVR_MEGA)
#define ARDUINO_BOARD "Mega" #define ARDUINO_BOARD "Mega"
#elif defined(ARDUINO_AVR_MEGA2560) #elif defined(ARDUINO_AVR_MEGA2560)
#define ARDUINO_BOARD "Mega 2560" #define ARDUINO_BOARD "Mega 2560"
#elif defined(ARDUINO_AVR_MICRO) #elif defined(ARDUINO_AVR_MICRO)
#define ARDUINO_BOARD "Micro" #define ARDUINO_BOARD "Micro"
#elif defined(ARDUINO_AVR_MINI) #elif defined(ARDUINO_AVR_MINI)
#define ARDUINO_BOARD "Mini" #define ARDUINO_BOARD "Mini"
#elif defined(ARDUINO_AVR_NANO) #elif defined(ARDUINO_AVR_NANO)
#define ARDUINO_BOARD "Nano" #define ARDUINO_BOARD "Nano"
#elif defined(ARDUINO_AVR_NG) #elif defined(ARDUINO_AVR_NG)
#define ARDUINO_BOARD "NG" #define ARDUINO_BOARD "NG"
#elif defined(ARDUINO_AVR_PRO) #elif defined(ARDUINO_AVR_PRO)
#define ARDUINO_BOARD "Pro" #define ARDUINO_BOARD "Pro"
#elif defined(ARDUINO_AVR_ROBOT_CONTROL) #elif defined(ARDUINO_AVR_ROBOT_CONTROL)
#define ARDUINO_BOARD "Robot Ctrl" #define ARDUINO_BOARD "Robot Ctrl"
#elif defined(ARDUINO_AVR_ROBOT_MOTOR) #elif defined(ARDUINO_AVR_ROBOT_MOTOR)
#define ARDUINO_BOARD "Robot Motor" #define ARDUINO_BOARD "Robot Motor"
#elif defined(ARDUINO_AVR_UNO) #elif defined(ARDUINO_AVR_UNO)
#define ARDUINO_BOARD "Uno" #define ARDUINO_BOARD "Uno"
#elif defined(ARDUINO_AVR_YUN) #elif defined(ARDUINO_AVR_YUN)
#define ARDUINO_BOARD "Yun" #define ARDUINO_BOARD "Yun"
#elif defined(ARDUINO_SAM_DUE) #elif defined(ARDUINO_SAM_DUE)
#define ARDUINO_BOARD "Due" #define ARDUINO_BOARD "Due"
#elif defined(ARDUINO_SAMD_ZERO) #elif defined(ARDUINO_SAMD_ZERO)
#define ARDUINO_BOARD "Zero" #define ARDUINO_BOARD "Zero"
#elif defined(ARDUINO_ARC32_TOOLS) #elif defined(ARDUINO_ARC32_TOOLS)
#define ARDUINO_BOARD "101" #define ARDUINO_BOARD "101"
#else #else
#define ARDUINO_BOARD "Unknown" #define ARDUINO_BOARD "Unknown"
#endif #endif
#endif #endif
#endif #endif

View File

@ -10,6 +10,6 @@
#define ETL_CALLBACK_TIMER_USE_ATOMIC_LOCK #define ETL_CALLBACK_TIMER_USE_ATOMIC_LOCK
#define ETL_NO_STL #define ETL_NO_STL
//#include "etl/profiles/auto.h" // #include "etl/profiles/auto.h"
#endif #endif

View File

@ -1,23 +1,23 @@
#include <stdio.h> #include <stdio.h>
//#if (__cplusplus < 201103L) // #if (__cplusplus < 201103L)
extern "C" extern "C"
{ {
//#endif // #endif
#include "Board_LED.h" // ::Board Support:LED
#include "Board_Buttons.h" // ::Board Support:Buttons #include "Board_Buttons.h" // ::Board Support:Buttons
//#if (__cplusplus < 201103L) #include "Board_LED.h" // ::Board Support:LED
// #if (__cplusplus < 201103L)
} }
//#endif // #endif
#include "stm32f4xx.h" // Device header #include "stm32f4xx.h" // Device header
#include "etl/function.h"
#include "etl/callback_timer.h"
#include "etl/vector.h"
#include "etl/iterator.h"
#include "etl/binary.h" #include "etl/binary.h"
#include "etl/callback_timer.h"
#include "etl/function.h"
#include "etl/iterator.h"
#include "etl/vector.h"
struct FP struct FP
{ {
@ -28,7 +28,7 @@ static etl::vector<FP, 10> power_callbacks;
void register_poweroff_callback(void (*function)()) void register_poweroff_callback(void (*function)())
{ {
FP fp = { function }; FP fp = {function};
power_callbacks.push_back(fp); power_callbacks.push_back(fp);
} }
@ -45,38 +45,38 @@ etl::timer::id::type swap_timers;
* SystemCoreClockConfigure: configure SystemCoreClock using HSI * SystemCoreClockConfigure: configure SystemCoreClock using HSI
(HSE is not populated on Nucleo board) (HSE is not populated on Nucleo board)
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
void SystemCoreClockConfigure(void) { void SystemCoreClockConfigure(void)
{
RCC->CR |= ((uint32_t)RCC_CR_HSION); // Enable HSI
while ((RCC->CR & RCC_CR_HSIRDY) == 0); // Wait for HSI Ready
RCC->CR |= ((uint32_t)RCC_CR_HSION); // Enable HSI RCC->CFGR = RCC_CFGR_SW_HSI; // HSI is system clock
while ((RCC->CR & RCC_CR_HSIRDY) == 0); // Wait for HSI Ready while ((RCC->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_HSI); // Wait for HSI used as system clock
RCC->CFGR = RCC_CFGR_SW_HSI; // HSI is system clock FLASH->ACR = FLASH_ACR_PRFTEN; // Enable Prefetch Buffer
while ((RCC->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_HSI); // Wait for HSI used as system clock FLASH->ACR |= FLASH_ACR_ICEN; // Instruction cache enable
FLASH->ACR |= FLASH_ACR_DCEN; // Data cache enable
FLASH->ACR |= FLASH_ACR_LATENCY_5WS; // Flash 5 wait state
FLASH->ACR = FLASH_ACR_PRFTEN; // Enable Prefetch Buffer RCC->CFGR |= RCC_CFGR_HPRE_DIV1; // HCLK = SYSCLK
FLASH->ACR |= FLASH_ACR_ICEN; // Instruction cache enable RCC->CFGR |= RCC_CFGR_PPRE1_DIV4; // APB1 = HCLK/4
FLASH->ACR |= FLASH_ACR_DCEN; // Data cache enable RCC->CFGR |= RCC_CFGR_PPRE2_DIV2; // APB2 = HCLK/2
FLASH->ACR |= FLASH_ACR_LATENCY_5WS; // Flash 5 wait state
RCC->CFGR |= RCC_CFGR_HPRE_DIV1; // HCLK = SYSCLK RCC->CR &= ~RCC_CR_PLLON; // Disable PLL
RCC->CFGR |= RCC_CFGR_PPRE1_DIV4; // APB1 = HCLK/4
RCC->CFGR |= RCC_CFGR_PPRE2_DIV2; // APB2 = HCLK/2
RCC->CR &= ~RCC_CR_PLLON; // Disable PLL
// PLL configuration: VCO = HSI/M * N, Sysclk = VCO/P // PLL configuration: VCO = HSI/M * N, Sysclk = VCO/P
RCC->PLLCFGR = ( 16ul | // PLL_M = 16 RCC->PLLCFGR = (16ul | // PLL_M = 16
(384ul << 6U) | // PLL_N = 384 (384ul << 6U) | // PLL_N = 384
( 3ul << 16U) | // PLL_P = 8 (3ul << 16U) | // PLL_P = 8
(RCC_PLLCFGR_PLLSRC_HSI) | // PLL_SRC = HSI (RCC_PLLCFGR_PLLSRC_HSI) | // PLL_SRC = HSI
( 8ul << 24U) ); // PLL_Q = 8 (8ul << 24U)); // PLL_Q = 8
RCC->CR |= RCC_CR_PLLON; // Enable PLL RCC->CR |= RCC_CR_PLLON; // Enable PLL
while((RCC->CR & RCC_CR_PLLRDY) == 0) __NOP(); // Wait till PLL is ready while ((RCC->CR & RCC_CR_PLLRDY) == 0) __NOP(); // Wait till PLL is ready
RCC->CFGR &= ~RCC_CFGR_SW; // Select PLL as system clock source RCC->CFGR &= ~RCC_CFGR_SW; // Select PLL as system clock source
RCC->CFGR |= RCC_CFGR_SW_PLL; RCC->CFGR |= RCC_CFGR_SW_PLL;
while ((RCC->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_PLL); // Wait till PLL is system clock src while ((RCC->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_PLL); // Wait till PLL is system clock src
} }
void StartTimers() void StartTimers()
@ -123,7 +123,7 @@ void LedToggle()
int main() int main()
{ {
SystemCoreClockConfigure(); // configure HSI as System Clock SystemCoreClockConfigure(); // configure HSI as System Clock
SystemCoreClockUpdate(); SystemCoreClockUpdate();
LED_Initialize(); LED_Initialize();
@ -131,10 +131,10 @@ int main()
// The LEDs will start flashing fast after 2 seconds. // The LEDs will start flashing fast after 2 seconds.
// After another 5 seconds they will start flashing slower. // After another 5 seconds they will start flashing slower.
short_toggle = callback_timer.register_timer(LedToggle, 50, etl::timer::mode::REPEATING); short_toggle = callback_timer.register_timer(LedToggle, 50, etl::timer::mode::REPEATING);
long_toggle = callback_timer.register_timer(LedToggle, 100, etl::timer::mode::REPEATING); long_toggle = callback_timer.register_timer(LedToggle, 100, etl::timer::mode::REPEATING);
start_timers = callback_timer.register_timer(StartTimers, 2000, etl::timer::mode::SINGLE_SHOT); start_timers = callback_timer.register_timer(StartTimers, 2000, etl::timer::mode::SINGLE_SHOT);
swap_timers = callback_timer.register_timer(SwapTimers, 1500, etl::timer::mode::SINGLE_SHOT); swap_timers = callback_timer.register_timer(SwapTimers, 1500, etl::timer::mode::SINGLE_SHOT);
SysTick_Config(SystemCoreClock / 1000); SysTick_Config(SystemCoreClock / 1000);
@ -152,7 +152,7 @@ extern "C"
{ {
void SysTick_Handler() void SysTick_Handler()
{ {
const uint32_t TICK = 1U; const uint32_t TICK = 1U;
static uint32_t nticks = TICK; static uint32_t nticks = TICK;
if (callback_timer.tick(nticks)) if (callback_timer.tick(nticks))

View File

@ -11,8 +11,8 @@ enum VectorId
USART1_IRQ_HANDLER = 52, USART1_IRQ_HANDLER = 52,
USART2_IRQ_HANDLER = 53, USART2_IRQ_HANDLER = 53,
VECTOR_ID_END, VECTOR_ID_END,
VECTOR_ID_OFFSET = TIM1_CC_IRQ_HANDLER, VECTOR_ID_OFFSET = TIM1_CC_IRQ_HANDLER,
VECTOR_ID_RANGE = VECTOR_ID_END - VECTOR_ID_OFFSET VECTOR_ID_RANGE = VECTOR_ID_END - VECTOR_ID_OFFSET
}; };
typedef etl::delegate_service<VECTOR_ID_RANGE, VECTOR_ID_OFFSET> InterruptVectors; typedef etl::delegate_service<VECTOR_ID_RANGE, VECTOR_ID_OFFSET> InterruptVectors;
@ -91,8 +91,8 @@ public:
// Constructor. // Constructor.
Uart(int port_id, size_t interruptId) Uart(int port_id, size_t interruptId)
: port_id(port_id), : port_id(port_id)
callback(etl::delegate<void(size_t)>::create<Uart, &Uart::InterruptHandler>(*this)) , callback(etl::delegate<void(size_t)>::create<Uart, &Uart::InterruptHandler>(*this))
{ {
GetInterruptVectorsInstance().register_delegate(interruptId, callback); GetInterruptVectorsInstance().register_delegate(interruptId, callback);
} }
@ -119,7 +119,8 @@ Uart uart1(0, USART1_IRQ_HANDLER);
Uart uart2(1, USART2_IRQ_HANDLER); Uart uart2(1, USART2_IRQ_HANDLER);
// Declare a global callback for the timer. // Declare a global callback for the timer.
// Uses the most efficient callback type for a class, as everything is known at compile time. // Uses the most efficient callback type for a class, as everything is known at
// compile time.
etl::delegate<void(size_t)> timer_member_callback = etl::delegate<void(size_t)>::create<Timer, timer, &Timer::InterruptHandler>(); etl::delegate<void(size_t)> timer_member_callback = etl::delegate<void(size_t)>::create<Timer, timer, &Timer::InterruptHandler>();
// Declare the callbacks for the free functions. // Declare the callbacks for the free functions.

View File

@ -1,7 +1,7 @@
#include <iostream> #include <iostream>
#include "etl/function.h"
#include "etl/callback_service.h" #include "etl/callback_service.h"
#include "etl/function.h"
enum VectorId enum VectorId
{ {
@ -11,8 +11,8 @@ enum VectorId
USART1_IRQ_HANDLER = 52, USART1_IRQ_HANDLER = 52,
USART2_IRQ_HANDLER = 53, USART2_IRQ_HANDLER = 53,
VECTOR_ID_END, VECTOR_ID_END,
VECTOR_ID_OFFSET = TIM1_CC_IRQ_HANDLER, VECTOR_ID_OFFSET = TIM1_CC_IRQ_HANDLER,
VECTOR_ID_RANGE = VECTOR_ID_END - VECTOR_ID_OFFSET VECTOR_ID_RANGE = VECTOR_ID_END - VECTOR_ID_OFFSET
}; };
typedef etl::callback_service<VECTOR_ID_RANGE, VECTOR_ID_OFFSET> InterruptVectors; typedef etl::callback_service<VECTOR_ID_RANGE, VECTOR_ID_OFFSET> InterruptVectors;
@ -91,8 +91,8 @@ public:
// Constructor. // Constructor.
Uart(int port_id, int interruptId) Uart(int port_id, int interruptId)
: port_id(port_id), : port_id(port_id)
callback(*this) , callback(*this)
{ {
GetInterruptVectorsInstance().register_callback(interruptId, callback); GetInterruptVectorsInstance().register_callback(interruptId, callback);
} }
@ -119,7 +119,8 @@ Uart uart1(0, USART1_IRQ_HANDLER);
Uart uart2(1, USART2_IRQ_HANDLER); Uart uart2(1, USART2_IRQ_HANDLER);
// Declare a global callback for the timer. // Declare a global callback for the timer.
// Uses the most efficient callback type for a class, as everything is known at compile time. // Uses the most efficient callback type for a class, as everything is known at
// compile time.
etl::function_imp<Timer, size_t, timer, &Timer::InterruptHandler> timer_member_callback; etl::function_imp<Timer, size_t, timer, &Timer::InterruptHandler> timer_member_callback;
// Declare the callbacks for the free functions. // Declare the callbacks for the free functions.

View File

@ -1,13 +1,13 @@
#include <iostream>
#include <thread>
#include <atomic> #include <atomic>
#include <string>
#include <chrono> #include <chrono>
#include <iostream>
#include <string>
#include <thread>
#include "etl/mutex.h"
#include "etl/message.h" #include "etl/message.h"
#include "etl/message_router.h" #include "etl/message_router.h"
#include "etl/mutex.h"
//************************************* //*************************************
struct Message1 : public etl::message<1> struct Message1 : public etl::message<1>
@ -48,9 +48,7 @@ public:
} }
//***************** //*****************
void on_receive_unknown(const etl::imessage&) void on_receive_unknown(const etl::imessage&) {}
{
}
std::string result; std::string result;
@ -61,7 +59,7 @@ private:
//************************************* //*************************************
etl::atomic<bool> start = false; etl::atomic<bool> start = false;
Router router; Router router;
//************************************* //*************************************
void thread1() void thread1()
@ -106,5 +104,3 @@ int main()
return 0; return 0;
} }

View File

@ -31,9 +31,9 @@ SOFTWARE.
// derived class. // derived class.
//***************************************************************************** //*****************************************************************************
#include "etl/queue.h"
#include "etl/fsm.h" #include "etl/fsm.h"
#include "etl/message_packet.h" #include "etl/message_packet.h"
#include "etl/queue.h"
#include <iostream> #include <iostream>
#include <string> #include <string>
@ -122,7 +122,7 @@ public:
while (!queue.empty()) while (!queue.empty())
{ {
message_packet& packet = queue.front(); message_packet& packet = queue.front();
etl::imessage& msg = packet.get(); etl::imessage& msg = packet.get();
std::cout << "Processing message " << int(msg.get_message_id()) << std::endl; std::cout << "Processing message " << int(msg.get_message_id()) << std::endl;
// Call the base class's receive function. // Call the base class's receive function.
@ -258,7 +258,7 @@ int main()
State2 state2; State2 state2;
// The list of states. // The list of states.
etl::ifsm_state* state_list[] = { &state1, &state2 }; etl::ifsm_state* state_list[] = {&state1, &state2};
// Define some messages. // Define some messages.
Message1 m1(1); Message1 m1(1);
@ -285,4 +285,3 @@ int main()
return 0; return 0;
} }

View File

@ -1,6 +1,6 @@
#include "etl/queue.h"
#include "etl/message_router.h" #include "etl/message_router.h"
#include "etl/queue.h"
#include <iostream> #include <iostream>
#include <string> #include <string>
@ -81,7 +81,7 @@ public:
while (!queue.empty()) while (!queue.empty())
{ {
message_packet& packet = queue.front(); message_packet& packet = queue.front();
etl::imessage& msg = packet.get(); etl::imessage& msg = packet.get();
std::cout << "Processing message " << int(msg.get_message_id()) << std::endl; std::cout << "Processing message " << int(msg.get_message_id()) << std::endl;
// Call the base class's receive function. // Call the base class's receive function.
@ -146,4 +146,3 @@ int main()
return 0; return 0;
} }

View File

@ -31,9 +31,9 @@ SOFTWARE.
// Experiment with the different scheduling policies. // Experiment with the different scheduling policies.
//***************************************************************************** //*****************************************************************************
#include "etl/function.h"
#include "etl/scheduler.h" #include "etl/scheduler.h"
#include "etl/task.h" #include "etl/task.h"
#include "etl/function.h"
#include <iostream> #include <iostream>
#include <string> #include <string>
@ -50,13 +50,13 @@ public:
: task(1) : task(1)
, work(3) , work(3)
{ {
} }
//************************************* //*************************************
uint32_t task_request_work() const uint32_t task_request_work() const
{ {
return work; // How much work do we still have to do? This could be a message queue length. return work; // How much work do we still have to do? This could be a
// message queue length.
} }
//************************************* //*************************************
@ -83,13 +83,13 @@ public:
: task(2) : task(2)
, work(4) , work(4)
{ {
} }
//************************************* //*************************************
uint32_t task_request_work() const uint32_t task_request_work() const
{ {
return work; // How much work do we still have to do? This could be a message queue length. return work; // How much work do we still have to do? This could be a
// message queue length.
} }
//************************************* //*************************************
@ -115,7 +115,6 @@ public:
Idle(etl::ischeduler& scheduler_) Idle(etl::ischeduler& scheduler_)
: scheduler(scheduler_) : scheduler(scheduler_)
{ {
} }
//************************************* //*************************************
@ -181,4 +180,3 @@ int main()
return 0; return 0;
} }

View File

@ -2,18 +2,18 @@
// Shared message example // Shared message example
//***************************************************************************** //*****************************************************************************
#include "etl/shared_message.h"
#include "etl/message.h"
#include "etl/reference_counted_message_pool.h"
#include "etl/message_router.h"
#include "etl/message_bus.h"
#include "etl/fixed_sized_memory_block_allocator.h" #include "etl/fixed_sized_memory_block_allocator.h"
#include "etl/message.h"
#include "etl/message_bus.h"
#include "etl/message_router.h"
#include "etl/queue.h" #include "etl/queue.h"
#include "etl/reference_counted_message_pool.h"
#include "etl/shared_message.h"
#include <iostream>
#include <atomic> #include <atomic>
#include <string> #include <iostream>
#include <mutex> #include <mutex>
#include <string>
constexpr etl::message_router_id_t RouterId1 = 1U; constexpr etl::message_router_id_t RouterId1 = 1U;
constexpr etl::message_router_id_t RouterId2 = 2U; constexpr etl::message_router_id_t RouterId2 = 2U;
@ -26,9 +26,8 @@ struct Message1 : public etl::message<1>
Message1(std::string s_) Message1(std::string s_)
: s(s_) : s(s_)
{ {
} }
std::string s; std::string s;
}; };
@ -40,10 +39,10 @@ struct Message2 : public etl::message<2>
Message2(std::string s_) Message2(std::string s_)
: s(s_) : s(s_)
{ {
} }
std::string s; std::string s;
char data[100]; char data[100];
}; };
@ -55,7 +54,6 @@ struct Message3 : public etl::message<3>
Message3(std::string s_) Message3(std::string s_)
: s(s_) : s(s_)
{ {
} }
std::string s; std::string s;
@ -199,7 +197,7 @@ struct Bus : public etl::message_bus<2U>
//***************************************************************************** //*****************************************************************************
MessageRouter1 router1; MessageRouter1 router1;
MessageRouter2 router2; MessageRouter2 router2;
Bus bus; Bus bus;
//***************************************************************************** //*****************************************************************************
// The thread safe message pool. Uses atomic uint32_t for counting. // The thread safe message pool. Uses atomic uint32_t for counting.
@ -230,8 +228,8 @@ private:
}; };
//***************************************************************************** //*****************************************************************************
// The memory block allocator that supplies the pool with memory // The memory block allocator that supplies the pool with memory
// to store reference counted messages in. // to store reference counted messages in.
// The reference counted message parameters type for the messages we will use. // The reference counted message parameters type for the messages we will use.
using message_parameters_small = MessagePool::pool_message_parameters<Message1, Message3>; using message_parameters_small = MessagePool::pool_message_parameters<Message1, Message3>;
@ -243,10 +241,12 @@ constexpr size_t max_alignment_small = message_parameters_small::max_alignment;
constexpr size_t max_size_large = message_parameters_large::max_size; constexpr size_t max_size_large = message_parameters_large::max_size;
constexpr size_t max_alignment_large = message_parameters_large::max_alignment; constexpr size_t max_alignment_large = message_parameters_large::max_alignment;
// A fixed memory block allocator for 4 items, using the parameters from the smaller messages. // A fixed memory block allocator for 4 items, using the parameters from the
// smaller messages.
etl::fixed_sized_memory_block_allocator<max_size_small, max_alignment_small, 4U> memory_allocator; etl::fixed_sized_memory_block_allocator<max_size_small, max_alignment_small, 4U> memory_allocator;
// A fixed memory block allocator for 4 items, using the parameters from the larger message. // A fixed memory block allocator for 4 items, using the parameters from the
// larger message.
etl::fixed_sized_memory_block_allocator<max_size_large, max_alignment_large, 4U> memory_allocator_successor; etl::fixed_sized_memory_block_allocator<max_size_large, max_alignment_large, 4U> memory_allocator_successor;
//***************************************************************************** //*****************************************************************************
@ -256,8 +256,8 @@ etl::fixed_sized_memory_block_allocator<max_size_large, max_alignment_large, 4U>
MessagePool message_pool(memory_allocator); MessagePool message_pool(memory_allocator);
//***************************************************************************** //*****************************************************************************
// A statically allocated reference counted message that is never allocated or released by a pool. // A statically allocated reference counted message that is never allocated or
// Contains a copy of Message3("Three"). // released by a pool. Contains a copy of Message3("Three").
//***************************************************************************** //*****************************************************************************
etl::persistent_message<Message3> pm3(Message3("Three")); etl::persistent_message<Message3> pm3(Message3("Three"));
@ -269,10 +269,15 @@ int main()
Message1 m1("One"); Message1 m1("One");
Message2 m2("Two"); Message2 m2("Two");
etl::shared_message sm1(message_pool, m1); // Created a shared message by allocating a reference counted message from message_pool containing a copy of m1. etl::shared_message sm1(message_pool,
etl::shared_message sm2(message_pool, m2); // Created a shared message by allocating a reference counted message from message_pool containing a copy of m2. m1); // Created a shared message by allocating a reference counted message
etl::shared_message sm3(pm3); // Created a shared message from a statically allocated persistent message. // from message_pool containing a copy of m1.
etl::shared_message sm2(message_pool,
m2); // Created a shared message by allocating a reference counted message
// from message_pool containing a copy of m2.
etl::shared_message sm3(pm3); // Created a shared message from a statically
// allocated persistent message.
bus.subscribe(router1); // Subscribe router1 to the bus. bus.subscribe(router1); // Subscribe router1 to the bus.
bus.subscribe(router2); // Subscribe router2 to the bus. bus.subscribe(router2); // Subscribe router2 to the bus.

View File

@ -6,7 +6,8 @@
struct S struct S
{ {
S(int a_, double b_) S(int a_, double b_)
: a(a_), b(b_) : a(a_)
, b(b_)
{ {
} }
@ -17,11 +18,11 @@ struct S
int main() int main()
{ {
etl::pool<S, 10> pool; etl::pool<S, 10> pool;
auto pool_deleter = [&pool](auto ptr) auto pool_deleter = [&pool](auto ptr)
{ {
std::cout << "Releasing S(" << ptr->a << ", " << ptr->b << ") back to pool." << std::endl; std::cout << "Releasing S(" << ptr->a << ", " << ptr->b << ") back to pool." << std::endl;
pool.destroy(ptr); pool.destroy(ptr);
}; };
using Unique = etl::unique_ptr<S, decltype(pool_deleter)>; using Unique = etl::unique_ptr<S, decltype(pool_deleter)>;
Unique us1(pool.create(1, 2), pool_deleter); Unique us1(pool.create(1, 2), pool_deleter);

View File

@ -88,35 +88,35 @@ public:
// Notify observers about a position event. // Notify observers about a position event.
void Position_Event() void Position_Event()
{ {
Position position = { 100, 200 }; Position position = {100, 200};
notify_observers(position); notify_observers(position);
} }
// Notify observers about a button up event. // Notify observers about a button up event.
void Button_Event_Up() void Button_Event_Up()
{ {
Button button = { Button::Up }; Button button = {Button::Up};
notify_observers(button); notify_observers(button);
} }
// Notify observers about a button down event. // Notify observers about a button down event.
void Button_Event_Down() void Button_Event_Down()
{ {
Button button = { Button::Down }; Button button = {Button::Down};
notify_observers(button); notify_observers(button);
} }
// Notify observers about a wheel up event. // Notify observers about a wheel up event.
void Wheel_Event_Up() void Wheel_Event_Up()
{ {
Wheel wheel = { 50 }; Wheel wheel = {50};
notify_observers(wheel); notify_observers(wheel);
} }
// Notify observers about a wheel down event. // Notify observers about a wheel down event.
void Wheel_Event_Down() void Wheel_Event_Down()
{ {
Wheel wheel = { -25 }; Wheel wheel = {-25};
notify_observers(wheel); notify_observers(wheel);
} }
}; };
@ -137,6 +137,6 @@ int main()
mouse_driver.Position_Event(); mouse_driver.Position_Event();
mouse_driver.Wheel_Event_Down(); mouse_driver.Wheel_Event_Down();
mouse_driver.Wheel_Event_Up(); mouse_driver.Wheel_Event_Up();
return 0; return 0;
} }

View File

@ -32,9 +32,9 @@ SOFTWARE.
#define ETL_ABSOLUTE_INCLUDED #define ETL_ABSOLUTE_INCLUDED
#include "platform.h" #include "platform.h"
#include "type_traits.h"
#include "integral_limits.h"
#include "error_handler.h" #include "error_handler.h"
#include "integral_limits.h"
#include "type_traits.h"
namespace etl namespace etl
{ {
@ -52,26 +52,20 @@ namespace etl
ETL_ASSERT_FAIL(ETL_ERROR_GENERIC("absolute value of minimum signed integer is undefined")); ETL_ASSERT_FAIL(ETL_ERROR_GENERIC("absolute value of minimum signed integer is undefined"));
return T(0); return T(0);
} }
} } // namespace private_absolute
//*************************************************************************** //***************************************************************************
// For signed types. // For signed types.
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR typename etl::enable_if< etl::is_signed<T>::value && etl::is_integral<T>::value, T>::type absolute(T value)
ETL_CONSTEXPR
typename etl::enable_if<etl::is_signed<T>::value && etl::is_integral<T>::value, T>::type
absolute(T value)
{ {
return (value == etl::integral_limits<T>::min) ? etl::private_absolute::signed_min_error<T>() return (value == etl::integral_limits<T>::min) ? etl::private_absolute::signed_min_error<T>() : static_cast<T>((value < T(0)) ? -value : value);
: static_cast<T>((value < T(0)) ? -value : value);
} }
template <typename T> template <typename T>
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR typename etl::enable_if< etl::is_signed<T>::value && !etl::is_integral<T>::value, T>::type absolute(T value)
ETL_CONSTEXPR ETL_NOEXCEPT
typename etl::enable_if<etl::is_signed<T>::value && !etl::is_integral<T>::value, T>::type
absolute(T value) ETL_NOEXCEPT
{ {
return (value < T(0)) ? -value : value; return (value < T(0)) ? -value : value;
} }
@ -80,10 +74,7 @@ namespace etl
// For unsigned types. // For unsigned types.
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR typename etl::enable_if<etl::is_unsigned<T>::value, T>::type absolute(T value) ETL_NOEXCEPT
ETL_CONSTEXPR
typename etl::enable_if<etl::is_unsigned<T>::value, T>::type
absolute(T value) ETL_NOEXCEPT
{ {
return value; return value;
} }
@ -93,15 +84,14 @@ namespace etl
// Returns the result as the unsigned type. // Returns the result as the unsigned type.
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR typename etl::enable_if<etl::is_signed<T>::value, typename etl::make_unsigned<T>::type>::type absolute_unsigned(T value)
ETL_CONSTEXPR ETL_NOEXCEPT
typename etl::enable_if<etl::is_signed<T>::value, typename etl::make_unsigned<T>::type>::type
absolute_unsigned(T value) ETL_NOEXCEPT
{ {
typedef typename etl::make_unsigned<T>::type TReturn; typedef typename etl::make_unsigned<T>::type TReturn;
return (value == etl::integral_limits<T>::min) ? (etl::integral_limits<TReturn>::max / 2U) + 1U return (value == etl::integral_limits<T>::min) ? (etl::integral_limits<TReturn>::max / 2U) + 1U
: (value < T(0)) ? TReturn(-value) : TReturn(value); : (value < T(0)) ? TReturn(-value)
: TReturn(value);
} }
//*************************************************************************** //***************************************************************************
@ -109,14 +99,10 @@ namespace etl
// Returns the result as the unsigned type. // Returns the result as the unsigned type.
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR typename etl::enable_if<etl::is_unsigned<T>::value, T>::type absolute_unsigned(T value) ETL_NOEXCEPT
ETL_CONSTEXPR
typename etl::enable_if<etl::is_unsigned<T>::value, T>::type
absolute_unsigned(T value) ETL_NOEXCEPT
{ {
return etl::absolute(value); return etl::absolute(value);
} }
} } // namespace etl
#endif #endif

File diff suppressed because it is too large Load Diff

View File

@ -32,10 +32,10 @@ SOFTWARE.
#define ETL_ALIGNMENT_INCLUDED #define ETL_ALIGNMENT_INCLUDED
#include "platform.h" #include "platform.h"
#include "type_traits.h"
#include "static_assert.h"
#include "error_handler.h" #include "error_handler.h"
#include "exception.h" #include "exception.h"
#include "static_assert.h"
#include "type_traits.h"
#include "utility.h" #include "utility.h"
#include <stdint.h> #include <stdint.h>
@ -124,28 +124,28 @@ namespace etl
// Matching alignment. // Matching alignment.
template <size_t Alignment, typename T1, typename... TRest> template <size_t Alignment, typename T1, typename... TRest>
class type_with_alignment_matcher<true, Alignment, T1, TRest...> class type_with_alignment_matcher<true, Alignment, T1, TRest...>
{ {
public: public:
typedef T1 type; typedef T1 type;
}; };
// Non-matching alignment // Non-matching alignment
template <size_t Alignment, typename T1, typename T2, typename... TRest> template <size_t Alignment, typename T1, typename T2, typename... TRest>
class type_with_alignment_matcher <false, Alignment, T1, T2, TRest...> class type_with_alignment_matcher<false, Alignment, T1, T2, TRest...>
{ {
public: public:
typedef typename type_with_alignment_matcher < Alignment <= etl::alignment_of<T2>::value , Alignment, T2, TRest... > ::type type; typedef typename type_with_alignment_matcher< Alignment <= etl::alignment_of<T2>::value, Alignment, T2, TRest... >::type type;
}; };
// Non-matching alignment, none left. // Non-matching alignment, none left.
template <size_t Alignment, typename T1> template <size_t Alignment, typename T1>
class type_with_alignment_matcher <false, Alignment, T1> class type_with_alignment_matcher<false, Alignment, T1>
{ {
public: public:
typedef char type; typedef char type;
}; };
@ -153,23 +153,23 @@ namespace etl
// Helper. // Helper.
//*************************************************************************** //***************************************************************************
template <size_t Alignment, typename T1, typename... T> template <size_t Alignment, typename T1, typename... T>
class type_with_alignment_helper class type_with_alignment_helper
{ {
public: public:
typedef typename type_with_alignment_matcher<Alignment <= etl::alignment_of<T1>::value, Alignment, T1, T...>::type type; typedef typename type_with_alignment_matcher<Alignment <= etl::alignment_of<T1>::value, Alignment, T1, T...>::type type;
}; };
#else #else
//*************************************************************************** //***************************************************************************
// Matcher. // Matcher.
//*************************************************************************** //***************************************************************************
template <bool Is_Match, const size_t Alignment, typename T1 = void, typename T2 = void, typename T3 = void, typename T4 = void, template <bool Is_Match, const size_t Alignment, typename T1 = void, typename T2 = void, typename T3 = void, typename T4 = void,
typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void> typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void>
class type_with_alignment_matcher; class type_with_alignment_matcher;
// Matching alignment. // Matching alignment.
template <size_t Alignment, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> template <size_t Alignment, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
class type_with_alignment_matcher <true, Alignment, T1, T2, T3, T4, T5, T6, T7, T8> class type_with_alignment_matcher<true, Alignment, T1, T2, T3, T4, T5, T6, T7, T8>
{ {
public: public:
@ -178,16 +178,17 @@ namespace etl
// Non-matching alignment. // Non-matching alignment.
template <size_t Alignment, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> template <size_t Alignment, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
class type_with_alignment_matcher <false, Alignment, T1, T2, T3, T4, T5, T6, T7, T8> class type_with_alignment_matcher<false, Alignment, T1, T2, T3, T4, T5, T6, T7, T8>
{ {
public: public:
typedef typename type_with_alignment_matcher<Alignment <= etl::alignment_of<T2>::value, Alignment, T2, T3, T4, T5, T6, T7, T8, void>::type type; typedef
typename type_with_alignment_matcher< Alignment <= etl::alignment_of<T2>::value, Alignment, T2, T3, T4, T5, T6, T7, T8, void>::type type;
}; };
// Non-matching alignment, none left. // Non-matching alignment, none left.
template <size_t Alignment> template <size_t Alignment>
class type_with_alignment_matcher <false, Alignment, void, void, void, void, void, void, void, void> class type_with_alignment_matcher<false, Alignment, void, void, void, void, void, void, void, void>
{ {
public: public:
@ -197,16 +198,16 @@ namespace etl
//*************************************************************************** //***************************************************************************
// Helper. // Helper.
//*************************************************************************** //***************************************************************************
template <size_t Alignment, typename T1, typename T2 = void, typename T3 = void, typename T4 = void, template <size_t Alignment, typename T1, typename T2 = void, typename T3 = void, typename T4 = void, typename T5 = void, typename T6 = void,
typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void> typename T7 = void, typename T8 = void>
class type_with_alignment_helper class type_with_alignment_helper
{ {
public: public:
typedef typename type_with_alignment_matcher<Alignment <= etl::alignment_of<T1>::value, Alignment, T1, T2, T3, T4, T5, T6, T7, T8>::type type; typedef typename type_with_alignment_matcher< Alignment <= etl::alignment_of<T1>::value, Alignment, T1, T2, T3, T4, T5, T6, T7, T8>::type type;
}; };
#endif #endif
} } // namespace private_alignment
//*************************************************************************** //***************************************************************************
/// Gets a type that has the same as the specified alignment. /// Gets a type that has the same as the specified alignment.
@ -218,12 +219,17 @@ namespace etl
public: public:
#if ETL_USING_CPP11 #if ETL_USING_CPP11
typedef struct { alignas(Alignment) char dummy; } type; typedef struct
{
alignas(Alignment) char dummy;
} type;
#else #else
#if ETL_NOT_USING_64BIT_TYPES #if ETL_NOT_USING_64BIT_TYPES
typedef typename private_alignment::type_with_alignment_helper<Alignment, int_least8_t, int_least16_t, int32_t, float, double, void*>::type type; typedef typename private_alignment::type_with_alignment_helper< Alignment, int_least8_t, int_least16_t, int32_t, float, double, void*>::type type;
#else #else
typedef typename private_alignment::type_with_alignment_helper<Alignment, int_least8_t, int_least16_t, int32_t, int64_t, float, double, void*>::type type; typedef
typename private_alignment::type_with_alignment_helper< Alignment, int_least8_t, int_least16_t, int32_t, int64_t, float, double, void*>::type
type;
#endif #endif
#endif #endif
@ -247,35 +253,35 @@ namespace etl
{ {
/// Convert to T reference. /// Convert to T reference.
template <typename T> template <typename T>
operator T& () operator T&()
{ {
ETL_STATIC_ASSERT((etl::is_same<T*, void*>:: value || ((Alignment % etl::alignment_of<T>::value) == 0)), "Incompatible alignment"); ETL_STATIC_ASSERT((etl::is_same<T*, void*>::value || ((Alignment % etl::alignment_of<T>::value) == 0)), "Incompatible alignment");
T* t = *this; T* t = *this;
return *t; return *t;
} }
/// Convert to const T reference. /// Convert to const T reference.
template <typename T> template <typename T>
operator const T& () const operator const T&() const
{ {
ETL_STATIC_ASSERT((etl::is_same<T*, void*>:: value || ((Alignment % etl::alignment_of<T>::value) == 0)), "Incompatible alignment"); ETL_STATIC_ASSERT((etl::is_same<T*, void*>::value || ((Alignment % etl::alignment_of<T>::value) == 0)), "Incompatible alignment");
const T* t = *this; const T* t = *this;
return *t; return *t;
} }
/// Convert to T pointer. /// Convert to T pointer.
template <typename T> template <typename T>
operator T* () operator T*()
{ {
ETL_STATIC_ASSERT((etl::is_same<T*, void*>:: value || ((Alignment % etl::alignment_of<T>::value) == 0)), "Incompatible alignment"); ETL_STATIC_ASSERT((etl::is_same<T*, void*>::value || ((Alignment % etl::alignment_of<T>::value) == 0)), "Incompatible alignment");
return reinterpret_cast<T*>(data); return reinterpret_cast<T*>(data);
} }
/// Convert to const T pointer. /// Convert to const T pointer.
template <typename T> template <typename T>
operator const T* () const operator const T*() const
{ {
ETL_STATIC_ASSERT((etl::is_same<T*, void*>:: value || ((Alignment % etl::alignment_of<T>::value) == 0)), "Incompatible alignment"); ETL_STATIC_ASSERT((etl::is_same<T*, void*>::value || ((Alignment % etl::alignment_of<T>::value) == 0)), "Incompatible alignment");
return reinterpret_cast<const T*>(data); return reinterpret_cast<const T*>(data);
} }
@ -283,7 +289,7 @@ namespace etl
template <typename T> template <typename T>
T& get_reference() T& get_reference()
{ {
ETL_STATIC_ASSERT((etl::is_same<T*, void*>:: value || ((Alignment % etl::alignment_of<T>::value) == 0)), "Incompatible alignment"); ETL_STATIC_ASSERT((etl::is_same<T*, void*>::value || ((Alignment % etl::alignment_of<T>::value) == 0)), "Incompatible alignment");
T* t = *this; T* t = *this;
return *t; return *t;
} }
@ -292,7 +298,7 @@ namespace etl
template <typename T> template <typename T>
const T& get_reference() const const T& get_reference() const
{ {
ETL_STATIC_ASSERT((etl::is_same<T*, void*>:: value || ((Alignment % etl::alignment_of<T>::value) == 0)), "Incompatible alignment"); ETL_STATIC_ASSERT((etl::is_same<T*, void*>::value || ((Alignment % etl::alignment_of<T>::value) == 0)), "Incompatible alignment");
const T* t = *this; const T* t = *this;
return *t; return *t;
} }
@ -301,7 +307,7 @@ namespace etl
template <typename T> template <typename T>
T* get_address() T* get_address()
{ {
ETL_STATIC_ASSERT((etl::is_same<T*, void*>:: value || ((Alignment % etl::alignment_of<T>::value) == 0)), "Incompatible alignment"); ETL_STATIC_ASSERT((etl::is_same<T*, void*>::value || ((Alignment % etl::alignment_of<T>::value) == 0)), "Incompatible alignment");
return reinterpret_cast<T*>(data); return reinterpret_cast<T*>(data);
} }
@ -309,7 +315,7 @@ namespace etl
template <typename T> template <typename T>
const T* get_address() const const T* get_address() const
{ {
ETL_STATIC_ASSERT((etl::is_same<T*, void*>:: value || ((Alignment % etl::alignment_of<T>::value) == 0)), "Incompatible alignment"); ETL_STATIC_ASSERT((etl::is_same<T*, void*>::value || ((Alignment % etl::alignment_of<T>::value) == 0)), "Incompatible alignment");
return reinterpret_cast<const T*>(data); return reinterpret_cast<const T*>(data);
} }
@ -318,8 +324,9 @@ namespace etl
#else #else
union union
{ {
char data[Length]; char data[Length];
typename etl::type_with_alignment<Alignment>::type etl_alignment_type; // A POD type that has the same alignment as Alignment. typename etl::type_with_alignment<Alignment>::type etl_alignment_type; // A POD type that has the same alignment
// as Alignment.
}; };
#endif #endif
}; };
@ -373,7 +380,8 @@ namespace etl
#if ETL_USING_CPP11 #if ETL_USING_CPP11
//*************************************************************************** //***************************************************************************
/// Constructs the instance of T forwarding the given \p args to its constructor. /// Constructs the instance of T forwarding the given \p args to its
/// constructor.
//*************************************************************************** //***************************************************************************
template <typename... TArgs> template <typename... TArgs>
typed_storage(TArgs&&... args) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS) typed_storage(TArgs&&... args) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
@ -424,8 +432,8 @@ namespace etl
#endif #endif
//*************************************************************************** //***************************************************************************
/// Default destructor which will NOT call the destructor of the object which /// Default destructor which will NOT call the destructor of the object
/// was created by calling create(). /// which was created by calling create().
//*************************************************************************** //***************************************************************************
~typed_storage() ETL_NOEXCEPT ~typed_storage() ETL_NOEXCEPT
{ {
@ -443,67 +451,72 @@ namespace etl
#if ETL_USING_CPP11 #if ETL_USING_CPP11
//*************************************************************************** //***************************************************************************
/// Constructs the instance of T forwarding the given \p args to its constructor. /// Constructs the instance of T forwarding the given \p args to its
/// \returns the instance of T which has been constructed in the internal byte array. /// constructor. \returns the instance of T which has been constructed in
/// the internal byte array.
//*************************************************************************** //***************************************************************************
template <typename... TArgs> template <typename... TArgs>
reference create(TArgs&&... args) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS) reference create(TArgs&&... args) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
{ {
ETL_ASSERT(!has_value(), ETL_ERROR(etl::typed_storage_error)); ETL_ASSERT(!has_value(), ETL_ERROR(etl::typed_storage_error));
pointer p = ::new (&storage.value) value_type(etl::forward<TArgs>(args)...); pointer p = ::new (&storage.value) value_type(etl::forward<TArgs>(args)...);
valid = true; valid = true;
return *p; return *p;
} }
#else #else
//*************************************************************************** //***************************************************************************
/// Constructs the instance of T with type T1 /// Constructs the instance of T with type T1
/// \returns the instance of T which has been constructed in the internal byte array. /// \returns the instance of T which has been constructed in the internal
/// byte array.
//*************************************************************************** //***************************************************************************
template <typename T1> template <typename T1>
reference create(const T1& t1) reference create(const T1& t1)
{ {
ETL_ASSERT(!has_value(), ETL_ERROR(etl::typed_storage_error)); ETL_ASSERT(!has_value(), ETL_ERROR(etl::typed_storage_error));
pointer p = ::new (&storage.value) value_type(t1); pointer p = ::new (&storage.value) value_type(t1);
valid = true; valid = true;
return *p; return *p;
} }
//*************************************************************************** //***************************************************************************
/// Constructs the instance of T with types T1, T2 /// Constructs the instance of T with types T1, T2
/// \returns the instance of T which has been constructed in the internal byte array. /// \returns the instance of T which has been constructed in the internal
/// byte array.
//*************************************************************************** //***************************************************************************
template <typename T1, typename T2> template <typename T1, typename T2>
reference create(const T1& t1, const T2& t2) reference create(const T1& t1, const T2& t2)
{ {
ETL_ASSERT(!has_value(), ETL_ERROR(etl::typed_storage_error)); ETL_ASSERT(!has_value(), ETL_ERROR(etl::typed_storage_error));
pointer p = ::new (&storage.value) value_type(t1, t2); pointer p = ::new (&storage.value) value_type(t1, t2);
valid = true; valid = true;
return *p; return *p;
} }
//*************************************************************************** //***************************************************************************
/// Constructs the instance of T with types T1, T2, T3 /// Constructs the instance of T with types T1, T2, T3
/// \returns the instance of T which has been constructed in the internal byte array. /// \returns the instance of T which has been constructed in the internal
/// byte array.
//*************************************************************************** //***************************************************************************
template <typename T1, typename T2, typename T3> template <typename T1, typename T2, typename T3>
reference create(const T1& t1, const T2& t2, const T3& t3) reference create(const T1& t1, const T2& t2, const T3& t3)
{ {
ETL_ASSERT(!has_value(), ETL_ERROR(etl::typed_storage_error)); ETL_ASSERT(!has_value(), ETL_ERROR(etl::typed_storage_error));
pointer p = ::new (&storage.value) value_type(t1, t2, t3); pointer p = ::new (&storage.value) value_type(t1, t2, t3);
valid = true; valid = true;
return *p; return *p;
} }
//*************************************************************************** //***************************************************************************
/// Constructs the instance of T with types T1, T2, T3, T4 /// Constructs the instance of T with types T1, T2, T3, T4
/// \returns the instance of T which has been constructed in the internal byte array. /// \returns the instance of T which has been constructed in the internal
/// byte array.
//*************************************************************************** //***************************************************************************
template <typename T1, typename T2, typename T3, typename T4> template <typename T1, typename T2, typename T3, typename T4>
reference create(const T1& t1, const T2& t2, const T3& t3, const T4& t4) reference create(const T1& t1, const T2& t2, const T3& t3, const T4& t4)
{ {
ETL_ASSERT(!has_value(), ETL_ERROR(etl::typed_storage_error)); ETL_ASSERT(!has_value(), ETL_ERROR(etl::typed_storage_error));
pointer p = ::new (&storage.value) value_type(t1, t2, t3, t4); pointer p = ::new (&storage.value) value_type(t1, t2, t3, t4);
valid = true; valid = true;
return *p; return *p;
} }
#endif #endif
@ -536,7 +549,7 @@ namespace etl
const_pointer operator->() const ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS) const_pointer operator->() const ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
{ {
ETL_ASSERT(has_value(), ETL_ERROR(etl::typed_storage_error)); ETL_ASSERT(has_value(), ETL_ERROR(etl::typed_storage_error));
return &storage.value; return &storage.value;
} }
@ -559,11 +572,13 @@ namespace etl
private: private:
typed_storage(etl::typed_storage<T>&) ETL_DELETE; typed_storage(etl::typed_storage<T>&) ETL_DELETE;
typed_storage& operator =(etl::typed_storage<T>&) ETL_DELETE; typed_storage& operator=(etl::typed_storage<T>&) ETL_DELETE;
struct dummy_t {}; struct dummy_t
{
};
//******************************* //*******************************
union union_type union union_type
{ {
ETL_CONSTEXPR union_type() ETL_NOEXCEPT ETL_CONSTEXPR union_type() ETL_NOEXCEPT
@ -571,9 +586,7 @@ namespace etl
{ {
} }
~union_type() ETL_NOEXCEPT ~union_type() ETL_NOEXCEPT {}
{
}
dummy_t dummy; dummy_t dummy;
value_type value; value_type value;
@ -600,7 +613,7 @@ namespace etl
typedef const T& const_reference; typedef const T& const_reference;
typedef T* pointer; typedef T* pointer;
typedef const T* const_pointer; typedef const T* const_pointer;
template <typename U> template <typename U>
friend ETL_CONSTEXPR14 void swap(typed_storage_ext<U>& lhs, typed_storage_ext<U>& rhs) ETL_NOEXCEPT; friend ETL_CONSTEXPR14 void swap(typed_storage_ext<U>& lhs, typed_storage_ext<U>& rhs) ETL_NOEXCEPT;
@ -608,15 +621,16 @@ namespace etl
/// Constructor. /// Constructor.
//*************************************************************************** //***************************************************************************
typed_storage_ext(void* pbuffer_) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS) typed_storage_ext(void* pbuffer_) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
: pbuffer(reinterpret_cast<T*>(pbuffer_)), : pbuffer(reinterpret_cast<T*>(pbuffer_))
valid(false) , valid(false)
{ {
ETL_ASSERT(etl::is_aligned(pbuffer_, etl::alignment_of<T>::value), ETL_ERROR(etl::alignment_error)); ETL_ASSERT(etl::is_aligned(pbuffer_, etl::alignment_of<T>::value), ETL_ERROR(etl::alignment_error));
} }
#if ETL_USING_CPP11 #if ETL_USING_CPP11
//*************************************************************************** //***************************************************************************
/// Constructs the instance of T forwarding the given \p args to its constructor. /// Constructs the instance of T forwarding the given \p args to its
/// constructor.
//*************************************************************************** //***************************************************************************
template <typename... TArgs> template <typename... TArgs>
typed_storage_ext(void* pbuffer_, TArgs&&... args) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS) typed_storage_ext(void* pbuffer_, TArgs&&... args) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
@ -689,8 +703,8 @@ namespace etl
#endif #endif
//*************************************************************************** //***************************************************************************
/// Default destructor which will NOT call the destructor of the object which /// Default destructor which will NOT call the destructor of the object
/// was created by calling create(). /// which was created by calling create().
//*************************************************************************** //***************************************************************************
~typed_storage_ext() ETL_NOEXCEPT ~typed_storage_ext() ETL_NOEXCEPT
{ {
@ -708,67 +722,72 @@ namespace etl
#if ETL_USING_CPP11 #if ETL_USING_CPP11
//*************************************************************************** //***************************************************************************
/// Constructs the instance of T forwarding the given \p args to its constructor. /// Constructs the instance of T forwarding the given \p args to its
/// \returns the instance of T which has been constructed in the external buffer. /// constructor. \returns the instance of T which has been constructed in
/// the external buffer.
//*************************************************************************** //***************************************************************************
template <typename... TArgs> template <typename... TArgs>
reference create(TArgs&&... args) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS) reference create(TArgs&&... args) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
{ {
ETL_ASSERT(!has_value(), ETL_ERROR(etl::typed_storage_error)); ETL_ASSERT(!has_value(), ETL_ERROR(etl::typed_storage_error));
pointer p = ::new (pbuffer) value_type(etl::forward<TArgs>(args)...); pointer p = ::new (pbuffer) value_type(etl::forward<TArgs>(args)...);
valid = true; valid = true;
return *p; return *p;
} }
#else #else
//*************************************************************************** //***************************************************************************
/// Constructs the instance of T with type T1 /// Constructs the instance of T with type T1
/// \returns the instance of T which has been constructed in the external buffer. /// \returns the instance of T which has been constructed in the external
/// buffer.
//*************************************************************************** //***************************************************************************
template <typename T1> template <typename T1>
reference create(const T1& t1) reference create(const T1& t1)
{ {
ETL_ASSERT(!has_value(), ETL_ERROR(etl::typed_storage_error)); ETL_ASSERT(!has_value(), ETL_ERROR(etl::typed_storage_error));
pointer p = ::new (pbuffer) value_type(t1); pointer p = ::new (pbuffer) value_type(t1);
valid = true; valid = true;
return *p; return *p;
} }
//*************************************************************************** //***************************************************************************
/// Constructs the instance of T with types T1, T2 /// Constructs the instance of T with types T1, T2
/// \returns the instance of T which has been constructed in the external buffer. /// \returns the instance of T which has been constructed in the external
/// buffer.
//*************************************************************************** //***************************************************************************
template <typename T1, typename T2> template <typename T1, typename T2>
reference create(const T1& t1, const T2& t2) reference create(const T1& t1, const T2& t2)
{ {
ETL_ASSERT(!has_value(), ETL_ERROR(etl::typed_storage_error)); ETL_ASSERT(!has_value(), ETL_ERROR(etl::typed_storage_error));
pointer p = ::new (pbuffer) value_type(t1, t2); pointer p = ::new (pbuffer) value_type(t1, t2);
valid = true; valid = true;
return *p; return *p;
} }
//*************************************************************************** //***************************************************************************
/// Constructs the instance of T with types T1, T2, T3 /// Constructs the instance of T with types T1, T2, T3
/// \returns the instance of T which has been constructed in the external buffer. /// \returns the instance of T which has been constructed in the external
/// buffer.
//*************************************************************************** //***************************************************************************
template <typename T1, typename T2, typename T3> template <typename T1, typename T2, typename T3>
reference create(const T1& t1, const T2& t2, const T3& t3) reference create(const T1& t1, const T2& t2, const T3& t3)
{ {
ETL_ASSERT(!has_value(), ETL_ERROR(etl::typed_storage_error)); ETL_ASSERT(!has_value(), ETL_ERROR(etl::typed_storage_error));
pointer p = ::new (pbuffer) value_type(t1, t2, t3); pointer p = ::new (pbuffer) value_type(t1, t2, t3);
valid = true; valid = true;
return *p; return *p;
} }
//*************************************************************************** //***************************************************************************
/// Constructs the instance of T with types T1, T2, T3, T4 /// Constructs the instance of T with types T1, T2, T3, T4
/// \returns the instance of T which has been constructed in the external buffer. /// \returns the instance of T which has been constructed in the external
/// buffer.
//*************************************************************************** //***************************************************************************
template <typename T1, typename T2, typename T3, typename T4> template <typename T1, typename T2, typename T3, typename T4>
reference create(const T1& t1, const T2& t2, const T3& t3, const T4& t4) reference create(const T1& t1, const T2& t2, const T3& t3, const T4& t4)
{ {
ETL_ASSERT(!has_value(), ETL_ERROR(etl::typed_storage_error)); ETL_ASSERT(!has_value(), ETL_ERROR(etl::typed_storage_error));
pointer p = ::new (pbuffer) value_type(t1, t2, t3, t4); pointer p = ::new (pbuffer) value_type(t1, t2, t3, t4);
valid = true; valid = true;
return *p; return *p;
} }
#endif #endif
@ -824,10 +843,10 @@ namespace etl
private: private:
typed_storage_ext(etl::typed_storage_ext<T>&) ETL_DELETE; typed_storage_ext(etl::typed_storage_ext<T>&) ETL_DELETE;
typed_storage_ext& operator =(etl::typed_storage_ext<T>&) ETL_DELETE; typed_storage_ext& operator=(etl::typed_storage_ext<T>&) ETL_DELETE;
pointer pbuffer; pointer pbuffer;
bool valid; bool valid;
}; };
//*************************************************************************** //***************************************************************************
@ -839,8 +858,8 @@ namespace etl
using ETL_OR_STD::swap; using ETL_OR_STD::swap;
swap(lhs.pbuffer, rhs.pbuffer); swap(lhs.pbuffer, rhs.pbuffer);
swap(lhs.valid, rhs.valid); swap(lhs.valid, rhs.valid);
} }
} } // namespace etl
#endif #endif

View File

@ -33,15 +33,15 @@ SOFTWARE.
#include "platform.h" #include "platform.h"
#include "algorithm.h" #include "algorithm.h"
#include "iterator.h" #include "error_handler.h"
#include "functional.h"
#include "exception.h" #include "exception.h"
#include "type_traits.h" #include "functional.h"
#include "initializer_list.h"
#include "iterator.h"
#include "nth_type.h"
#include "parameter_type.h" #include "parameter_type.h"
#include "static_assert.h" #include "static_assert.h"
#include "error_handler.h" #include "type_traits.h"
#include "nth_type.h"
#include "initializer_list.h"
#include <stddef.h> #include <stddef.h>
@ -94,15 +94,15 @@ namespace etl
static ETL_CONSTANT size_t SIZE = SIZE_; static ETL_CONSTANT size_t SIZE = SIZE_;
typedef T value_type; typedef T value_type;
typedef size_t size_type; typedef size_t size_type;
typedef ptrdiff_t difference_type; typedef ptrdiff_t difference_type;
typedef T& reference; typedef T& reference;
typedef const T& const_reference; typedef const T& const_reference;
typedef T* pointer; typedef T* pointer;
typedef const T* const_pointer; typedef const T* const_pointer;
typedef T* iterator; typedef T* iterator;
typedef const T* const_iterator; typedef const T* const_iterator;
typedef ETL_OR_STD::reverse_iterator<iterator> reverse_iterator; typedef ETL_OR_STD::reverse_iterator<iterator> reverse_iterator;
typedef ETL_OR_STD::reverse_iterator<const_iterator> const_reverse_iterator; typedef ETL_OR_STD::reverse_iterator<const_iterator> const_reverse_iterator;
@ -114,9 +114,7 @@ namespace etl
/// Returns a reference to the value at index 'i'. /// Returns a reference to the value at index 'i'.
///\param i The index of the element to access. ///\param i The index of the element to access.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14 reference at(size_t i) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
ETL_CONSTEXPR14
reference at(size_t i) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
{ {
ETL_ASSERT(i < SIZE, ETL_ERROR(array_out_of_range)); ETL_ASSERT(i < SIZE, ETL_ERROR(array_out_of_range));
@ -127,9 +125,7 @@ namespace etl
/// Returns a const reference to the value at index 'i'. /// Returns a const reference to the value at index 'i'.
///\param i The index of the element to access. ///\param i The index of the element to access.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14 const_reference at(size_t i) const ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
ETL_CONSTEXPR14
const_reference at(size_t i) const ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
{ {
ETL_ASSERT(i < SIZE, ETL_ERROR(array_out_of_range)); ETL_ASSERT(i < SIZE, ETL_ERROR(array_out_of_range));
@ -141,9 +137,7 @@ namespace etl
/// Returns a reference to the value at index 'i'. /// Returns a reference to the value at index 'i'.
///\param i The index of the element to access. ///\param i The index of the element to access.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14 reference operator[](size_t i) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS || ETL_NOT_CHECKING_INDEX_OPERATOR)
ETL_CONSTEXPR14
reference operator[](size_t i) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS || ETL_NOT_CHECKING_INDEX_OPERATOR)
{ {
ETL_ASSERT_CHECK_INDEX_OPERATOR(i < SIZE, ETL_ERROR(array_out_of_range)); ETL_ASSERT_CHECK_INDEX_OPERATOR(i < SIZE, ETL_ERROR(array_out_of_range));
@ -155,8 +149,7 @@ namespace etl
/// Returns a const reference to the value at index 'i'. /// Returns a const reference to the value at index 'i'.
///\param i The index of the element to access. ///\param i The index of the element to access.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR const_reference operator[](size_t i) const ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS || ETL_NOT_CHECKING_INDEX_OPERATOR)
ETL_CONSTEXPR const_reference operator[](size_t i) const ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS || ETL_NOT_CHECKING_INDEX_OPERATOR)
{ {
// Throwing from c++11 constexpr requires special syntax // Throwing from c++11 constexpr requires special syntax
#if ETL_USING_CPP11 && ETL_NOT_USING_CPP14 && ETL_USING_EXCEPTIONS && ETL_CHECKING_INDEX_OPERATOR #if ETL_USING_CPP11 && ETL_NOT_USING_CPP14 && ETL_USING_EXCEPTIONS && ETL_CHECKING_INDEX_OPERATOR
@ -171,9 +164,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns a reference to the first element. /// Returns a reference to the first element.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14 reference front() ETL_NOEXCEPT
ETL_CONSTEXPR14
reference front() ETL_NOEXCEPT
{ {
ETL_STATIC_ASSERT(SIZE > 0, "Array is empty."); ETL_STATIC_ASSERT(SIZE > 0, "Array is empty.");
@ -183,8 +174,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns a const reference to the first element. /// Returns a const reference to the first element.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR const_reference front() const ETL_NOEXCEPT
ETL_CONSTEXPR const_reference front() const ETL_NOEXCEPT
{ {
ETL_STATIC_ASSERT(SIZE > 0, "Array is empty."); ETL_STATIC_ASSERT(SIZE > 0, "Array is empty.");
@ -194,9 +184,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns a reference to the last element. /// Returns a reference to the last element.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14 reference back() ETL_NOEXCEPT
ETL_CONSTEXPR14
reference back() ETL_NOEXCEPT
{ {
ETL_STATIC_ASSERT(SIZE > 0, "Array is empty."); ETL_STATIC_ASSERT(SIZE > 0, "Array is empty.");
@ -206,8 +194,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns a const reference to the last element. /// Returns a const reference to the last element.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR const_reference back() const ETL_NOEXCEPT
ETL_CONSTEXPR const_reference back() const ETL_NOEXCEPT
{ {
ETL_STATIC_ASSERT(SIZE > 0, "Array is empty."); ETL_STATIC_ASSERT(SIZE > 0, "Array is empty.");
@ -217,9 +204,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns a pointer to the first element of the internal buffer. /// Returns a pointer to the first element of the internal buffer.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14 pointer data() ETL_NOEXCEPT
ETL_CONSTEXPR14
pointer data() ETL_NOEXCEPT
{ {
return _buffer; return _buffer;
} }
@ -227,8 +212,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns a const pointer to the first element of the internal buffer. /// Returns a const pointer to the first element of the internal buffer.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR const_pointer data() const ETL_NOEXCEPT
ETL_CONSTEXPR const_pointer data() const ETL_NOEXCEPT
{ {
return _buffer; return _buffer;
} }
@ -240,9 +224,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns an iterator to the beginning of the array. /// Returns an iterator to the beginning of the array.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14 iterator begin() ETL_NOEXCEPT
ETL_CONSTEXPR14
iterator begin() ETL_NOEXCEPT
{ {
return _buffer; return _buffer;
} }
@ -250,8 +232,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns a const iterator to the beginning of the array. /// Returns a const iterator to the beginning of the array.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR const_iterator begin() const ETL_NOEXCEPT
ETL_CONSTEXPR const_iterator begin() const ETL_NOEXCEPT
{ {
return _buffer; return _buffer;
} }
@ -259,8 +240,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns a const iterator to the beginning of the array. /// Returns a const iterator to the beginning of the array.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR const_iterator cbegin() const ETL_NOEXCEPT
ETL_CONSTEXPR const_iterator cbegin() const ETL_NOEXCEPT
{ {
return begin(); return begin();
} }
@ -268,9 +248,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns an iterator to the end of the array. /// Returns an iterator to the end of the array.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14 iterator end() ETL_NOEXCEPT
ETL_CONSTEXPR14
iterator end() ETL_NOEXCEPT
{ {
return _buffer + SIZE; return _buffer + SIZE;
} }
@ -278,8 +256,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns a const iterator to the end of the array. /// Returns a const iterator to the end of the array.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR const_iterator end() const ETL_NOEXCEPT
ETL_CONSTEXPR const_iterator end() const ETL_NOEXCEPT
{ {
return _buffer + SIZE; return _buffer + SIZE;
} }
@ -287,8 +264,7 @@ namespace etl
//************************************************************************* //*************************************************************************
// Returns a const iterator to the end of the array. // Returns a const iterator to the end of the array.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR const_iterator cend() const ETL_NOEXCEPT
ETL_CONSTEXPR const_iterator cend() const ETL_NOEXCEPT
{ {
return _buffer + SIZE; return _buffer + SIZE;
} }
@ -296,9 +272,7 @@ namespace etl
//************************************************************************* //*************************************************************************
// Returns an reverse iterator to the reverse beginning of the array. // Returns an reverse iterator to the reverse beginning of the array.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14 reverse_iterator rbegin() ETL_NOEXCEPT
ETL_CONSTEXPR14
reverse_iterator rbegin() ETL_NOEXCEPT
{ {
return reverse_iterator(end()); return reverse_iterator(end());
} }
@ -306,8 +280,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns a const reverse iterator to the reverse beginning of the array. /// Returns a const reverse iterator to the reverse beginning of the array.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR const_reverse_iterator rbegin() const ETL_NOEXCEPT
ETL_CONSTEXPR const_reverse_iterator rbegin() const ETL_NOEXCEPT
{ {
return const_reverse_iterator(end()); return const_reverse_iterator(end());
} }
@ -315,8 +288,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns a const reverse iterator to the reverse beginning of the array. /// Returns a const reverse iterator to the reverse beginning of the array.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR const_reverse_iterator crbegin() const ETL_NOEXCEPT
ETL_CONSTEXPR const_reverse_iterator crbegin() const ETL_NOEXCEPT
{ {
return const_reverse_iterator(end()); return const_reverse_iterator(end());
} }
@ -324,9 +296,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns a reverse iterator to the end of the array. /// Returns a reverse iterator to the end of the array.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14 reverse_iterator rend() ETL_NOEXCEPT
ETL_CONSTEXPR14
reverse_iterator rend() ETL_NOEXCEPT
{ {
return reverse_iterator(begin()); return reverse_iterator(begin());
} }
@ -334,8 +304,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns a const reverse iterator to the end of the array. /// Returns a const reverse iterator to the end of the array.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR const_reverse_iterator rend() const ETL_NOEXCEPT
ETL_CONSTEXPR const_reverse_iterator rend() const ETL_NOEXCEPT
{ {
return const_reverse_iterator(begin()); return const_reverse_iterator(begin());
} }
@ -343,8 +312,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns a const reverse iterator to the end of the array. /// Returns a const reverse iterator to the end of the array.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR const_reverse_iterator crend() const ETL_NOEXCEPT
ETL_CONSTEXPR const_reverse_iterator crend() const ETL_NOEXCEPT
{ {
return const_reverse_iterator(begin()); return const_reverse_iterator(begin());
} }
@ -356,8 +324,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns <b>true</b> if the array size is zero. /// Returns <b>true</b> if the array size is zero.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR bool empty() const ETL_NOEXCEPT
ETL_CONSTEXPR bool empty() const ETL_NOEXCEPT
{ {
return (SIZE == 0); return (SIZE == 0);
} }
@ -365,8 +332,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns the size of the array. /// Returns the size of the array.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR size_t size() const ETL_NOEXCEPT
ETL_CONSTEXPR size_t size() const ETL_NOEXCEPT
{ {
return SIZE; return SIZE;
} }
@ -374,8 +340,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns the maximum possible size of the array. /// Returns the maximum possible size of the array.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR size_t max_size() const ETL_NOEXCEPT
ETL_CONSTEXPR size_t max_size() const ETL_NOEXCEPT
{ {
return SIZE; return SIZE;
} }
@ -409,7 +374,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Fills the array from the range. /// Fills the array from the range.
/// If the range is smaller than the array then the unused array elements are left unmodified. /// If the range is smaller than the array then the unused array elements
/// are left unmodified.
///\param first The iterator to the first item in the range. ///\param first The iterator to the first item in the range.
///\param last The iterator to one past the final item in the range. ///\param last The iterator to one past the final item in the range.
///\return An iterator to the first unassigned array element, or end(). ///\return An iterator to the first unassigned array element, or end().
@ -422,7 +388,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Fills the array from the range. /// Fills the array from the range.
/// If the range is smaller than the array then the unused array elements are initialised with the supplied value. /// If the range is smaller than the array then the unused array elements
/// are initialised with the supplied value.
///\param first The iterator to the first item in the range. ///\param first The iterator to the first item in the range.
///\param last The iterator to one past the final item in the range. ///\param last The iterator to one past the final item in the range.
///\return An iterator to the first array element set to 'value', or end(). ///\return An iterator to the first array element set to 'value', or end().
@ -570,7 +537,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Erases a value from the array. /// Erases a value from the array.
///\param position The index of the position to erase at. ///\param position The index of the position to erase at.
///\param value The value to use to overwrite the last element in the array. ///\param value The value to use to overwrite the last element in the
/// array.
//************************************************************************* //*************************************************************************
inline iterator erase_at(size_t position, parameter_t value) inline iterator erase_at(size_t position, parameter_t value)
{ {
@ -582,7 +550,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Erases a value from the array. /// Erases a value from the array.
///\param position The iterator to the position to erase at. ///\param position The iterator to the position to erase at.
///\param value The value to use to overwrite the last element in the array. ///\param value The value to use to overwrite the last element in the
/// array.
//************************************************************************* //*************************************************************************
iterator erase(const_iterator position, parameter_t value) iterator erase(const_iterator position, parameter_t value)
{ {
@ -600,7 +569,8 @@ namespace etl
/// Erases a range of values from the array. /// Erases a range of values from the array.
///\param first The first item to erase. ///\param first The first item to erase.
///\param last The one past the last item to erase. ///\param last The one past the last item to erase.
///\param value The value to use to overwrite the last elements in the array. ///\param value The value to use to overwrite the last elements in the
/// array.
//************************************************************************* //*************************************************************************
iterator erase_range(size_t first, size_t last, parameter_t value) iterator erase_range(size_t first, size_t last, parameter_t value)
{ {
@ -613,7 +583,8 @@ namespace etl
/// Erases a range of values from the array. /// Erases a range of values from the array.
///\param first The first item to erase. ///\param first The first item to erase.
///\param last The one past the last item to erase. ///\param last The one past the last item to erase.
///\param value The value to use to overwrite the last elements in the array. ///\param value The value to use to overwrite the last elements in the
/// array.
//************************************************************************* //*************************************************************************
iterator erase(const_iterator first, const_iterator last, parameter_t value) iterator erase(const_iterator first, const_iterator last, parameter_t value)
{ {
@ -660,15 +631,15 @@ namespace etl
static ETL_CONSTANT size_t SIZE = 0; static ETL_CONSTANT size_t SIZE = 0;
typedef T value_type; typedef T value_type;
typedef size_t size_type; typedef size_t size_type;
typedef ptrdiff_t difference_type; typedef ptrdiff_t difference_type;
typedef T& reference; typedef T& reference;
typedef const T& const_reference; typedef const T& const_reference;
typedef T* pointer; typedef T* pointer;
typedef const T* const_pointer; typedef const T* const_pointer;
typedef T* iterator; typedef T* iterator;
typedef const T* const_iterator; typedef const T* const_iterator;
typedef ETL_OR_STD::reverse_iterator<iterator> reverse_iterator; typedef ETL_OR_STD::reverse_iterator<iterator> reverse_iterator;
typedef ETL_OR_STD::reverse_iterator<const_iterator> const_reverse_iterator; typedef ETL_OR_STD::reverse_iterator<const_iterator> const_reverse_iterator;
@ -680,9 +651,7 @@ namespace etl
/// Returns a reference to the value at index 'i'. /// Returns a reference to the value at index 'i'.
///\param i The index of the element to access. ///\param i The index of the element to access.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14 reference at(size_t) ETL_NOEXCEPT
ETL_CONSTEXPR14
reference at(size_t) ETL_NOEXCEPT
{ {
return *data(); return *data();
} }
@ -691,9 +660,7 @@ namespace etl
/// Returns a const reference to the value at index 'i'. /// Returns a const reference to the value at index 'i'.
///\param i The index of the element to access. ///\param i The index of the element to access.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14 const_reference at(size_t) const ETL_NOEXCEPT
ETL_CONSTEXPR14
const_reference at(size_t) const ETL_NOEXCEPT
{ {
return *data(); return *data();
} }
@ -703,9 +670,7 @@ namespace etl
/// Returns a reference to the value at index 'i'. /// Returns a reference to the value at index 'i'.
///\param i The index of the element to access. ///\param i The index of the element to access.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14 reference operator[](size_t) ETL_NOEXCEPT
ETL_CONSTEXPR14
reference operator[](size_t) ETL_NOEXCEPT
{ {
return *data(); return *data();
} }
@ -715,8 +680,7 @@ namespace etl
/// Returns a const reference to the value at index 'i'. /// Returns a const reference to the value at index 'i'.
///\param i The index of the element to access. ///\param i The index of the element to access.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR const_reference operator[](size_t) const ETL_NOEXCEPT
ETL_CONSTEXPR const_reference operator[](size_t) const ETL_NOEXCEPT
{ {
return *data(); return *data();
} }
@ -724,9 +688,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns a reference to the first element. /// Returns a reference to the first element.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14 reference front() ETL_NOEXCEPT
ETL_CONSTEXPR14
reference front() ETL_NOEXCEPT
{ {
return *data(); return *data();
} }
@ -734,8 +696,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns a const reference to the first element. /// Returns a const reference to the first element.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR const_reference front() const ETL_NOEXCEPT
ETL_CONSTEXPR const_reference front() const ETL_NOEXCEPT
{ {
return *data(); return *data();
} }
@ -743,9 +704,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns a reference to the last element. /// Returns a reference to the last element.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14 reference back() ETL_NOEXCEPT
ETL_CONSTEXPR14
reference back() ETL_NOEXCEPT
{ {
return *data(); return *data();
} }
@ -753,8 +712,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns a const reference to the last element. /// Returns a const reference to the last element.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR const_reference back() const
ETL_CONSTEXPR const_reference back() const
{ {
return *data(); return *data();
} }
@ -762,9 +720,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns a pointer to the first element of the internal buffer. /// Returns a pointer to the first element of the internal buffer.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14 pointer data() ETL_NOEXCEPT
ETL_CONSTEXPR14
pointer data() ETL_NOEXCEPT
{ {
return (T*)0; return (T*)0;
} }
@ -772,8 +728,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns a const pointer to the first element of the internal buffer. /// Returns a const pointer to the first element of the internal buffer.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR const_pointer data() const ETL_NOEXCEPT
ETL_CONSTEXPR const_pointer data() const ETL_NOEXCEPT
{ {
return (const T*)0; return (const T*)0;
} }
@ -785,9 +740,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns an iterator to the beginning of the array. /// Returns an iterator to the beginning of the array.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14 iterator begin() ETL_NOEXCEPT
ETL_CONSTEXPR14
iterator begin() ETL_NOEXCEPT
{ {
return iterator(); return iterator();
} }
@ -795,8 +748,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns a const iterator to the beginning of the array. /// Returns a const iterator to the beginning of the array.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR const_iterator begin() const ETL_NOEXCEPT
ETL_CONSTEXPR const_iterator begin() const ETL_NOEXCEPT
{ {
return const_iterator(); return const_iterator();
} }
@ -804,8 +756,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns a const iterator to the beginning of the array. /// Returns a const iterator to the beginning of the array.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR const_iterator cbegin() const ETL_NOEXCEPT
ETL_CONSTEXPR const_iterator cbegin() const ETL_NOEXCEPT
{ {
return const_iterator(); return const_iterator();
} }
@ -813,9 +764,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns an iterator to the end of the array. /// Returns an iterator to the end of the array.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14 iterator end() ETL_NOEXCEPT
ETL_CONSTEXPR14
iterator end() ETL_NOEXCEPT
{ {
return iterator(); return iterator();
} }
@ -823,8 +772,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns a const iterator to the end of the array. /// Returns a const iterator to the end of the array.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR const_iterator end() const ETL_NOEXCEPT
ETL_CONSTEXPR const_iterator end() const ETL_NOEXCEPT
{ {
return const_iterator(); return const_iterator();
} }
@ -832,8 +780,7 @@ namespace etl
//************************************************************************* //*************************************************************************
// Returns a const iterator to the end of the array. // Returns a const iterator to the end of the array.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR const_iterator cend() const ETL_NOEXCEPT
ETL_CONSTEXPR const_iterator cend() const ETL_NOEXCEPT
{ {
return const_iterator(); return const_iterator();
} }
@ -841,9 +788,7 @@ namespace etl
//************************************************************************* //*************************************************************************
// Returns an reverse iterator to the reverse beginning of the array. // Returns an reverse iterator to the reverse beginning of the array.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14 reverse_iterator rbegin() ETL_NOEXCEPT
ETL_CONSTEXPR14
reverse_iterator rbegin() ETL_NOEXCEPT
{ {
return reverse_iterator(end()); return reverse_iterator(end());
} }
@ -851,8 +796,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns a const reverse iterator to the reverse beginning of the array. /// Returns a const reverse iterator to the reverse beginning of the array.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR const_reverse_iterator rbegin() const ETL_NOEXCEPT
ETL_CONSTEXPR const_reverse_iterator rbegin() const ETL_NOEXCEPT
{ {
return const_reverse_iterator(end()); return const_reverse_iterator(end());
} }
@ -860,8 +804,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns a const reverse iterator to the reverse beginning of the array. /// Returns a const reverse iterator to the reverse beginning of the array.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR const_reverse_iterator crbegin() const ETL_NOEXCEPT
ETL_CONSTEXPR const_reverse_iterator crbegin() const ETL_NOEXCEPT
{ {
return const_reverse_iterator(end()); return const_reverse_iterator(end());
} }
@ -869,9 +812,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns a reverse iterator to the end of the array. /// Returns a reverse iterator to the end of the array.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14 reverse_iterator rend() ETL_NOEXCEPT
ETL_CONSTEXPR14
reverse_iterator rend() ETL_NOEXCEPT
{ {
return reverse_iterator(begin()); return reverse_iterator(begin());
} }
@ -879,8 +820,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns a const reverse iterator to the end of the array. /// Returns a const reverse iterator to the end of the array.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR const_reverse_iterator rend() const ETL_NOEXCEPT
ETL_CONSTEXPR const_reverse_iterator rend() const ETL_NOEXCEPT
{ {
return const_reverse_iterator(begin()); return const_reverse_iterator(begin());
} }
@ -888,8 +828,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns a const reverse iterator to the end of the array. /// Returns a const reverse iterator to the end of the array.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR const_reverse_iterator crend() const ETL_NOEXCEPT
ETL_CONSTEXPR const_reverse_iterator crend() const ETL_NOEXCEPT
{ {
return const_reverse_iterator(begin()); return const_reverse_iterator(begin());
} }
@ -901,8 +840,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns <b>true</b> if the array size is zero. /// Returns <b>true</b> if the array size is zero.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR bool empty() const ETL_NOEXCEPT
ETL_CONSTEXPR bool empty() const ETL_NOEXCEPT
{ {
return true; return true;
} }
@ -910,8 +848,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns the size of the array. /// Returns the size of the array.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR size_t size() const ETL_NOEXCEPT
ETL_CONSTEXPR size_t size() const ETL_NOEXCEPT
{ {
return 0; return 0;
} }
@ -919,8 +856,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns the maximum possible size of the array. /// Returns the maximum possible size of the array.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR size_t max_size() const ETL_NOEXCEPT
ETL_CONSTEXPR size_t max_size() const ETL_NOEXCEPT
{ {
return 0; return 0;
} }
@ -947,7 +883,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Fills the array from the range. /// Fills the array from the range.
/// If the range is smaller than the array then the unused array elements are left unmodified. /// If the range is smaller than the array then the unused array elements
/// are left unmodified.
///\param first The iterator to the first item in the range. ///\param first The iterator to the first item in the range.
///\param last The iterator to one past the final item in the range. ///\param last The iterator to one past the final item in the range.
///\return An iterator to the first unassigned array element, or end(). ///\return An iterator to the first unassigned array element, or end().
@ -960,7 +897,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Fills the array from the range. /// Fills the array from the range.
/// If the range is smaller than the array then the unused array elements are initialised with the supplied value. /// If the range is smaller than the array then the unused array elements
/// are initialised with the supplied value.
///\param first The iterator to the first item in the range. ///\param first The iterator to the first item in the range.
///\param last The iterator to one past the final item in the range. ///\param last The iterator to one past the final item in the range.
///\return An iterator to the first array element set to 'value', or end(). ///\return An iterator to the first array element set to 'value', or end().
@ -1060,7 +998,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Erases a value from the array. /// Erases a value from the array.
///\param position The index of the position to erase at. ///\param position The index of the position to erase at.
///\param value The value to use to overwrite the last element in the array. ///\param value The value to use to overwrite the last element in the
/// array.
//************************************************************************* //*************************************************************************
inline iterator erase_at(size_t, parameter_t) ETL_NOEXCEPT inline iterator erase_at(size_t, parameter_t) ETL_NOEXCEPT
{ {
@ -1070,7 +1009,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Erases a value from the array. /// Erases a value from the array.
///\param position The iterator to the position to erase at. ///\param position The iterator to the position to erase at.
///\param value The value to use to overwrite the last element in the array. ///\param value The value to use to overwrite the last element in the
/// array.
//************************************************************************* //*************************************************************************
iterator erase(const_iterator, parameter_t) ETL_NOEXCEPT iterator erase(const_iterator, parameter_t) ETL_NOEXCEPT
{ {
@ -1081,7 +1021,8 @@ namespace etl
/// Erases a range of values from the array. /// Erases a range of values from the array.
///\param first The first item to erase. ///\param first The first item to erase.
///\param last The one past the last item to erase. ///\param last The one past the last item to erase.
///\param value The value to use to overwrite the last elements in the array. ///\param value The value to use to overwrite the last elements in the
/// array.
//************************************************************************* //*************************************************************************
iterator erase_range(size_t, size_t, parameter_t) ETL_NOEXCEPT iterator erase_range(size_t, size_t, parameter_t) ETL_NOEXCEPT
{ {
@ -1091,7 +1032,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Erases a range of values from the array. /// Erases a range of values from the array.
///\param position The iterator to the position to erase at. ///\param position The iterator to the position to erase at.
///\param value The value to use to overwrite the last elements in the array. ///\param value The value to use to overwrite the last elements in the
/// array.
//************************************************************************* //*************************************************************************
iterator erase(const_iterator, const_iterator, parameter_t) ETL_NOEXCEPT iterator erase(const_iterator, const_iterator, parameter_t) ETL_NOEXCEPT
{ {
@ -1114,7 +1056,7 @@ namespace etl
template <typename T, typename... TValues> template <typename T, typename... TValues>
constexpr auto make_array(TValues&&... values) ETL_NOEXCEPT -> etl::array<T, sizeof...(TValues)> constexpr auto make_array(TValues&&... values) ETL_NOEXCEPT -> etl::array<T, sizeof...(TValues)>
{ {
return { etl::forward<T>(values)... }; return {etl::forward<T>(values)...};
} }
#endif #endif
@ -1124,7 +1066,7 @@ namespace etl
///\param rhs The second array. ///\param rhs The second array.
//************************************************************************* //*************************************************************************
template <typename T, const size_t SIZE> template <typename T, const size_t SIZE>
void swap(etl::array<T, SIZE> &lhs, etl::array<T, SIZE> &rhs) void swap(etl::array<T, SIZE>& lhs, etl::array<T, SIZE>& rhs)
{ {
lhs.swap(rhs); lhs.swap(rhs);
} }
@ -1136,7 +1078,7 @@ namespace etl
///\return <b>true</b> if the arrays are equal, otherwise <b>false</b> ///\return <b>true</b> if the arrays are equal, otherwise <b>false</b>
//************************************************************************* //*************************************************************************
template <typename T, size_t SIZE> template <typename T, size_t SIZE>
ETL_CONSTEXPR14 bool operator ==(const etl::array<T, SIZE>& lhs, const etl::array<T, SIZE>& rhs) ETL_CONSTEXPR14 bool operator==(const etl::array<T, SIZE>& lhs, const etl::array<T, SIZE>& rhs)
{ {
return etl::equal(lhs.cbegin(), lhs.cend(), rhs.cbegin()); return etl::equal(lhs.cbegin(), lhs.cend(), rhs.cbegin());
} }
@ -1148,7 +1090,7 @@ namespace etl
///\return <b>true</b> if the arrays are not equal, otherwise <b>false</b> ///\return <b>true</b> if the arrays are not equal, otherwise <b>false</b>
//************************************************************************* //*************************************************************************
template <typename T, size_t SIZE> template <typename T, size_t SIZE>
ETL_CONSTEXPR14 bool operator !=(const etl::array<T, SIZE>& lhs, const etl::array<T, SIZE>& rhs) ETL_CONSTEXPR14 bool operator!=(const etl::array<T, SIZE>& lhs, const etl::array<T, SIZE>& rhs)
{ {
return !(lhs == rhs); return !(lhs == rhs);
} }
@ -1157,25 +1099,25 @@ namespace etl
/// Less than operator. /// Less than operator.
///\param lhs The first array. ///\param lhs The first array.
///\param rhs The second array. ///\param rhs The second array.
///\return <b>true</b> if the first array is lexicographically less than the second, otherwise <b>false</b> ///\return <b>true</b> if the first array is lexicographically less than the
/// second, otherwise <b>false</b>
//************************************************************************* //*************************************************************************
template <typename T, size_t SIZE> template <typename T, size_t SIZE>
bool operator <(const etl::array<T, SIZE>& lhs, const etl::array<T, SIZE>& rhs) bool operator<(const etl::array<T, SIZE>& lhs, const etl::array<T, SIZE>& rhs)
{ {
return etl::lexicographical_compare(lhs.cbegin(), return etl::lexicographical_compare(lhs.cbegin(), lhs.cend(), rhs.cbegin(), rhs.cend());
lhs.cend(),
rhs.cbegin(),
rhs.cend());
} }
//************************************************************************* //*************************************************************************
/// Less than or equal operator. /// Less than or equal operator.
///\param lhs The first array. ///\param lhs The first array.
///\param rhs The second array. ///\param rhs The second array.
///\return <b>true</b> if the first array is lexicographically less than or equal to the second, otherwise <b>false</b> ///\return <b>true</b> if the first array is lexicographically less than or
/// equal to the second, otherwise
///< b>false</b>
//************************************************************************* //*************************************************************************
template <typename T, size_t SIZE> template <typename T, size_t SIZE>
bool operator <=(const etl::array<T, SIZE>& lhs, const etl::array<T, SIZE>& rhs) bool operator<=(const etl::array<T, SIZE>& lhs, const etl::array<T, SIZE>& rhs)
{ {
return !(lhs > rhs); return !(lhs > rhs);
} }
@ -1184,10 +1126,11 @@ namespace etl
/// Greater than operator. /// Greater than operator.
///\param lhs The first array. ///\param lhs The first array.
///\param rhs The second array. ///\param rhs The second array.
///\return <b>true</b> if the first array is lexicographically greater than the second, otherwise <b>false</b> ///\return <b>true</b> if the first array is lexicographically greater than
/// the second, otherwise <b>false</b>
template <typename T, size_t SIZE> template <typename T, size_t SIZE>
//************************************************************************* //*************************************************************************
bool operator >(const etl::array<T, SIZE>& lhs, const etl::array<T, SIZE>& rhs) bool operator>(const etl::array<T, SIZE>& lhs, const etl::array<T, SIZE>& rhs)
{ {
return (rhs < lhs); return (rhs < lhs);
} }
@ -1196,10 +1139,12 @@ namespace etl
/// Greater than or equal operator. /// Greater than or equal operator.
///\param lhs The first array. ///\param lhs The first array.
///\param rhs The second array. ///\param rhs The second array.
///\return <b>true</b> if the first array is lexicographically greater than or equal to the second, otherwise <b>false</b> ///\return <b>true</b> if the first array is lexicographically greater than or
/// equal to the second, otherwise
///< b>false</b>
//************************************************************************* //*************************************************************************
template <typename T, size_t SIZE> template <typename T, size_t SIZE>
bool operator >=(const etl::array<T, SIZE>& lhs, const etl::array<T, SIZE>& rhs) bool operator>=(const etl::array<T, SIZE>& lhs, const etl::array<T, SIZE>& rhs)
{ {
return !(lhs < rhs); return !(lhs < rhs);
} }
@ -1233,6 +1178,6 @@ namespace etl
ETL_STATIC_ASSERT(Index < Size, "Index out of bounds"); ETL_STATIC_ASSERT(Index < Size, "Index out of bounds");
return a[Index]; return a[Index];
} }
} } // namespace etl
#endif #endif

View File

@ -32,18 +32,18 @@ SOFTWARE.
#define ETL_ARRAY_VIEW_INCLUDED #define ETL_ARRAY_VIEW_INCLUDED
#include "platform.h" #include "platform.h"
#include "memory.h" #include "algorithm.h"
#include "array.h" #include "array.h"
#include "iterator.h"
#include "error_handler.h" #include "error_handler.h"
#include "exception.h" #include "exception.h"
#include "nullptr.h"
#include "hash.h" #include "hash.h"
#include "algorithm.h" #include "iterator.h"
#include "memory.h"
#include "nullptr.h"
#include "type_traits.h" #include "type_traits.h"
#if ETL_USING_STL && ETL_USING_CPP11 #if ETL_USING_STL && ETL_USING_CPP11
#include <array> #include <array>
#endif #endif
///\defgroup array array ///\defgroup array array
@ -114,22 +114,22 @@ namespace etl
{ {
public: public:
typedef T value_type; typedef T value_type;
typedef size_t size_type; typedef size_t size_type;
typedef const T& const_reference; typedef const T& const_reference;
typedef const T* const_pointer; typedef const T* const_pointer;
typedef const T* const_iterator; typedef const T* const_iterator;
typedef ETL_OR_STD::reverse_iterator<const_iterator> const_reverse_iterator; typedef ETL_OR_STD::reverse_iterator<const_iterator> const_reverse_iterator;
#if defined(ETL_ARRAY_VIEW_IS_MUTABLE) #if defined(ETL_ARRAY_VIEW_IS_MUTABLE)
typedef T* pointer; typedef T* pointer;
typedef T& reference; typedef T& reference;
typedef T* iterator; typedef T* iterator;
typedef ETL_OR_STD::reverse_iterator<iterator> reverse_iterator; typedef ETL_OR_STD::reverse_iterator<iterator> reverse_iterator;
#else #else
typedef const_pointer pointer; typedef const_pointer pointer;
typedef const_reference reference; typedef const_reference reference;
typedef const_pointer iterator; typedef const_pointer iterator;
typedef const_reverse_iterator reverse_iterator; typedef const_reverse_iterator reverse_iterator;
#endif #endif
@ -137,8 +137,8 @@ namespace etl
/// Default constructor. /// Default constructor.
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR array_view() ETL_NOEXCEPT ETL_CONSTEXPR array_view() ETL_NOEXCEPT
: mbegin(ETL_NULLPTR), : mbegin(ETL_NULLPTR)
mend(ETL_NULLPTR) , mend(ETL_NULLPTR)
{ {
} }
@ -146,7 +146,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Construct from etl::array. /// Construct from etl::array.
//************************************************************************* //*************************************************************************
template <typename U, size_t Size, typename = typename etl::enable_if<etl::is_same<etl::remove_cv_t<T>, etl::remove_cv_t<U>>::value, void>::type> template < typename U, size_t Size,
typename = typename etl::enable_if< etl::is_same<etl::remove_cv_t<T>, etl::remove_cv_t<U>>::value, void>::type>
ETL_CONSTEXPR array_view(etl::array<U, Size>& a) ETL_NOEXCEPT ETL_CONSTEXPR array_view(etl::array<U, Size>& a) ETL_NOEXCEPT
: mbegin(a.data()) : mbegin(a.data())
, mend(a.data() + a.size()) , mend(a.data() + a.size())
@ -156,7 +157,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Construct from etl::array. /// Construct from etl::array.
//************************************************************************* //*************************************************************************
template <typename U, size_t Size, typename = typename etl::enable_if<etl::is_same<etl::remove_cv_t<T>, etl::remove_cv_t<U>>::value, void>::type> template < typename U, size_t Size,
typename = typename etl::enable_if< etl::is_same<etl::remove_cv_t<T>, etl::remove_cv_t<U>>::value, void>::type>
ETL_CONSTEXPR array_view(const etl::array<U, Size>& a) ETL_NOEXCEPT ETL_CONSTEXPR array_view(const etl::array<U, Size>& a) ETL_NOEXCEPT
: mbegin(a.data()) : mbegin(a.data())
, mend(a.data() + a.size()) , mend(a.data() + a.size())
@ -167,7 +169,9 @@ namespace etl
/// Construct from etl::array. /// Construct from etl::array.
//************************************************************************* //*************************************************************************
template <typename U, size_t Size> template <typename U, size_t Size>
ETL_CONSTEXPR array_view(etl::array<U, Size>& a, typename etl::enable_if<etl::is_same<typename etl::remove_cv<T>::type, typename etl::remove_cv<U>::type>::value, void>::type* = 0) ETL_NOEXCEPT ETL_CONSTEXPR array_view(
etl::array<U, Size>& a,
typename etl::enable_if< etl::is_same<typename etl::remove_cv<T>::type, typename etl::remove_cv<U>::type>::value, void>::type* = 0) ETL_NOEXCEPT
: mbegin(a.data()) : mbegin(a.data())
, mend(a.data() + a.size()) , mend(a.data() + a.size())
{ {
@ -177,7 +181,9 @@ namespace etl
/// Construct from etl::array. /// Construct from etl::array.
//************************************************************************* //*************************************************************************
template <typename U, size_t Size> template <typename U, size_t Size>
ETL_CONSTEXPR array_view(const etl::array<U, Size>& a, typename etl::enable_if<etl::is_same<typename etl::remove_cv<T>::type, typename etl::remove_cv<U>::type>::value, void>::type* = 0) ETL_NOEXCEPT ETL_CONSTEXPR array_view(
const etl::array<U, Size>& a,
typename etl::enable_if< etl::is_same<typename etl::remove_cv<T>::type, typename etl::remove_cv<U>::type>::value, void>::type* = 0) ETL_NOEXCEPT
: mbegin(a.data()) : mbegin(a.data())
, mend(a.data() + a.size()) , mend(a.data() + a.size())
{ {
@ -188,7 +194,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Construct from std::array. /// Construct from std::array.
//************************************************************************* //*************************************************************************
template <typename U, size_t Size, typename = typename etl::enable_if<etl::is_same<etl::remove_cv_t<T>, etl::remove_cv_t<U>>::value, void>::type> template < typename U, size_t Size,
typename = typename etl::enable_if< etl::is_same<etl::remove_cv_t<T>, etl::remove_cv_t<U>>::value, void>::type>
ETL_CONSTEXPR array_view(std::array<U, Size>& a) ETL_NOEXCEPT ETL_CONSTEXPR array_view(std::array<U, Size>& a) ETL_NOEXCEPT
: mbegin(a.data()) : mbegin(a.data())
, mend(a.data() + a.size()) , mend(a.data() + a.size())
@ -198,7 +205,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Construct from std::array. /// Construct from std::array.
//************************************************************************* //*************************************************************************
template <typename U, size_t Size, typename = typename etl::enable_if<etl::is_same<etl::remove_cv_t<T>, etl::remove_cv_t<U>>::value, void>::type> template < typename U, size_t Size,
typename = typename etl::enable_if< etl::is_same<etl::remove_cv_t<T>, etl::remove_cv_t<U>>::value, void>::type>
ETL_CONSTEXPR array_view(const std::array<U, Size>& a) ETL_NOEXCEPT ETL_CONSTEXPR array_view(const std::array<U, Size>& a) ETL_NOEXCEPT
: mbegin(a.data()) : mbegin(a.data())
, mend(a.data() + a.size()) , mend(a.data() + a.size())
@ -211,10 +219,12 @@ namespace etl
/// Construct from a container or other type that supports /// Construct from a container or other type that supports
/// data() and size() member functions. /// data() and size() member functions.
//************************************************************************* //*************************************************************************
template <typename TContainer, typename = typename etl::enable_if<!etl::is_pointer<etl::remove_reference_t<TContainer>>::value && template < typename TContainer,
!etl::is_array<etl::remove_reference_t<TContainer>>::value && typename = typename etl::enable_if<
etl::is_same<etl::remove_cv_t<T>, etl::remove_cv_t<typename etl::remove_reference_t<TContainer>::value_type>>::value, void>::type> !etl::is_pointer<etl::remove_reference_t<TContainer>>::value && !etl::is_array<etl::remove_reference_t<TContainer>>::value
ETL_CONSTEXPR array_view(TContainer&& a) ETL_NOEXCEPT && etl::is_same<etl::remove_cv_t<T>, etl::remove_cv_t<typename etl::remove_reference_t< TContainer>::value_type>>::value,
void>::type>
ETL_CONSTEXPR array_view(TContainer&& a) ETL_NOEXCEPT
: mbegin(a.data()) : mbegin(a.data())
, mend(a.data() + a.size()) , mend(a.data() + a.size())
{ {
@ -225,9 +235,12 @@ namespace etl
/// data() and size() member functions. /// data() and size() member functions.
//************************************************************************* //*************************************************************************
template <typename TContainer> template <typename TContainer>
ETL_CONSTEXPR array_view(TContainer& a, typename etl::enable_if<!etl::is_pointer<typename etl::remove_reference<TContainer>::type>::value && ETL_CONSTEXPR array_view(TContainer& a,
!etl::is_array<TContainer>::value && typename etl::enable_if<
etl::is_same<typename etl::remove_cv<T>::type, typename etl::remove_cv<typename etl::remove_reference<TContainer>::type::value_type>::type>::value, void>::type* = 0) ETL_NOEXCEPT !etl::is_pointer< typename etl::remove_reference<TContainer>::type>::value && !etl::is_array<TContainer>::value
&& etl::is_same< typename etl::remove_cv<T>::type,
typename etl::remove_cv<typename etl::remove_reference< TContainer>::type::value_type>::type>::value,
void>::type* = 0) ETL_NOEXCEPT
: mbegin(a.data()) : mbegin(a.data())
, mend(a.data() + a.size()) , mend(a.data() + a.size())
{ {
@ -238,9 +251,12 @@ namespace etl
/// data() and size() member functions. /// data() and size() member functions.
//************************************************************************* //*************************************************************************
template <typename TContainer> template <typename TContainer>
ETL_CONSTEXPR array_view(const TContainer& a, typename etl::enable_if<!etl::is_pointer<typename etl::remove_reference<TContainer>::type>::value && ETL_CONSTEXPR array_view(const TContainer& a,
!etl::is_array<TContainer>::value && typename etl::enable_if<
etl::is_same<typename etl::remove_cv<T>::type, typename etl::remove_cv<typename etl::remove_reference<TContainer>::type::value_type>::type>::value, void>::type* = 0) ETL_NOEXCEPT !etl::is_pointer< typename etl::remove_reference<TContainer>::type>::value && !etl::is_array<TContainer>::value
&& etl::is_same< typename etl::remove_cv<T>::type,
typename etl::remove_cv<typename etl::remove_reference< TContainer>::type::value_type>::type>::value,
void>::type* = 0) ETL_NOEXCEPT
: mbegin(a.data()) : mbegin(a.data())
, mend(a.data() + a.size()) , mend(a.data() + a.size())
{ {
@ -252,29 +268,28 @@ namespace etl
//************************************************************************* //*************************************************************************
template <typename TIterator> template <typename TIterator>
ETL_CONSTEXPR array_view(const TIterator begin_, const TIterator end_) ETL_NOEXCEPT ETL_CONSTEXPR array_view(const TIterator begin_, const TIterator end_) ETL_NOEXCEPT
: mbegin(etl::to_address(begin_)), : mbegin(etl::to_address(begin_))
mend(etl::to_address(begin_) + etl::distance(begin_, end_)) , mend(etl::to_address(begin_) + etl::distance(begin_, end_))
{ {
} }
//************************************************************************* //*************************************************************************
/// Construct from iterator and size /// Construct from iterator and size
//************************************************************************* //*************************************************************************
template <typename TIterator, template <typename TIterator, typename TSize>
typename TSize>
ETL_CONSTEXPR array_view(const TIterator begin_, const TSize size_) ETL_NOEXCEPT ETL_CONSTEXPR array_view(const TIterator begin_, const TSize size_) ETL_NOEXCEPT
: mbegin(etl::to_address(begin_)), : mbegin(etl::to_address(begin_))
mend(etl::to_address(begin_) + size_) , mend(etl::to_address(begin_) + size_)
{ {
} }
//************************************************************************* //*************************************************************************
/// Construct from C array /// Construct from C array
//************************************************************************* //*************************************************************************
template<size_t Array_Size> template <size_t Array_Size>
ETL_CONSTEXPR array_view(T(&begin_)[Array_Size]) ETL_NOEXCEPT ETL_CONSTEXPR array_view(T (&begin_)[Array_Size]) ETL_NOEXCEPT
: mbegin(begin_), : mbegin(begin_)
mend(begin_ + Array_Size) , mend(begin_ + Array_Size)
{ {
} }
@ -282,14 +297,15 @@ namespace etl
/// Copy constructor /// Copy constructor
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR array_view(const array_view& other) ETL_NOEXCEPT ETL_CONSTEXPR array_view(const array_view& other) ETL_NOEXCEPT
: mbegin(other.mbegin), : mbegin(other.mbegin)
mend(other.mend) , mend(other.mend)
{ {
} }
//************************************************************************* //*************************************************************************
/// Returns a reference to the first element. /// Returns a reference to the first element.
/// If asserts or exceptions are enabled, throws an etl::array_view_empty if the view is empty. /// If asserts or exceptions are enabled, throws an etl::array_view_empty if
/// the view is empty.
//************************************************************************* //*************************************************************************
reference front() reference front()
{ {
@ -299,7 +315,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns a const reference to the first element. /// Returns a const reference to the first element.
/// If asserts or exceptions are enabled, throws an etl::array_view_empty if the view is empty. /// If asserts or exceptions are enabled, throws an etl::array_view_empty if
/// the view is empty.
//************************************************************************* //*************************************************************************
const_reference front() const const_reference front() const
{ {
@ -309,7 +326,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns a reference to the last element. /// Returns a reference to the last element.
/// If asserts or exceptions are enabled, throws an etl::array_view_empty if the view is empty. /// If asserts or exceptions are enabled, throws an etl::array_view_empty if
/// the view is empty.
//************************************************************************* //*************************************************************************
reference back() reference back()
{ {
@ -319,7 +337,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns a const reference to the last element. /// Returns a const reference to the last element.
/// If asserts or exceptions are enabled, throws an etl::array_view_empty if the view is empty. /// If asserts or exceptions are enabled, throws an etl::array_view_empty if
/// the view is empty.
//************************************************************************* //*************************************************************************
const_reference back() const const_reference back() const
{ {
@ -486,8 +505,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Assign from iterator and size. /// Assign from iterator and size.
//************************************************************************* //*************************************************************************
template <typename TIterator, template <typename TIterator, typename TSize>
typename TSize>
void assign(const TIterator begin_, const TSize size_) void assign(const TIterator begin_, const TSize size_)
{ {
mbegin = etl::to_address(begin_); mbegin = etl::to_address(begin_);
@ -497,7 +515,8 @@ namespace etl
#if defined(ETL_ARRAY_VIEW_IS_MUTABLE) #if defined(ETL_ARRAY_VIEW_IS_MUTABLE)
//************************************************************************* //*************************************************************************
/// Returns a reference to the indexed value. /// Returns a reference to the indexed value.
/// If asserts or exceptions are enabled, throws an etl::array_view_bounds if the index is out of bounds. /// If asserts or exceptions are enabled, throws an etl::array_view_bounds
/// if the index is out of bounds.
//************************************************************************* //*************************************************************************
reference operator[](const size_t i) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS || ETL_NOT_CHECKING_INDEX_OPERATOR) reference operator[](const size_t i) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS || ETL_NOT_CHECKING_INDEX_OPERATOR)
{ {
@ -509,7 +528,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns a const reference to the indexed value. /// Returns a const reference to the indexed value.
/// If asserts or exceptions are enabled, throws an etl::array_view_bounds if the index is out of bounds. /// If asserts or exceptions are enabled, throws an etl::array_view_bounds
/// if the index is out of bounds.
//************************************************************************* //*************************************************************************
const_reference operator[](const size_t i) const ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS || ETL_NOT_CHECKING_INDEX_OPERATOR) const_reference operator[](const size_t i) const ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS || ETL_NOT_CHECKING_INDEX_OPERATOR)
{ {
@ -556,10 +576,10 @@ namespace etl
//************************************************************************* //*************************************************************************
void remove_prefix(const size_type n) ETL_NOEXCEPT void remove_prefix(const size_type n) ETL_NOEXCEPT
{ {
if (n < size()) if (n < size())
mbegin += n; mbegin += n;
else else
mbegin = mend; mbegin = mend;
} }
//************************************************************************* //*************************************************************************
@ -567,10 +587,10 @@ namespace etl
//************************************************************************* //*************************************************************************
void remove_suffix(const size_type n) ETL_NOEXCEPT void remove_suffix(const size_type n) ETL_NOEXCEPT
{ {
if (n < size()) if (n < size())
mend -= n; mend -= n;
else else
mend = mbegin; mend = mbegin;
} }
//************************************************************************* //*************************************************************************
@ -584,16 +604,15 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Equality for array views. /// Equality for array views.
//************************************************************************* //*************************************************************************
friend bool operator == (const array_view<T>& lhs, const array_view<T>& rhs) friend bool operator==(const array_view<T>& lhs, const array_view<T>& rhs)
{ {
return (lhs.size() == rhs.size()) && return (lhs.size() == rhs.size()) && etl::equal(lhs.begin(), lhs.end(), rhs.begin());
etl::equal(lhs.begin(), lhs.end(), rhs.begin());
} }
//************************************************************************* //*************************************************************************
/// Inequality for array views. /// Inequality for array views.
//************************************************************************* //*************************************************************************
friend bool operator != (const array_view<T>& lhs, const array_view<T>& rhs) friend bool operator!=(const array_view<T>& lhs, const array_view<T>& rhs)
{ {
return !(lhs == rhs); return !(lhs == rhs);
} }
@ -601,7 +620,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Less-than for array views. /// Less-than for array views.
//************************************************************************* //*************************************************************************
friend bool operator < (const array_view<T>& lhs, const array_view<T>& rhs) friend bool operator<(const array_view<T>& lhs, const array_view<T>& rhs)
{ {
return etl::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end()); return etl::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
} }
@ -609,7 +628,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Greater-than for array views. /// Greater-than for array views.
//************************************************************************* //*************************************************************************
friend bool operator > (const array_view<T>& lhs, const array_view<T>& rhs) friend bool operator>(const array_view<T>& lhs, const array_view<T>& rhs)
{ {
return rhs < lhs; return rhs < lhs;
} }
@ -617,7 +636,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Less-than-equal for array views. /// Less-than-equal for array views.
//************************************************************************* //*************************************************************************
friend bool operator <= (const array_view<T>& lhs, const array_view<T>& rhs) friend bool operator<=(const array_view<T>& lhs, const array_view<T>& rhs)
{ {
return !(lhs > rhs); return !(lhs > rhs);
} }
@ -625,7 +644,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Greater-than-equal for array views. /// Greater-than-equal for array views.
//************************************************************************* //*************************************************************************
friend bool operator >= (const array_view<T>& lhs, const array_view<T>& rhs) friend bool operator>=(const array_view<T>& lhs, const array_view<T>& rhs)
{ {
return !(lhs < rhs); return !(lhs < rhs);
} }
@ -641,18 +660,14 @@ namespace etl
//************************************************************************* //*************************************************************************
#if ETL_USING_CPP17 #if ETL_USING_CPP17
template <typename TArray> template <typename TArray>
array_view(TArray& a) array_view(TArray& a) -> array_view<typename TArray::value_type>;
-> array_view<typename TArray::value_type>;
template <typename TIterator> template <typename TIterator>
array_view(const TIterator begin_, const TIterator end_) array_view(const TIterator begin_, const TIterator end_) -> array_view<etl::remove_pointer_t<TIterator>>;
-> array_view<etl::remove_pointer_t<TIterator>>;
template <typename TIterator, template <typename TIterator, typename TSize>
typename TSize> array_view(const TIterator begin_, const TSize size_) -> array_view<etl::remove_pointer_t<TIterator>>;
array_view(const TIterator begin_, const TSize size_) #endif
-> array_view<etl::remove_pointer_t<TIterator>>;
#endif
//************************************************************************* //*************************************************************************
/// Hash function. /// Hash function.
@ -668,7 +683,7 @@ namespace etl
} }
}; };
#endif #endif
} } // namespace etl
//************************************************************************* //*************************************************************************
/// Swaps the values. /// Swaps the values.

View File

@ -32,12 +32,12 @@ SOFTWARE.
#define ETL_ARRAY_WRAPPER_INCLUDED #define ETL_ARRAY_WRAPPER_INCLUDED
#include "platform.h" #include "platform.h"
#include "iterator.h" #include "algorithm.h"
#include "error_handler.h" #include "error_handler.h"
#include "exception.h" #include "exception.h"
#include "hash.h" #include "hash.h"
#include "iterator.h"
#include "parameter_type.h" #include "parameter_type.h"
#include "algorithm.h"
///\defgroup array array ///\defgroup array array
/// A wrapper for arrays /// A wrapper for arrays
@ -75,19 +75,19 @@ namespace etl
//*************************************************************************** //***************************************************************************
/// Array wrapper. /// Array wrapper.
//*************************************************************************** //***************************************************************************
template <typename T, size_t SIZE_, T(&ARRAY_)[SIZE_]> template <typename T, size_t SIZE_, T (&ARRAY_)[SIZE_]>
class array_wrapper class array_wrapper
{ {
public: public:
typedef T value_type; typedef T value_type;
typedef size_t size_type; typedef size_t size_type;
typedef T& reference; typedef T& reference;
typedef const T& const_reference; typedef const T& const_reference;
typedef T* pointer; typedef T* pointer;
typedef const T* const_pointer; typedef const T* const_pointer;
typedef T* iterator; typedef T* iterator;
typedef const T* const_iterator; typedef const T* const_iterator;
typedef ETL_OR_STD::reverse_iterator<iterator> reverse_iterator; typedef ETL_OR_STD::reverse_iterator<iterator> reverse_iterator;
typedef ETL_OR_STD::reverse_iterator<const_iterator> const_reverse_iterator; typedef ETL_OR_STD::reverse_iterator<const_iterator> const_reverse_iterator;
@ -268,7 +268,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns a reference to the indexed value. /// Returns a reference to the indexed value.
/// If asserts or exceptions are enabled, throws an etl::array_wrapper_bounds if the index is out of bounds. /// If asserts or exceptions are enabled, throws an
/// etl::array_wrapper_bounds if the index is out of bounds.
//************************************************************************* //*************************************************************************
reference operator[](size_t i) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS || ETL_NOT_CHECKING_INDEX_OPERATOR) reference operator[](size_t i) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS || ETL_NOT_CHECKING_INDEX_OPERATOR)
{ {
@ -278,14 +279,15 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns a const reference to the indexed value. /// Returns a const reference to the indexed value.
/// If asserts or exceptions are enabled, throws an etl::array_wrapper_bounds if the index is out of bounds. /// If asserts or exceptions are enabled, throws an
/// etl::array_wrapper_bounds if the index is out of bounds.
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR const_reference operator[](size_t i) const ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS || ETL_NOT_CHECKING_INDEX_OPERATOR) ETL_CONSTEXPR const_reference operator[](size_t i) const ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS || ETL_NOT_CHECKING_INDEX_OPERATOR)
{ {
// Throwing from c++11 constexpr requires special syntax // Throwing from c++11 constexpr requires special syntax
#if ETL_USING_CPP11 && ETL_NOT_USING_CPP14 && ETL_USING_EXCEPTIONS && ETL_CHECKING_INDEX_OPERATOR #if ETL_USING_CPP11 && ETL_NOT_USING_CPP14 && ETL_USING_EXCEPTIONS && ETL_CHECKING_INDEX_OPERATOR
return i < SIZE ? ARRAY_[i] : throw(ETL_ERROR(etl::array_wrapper_bounds)); return i < SIZE ? ARRAY_[i] : throw(ETL_ERROR(etl::array_wrapper_bounds));
#else #else
ETL_ASSERT_CHECK_INDEX_OPERATOR(i < SIZE, ETL_ERROR(etl::array_wrapper_bounds)); ETL_ASSERT_CHECK_INDEX_OPERATOR(i < SIZE, ETL_ERROR(etl::array_wrapper_bounds));
return ARRAY_[i]; return ARRAY_[i];
#endif #endif
@ -320,9 +322,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Swaps the contents of arrays. /// Swaps the contents of arrays.
//************************************************************************* //*************************************************************************
template <typename U, U(&ARRAYOTHER)[SIZE_]> template <typename U, U (&ARRAYOTHER)[SIZE_]>
typename etl::enable_if<etl::is_same<T, U>::value, void>::type typename etl::enable_if<etl::is_same<T, U>::value, void>::type swap(etl::array_wrapper<U, SIZE_, ARRAYOTHER>& other)
swap(etl::array_wrapper<U, SIZE_, ARRAYOTHER>& other)
{ {
using ETL_OR_STD::swap; // Allow ADL using ETL_OR_STD::swap; // Allow ADL
@ -336,9 +337,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Equality for array wrappers. /// Equality for array wrappers.
//************************************************************************* //*************************************************************************
template <typename TL, typename TR, size_t SIZEL, size_t SIZER, TL(&ARRAYL)[SIZEL], TR(&ARRAYR)[SIZER]> template <typename TL, typename TR, size_t SIZEL, size_t SIZER, TL (&ARRAYL)[SIZEL], TR (&ARRAYR)[SIZER]>
bool operator == (const etl::array_wrapper<TL, SIZEL, ARRAYL>& lhs, bool operator==(const etl::array_wrapper<TL, SIZEL, ARRAYL>& lhs, const etl::array_wrapper<TR, SIZER, ARRAYR>& rhs)
const etl::array_wrapper<TR, SIZER, ARRAYR>& rhs)
{ {
return (SIZEL == SIZER) && etl::equal(lhs.begin(), lhs.end(), rhs.begin()); return (SIZEL == SIZER) && etl::equal(lhs.begin(), lhs.end(), rhs.begin());
} }
@ -346,9 +346,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Inequality for array wrapper. /// Inequality for array wrapper.
//************************************************************************* //*************************************************************************
template <typename TL, typename TR, size_t SIZEL, size_t SIZER, TL(&ARRAYL)[SIZEL], TR(&ARRAYR)[SIZER]> template <typename TL, typename TR, size_t SIZEL, size_t SIZER, TL (&ARRAYL)[SIZEL], TR (&ARRAYR)[SIZER]>
bool operator != (const etl::array_wrapper<TL, SIZEL, ARRAYL>& lhs, bool operator!=(const etl::array_wrapper<TL, SIZEL, ARRAYL>& lhs, const etl::array_wrapper<TR, SIZER, ARRAYR>& rhs)
const etl::array_wrapper<TR, SIZER, ARRAYR>& rhs)
{ {
return !(lhs == rhs); return !(lhs == rhs);
} }
@ -356,9 +355,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Less-than for array wrapper. /// Less-than for array wrapper.
//************************************************************************* //*************************************************************************
template <typename TL, typename TR, size_t SIZEL, size_t SIZER, TL(&ARRAYL)[SIZEL], TR(&ARRAYR)[SIZER]> template <typename TL, typename TR, size_t SIZEL, size_t SIZER, TL (&ARRAYL)[SIZEL], TR (&ARRAYR)[SIZER]>
bool operator < (const etl::array_wrapper<TL, SIZEL, ARRAYL>& lhs, bool operator<(const etl::array_wrapper<TL, SIZEL, ARRAYL>& lhs, const etl::array_wrapper<TR, SIZER, ARRAYR>& rhs)
const etl::array_wrapper<TR, SIZER, ARRAYR>& rhs)
{ {
return etl::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end()); return etl::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
} }
@ -366,9 +364,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Greater-than for array wrapper. /// Greater-than for array wrapper.
//************************************************************************* //*************************************************************************
template <typename TL, typename TR, size_t SIZEL, size_t SIZER, TL(&ARRAYL)[SIZEL], TR(&ARRAYR)[SIZER]> template <typename TL, typename TR, size_t SIZEL, size_t SIZER, TL (&ARRAYL)[SIZEL], TR (&ARRAYR)[SIZER]>
bool operator > (const etl::array_wrapper<TL, SIZEL, ARRAYL>& lhs, bool operator>(const etl::array_wrapper<TL, SIZEL, ARRAYL>& lhs, const etl::array_wrapper<TR, SIZER, ARRAYR>& rhs)
const etl::array_wrapper<TR, SIZER, ARRAYR>& rhs)
{ {
return rhs < lhs; return rhs < lhs;
} }
@ -376,9 +373,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Less-than-equal for array wrapper. /// Less-than-equal for array wrapper.
//************************************************************************* //*************************************************************************
template <typename TL, typename TR, size_t SIZEL, size_t SIZER, TL(&ARRAYL)[SIZEL], TR(&ARRAYR)[SIZER]> template <typename TL, typename TR, size_t SIZEL, size_t SIZER, TL (&ARRAYL)[SIZEL], TR (&ARRAYR)[SIZER]>
bool operator <= (const etl::array_wrapper<TL, SIZEL, ARRAYL>& lhs, bool operator<=(const etl::array_wrapper<TL, SIZEL, ARRAYL>& lhs, const etl::array_wrapper<TR, SIZER, ARRAYR>& rhs)
const etl::array_wrapper<TR, SIZER, ARRAYR>& rhs)
{ {
return !(lhs > rhs); return !(lhs > rhs);
} }
@ -386,9 +382,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Greater-than-equal for array wrapper. /// Greater-than-equal for array wrapper.
//************************************************************************* //*************************************************************************
template <typename TL, typename TR, size_t SIZEL, size_t SIZER, TL(&ARRAYL)[SIZEL], TR(&ARRAYR)[SIZER]> template <typename TL, typename TR, size_t SIZEL, size_t SIZER, TL (&ARRAYL)[SIZEL], TR (&ARRAYR)[SIZER]>
bool operator >= (const etl::array_wrapper<TL, SIZEL, ARRAYL>& lhs, bool operator>=(const etl::array_wrapper<TL, SIZEL, ARRAYL>& lhs, const etl::array_wrapper<TR, SIZER, ARRAYR>& rhs)
const etl::array_wrapper<TR, SIZER, ARRAYR>& rhs)
{ {
return !(lhs < rhs); return !(lhs < rhs);
} }
@ -397,7 +392,7 @@ namespace etl
/// Hash function. /// Hash function.
//************************************************************************* //*************************************************************************
#if ETL_USING_8BIT_TYPES #if ETL_USING_8BIT_TYPES
template <typename T, size_t SIZE, T(&ARRAY)[SIZE]> template <typename T, size_t SIZE, T (&ARRAY)[SIZE]>
struct hash<etl::array_wrapper<T, SIZE, ARRAY> > struct hash<etl::array_wrapper<T, SIZE, ARRAY> >
{ {
size_t operator()(const etl::array_wrapper<T, SIZE, ARRAY>& aw) const size_t operator()(const etl::array_wrapper<T, SIZE, ARRAY>& aw) const
@ -409,19 +404,17 @@ namespace etl
} }
}; };
#endif #endif
} } // namespace etl
//************************************************************************* //*************************************************************************
/// Swap. /// Swap.
//************************************************************************* //*************************************************************************
template <typename T, size_t SIZE, T(&ARRAYL)[SIZE], T(&ARRAYR)[SIZE]> template <typename T, size_t SIZE, T (&ARRAYL)[SIZE], T (&ARRAYR)[SIZE]>
void swap(etl::array_wrapper<T, SIZE, ARRAYL>& lhs, void swap(etl::array_wrapper<T, SIZE, ARRAYL>& lhs, etl::array_wrapper<T, SIZE, ARRAYR>& rhs)
etl::array_wrapper<T, SIZE, ARRAYR>& rhs)
{ {
lhs.swap(rhs); lhs.swap(rhs);
} }
#define ETL_ARRAY_WRAPPER(arraytype, arrayobject) etl::array_wrapper<arraytype, ETL_ARRAY_SIZE(arrayobject), arrayobject> #define ETL_ARRAY_WRAPPER(arraytype, arrayobject) etl::array_wrapper<arraytype, ETL_ARRAY_SIZE(arrayobject), arrayobject>
#endif #endif

View File

@ -32,7 +32,7 @@ SOFTWARE.
#include "platform.h" #include "platform.h"
#if ETL_HAS_ATOMIC #if ETL_HAS_ATOMIC
#if (ETL_USING_CPP11 && (ETL_USING_STL || defined(ETL_IN_UNIT_TEST))) #if (ETL_USING_CPP11 && (ETL_USING_STL || defined(ETL_IN_UNIT_TEST)))
#include "atomic/atomic_std.h" #include "atomic/atomic_std.h"
#elif defined(ETL_COMPILER_ARM5) #elif defined(ETL_COMPILER_ARM5)
#include "atomic/atomic_arm.h" #include "atomic/atomic_arm.h"

View File

@ -30,11 +30,11 @@ SOFTWARE.
#define ETL_ATOMIC_GCC_SYNC_INCLUDED #define ETL_ATOMIC_GCC_SYNC_INCLUDED
#include "../platform.h" #include "../platform.h"
#include "../type_traits.h"
#include "../static_assert.h"
#include "../nullptr.h"
#include "../char_traits.h" #include "../char_traits.h"
#include "../mutex.h" #include "../mutex.h"
#include "../nullptr.h"
#include "../static_assert.h"
#include "../type_traits.h"
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
@ -75,12 +75,20 @@ namespace etl
{ {
#if defined(ETL_USE_ATOMIC_BUILTINS) #if defined(ETL_USE_ATOMIC_BUILTINS)
#define ETL_BUILTIN_LOCK do { while (__atomic_test_and_set(&flag, etl::memory_order_seq_cst)) {} } while (0) #define ETL_BUILTIN_LOCK \
#define ETL_BUILTIN_UNLOCK do { __atomic_clear(&flag, etl::memory_order_seq_cst); } while (0) do { \
while (__atomic_test_and_set(&flag, etl::memory_order_seq_cst)) \
{ \
} \
} while (0)
#define ETL_BUILTIN_UNLOCK \
do { \
__atomic_clear(&flag, etl::memory_order_seq_cst); \
} while (0)
//*************************************************************************** //***************************************************************************
// Atomic type for pre C++11 GCC compilers that support the builtin '__atomic' functions. // Atomic type for pre C++11 GCC compilers that support the builtin '__atomic'
// Only integral and pointer types are supported. // functions. Only integral and pointer types are supported.
//*************************************************************************** //***************************************************************************
typedef enum memory_order typedef enum memory_order
@ -121,14 +129,14 @@ namespace etl
} }
// Assignment // Assignment
T operator =(T v) T operator=(T v)
{ {
store(v); store(v);
return v; return v;
} }
T operator =(T v) volatile T operator=(T v) volatile
{ {
store(v); store(v);
@ -136,106 +144,106 @@ namespace etl
} }
// Pre-increment // Pre-increment
T operator ++() T operator++()
{ {
return __atomic_add_fetch(&value, 1, etl::memory_order_seq_cst); return __atomic_add_fetch(&value, 1, etl::memory_order_seq_cst);
} }
T operator ++() volatile T operator++() volatile
{ {
return __atomic_add_fetch(&value, 1, etl::memory_order_seq_cst); return __atomic_add_fetch(&value, 1, etl::memory_order_seq_cst);
} }
// Post-increment // Post-increment
T operator ++(int) T operator++(int)
{ {
return __atomic_fetch_add(&value, 1, etl::memory_order_seq_cst); return __atomic_fetch_add(&value, 1, etl::memory_order_seq_cst);
} }
T operator ++(int) volatile T operator++(int) volatile
{ {
return __atomic_fetch_add(&value, 1, etl::memory_order_seq_cst); return __atomic_fetch_add(&value, 1, etl::memory_order_seq_cst);
} }
// Pre-decrement // Pre-decrement
T operator --() T operator--()
{ {
return __atomic_sub_fetch(&value, 1, etl::memory_order_seq_cst); return __atomic_sub_fetch(&value, 1, etl::memory_order_seq_cst);
} }
T operator --() volatile T operator--() volatile
{ {
return __atomic_sub_fetch(&value, 1, etl::memory_order_seq_cst); return __atomic_sub_fetch(&value, 1, etl::memory_order_seq_cst);
} }
// Post-decrement // Post-decrement
T operator --(int) T operator--(int)
{ {
return __atomic_fetch_sub(&value, 1, etl::memory_order_seq_cst); return __atomic_fetch_sub(&value, 1, etl::memory_order_seq_cst);
} }
T operator --(int) volatile T operator--(int) volatile
{ {
return __atomic_fetch_sub(&value, 1, etl::memory_order_seq_cst); return __atomic_fetch_sub(&value, 1, etl::memory_order_seq_cst);
} }
// Add // Add
T operator +=(T v) T operator+=(T v)
{ {
return __atomic_fetch_add(&value, v, etl::memory_order_seq_cst); return __atomic_fetch_add(&value, v, etl::memory_order_seq_cst);
} }
T operator +=(T v) volatile T operator+=(T v) volatile
{ {
return __atomic_fetch_add(&value, v, etl::memory_order_seq_cst); return __atomic_fetch_add(&value, v, etl::memory_order_seq_cst);
} }
// Subtract // Subtract
T operator -=(T v) T operator-=(T v)
{ {
return __atomic_fetch_sub(&value, v, etl::memory_order_seq_cst); return __atomic_fetch_sub(&value, v, etl::memory_order_seq_cst);
} }
T operator -=(T v) volatile T operator-=(T v) volatile
{ {
return __atomic_fetch_sub(&value, v, etl::memory_order_seq_cst); return __atomic_fetch_sub(&value, v, etl::memory_order_seq_cst);
} }
// And // And
T operator &=(T v) T operator&=(T v)
{ {
return __atomic_fetch_and(&value, v, etl::memory_order_seq_cst); return __atomic_fetch_and(&value, v, etl::memory_order_seq_cst);
} }
T operator &=(T v) volatile T operator&=(T v) volatile
{ {
return __atomic_fetch_and(&value, v, etl::memory_order_seq_cst); return __atomic_fetch_and(&value, v, etl::memory_order_seq_cst);
} }
// Or // Or
T operator |=(T v) T operator|=(T v)
{ {
return __atomic_fetch_or(&value, v, etl::memory_order_seq_cst); return __atomic_fetch_or(&value, v, etl::memory_order_seq_cst);
} }
T operator |=(T v) volatile T operator|=(T v) volatile
{ {
return __atomic_fetch_or(&value, v, etl::memory_order_seq_cst); return __atomic_fetch_or(&value, v, etl::memory_order_seq_cst);
} }
// Exclusive or // Exclusive or
T operator ^=(T v) T operator^=(T v)
{ {
return __atomic_fetch_xor(&value, v, etl::memory_order_seq_cst); return __atomic_fetch_xor(&value, v, etl::memory_order_seq_cst);
} }
T operator ^=(T v) volatile T operator^=(T v) volatile
{ {
return __atomic_fetch_xor(&value, v, etl::memory_order_seq_cst); return __atomic_fetch_xor(&value, v, etl::memory_order_seq_cst);
} }
// Conversion operator // Conversion operator
operator T () const operator T() const
{ {
return __atomic_fetch_add(&value, 0, etl::memory_order_seq_cst); return __atomic_fetch_add(&value, 0, etl::memory_order_seq_cst);
} }
@ -388,8 +396,8 @@ namespace etl
private: private:
atomic& operator =(const atomic&) ETL_DELETE; atomic& operator=(const atomic&) ETL_DELETE;
atomic& operator =(const atomic&) volatile ETL_DELETE; atomic& operator=(const atomic&) volatile ETL_DELETE;
mutable T value; mutable T value;
}; };
@ -413,14 +421,14 @@ namespace etl
} }
// Assignment // Assignment
T* operator =(T* v) T* operator=(T* v)
{ {
store(v); store(v);
return v; return v;
} }
T* operator =(T* v) volatile T* operator=(T* v) volatile
{ {
store(v); store(v);
@ -428,73 +436,77 @@ namespace etl
} }
// Pre-increment // Pre-increment
T* operator ++() T* operator++()
{ {
return reinterpret_cast<T*>(__atomic_add_fetch(&value, sizeof(T), etl::memory_order_seq_cst)); return reinterpret_cast<T*>(__atomic_add_fetch(&value, sizeof(T), etl::memory_order_seq_cst));
} }
T* operator ++() volatile T* operator++() volatile
{ {
return reinterpret_cast<T*>(__atomic_add_fetch(&value, sizeof(T), etl::memory_order_seq_cst)); return reinterpret_cast<T*>(__atomic_add_fetch(&value, sizeof(T), etl::memory_order_seq_cst));
} }
// Post-increment // Post-increment
T* operator ++(int) T* operator++(int)
{ {
return reinterpret_cast<T*>(__atomic_fetch_add(&value, sizeof(T), etl::memory_order_seq_cst)); return reinterpret_cast<T*>(__atomic_fetch_add(&value, sizeof(T), etl::memory_order_seq_cst));
} }
T* operator ++(int) volatile T* operator++(int) volatile
{ {
return reinterpret_cast<T*>(__atomic_fetch_add(&value, sizeof(T), etl::memory_order_seq_cst)); return reinterpret_cast<T*>(__atomic_fetch_add(&value, sizeof(T), etl::memory_order_seq_cst));
} }
// Pre-decrement // Pre-decrement
T* operator --() T* operator--()
{ {
return reinterpret_cast<T*>(__atomic_sub_fetch(&value, sizeof(T), etl::memory_order_seq_cst)); return reinterpret_cast<T*>(__atomic_sub_fetch(&value, sizeof(T), etl::memory_order_seq_cst));
} }
T* operator --() volatile T* operator--() volatile
{ {
return reinterpret_cast<T*>(__atomic_sub_fetch(&value, sizeof(T), etl::memory_order_seq_cst)); return reinterpret_cast<T*>(__atomic_sub_fetch(&value, sizeof(T), etl::memory_order_seq_cst));
} }
// Post-decrement // Post-decrement
T* operator --(int) T* operator--(int)
{ {
return reinterpret_cast<T*>(__atomic_fetch_sub(&value, sizeof(T), etl::memory_order_seq_cst)); return reinterpret_cast<T*>(__atomic_fetch_sub(&value, sizeof(T), etl::memory_order_seq_cst));
} }
T* operator --(int) volatile T* operator--(int) volatile
{ {
return reinterpret_cast<T*>(__atomic_fetch_sub(&value, sizeof(T), etl::memory_order_seq_cst)); return reinterpret_cast<T*>(__atomic_fetch_sub(&value, sizeof(T), etl::memory_order_seq_cst));
} }
// Add // Add
T* operator +=(ptrdiff_t v) T* operator+=(ptrdiff_t v)
{ {
return reinterpret_cast<T*>(__atomic_fetch_add(&value, static_cast<uintptr_t>(v * static_cast<ptrdiff_t>(sizeof(T))), etl::memory_order_seq_cst)); return reinterpret_cast<T*>(
__atomic_fetch_add(&value, static_cast<uintptr_t>(v * static_cast<ptrdiff_t>(sizeof(T))), etl::memory_order_seq_cst));
} }
T* operator +=(ptrdiff_t v) volatile T* operator+=(ptrdiff_t v) volatile
{ {
return reinterpret_cast<T*>(__atomic_fetch_add(&value, static_cast<uintptr_t>(v * static_cast<ptrdiff_t>(sizeof(T))), etl::memory_order_seq_cst)); return reinterpret_cast<T*>(
__atomic_fetch_add(&value, static_cast<uintptr_t>(v * static_cast<ptrdiff_t>(sizeof(T))), etl::memory_order_seq_cst));
} }
// Subtract // Subtract
T* operator -=(ptrdiff_t v) T* operator-=(ptrdiff_t v)
{ {
return reinterpret_cast<T*>(__atomic_fetch_sub(&value, static_cast<uintptr_t>(v * static_cast<ptrdiff_t>(sizeof(T))), etl::memory_order_seq_cst)); return reinterpret_cast<T*>(
__atomic_fetch_sub(&value, static_cast<uintptr_t>(v * static_cast<ptrdiff_t>(sizeof(T))), etl::memory_order_seq_cst));
} }
T* operator -=(ptrdiff_t v) volatile T* operator-=(ptrdiff_t v) volatile
{ {
return reinterpret_cast<T*>(__atomic_fetch_sub(&value, static_cast<uintptr_t>(v * static_cast<ptrdiff_t>(sizeof(T))), etl::memory_order_seq_cst)); return reinterpret_cast<T*>(
__atomic_fetch_sub(&value, static_cast<uintptr_t>(v * static_cast<ptrdiff_t>(sizeof(T))), etl::memory_order_seq_cst));
} }
// Conversion operator // Conversion operator
operator T* () const operator T*() const
{ {
return reinterpret_cast<T*>(__atomic_fetch_add(&value, 0, etl::memory_order_seq_cst)); return reinterpret_cast<T*>(__atomic_fetch_add(&value, 0, etl::memory_order_seq_cst));
} }
@ -630,8 +642,8 @@ namespace etl
private: private:
atomic& operator =(const atomic&) ETL_DELETE; atomic& operator=(const atomic&) ETL_DELETE;
atomic& operator =(const atomic&) volatile ETL_DELETE; atomic& operator=(const atomic&) volatile ETL_DELETE;
mutable uintptr_t value; mutable uintptr_t value;
}; };
@ -655,14 +667,14 @@ namespace etl
} }
// Assignment // Assignment
bool operator =(bool v) bool operator=(bool v)
{ {
store(v); store(v);
return v; return v;
} }
bool operator =(bool v) volatile bool operator=(bool v) volatile
{ {
store(v); store(v);
@ -670,7 +682,7 @@ namespace etl
} }
// Conversion operator // Conversion operator
operator bool () const operator bool() const
{ {
return static_cast<bool>(__atomic_fetch_add(&value, 0, etl::memory_order_seq_cst)); return static_cast<bool>(__atomic_fetch_add(&value, 0, etl::memory_order_seq_cst));
} }
@ -728,7 +740,7 @@ namespace etl
bool compare_exchange_weak(bool& expected, bool desired, etl::memory_order order = etl::memory_order_seq_cst) bool compare_exchange_weak(bool& expected, bool desired, etl::memory_order order = etl::memory_order_seq_cst)
{ {
char expected_v = char(expected); char expected_v = char(expected);
char desired_v = char(desired); char desired_v = char(desired);
return __atomic_compare_exchange_n(&value, &expected_v, desired_v, true, order, order); return __atomic_compare_exchange_n(&value, &expected_v, desired_v, true, order, order);
} }
@ -736,7 +748,7 @@ namespace etl
bool compare_exchange_weak(bool& expected, bool desired, etl::memory_order order = etl::memory_order_seq_cst) volatile bool compare_exchange_weak(bool& expected, bool desired, etl::memory_order order = etl::memory_order_seq_cst) volatile
{ {
char expected_v = char(expected); char expected_v = char(expected);
char desired_v = char(desired); char desired_v = char(desired);
return __atomic_compare_exchange_n(&value, &expected_v, desired_v, true, order, order); return __atomic_compare_exchange_n(&value, &expected_v, desired_v, true, order, order);
} }
@ -744,7 +756,7 @@ namespace etl
bool compare_exchange_weak(bool& expected, bool desired, etl::memory_order success, etl::memory_order failure) bool compare_exchange_weak(bool& expected, bool desired, etl::memory_order success, etl::memory_order failure)
{ {
char expected_v = char(expected); char expected_v = char(expected);
char desired_v = char(desired); char desired_v = char(desired);
return __atomic_compare_exchange_n(&value, &expected_v, desired_v, true, success, failure); return __atomic_compare_exchange_n(&value, &expected_v, desired_v, true, success, failure);
} }
@ -792,8 +804,8 @@ namespace etl
private: private:
atomic& operator =(const atomic&) ETL_DELETE; atomic& operator=(const atomic&) ETL_DELETE;
atomic& operator =(const atomic&) volatile ETL_DELETE; atomic& operator=(const atomic&) volatile ETL_DELETE;
mutable char value; mutable char value;
}; };
@ -827,7 +839,7 @@ namespace etl
} }
// Assignment // Assignment
T operator =(T v) T operator=(T v)
{ {
store(v); store(v);
@ -835,7 +847,7 @@ namespace etl
} }
// Conversion operator // Conversion operator
operator T () const operator T() const
{ {
ETL_BUILTIN_LOCK; ETL_BUILTIN_LOCK;
T result = value; T result = value;
@ -876,7 +888,7 @@ namespace etl
(void)order; (void)order;
ETL_BUILTIN_LOCK; ETL_BUILTIN_LOCK;
T result = value; T result = value;
value = v; value = v;
ETL_BUILTIN_UNLOCK; ETL_BUILTIN_UNLOCK;
return result; return result;
@ -891,7 +903,7 @@ namespace etl
ETL_BUILTIN_LOCK; ETL_BUILTIN_LOCK;
if (memcmp(&value, &expected, sizeof(T)) == 0) if (memcmp(&value, &expected, sizeof(T)) == 0)
{ {
value = desired; value = desired;
result = true; result = true;
} }
else else
@ -926,26 +938,34 @@ namespace etl
private: private:
atomic& operator =(const atomic&) ETL_DELETE; atomic& operator=(const atomic&) ETL_DELETE;
atomic& operator =(const atomic&) volatile ETL_DELETE; atomic& operator=(const atomic&) volatile ETL_DELETE;
mutable char flag; mutable char flag;
mutable T value; mutable T value;
}; };
#undef ETL_BUILTIN_LOCK #undef ETL_BUILTIN_LOCK
#undef ETL_BUILTIN_UNLOCK #undef ETL_BUILTIN_UNLOCK
#endif #endif
#if defined(ETL_USE_SYNC_BUILTINS) #if defined(ETL_USE_SYNC_BUILTINS)
#define ETL_BUILTIN_LOCK do { while (__sync_lock_test_and_set(&flag, 1U)) {} } while(0) #define ETL_BUILTIN_LOCK \
#define ETL_BUILTIN_UNLOCK do { __sync_lock_release(&flag); } while(0) do { \
while (__sync_lock_test_and_set(&flag, 1U)) \
{ \
} \
} while (0)
#define ETL_BUILTIN_UNLOCK \
do { \
__sync_lock_release(&flag); \
} while (0)
//*************************************************************************** //***************************************************************************
// Atomic type for pre C++11 GCC compilers that support the builtin '__sync' functions. // Atomic type for pre C++11 GCC compilers that support the builtin '__sync'
// Only integral and pointer types are supported. // functions. Only integral and pointer types are supported.
//*************************************************************************** //***************************************************************************
typedef enum memory_order typedef enum memory_order
@ -988,14 +1008,14 @@ namespace etl
} }
// Assignment // Assignment
T operator =(T v) T operator=(T v)
{ {
store(v); store(v);
return v; return v;
} }
T operator =(T v) volatile T operator=(T v) volatile
{ {
store(v); store(v);
@ -1003,106 +1023,106 @@ namespace etl
} }
// Pre-increment // Pre-increment
T operator ++() T operator++()
{ {
return __sync_add_and_fetch(&value, 1); return __sync_add_and_fetch(&value, 1);
} }
T operator ++() volatile T operator++() volatile
{ {
return __sync_add_and_fetch(&value, 1); return __sync_add_and_fetch(&value, 1);
} }
// Post-increment // Post-increment
T operator ++(int) T operator++(int)
{ {
return __sync_fetch_and_add(&value, 1); return __sync_fetch_and_add(&value, 1);
} }
T operator ++(int) volatile T operator++(int) volatile
{ {
return __sync_fetch_and_add(&value, 1); return __sync_fetch_and_add(&value, 1);
} }
// Pre-decrement // Pre-decrement
T operator --() T operator--()
{ {
return __sync_sub_and_fetch(&value, 1); return __sync_sub_and_fetch(&value, 1);
} }
T operator --() volatile T operator--() volatile
{ {
return __sync_sub_and_fetch(&value, 1); return __sync_sub_and_fetch(&value, 1);
} }
// Post-decrement // Post-decrement
T operator --(int) T operator--(int)
{ {
return __sync_fetch_and_sub(&value, 1); return __sync_fetch_and_sub(&value, 1);
} }
T operator --(int) volatile T operator--(int) volatile
{ {
return __sync_fetch_and_sub(&value, 1); return __sync_fetch_and_sub(&value, 1);
} }
// Add // Add
T operator +=(T v) T operator+=(T v)
{ {
return __sync_fetch_and_add(&value, v); return __sync_fetch_and_add(&value, v);
} }
T operator +=(T v) volatile T operator+=(T v) volatile
{ {
return __sync_fetch_and_add(&value, v); return __sync_fetch_and_add(&value, v);
} }
// Subtract // Subtract
T operator -=(T v) T operator-=(T v)
{ {
return __sync_fetch_and_sub(&value, v); return __sync_fetch_and_sub(&value, v);
} }
T operator -=(T v) volatile T operator-=(T v) volatile
{ {
return __sync_fetch_and_sub(&value, v); return __sync_fetch_and_sub(&value, v);
} }
// And // And
T operator &=(T v) T operator&=(T v)
{ {
return __sync_fetch_and_and(&value, v); return __sync_fetch_and_and(&value, v);
} }
T operator &=(T v) volatile T operator&=(T v) volatile
{ {
return __sync_fetch_and_and(&value, v); return __sync_fetch_and_and(&value, v);
} }
// Or // Or
T operator |=(T v) T operator|=(T v)
{ {
return __sync_fetch_and_or(&value, v); return __sync_fetch_and_or(&value, v);
} }
T operator |=(T v) volatile T operator|=(T v) volatile
{ {
return __sync_fetch_and_or(&value, v); return __sync_fetch_and_or(&value, v);
} }
// Exclusive or // Exclusive or
T operator ^=(T v) T operator^=(T v)
{ {
return __sync_fetch_and_xor(&value, v); return __sync_fetch_and_xor(&value, v);
} }
T operator ^=(T v) volatile T operator^=(T v) volatile
{ {
return __sync_fetch_and_xor(&value, v); return __sync_fetch_and_xor(&value, v);
} }
// Conversion operator // Conversion operator
operator T () const operator T() const
{ {
return __sync_fetch_and_add(&value, 0); return __sync_fetch_and_add(&value, 0);
} }
@ -1367,8 +1387,8 @@ namespace etl
private: private:
atomic& operator =(const atomic&) ETL_DELETE; atomic& operator=(const atomic&) ETL_DELETE;
atomic& operator =(const atomic&) volatile ETL_DELETE; atomic& operator=(const atomic&) volatile ETL_DELETE;
mutable volatile T value; mutable volatile T value;
}; };
@ -1392,14 +1412,14 @@ namespace etl
} }
// Assignment // Assignment
T* operator =(T* v) T* operator=(T* v)
{ {
store(v); store(v);
return v; return v;
} }
T* operator =(T* v) volatile T* operator=(T* v) volatile
{ {
store(v); store(v);
@ -1407,78 +1427,78 @@ namespace etl
} }
// Pre-increment // Pre-increment
T* operator ++() T* operator++()
{ {
return reinterpret_cast<T*>(__sync_add_and_fetch(&value, sizeof(T))); return reinterpret_cast<T*>(__sync_add_and_fetch(&value, sizeof(T)));
} }
T* operator ++() volatile T* operator++() volatile
{ {
return reinterpret_cast<T*>(__sync_add_and_fetch(&value, sizeof(T))); return reinterpret_cast<T*>(__sync_add_and_fetch(&value, sizeof(T)));
} }
// Post-increment // Post-increment
T* operator ++(int) T* operator++(int)
{ {
return reinterpret_cast<T*>(__sync_fetch_and_add(&value, sizeof(T))); return reinterpret_cast<T*>(__sync_fetch_and_add(&value, sizeof(T)));
} }
T* operator ++(int) volatile T* operator++(int) volatile
{ {
return reinterpret_cast<T*>(__sync_fetch_and_add(&value, sizeof(T))); return reinterpret_cast<T*>(__sync_fetch_and_add(&value, sizeof(T)));
} }
// Pre-decrement // Pre-decrement
T* operator --() T* operator--()
{ {
return reinterpret_cast<T*>(__sync_sub_and_fetch(&value, sizeof(T))); return reinterpret_cast<T*>(__sync_sub_and_fetch(&value, sizeof(T)));
} }
T* operator --() volatile T* operator--() volatile
{ {
return reinterpret_cast<T*>(__sync_sub_and_fetch(&value, sizeof(T))); return reinterpret_cast<T*>(__sync_sub_and_fetch(&value, sizeof(T)));
} }
// Post-decrement // Post-decrement
T* operator --(int) T* operator--(int)
{ {
return reinterpret_cast<T*>(__sync_fetch_and_sub(&value, sizeof(T))); return reinterpret_cast<T*>(__sync_fetch_and_sub(&value, sizeof(T)));
} }
T* operator --(int) volatile T* operator--(int) volatile
{ {
return reinterpret_cast<T*>(__sync_fetch_and_sub(&value, sizeof(T))); return reinterpret_cast<T*>(__sync_fetch_and_sub(&value, sizeof(T)));
} }
// Add // Add
T* operator +=(ptrdiff_t v) T* operator+=(ptrdiff_t v)
{ {
return reinterpret_cast<T*>(__sync_fetch_and_add(&value, v * sizeof(T))); return reinterpret_cast<T*>(__sync_fetch_and_add(&value, v * sizeof(T)));
} }
T* operator +=(ptrdiff_t v) volatile T* operator+=(ptrdiff_t v) volatile
{ {
return reinterpret_cast<T*>(__sync_fetch_and_add(&value, v * sizeof(T))); return reinterpret_cast<T*>(__sync_fetch_and_add(&value, v * sizeof(T)));
} }
// Subtract // Subtract
T* operator -=(ptrdiff_t v) T* operator-=(ptrdiff_t v)
{ {
return reinterpret_cast<T*>(__sync_fetch_and_sub(&value, v * sizeof(T))); return reinterpret_cast<T*>(__sync_fetch_and_sub(&value, v * sizeof(T)));
} }
T* operator -=(ptrdiff_t v) volatile T* operator-=(ptrdiff_t v) volatile
{ {
return reinterpret_cast<T*>(__sync_fetch_and_sub(&value, v * sizeof(T))); return reinterpret_cast<T*>(__sync_fetch_and_sub(&value, v * sizeof(T)));
} }
// Conversion operator // Conversion operator
operator T* () const operator T*() const
{ {
return reinterpret_cast<T*>(__sync_fetch_and_add(&value, 0)); return reinterpret_cast<T*>(__sync_fetch_and_add(&value, 0));
} }
operator T* () volatile const operator T*() volatile const
{ {
return reinterpret_cast<T*>(__sync_fetch_and_add(&value, 0)); return reinterpret_cast<T*>(__sync_fetch_and_add(&value, 0));
} }
@ -1677,8 +1697,8 @@ namespace etl
private: private:
atomic& operator =(const atomic&) ETL_DELETE; atomic& operator=(const atomic&) ETL_DELETE;
atomic& operator =(const atomic&) volatile ETL_DELETE; atomic& operator=(const atomic&) volatile ETL_DELETE;
mutable uintptr_t value; mutable uintptr_t value;
}; };
@ -1702,14 +1722,14 @@ namespace etl
} }
// Assignment // Assignment
bool operator =(bool v) bool operator=(bool v)
{ {
store(v); store(v);
return v; return v;
} }
bool operator =(bool v) volatile bool operator=(bool v) volatile
{ {
store(v); store(v);
@ -1899,8 +1919,8 @@ namespace etl
private: private:
atomic& operator =(const atomic&) ETL_DELETE; atomic& operator=(const atomic&) ETL_DELETE;
atomic& operator =(const atomic&) volatile ETL_DELETE; atomic& operator=(const atomic&) volatile ETL_DELETE;
mutable char value; mutable char value;
}; };
@ -1934,7 +1954,7 @@ namespace etl
} }
// Assignment // Assignment
T operator =(T v) T operator=(T v)
{ {
store(v); store(v);
@ -1942,7 +1962,7 @@ namespace etl
} }
// Conversion operator // Conversion operator
operator T () const operator T() const
{ {
ETL_BUILTIN_LOCK; ETL_BUILTIN_LOCK;
T result = value; T result = value;
@ -1980,7 +2000,7 @@ namespace etl
{ {
ETL_BUILTIN_LOCK; ETL_BUILTIN_LOCK;
T result = value; T result = value;
value = v; value = v;
ETL_BUILTIN_UNLOCK; ETL_BUILTIN_UNLOCK;
return result; return result;
@ -1994,7 +2014,7 @@ namespace etl
ETL_BUILTIN_LOCK; ETL_BUILTIN_LOCK;
if (memcmp(&value, &expected, sizeof(T)) == 0) if (memcmp(&value, &expected, sizeof(T)) == 0)
{ {
value = desired; value = desired;
result = true; result = true;
} }
else else
@ -2024,79 +2044,78 @@ namespace etl
private: private:
atomic& operator =(const atomic&) ETL_DELETE; atomic& operator=(const atomic&) ETL_DELETE;
atomic& operator =(const atomic&) volatile ETL_DELETE; atomic& operator=(const atomic&) volatile ETL_DELETE;
mutable char flag; mutable char flag;
mutable T value; mutable T value;
}; };
#undef ETL_SYNC_BUILTIN_LOCK #undef ETL_SYNC_BUILTIN_LOCK
#undef ETL_SYNC_BUILTIN_UNLOCK #undef ETL_SYNC_BUILTIN_UNLOCK
#endif #endif
typedef etl::atomic<bool> atomic_bool; typedef etl::atomic<bool> atomic_bool;
typedef etl::atomic<char> atomic_char; typedef etl::atomic<char> atomic_char;
typedef etl::atomic<signed char> atomic_schar; typedef etl::atomic<signed char> atomic_schar;
typedef etl::atomic<unsigned char> atomic_uchar; typedef etl::atomic<unsigned char> atomic_uchar;
typedef etl::atomic<short> atomic_short; typedef etl::atomic<short> atomic_short;
typedef etl::atomic<unsigned short> atomic_ushort; typedef etl::atomic<unsigned short> atomic_ushort;
typedef etl::atomic<int> atomic_int; typedef etl::atomic<int> atomic_int;
typedef etl::atomic<unsigned int> atomic_uint; typedef etl::atomic<unsigned int> atomic_uint;
typedef etl::atomic<long> atomic_long; typedef etl::atomic<long> atomic_long;
typedef etl::atomic<unsigned long> atomic_ulong; typedef etl::atomic<unsigned long> atomic_ulong;
typedef etl::atomic<long long> atomic_llong; typedef etl::atomic<long long> atomic_llong;
typedef etl::atomic<unsigned long long> atomic_ullong; typedef etl::atomic<unsigned long long> atomic_ullong;
typedef etl::atomic<wchar_t> atomic_wchar_t; typedef etl::atomic<wchar_t> atomic_wchar_t;
#if ETL_HAS_NATIVE_CHAR8_T #if ETL_HAS_NATIVE_CHAR8_T
typedef etl::atomic<char8_t> atomic_char8_t; typedef etl::atomic<char8_t> atomic_char8_t;
#endif #endif
#if ETL_HAS_NATIVE_CHAR16_T #if ETL_HAS_NATIVE_CHAR16_T
typedef etl::atomic<char16_t> atomic_char16_t; typedef etl::atomic<char16_t> atomic_char16_t;
#endif #endif
#if ETL_HAS_NATIVE_CHAR32_T #if ETL_HAS_NATIVE_CHAR32_T
typedef etl::atomic<char32_t> atomic_char32_t; typedef etl::atomic<char32_t> atomic_char32_t;
#endif #endif
#if ETL_USING_8BIT_TYPES #if ETL_USING_8BIT_TYPES
typedef etl::atomic<uint8_t> atomic_uint8_t; typedef etl::atomic<uint8_t> atomic_uint8_t;
typedef etl::atomic<int8_t> atomic_int8_t; typedef etl::atomic<int8_t> atomic_int8_t;
#endif #endif
typedef etl::atomic<uint16_t> atomic_uint16_t; typedef etl::atomic<uint16_t> atomic_uint16_t;
typedef etl::atomic<int16_t> atomic_int16_t; typedef etl::atomic<int16_t> atomic_int16_t;
typedef etl::atomic<uint32_t> atomic_uint32_t; typedef etl::atomic<uint32_t> atomic_uint32_t;
typedef etl::atomic<int32_t> atomic_int32_t; typedef etl::atomic<int32_t> atomic_int32_t;
#if ETL_USING_64BIT_TYPES #if ETL_USING_64BIT_TYPES
typedef etl::atomic<uint64_t> atomic_uint64_t; typedef etl::atomic<uint64_t> atomic_uint64_t;
typedef etl::atomic<int64_t> atomic_int64_t; typedef etl::atomic<int64_t> atomic_int64_t;
#endif #endif
typedef etl::atomic<int_least8_t> atomic_int_least8_t; typedef etl::atomic<int_least8_t> atomic_int_least8_t;
typedef etl::atomic<uint_least8_t> atomic_uint_least8_t; typedef etl::atomic<uint_least8_t> atomic_uint_least8_t;
typedef etl::atomic<int_least16_t> atomic_int_least16_t; typedef etl::atomic<int_least16_t> atomic_int_least16_t;
typedef etl::atomic<uint_least16_t> atomic_uint_least16_t; typedef etl::atomic<uint_least16_t> atomic_uint_least16_t;
typedef etl::atomic<int_least32_t> atomic_int_least32_t; typedef etl::atomic<int_least32_t> atomic_int_least32_t;
typedef etl::atomic<uint_least32_t> atomic_uint_least32_t; typedef etl::atomic<uint_least32_t> atomic_uint_least32_t;
#if ETL_USING_64BIT_TYPES #if ETL_USING_64BIT_TYPES
typedef etl::atomic<int_least64_t> atomic_int_least64_t; typedef etl::atomic<int_least64_t> atomic_int_least64_t;
typedef etl::atomic<uint_least64_t> atomic_uint_least64_t; typedef etl::atomic<uint_least64_t> atomic_uint_least64_t;
#endif #endif
typedef etl::atomic<int_fast8_t> atomic_int_fast8_t; typedef etl::atomic<int_fast8_t> atomic_int_fast8_t;
typedef etl::atomic<uint_fast8_t> atomic_uint_fast8_t; typedef etl::atomic<uint_fast8_t> atomic_uint_fast8_t;
typedef etl::atomic<int_fast16_t> atomic_int_fast16_t; typedef etl::atomic<int_fast16_t> atomic_int_fast16_t;
typedef etl::atomic<uint_fast16_t> atomic_uint_fast16_t; typedef etl::atomic<uint_fast16_t> atomic_uint_fast16_t;
typedef etl::atomic<int_fast32_t> atomic_int_fast32_t; typedef etl::atomic<int_fast32_t> atomic_int_fast32_t;
typedef etl::atomic<uint_fast32_t> atomic_uint_fast32_t; typedef etl::atomic<uint_fast32_t> atomic_uint_fast32_t;
#if ETL_USING_64BIT_TYPES #if ETL_USING_64BIT_TYPES
typedef etl::atomic<int_fast64_t> atomic_int_fast64_t; typedef etl::atomic<int_fast64_t> atomic_int_fast64_t;
typedef etl::atomic<uint_fast64_t> atomic_uint_fast64_t; typedef etl::atomic<uint_fast64_t> atomic_uint_fast64_t;
#endif #endif
typedef etl::atomic<intptr_t> atomic_intptr_t; typedef etl::atomic<intptr_t> atomic_intptr_t;
typedef etl::atomic<uintptr_t> atomic_uintptr_t; typedef etl::atomic<uintptr_t> atomic_uintptr_t;
typedef etl::atomic<size_t> atomic_size_t; typedef etl::atomic<size_t> atomic_size_t;
typedef etl::atomic<ptrdiff_t> atomic_ptrdiff_t; typedef etl::atomic<ptrdiff_t> atomic_ptrdiff_t;
typedef etl::atomic<intmax_t> atomic_intmax_t; typedef etl::atomic<intmax_t> atomic_intmax_t;
typedef etl::atomic<uintmax_t> atomic_uintmax_t; typedef etl::atomic<uintmax_t> atomic_uintmax_t;
} } // namespace etl
#endif #endif

View File

@ -30,8 +30,8 @@ SOFTWARE.
#define ETL_ATOMIC_STD_INCLUDED #define ETL_ATOMIC_STD_INCLUDED
#include "../platform.h" #include "../platform.h"
#include "../nullptr.h"
#include "../char_traits.h" #include "../char_traits.h"
#include "../nullptr.h"
#include <atomic> #include <atomic>
#include <stdint.h> #include <stdint.h>
@ -55,39 +55,39 @@ namespace etl
static ETL_CONSTANT etl::memory_order memory_order_acq_rel = std::memory_order_acq_rel; static ETL_CONSTANT etl::memory_order memory_order_acq_rel = std::memory_order_acq_rel;
static ETL_CONSTANT etl::memory_order memory_order_seq_cst = std::memory_order_seq_cst; static ETL_CONSTANT etl::memory_order memory_order_seq_cst = std::memory_order_seq_cst;
using atomic_bool = std::atomic<bool>; using atomic_bool = std::atomic<bool>;
using atomic_char = std::atomic<char>; using atomic_char = std::atomic<char>;
using atomic_schar = std::atomic<signed char>; using atomic_schar = std::atomic<signed char>;
using atomic_uchar = std::atomic<unsigned char>; using atomic_uchar = std::atomic<unsigned char>;
using atomic_short = std::atomic<short>; using atomic_short = std::atomic<short>;
using atomic_ushort = std::atomic<unsigned short>; using atomic_ushort = std::atomic<unsigned short>;
using atomic_int = std::atomic<int>; using atomic_int = std::atomic<int>;
using atomic_uint = std::atomic<unsigned int>; using atomic_uint = std::atomic<unsigned int>;
using atomic_long = std::atomic<long>; using atomic_long = std::atomic<long>;
using atomic_ulong = std::atomic<unsigned long>; using atomic_ulong = std::atomic<unsigned long>;
using atomic_llong = std::atomic<long long>; using atomic_llong = std::atomic<long long>;
using atomic_ullong = std::atomic<unsigned long long>; using atomic_ullong = std::atomic<unsigned long long>;
using atomic_wchar_t = std::atomic<wchar_t>; using atomic_wchar_t = std::atomic<wchar_t>;
#if ETL_HAS_NATIVE_CHAR8_T #if ETL_HAS_NATIVE_CHAR8_T
using atomic_char8_t = std::atomic<char8_t>; using atomic_char8_t = std::atomic<char8_t>;
#endif #endif
#if ETL_HAS_NATIVE_CHAR16_T #if ETL_HAS_NATIVE_CHAR16_T
using atomic_char16_t = std::atomic<char16_t>; using atomic_char16_t = std::atomic<char16_t>;
#endif #endif
#if ETL_HAS_NATIVE_CHAR32_T #if ETL_HAS_NATIVE_CHAR32_T
using atomic_char32_t = std::atomic<char32_t>; using atomic_char32_t = std::atomic<char32_t>;
#endif #endif
#if ETL_USING_8BIT_TYPES #if ETL_USING_8BIT_TYPES
using atomic_uint8_t = std::atomic<uint8_t>; using atomic_uint8_t = std::atomic<uint8_t>;
using atomic_int8_t = std::atomic<int8_t>; using atomic_int8_t = std::atomic<int8_t>;
#endif #endif
using atomic_uint16_t = std::atomic<uint16_t>; using atomic_uint16_t = std::atomic<uint16_t>;
using atomic_int16_t = std::atomic<int16_t>; using atomic_int16_t = std::atomic<int16_t>;
using atomic_uint32_t = std::atomic<uint32_t>; using atomic_uint32_t = std::atomic<uint32_t>;
using atomic_int32_t = std::atomic<int32_t>; using atomic_int32_t = std::atomic<int32_t>;
#if ETL_USING_64BIT_TYPES #if ETL_USING_64BIT_TYPES
using atomic_uint64_t = std::atomic<uint64_t>; using atomic_uint64_t = std::atomic<uint64_t>;
using atomic_int64_t = std::atomic<int64_t>; using atomic_int64_t = std::atomic<int64_t>;
#endif #endif
using atomic_int_least8_t = std::atomic<int_least8_t>; using atomic_int_least8_t = std::atomic<int_least8_t>;
using atomic_uint_least8_t = std::atomic<uint_least8_t>; using atomic_uint_least8_t = std::atomic<uint_least8_t>;
@ -99,22 +99,22 @@ namespace etl
using atomic_int_least64_t = std::atomic<int_least64_t>; using atomic_int_least64_t = std::atomic<int_least64_t>;
using atomic_uint_least64_t = std::atomic<uint_least64_t>; using atomic_uint_least64_t = std::atomic<uint_least64_t>;
#endif #endif
using atomic_int_fast8_t = std::atomic<int_fast8_t>; using atomic_int_fast8_t = std::atomic<int_fast8_t>;
using atomic_uint_fast8_t = std::atomic<uint_fast8_t>; using atomic_uint_fast8_t = std::atomic<uint_fast8_t>;
using atomic_int_fast16_t = std::atomic<int_fast16_t>; using atomic_int_fast16_t = std::atomic<int_fast16_t>;
using atomic_uint_fast16_t = std::atomic<uint_fast16_t>; using atomic_uint_fast16_t = std::atomic<uint_fast16_t>;
using atomic_int_fast32_t = std::atomic<int_fast32_t>; using atomic_int_fast32_t = std::atomic<int_fast32_t>;
using atomic_uint_fast32_t = std::atomic<uint_fast32_t>; using atomic_uint_fast32_t = std::atomic<uint_fast32_t>;
#if ETL_USING_64BIT_TYPES #if ETL_USING_64BIT_TYPES
using atomic_int_fast64_t = std::atomic<int_fast64_t>; using atomic_int_fast64_t = std::atomic<int_fast64_t>;
using atomic_uint_fast64_t = std::atomic<uint_fast64_t>; using atomic_uint_fast64_t = std::atomic<uint_fast64_t>;
#endif #endif
using atomic_intptr_t = std::atomic<intptr_t>; using atomic_intptr_t = std::atomic<intptr_t>;
using atomic_uintptr_t = std::atomic<uintptr_t>; using atomic_uintptr_t = std::atomic<uintptr_t>;
using atomic_size_t = std::atomic<size_t>; using atomic_size_t = std::atomic<size_t>;
using atomic_ptrdiff_t = std::atomic<ptrdiff_t>; using atomic_ptrdiff_t = std::atomic<ptrdiff_t>;
using atomic_intmax_t = std::atomic<intmax_t>; using atomic_intmax_t = std::atomic<intmax_t>;
using atomic_uintmax_t = std::atomic<uintmax_t>; using atomic_uintmax_t = std::atomic<uintmax_t>;
} } // namespace etl
#endif #endif

View File

@ -27,27 +27,29 @@ SOFTWARE.
#define ETL_BASE64_INCLUDED #define ETL_BASE64_INCLUDED
#include "platform.h" #include "platform.h"
#include "static_assert.h"
#include "exception.h"
#include "error_handler.h"
#include "type_traits.h"
#include "enum_type.h" #include "enum_type.h"
#include "error_handler.h"
#include "exception.h"
#include "integral_limits.h" #include "integral_limits.h"
#include "static_assert.h"
#include "type_traits.h"
#include <stdint.h> #include <stdint.h>
/************************************************************************************************************************************************************************** /**************************************************************************************************************************************************************************
* See https://en.wikipedia.org/wiki/Base64 * See https://en.wikipedia.org/wiki/Base64
* *
* Encoding Encoding characters Separate encoding of lines Decoding non-encoding characters * Encoding Encoding characters
* 62nd 63rd Pad Separators Length Checksum *Separate encoding of lines Decoding non-encoding characters 62nd 63rd Pad
* RFC 1421 : Base64 for Privacy - Enhanced Mail(deprecated) + / = mandatory CR + LF 64, or lower for the last line No No *Separators Length Checksum RFC 1421 : Base64 for
* RFC 2045 : Base64 transfer encoding for MIME + / = mandatory CR + LF At most 76 No Discarded *Privacy - Enhanced Mail(deprecated) + / = mandatory CR + LF 64,
* RFC 2152 : Base64 for UTF - 7 + / No No No *or lower for the last line No No RFC 2045 : Base64 transfer encoding for MIME
* RFC 3501 : Base64 encoding for IMAP mailbox names + , No No No *+ / = mandatory CR + LF At most 76 No Discarded RFC 2152 : Base64
* RFC 4648 : base64(standard)[a] + / = optional No No *for UTF - 7 + / No No No RFC
* RFC 4648 : base64url(URL - and filename - safe standard) - _ = optional No No *3501 : Base64 encoding for IMAP mailbox names + , No
**************************************************************************************************************************************************************************/ *No No RFC 4648 : base64(standard)[a] + / = optional No No RFC 4648 :
*base64url(URL - and filename - safe standard) - _ = optional No No
**************************************************************************************************************************************************************************/
namespace etl namespace etl
{ {
@ -114,8 +116,8 @@ namespace etl
{ {
enum enum_type enum enum_type
{ {
//RFC_1421, // Not implemented // RFC_1421, // Not implemented
//RFC_2045, // Not implemented // RFC_2045, // Not implemented
RFC_2152, RFC_2152,
RFC_3501, RFC_3501,
RFC_4648, RFC_4648,
@ -125,8 +127,8 @@ namespace etl
}; };
ETL_DECLARE_ENUM_TYPE(Encoding, int) ETL_DECLARE_ENUM_TYPE(Encoding, int)
//ETL_ENUM_TYPE(RFC_1421, "RFC_1421") // Not implemented // ETL_ENUM_TYPE(RFC_1421, "RFC_1421") // Not implemented
//ETL_ENUM_TYPE(RFC_2045, "RFC_2045") // Not implemented // ETL_ENUM_TYPE(RFC_2045, "RFC_2045") // Not implemented
ETL_ENUM_TYPE(RFC_2152, "RFC_2152") ETL_ENUM_TYPE(RFC_2152, "RFC_2152")
ETL_ENUM_TYPE(RFC_3501, "RFC_3501") ETL_ENUM_TYPE(RFC_3501, "RFC_3501")
ETL_ENUM_TYPE(RFC_4648, "RFC_4648") ETL_ENUM_TYPE(RFC_4648, "RFC_4648")
@ -166,16 +168,14 @@ namespace etl
enum enum
{ {
Invalid_Data = etl::integral_limits<int>::max, Invalid_Data = etl::integral_limits<int>::max,
Min_Encode_Buffer_Size = 4, Min_Encode_Buffer_Size = 4,
Min_Decode_Buffer_Size = 3 Min_Decode_Buffer_Size = 3
}; };
protected: protected:
ETL_CONSTEXPR14 ETL_CONSTEXPR14 base64(const char* encoder_table_, bool use_padding_)
base64(const char* encoder_table_,
bool use_padding_)
: encoder_table(encoder_table_) : encoder_table(encoder_table_)
, use_padding(use_padding_) , use_padding(use_padding_)
{ {
@ -184,9 +184,7 @@ namespace etl
//************************************************************************* //*************************************************************************
// Character set for RFC-1421, RFC-2045, RFC-2152 and RFC-4648 // Character set for RFC-1421, RFC-2045, RFC-2152 and RFC-4648
//************************************************************************* //*************************************************************************
static static ETL_CONSTEXPR14 const char* character_set_1()
ETL_CONSTEXPR14
const char* character_set_1()
{ {
return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
} }
@ -194,9 +192,7 @@ namespace etl
//************************************************************************* //*************************************************************************
// Character set for RFC-4648-URL // Character set for RFC-4648-URL
//************************************************************************* //*************************************************************************
static static ETL_CONSTEXPR14 const char* character_set_2()
ETL_CONSTEXPR14
const char* character_set_2()
{ {
return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
} }
@ -204,9 +200,7 @@ namespace etl
//************************************************************************* //*************************************************************************
// Character set for RFC-3501-URL // Character set for RFC-3501-URL
//************************************************************************* //*************************************************************************
static static ETL_CONSTEXPR14 const char* character_set_3()
ETL_CONSTEXPR14
const char* character_set_3()
{ {
return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,"; return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,";
} }
@ -214,5 +208,5 @@ namespace etl
const char* encoder_table; const char* encoder_table;
const bool use_padding; const bool use_padding;
}; };
} } // namespace etl
#endif #endif

View File

@ -1,5 +1,5 @@
//************************************************************************* //*************************************************************************
///Decode from Base64 from and to pointer/length /// Decode from Base64 from and to pointer/length
//*************************************************************************///\file //*************************************************************************///\file
/****************************************************************************** /******************************************************************************
@ -29,16 +29,16 @@ SOFTWARE.
#define ETL_BASE64_DECODER_INCLUDED #define ETL_BASE64_DECODER_INCLUDED
#include "platform.h" #include "platform.h"
#include "static_assert.h"
#include "error_handler.h"
#include "type_traits.h"
#include "binary.h"
#include "algorithm.h" #include "algorithm.h"
#include "binary.h"
#include "delegate.h"
#include "enum_type.h"
#include "error_handler.h"
#include "integral_limits.h" #include "integral_limits.h"
#include "iterator.h" #include "iterator.h"
#include "enum_type.h"
#include "delegate.h"
#include "span.h" #include "span.h"
#include "static_assert.h"
#include "type_traits.h"
#include "base64.h" #include "base64.h"
@ -48,11 +48,12 @@ SOFTWARE.
#include <iterator> #include <iterator>
#endif #endif
#define ETL_IS_8_BIT_INTEGRAL(Type) (etl::is_integral<typename etl::remove_cv<Type>::type>::value && \ #define ETL_IS_8_BIT_INTEGRAL(Type) \
(etl::integral_limits<typename etl::remove_cv<Type>::type>::bits == 8U)) (etl::is_integral<typename etl::remove_cv<Type>::type>::value && (etl::integral_limits<typename etl::remove_cv<Type>::type>::bits == 8U))
#define ETL_IS_ITERATOR_TYPE_8_BIT_INTEGRAL(Type) (etl::is_integral<typename etl::iterator_traits<typename etl::remove_cv<Type>::type>::value_type>::value && \ #define ETL_IS_ITERATOR_TYPE_8_BIT_INTEGRAL(Type) \
(etl::integral_limits<typename etl::iterator_traits<typename etl::remove_cv<Type>::type>::value_type>::bits == 8U)) (etl::is_integral< typename etl::iterator_traits< typename etl::remove_cv<Type>::type>::value_type>::value \
&& (etl::integral_limits< typename etl::iterator_traits< typename etl::remove_cv<Type>::type>::value_type>::bits == 8U))
namespace etl namespace etl
{ {
@ -70,8 +71,7 @@ namespace etl
/// Decode to Base64 /// Decode to Base64
//************************************************************************* //*************************************************************************
template <typename T> template <typename T>
ETL_CONSTEXPR14 ETL_CONSTEXPR14 bool decode(T value)
bool decode(T value)
{ {
ETL_STATIC_ASSERT(ETL_IS_8_BIT_INTEGRAL(T), "Input type must be an 8 bit integral"); ETL_STATIC_ASSERT(ETL_IS_8_BIT_INTEGRAL(T), "Input type must be an 8 bit integral");
@ -101,8 +101,7 @@ namespace etl
/// Decode from Base64 /// Decode from Base64
//************************************************************************* //*************************************************************************
template <typename TInputIterator> template <typename TInputIterator>
ETL_CONSTEXPR14 ETL_CONSTEXPR14 bool decode(TInputIterator input_begin, TInputIterator input_end)
bool decode(TInputIterator input_begin, TInputIterator input_end)
{ {
ETL_STATIC_ASSERT(ETL_IS_ITERATOR_TYPE_8_BIT_INTEGRAL(TInputIterator), "Input type must be an 8 bit integral"); ETL_STATIC_ASSERT(ETL_IS_ITERATOR_TYPE_8_BIT_INTEGRAL(TInputIterator), "Input type must be an 8 bit integral");
@ -121,8 +120,7 @@ namespace etl
/// Decode from Base64 /// Decode from Base64
//************************************************************************* //*************************************************************************
template <typename TInputIterator> template <typename TInputIterator>
ETL_CONSTEXPR14 ETL_CONSTEXPR14 bool decode(TInputIterator input_begin, size_t input_length)
bool decode(TInputIterator input_begin, size_t input_length)
{ {
ETL_STATIC_ASSERT(ETL_IS_ITERATOR_TYPE_8_BIT_INTEGRAL(TInputIterator), "Input type must be an 8 bit integral"); ETL_STATIC_ASSERT(ETL_IS_ITERATOR_TYPE_8_BIT_INTEGRAL(TInputIterator), "Input type must be an 8 bit integral");
@ -141,8 +139,7 @@ namespace etl
/// Decode from Base64 /// Decode from Base64
//************************************************************************* //*************************************************************************
template <typename TInputIterator> template <typename TInputIterator>
ETL_CONSTEXPR14 ETL_CONSTEXPR14 bool decode_final(TInputIterator input_begin, TInputIterator input_end)
bool decode_final(TInputIterator input_begin, TInputIterator input_end)
{ {
return decode(input_begin, input_end) && flush(); return decode(input_begin, input_end) && flush();
} }
@ -151,8 +148,7 @@ namespace etl
/// Decode from Base64 /// Decode from Base64
//************************************************************************* //*************************************************************************
template <typename TInputIterator> template <typename TInputIterator>
ETL_CONSTEXPR14 ETL_CONSTEXPR14 bool decode_final(TInputIterator input_begin, size_t input_length)
bool decode_final(TInputIterator input_begin, size_t input_length)
{ {
return decode(input_begin, input_length) && flush(); return decode(input_begin, input_length) && flush();
} }
@ -160,8 +156,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Flush any remaining data to the output. /// Flush any remaining data to the output.
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 ETL_CONSTEXPR14 bool flush()
bool flush()
{ {
// Encode any remaining input data. // Encode any remaining input data.
bool success = decode_block(); bool success = decode_block();
@ -193,32 +188,28 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Reset the encoder. /// Reset the encoder.
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 ETL_CONSTEXPR14 void restart()
void restart()
{ {
reset_input_buffer(); reset_input_buffer();
reset_output_buffer(); reset_output_buffer();
overflow_detected = false; overflow_detected = false;
invalid_data_detected = false; invalid_data_detected = false;
padding_received = false; padding_received = false;
} }
//************************************************************************* //*************************************************************************
/// Returns the beginning of the output buffer. /// Returns the beginning of the output buffer.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14 const unsigned char* begin() const
ETL_CONSTEXPR14
const unsigned char* begin() const
{ {
return p_output_buffer; return p_output_buffer;
} }
//************************************************************************* //*************************************************************************
/// This only returns a useful value if a callback has not been set or called. /// This only returns a useful value if a callback has not been set or
/// called.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14 const unsigned char* end() const
ETL_CONSTEXPR14
const unsigned char* end() const
{ {
return p_output_buffer + output_buffer_length; return p_output_buffer + output_buffer_length;
} }
@ -226,30 +217,26 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns the beginning of the output buffer. /// Returns the beginning of the output buffer.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14 const unsigned char* cbegin() const
ETL_CONSTEXPR14
const unsigned char* cbegin() const
{ {
return p_output_buffer; return p_output_buffer;
} }
//************************************************************************* //*************************************************************************
/// This only returns a useful value if a callback has not been set or called. /// This only returns a useful value if a callback has not been set or
/// called.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14 const unsigned char* cend() const
ETL_CONSTEXPR14
const unsigned char* cend() const
{ {
return p_output_buffer + output_buffer_length; return p_output_buffer + output_buffer_length;
} }
//************************************************************************* //*************************************************************************
/// Returns the size of the output buffer. /// Returns the size of the output buffer.
/// This only returns a useful value if a callback has not been set or called. /// This only returns a useful value if a callback has not been set or
/// called.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14 size_t size() const
ETL_CONSTEXPR14
size_t size() const
{ {
return output_buffer_length; return output_buffer_length;
} }
@ -257,20 +244,17 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns the maximum size of the output buffer. /// Returns the maximum size of the output buffer.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14 size_t buffer_size() const
ETL_CONSTEXPR14
size_t buffer_size() const
{ {
return output_buffer_max_size; return output_buffer_max_size;
} }
//************************************************************************* //*************************************************************************
/// Get a span of the output data. /// Get a span of the output data.
/// This only returns a useful span if a callback has not been set or called. /// This only returns a useful span if a callback has not been set or
/// called.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14 span_type span() const
ETL_CONSTEXPR14
span_type span() const
{ {
return span_type(begin(), end()); return span_type(begin(), end());
} }
@ -278,9 +262,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns true if the output buffer has overflowed /// Returns true if the output buffer has overflowed
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14 bool overflow() const
ETL_CONSTEXPR14
bool overflow() const
{ {
return overflow_detected; return overflow_detected;
} }
@ -288,9 +270,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns true if an invalid character was detected. /// Returns true if an invalid character was detected.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14 bool invalid_data() const
ETL_CONSTEXPR14
bool invalid_data() const
{ {
return invalid_data_detected; return invalid_data_detected;
} }
@ -298,9 +278,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns true if an error was detected. /// Returns true if an error was detected.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14 bool error() const
ETL_CONSTEXPR14
bool error() const
{ {
return overflow() || invalid_data(); return overflow() || invalid_data();
} }
@ -310,12 +288,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Constructor /// Constructor
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 ETL_CONSTEXPR14 ibase64_decoder(const char* encoder_table_, bool use_padding_, unsigned char* p_output_buffer_, size_t ouput_buffer_max_size_,
ibase64_decoder(const char* encoder_table_, callback_type callback_)
bool use_padding_,
unsigned char* p_output_buffer_,
size_t ouput_buffer_max_size_,
callback_type callback_)
: base64(encoder_table_, use_padding_) : base64(encoder_table_, use_padding_)
, input_buffer() , input_buffer()
, input_buffer_length(0) , input_buffer_length(0)
@ -333,9 +307,7 @@ namespace etl
/// Calculates the minimum buffer size required to decode from Base64 /// Calculates the minimum buffer size required to decode from Base64
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD
static static ETL_CONSTEXPR14 size_t decoded_size_from_valid_input_length(size_t input_length)
ETL_CONSTEXPR14
size_t decoded_size_from_valid_input_length(size_t input_length)
{ {
return input_length - (input_length / 4U); return input_length - (input_length / 4U);
} }
@ -343,14 +315,13 @@ namespace etl
private: private:
//************************************************************************* //*************************************************************************
// Translates a sextet into an index // Translates a sextet into an index
//************************************************************************* //*************************************************************************
template <typename T> template <typename T>
ETL_CONSTEXPR14 ETL_CONSTEXPR14 uint32_t get_index_from_sextet(T sextet)
uint32_t get_index_from_sextet(T sextet)
{ {
const char* encoder_table_end = encoder_table + 64; const char* encoder_table_end = encoder_table + 64;
const char* p_sextet = etl::find(encoder_table, encoder_table_end, static_cast<char>(sextet)); const char* p_sextet = etl::find(encoder_table, encoder_table_end, static_cast<char>(sextet));
if (p_sextet != encoder_table_end) if (p_sextet != encoder_table_end)
{ {
@ -369,8 +340,7 @@ namespace etl
template <typename T> template <typename T>
ETL_NODISCARD ETL_NODISCARD
static static
ETL_CONSTEXPR14 ETL_CONSTEXPR14 T padding()
T padding()
{ {
return static_cast<T>('='); return static_cast<T>('=');
} }
@ -378,51 +348,50 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Decode one block of data. /// Decode one block of data.
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 ETL_CONSTEXPR14 bool decode_block()
bool decode_block()
{ {
switch (input_buffer_length) switch (input_buffer_length)
{ {
// Only triggered on call to flush(). // Only triggered on call to flush().
case 2: case 2:
{ {
uint32_t sextets = (get_index_from_sextet(input_buffer[0]) << 6); uint32_t sextets = (get_index_from_sextet(input_buffer[0]) << 6);
sextets = sextets | (get_index_from_sextet(input_buffer[1])); sextets = sextets | (get_index_from_sextet(input_buffer[1]));
push_to_output_buffer((sextets >> 4) & 0xFF); push_to_output_buffer((sextets >> 4) & 0xFF);
break; break;
} }
// Only triggered on call to flush(). // Only triggered on call to flush().
case 3: case 3:
{ {
uint32_t sextets = (get_index_from_sextet(input_buffer[0]) << 12); uint32_t sextets = (get_index_from_sextet(input_buffer[0]) << 12);
sextets = sextets | (get_index_from_sextet(input_buffer[1]) << 6); sextets = sextets | (get_index_from_sextet(input_buffer[1]) << 6);
sextets = sextets | (get_index_from_sextet(input_buffer[2])); sextets = sextets | (get_index_from_sextet(input_buffer[2]));
push_to_output_buffer((sextets >> 10) & 0xFF); push_to_output_buffer((sextets >> 10) & 0xFF);
push_to_output_buffer((sextets >> 2) & 0xFF); push_to_output_buffer((sextets >> 2) & 0xFF);
break; break;
} }
// Only triggered on call to decode(). // Only triggered on call to decode().
case 4: case 4:
{ {
// Read in four sextets // Read in four sextets
uint32_t sextets = (get_index_from_sextet(input_buffer[0]) << 18); uint32_t sextets = (get_index_from_sextet(input_buffer[0]) << 18);
sextets = sextets | (get_index_from_sextet(input_buffer[1]) << 12); sextets = sextets | (get_index_from_sextet(input_buffer[1]) << 12);
sextets = sextets | (get_index_from_sextet(input_buffer[2]) << 6); sextets = sextets | (get_index_from_sextet(input_buffer[2]) << 6);
sextets = sextets | (get_index_from_sextet(input_buffer[3])); sextets = sextets | (get_index_from_sextet(input_buffer[3]));
// Write out three octets // Write out three octets
push_to_output_buffer((sextets >> 16) & 0xFF); push_to_output_buffer((sextets >> 16) & 0xFF);
push_to_output_buffer((sextets >> 8) & 0xFF); push_to_output_buffer((sextets >> 8) & 0xFF);
push_to_output_buffer((sextets >> 0) & 0xFF); push_to_output_buffer((sextets >> 0) & 0xFF);
break; break;
} }
default: default:
{ {
break; break;
} }
} }
ETL_ASSERT(!invalid_data_detected, ETL_ERROR(etl::base64_invalid_data)); ETL_ASSERT(!invalid_data_detected, ETL_ERROR(etl::base64_invalid_data));
@ -434,8 +403,7 @@ namespace etl
//************************************************************************* //*************************************************************************
// Push to the output buffer. // Push to the output buffer.
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 ETL_CONSTEXPR14 void push_to_output_buffer(unsigned char c)
void push_to_output_buffer(unsigned char c)
{ {
if (output_buffer_length < output_buffer_max_size) if (output_buffer_length < output_buffer_max_size)
{ {
@ -448,28 +416,25 @@ namespace etl
} }
//************************************************************************* //*************************************************************************
// //
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 ETL_CONSTEXPR14 bool output_buffer_is_full() const
bool output_buffer_is_full() const
{ {
return output_buffer_length == output_buffer_max_size; return output_buffer_length == output_buffer_max_size;
} }
//************************************************************************* //*************************************************************************
// //
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 ETL_CONSTEXPR14 bool output_buffer_is_empty() const
bool output_buffer_is_empty() const
{ {
return output_buffer_length == 0; return output_buffer_length == 0;
} }
//************************************************************************* //*************************************************************************
// //
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 ETL_CONSTEXPR14 void reset_output_buffer()
void reset_output_buffer()
{ {
output_buffer_length = 0; output_buffer_length = 0;
} }
@ -478,8 +443,7 @@ namespace etl
// Push to the input buffer. // Push to the input buffer.
//************************************************************************* //*************************************************************************
template <typename T> template <typename T>
ETL_CONSTEXPR14 ETL_CONSTEXPR14 void push_to_input_buffer(T value)
void push_to_input_buffer(T value)
{ {
if (value == padding<T>()) if (value == padding<T>())
{ {
@ -500,19 +464,17 @@ namespace etl
} }
//************************************************************************* //*************************************************************************
// //
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 ETL_CONSTEXPR14 bool input_buffer_is_full() const
bool input_buffer_is_full() const
{ {
return input_buffer_length == 4U; return input_buffer_length == 4U;
} }
//************************************************************************* //*************************************************************************
// //
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 ETL_CONSTEXPR14 void reset_input_buffer()
void reset_input_buffer()
{ {
input_buffer_length = 0; input_buffer_length = 0;
} }
@ -544,13 +506,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Base64 RFC-2152 constructor. /// Base64 RFC-2152 constructor.
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 ETL_CONSTEXPR14 base64_rfc2152_decoder()
base64_rfc2152_decoder() : ibase64_decoder(etl::base64::character_set_1(), etl::base64::Padding::No_Padding, output_buffer, Buffer_Size, callback_type())
: ibase64_decoder(etl::base64::character_set_1(),
etl::base64::Padding::No_Padding,
output_buffer,
Buffer_Size,
callback_type())
, output_buffer() , output_buffer()
{ {
} }
@ -558,13 +515,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Base64 RFC-2152 constructor. /// Base64 RFC-2152 constructor.
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 ETL_CONSTEXPR14 base64_rfc2152_decoder(callback_type callback_)
base64_rfc2152_decoder(callback_type callback_) : ibase64_decoder(etl::base64::character_set_1(), etl::base64::Padding::No_Padding, output_buffer, Buffer_Size, callback_)
: ibase64_decoder(etl::base64::character_set_1(),
etl::base64::Padding::No_Padding,
output_buffer,
Buffer_Size,
callback_)
, output_buffer() , output_buffer()
{ {
} }
@ -574,8 +526,7 @@ namespace etl
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD
static static
ETL_CONSTEXPR14 ETL_CONSTEXPR14 size_t safe_output_buffer_size(size_t input_length)
size_t safe_output_buffer_size(size_t input_length)
{ {
return ibase64_decoder::decoded_size_from_valid_input_length(input_length); return ibase64_decoder::decoded_size_from_valid_input_length(input_length);
} }
@ -599,13 +550,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Base64 RFC-3501 constructor. /// Base64 RFC-3501 constructor.
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 ETL_CONSTEXPR14 base64_rfc3501_decoder()
base64_rfc3501_decoder() : ibase64_decoder(etl::base64::character_set_3(), etl::base64::Padding::No_Padding, output_buffer, Buffer_Size, callback_type())
: ibase64_decoder(etl::base64::character_set_3(),
etl::base64::Padding::No_Padding,
output_buffer,
Buffer_Size,
callback_type())
, output_buffer() , output_buffer()
{ {
} }
@ -613,13 +559,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Base64 RFC-3501 constructor. /// Base64 RFC-3501 constructor.
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 ETL_CONSTEXPR14 base64_rfc3501_decoder(callback_type callback_)
base64_rfc3501_decoder(callback_type callback_) : ibase64_decoder(etl::base64::character_set_3(), etl::base64::Padding::No_Padding, output_buffer, Buffer_Size, callback_)
: ibase64_decoder(etl::base64::character_set_3(),
etl::base64::Padding::No_Padding,
output_buffer,
Buffer_Size,
callback_)
, output_buffer() , output_buffer()
{ {
} }
@ -629,8 +570,7 @@ namespace etl
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD
static static
ETL_CONSTEXPR14 ETL_CONSTEXPR14 size_t safe_output_buffer_size(size_t input_length)
size_t safe_output_buffer_size(size_t input_length)
{ {
return ibase64_decoder::decoded_size_from_valid_input_length(input_length); return ibase64_decoder::decoded_size_from_valid_input_length(input_length);
} }
@ -654,13 +594,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Base64 RFC-4648 constructor. /// Base64 RFC-4648 constructor.
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 ETL_CONSTEXPR14 base64_rfc4648_decoder()
base64_rfc4648_decoder() : ibase64_decoder(etl::base64::character_set_1(), etl::base64::Padding::No_Padding, output_buffer, Buffer_Size, callback_type())
: ibase64_decoder(etl::base64::character_set_1(),
etl::base64::Padding::No_Padding,
output_buffer,
Buffer_Size,
callback_type())
, output_buffer() , output_buffer()
{ {
} }
@ -668,13 +603,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Base64 RFC-4648 constructor. /// Base64 RFC-4648 constructor.
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 ETL_CONSTEXPR14 base64_rfc4648_decoder(callback_type callback_)
base64_rfc4648_decoder(callback_type callback_) : ibase64_decoder(etl::base64::character_set_1(), etl::base64::Padding::No_Padding, output_buffer, Buffer_Size, callback_)
: ibase64_decoder(etl::base64::character_set_1(),
etl::base64::Padding::No_Padding,
output_buffer,
Buffer_Size,
callback_)
, output_buffer() , output_buffer()
{ {
} }
@ -683,9 +613,8 @@ namespace etl
/// Calculate the required output encode buffer size. /// Calculate the required output encode buffer size.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD
static static
ETL_CONSTEXPR14 ETL_CONSTEXPR14 size_t safe_output_buffer_size(size_t input_length)
size_t safe_output_buffer_size(size_t input_length)
{ {
return ibase64_decoder::decoded_size_from_valid_input_length(input_length); return ibase64_decoder::decoded_size_from_valid_input_length(input_length);
} }
@ -709,13 +638,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Base64 RFC-4648-Padding constructor. /// Base64 RFC-4648-Padding constructor.
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 ETL_CONSTEXPR14 base64_rfc4648_padding_decoder()
base64_rfc4648_padding_decoder() : ibase64_decoder(etl::base64::character_set_1(), etl::base64::Padding::Use_Padding, output_buffer, Buffer_Size, callback_type())
: ibase64_decoder(etl::base64::character_set_1(),
etl::base64::Padding::Use_Padding,
output_buffer,
Buffer_Size,
callback_type())
, output_buffer() , output_buffer()
{ {
} }
@ -723,13 +647,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Base64 RFC-4648-Padding constructor. /// Base64 RFC-4648-Padding constructor.
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 ETL_CONSTEXPR14 base64_rfc4648_padding_decoder(callback_type callback_)
base64_rfc4648_padding_decoder(callback_type callback_) : ibase64_decoder(etl::base64::character_set_1(), etl::base64::Padding::Use_Padding, output_buffer, Buffer_Size, callback_)
: ibase64_decoder(etl::base64::character_set_1(),
etl::base64::Padding::Use_Padding,
output_buffer,
Buffer_Size,
callback_)
, output_buffer() , output_buffer()
{ {
} }
@ -739,8 +658,7 @@ namespace etl
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD
static static
ETL_CONSTEXPR14 ETL_CONSTEXPR14 size_t safe_output_buffer_size(size_t input_length)
size_t safe_output_buffer_size(size_t input_length)
{ {
return ibase64_decoder::decoded_size_from_valid_input_length(input_length); return ibase64_decoder::decoded_size_from_valid_input_length(input_length);
} }
@ -764,13 +682,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Base64 RFC-4648-Padding constructor. /// Base64 RFC-4648-Padding constructor.
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 ETL_CONSTEXPR14 base64_rfc4648_url_decoder()
base64_rfc4648_url_decoder() : ibase64_decoder(etl::base64::character_set_2(), etl::base64::Padding::No_Padding, output_buffer, Buffer_Size, callback_type())
: ibase64_decoder(etl::base64::character_set_2(),
etl::base64::Padding::No_Padding,
output_buffer,
Buffer_Size,
callback_type())
, output_buffer() , output_buffer()
{ {
} }
@ -778,13 +691,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Base64 RFC-4648-Padding constructor. /// Base64 RFC-4648-Padding constructor.
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 ETL_CONSTEXPR14 base64_rfc4648_url_decoder(callback_type callback_)
base64_rfc4648_url_decoder(callback_type callback_) : ibase64_decoder(etl::base64::character_set_2(), etl::base64::Padding::No_Padding, output_buffer, Buffer_Size, callback_)
: ibase64_decoder(etl::base64::character_set_2(),
etl::base64::Padding::No_Padding,
output_buffer,
Buffer_Size,
callback_)
, output_buffer() , output_buffer()
{ {
} }
@ -794,8 +702,7 @@ namespace etl
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD
static static
ETL_CONSTEXPR14 ETL_CONSTEXPR14 size_t safe_output_buffer_size(size_t input_length)
size_t safe_output_buffer_size(size_t input_length)
{ {
return ibase64_decoder::decoded_size_from_valid_input_length(input_length); return ibase64_decoder::decoded_size_from_valid_input_length(input_length);
} }
@ -819,13 +726,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Base64 RFC-4648-Padding constructor. /// Base64 RFC-4648-Padding constructor.
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 ETL_CONSTEXPR14 base64_rfc4648_url_padding_decoder()
base64_rfc4648_url_padding_decoder() : ibase64_decoder(etl::base64::character_set_2(), etl::base64::Padding::Use_Padding, output_buffer, Buffer_Size, callback_type())
: ibase64_decoder(etl::base64::character_set_2(),
etl::base64::Padding::Use_Padding,
output_buffer,
Buffer_Size,
callback_type())
, output_buffer() , output_buffer()
{ {
} }
@ -833,13 +735,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Base64 RFC-4648-Padding constructor. /// Base64 RFC-4648-Padding constructor.
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 ETL_CONSTEXPR14 base64_rfc4648_url_padding_decoder(callback_type callback_)
base64_rfc4648_url_padding_decoder(callback_type callback_) : ibase64_decoder(etl::base64::character_set_2(), etl::base64::Padding::Use_Padding, output_buffer, Buffer_Size, callback_)
: ibase64_decoder(etl::base64::character_set_2(),
etl::base64::Padding::Use_Padding,
output_buffer,
Buffer_Size,
callback_)
, output_buffer() , output_buffer()
{ {
} }
@ -849,8 +746,7 @@ namespace etl
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD
static static
ETL_CONSTEXPR14 ETL_CONSTEXPR14 size_t safe_output_buffer_size(size_t input_length)
size_t safe_output_buffer_size(size_t input_length)
{ {
return ibase64_decoder::decoded_size_from_valid_input_length(input_length); return ibase64_decoder::decoded_size_from_valid_input_length(input_length);
} }
@ -860,7 +756,7 @@ namespace etl
/// The internal output buffer. /// The internal output buffer.
unsigned char output_buffer[Buffer_Size]; unsigned char output_buffer[Buffer_Size];
}; };
} } // namespace etl
#undef ETL_IS_TYPE_8_BIT_INTEGRAL #undef ETL_IS_TYPE_8_BIT_INTEGRAL
#undef ETL_IS_ITERATOR_TYPE_8_BIT_INTEGRAL #undef ETL_IS_ITERATOR_TYPE_8_BIT_INTEGRAL

View File

@ -1,5 +1,5 @@
//************************************************************************* //*************************************************************************
///Decode from Base64 from and to pointer/length /// Decode from Base64 from and to pointer/length
//*************************************************************************///\file //*************************************************************************///\file
/****************************************************************************** /******************************************************************************
@ -29,16 +29,16 @@ SOFTWARE.
#define ETL_BASE64_ENCODER_INCLUDED #define ETL_BASE64_ENCODER_INCLUDED
#include "platform.h" #include "platform.h"
#include "static_assert.h"
#include "error_handler.h"
#include "type_traits.h"
#include "binary.h"
#include "algorithm.h" #include "algorithm.h"
#include "binary.h"
#include "delegate.h"
#include "enum_type.h"
#include "error_handler.h"
#include "integral_limits.h" #include "integral_limits.h"
#include "iterator.h" #include "iterator.h"
#include "enum_type.h"
#include "delegate.h"
#include "span.h" #include "span.h"
#include "static_assert.h"
#include "type_traits.h"
#include "base64.h" #include "base64.h"
@ -48,11 +48,12 @@ SOFTWARE.
#include <iterator> #include <iterator>
#endif #endif
#define ETL_IS_8_BIT_INTEGRAL(Type) (etl::is_integral<typename etl::remove_cv<Type>::type>::value && \ #define ETL_IS_8_BIT_INTEGRAL(Type) \
(etl::integral_limits<typename etl::remove_cv<Type>::type>::bits == 8U)) (etl::is_integral<typename etl::remove_cv<Type>::type>::value && (etl::integral_limits<typename etl::remove_cv<Type>::type>::bits == 8U))
#define ETL_IS_ITERATOR_TYPE_8_BIT_INTEGRAL(Type) (etl::is_integral<typename etl::iterator_traits<typename etl::remove_cv<Type>::type>::value_type>::value && \ #define ETL_IS_ITERATOR_TYPE_8_BIT_INTEGRAL(Type) \
(etl::integral_limits<typename etl::iterator_traits<typename etl::remove_cv<Type>::type>::value_type>::bits == 8U)) (etl::is_integral< typename etl::iterator_traits< typename etl::remove_cv<Type>::type>::value_type>::value \
&& (etl::integral_limits< typename etl::iterator_traits< typename etl::remove_cv<Type>::type>::value_type>::bits == 8U))
namespace etl namespace etl
{ {
@ -70,8 +71,7 @@ namespace etl
/// Encode to Base64 /// Encode to Base64
//************************************************************************* //*************************************************************************
template <typename T> template <typename T>
ETL_CONSTEXPR14 ETL_CONSTEXPR14 bool encode(T value)
bool encode(T value)
{ {
ETL_STATIC_ASSERT(ETL_IS_8_BIT_INTEGRAL(T), "Input type must be an 8 bit integral"); ETL_STATIC_ASSERT(ETL_IS_8_BIT_INTEGRAL(T), "Input type must be an 8 bit integral");
@ -99,8 +99,7 @@ namespace etl
/// Encode to Base64 /// Encode to Base64
//************************************************************************* //*************************************************************************
template <typename TInputIterator> template <typename TInputIterator>
ETL_CONSTEXPR14 ETL_CONSTEXPR14 bool encode(TInputIterator input_begin, size_t input_length)
bool encode(TInputIterator input_begin, size_t input_length)
{ {
ETL_STATIC_ASSERT(ETL_IS_ITERATOR_TYPE_8_BIT_INTEGRAL(TInputIterator), "Input type must be an 8 bit integral"); ETL_STATIC_ASSERT(ETL_IS_ITERATOR_TYPE_8_BIT_INTEGRAL(TInputIterator), "Input type must be an 8 bit integral");
@ -119,8 +118,7 @@ namespace etl
/// Encode to Base64 /// Encode to Base64
//************************************************************************* //*************************************************************************
template <typename TInputIterator> template <typename TInputIterator>
ETL_CONSTEXPR14 ETL_CONSTEXPR14 bool encode(TInputIterator input_begin, TInputIterator input_end)
bool encode(TInputIterator input_begin, TInputIterator input_end)
{ {
ETL_STATIC_ASSERT(ETL_IS_ITERATOR_TYPE_8_BIT_INTEGRAL(TInputIterator), "Input type must be an 8 bit integral"); ETL_STATIC_ASSERT(ETL_IS_ITERATOR_TYPE_8_BIT_INTEGRAL(TInputIterator), "Input type must be an 8 bit integral");
@ -139,8 +137,7 @@ namespace etl
/// Encode to Base64 /// Encode to Base64
//************************************************************************* //*************************************************************************
template <typename TInputIterator> template <typename TInputIterator>
ETL_CONSTEXPR14 ETL_CONSTEXPR14 bool encode_final(TInputIterator input_begin, size_t input_length)
bool encode_final(TInputIterator input_begin, size_t input_length)
{ {
return encode(input_begin, input_length) && flush(); return encode(input_begin, input_length) && flush();
} }
@ -149,8 +146,7 @@ namespace etl
/// Encode to Base64 /// Encode to Base64
//************************************************************************* //*************************************************************************
template <typename TInputIterator> template <typename TInputIterator>
ETL_CONSTEXPR14 ETL_CONSTEXPR14 bool encode_final(TInputIterator input_begin, TInputIterator input_end)
bool encode_final(TInputIterator input_begin, TInputIterator input_end)
{ {
return encode(input_begin, input_end) && flush(); return encode(input_begin, input_end) && flush();
} }
@ -158,8 +154,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Flush any remaining data to the output. /// Flush any remaining data to the output.
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 ETL_CONSTEXPR14 bool flush()
bool flush()
{ {
// Encode any remaining input data. // Encode any remaining input data.
bool success = encode_block(); bool success = encode_block();
@ -189,8 +184,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Reset the encoder. /// Reset the encoder.
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 ETL_CONSTEXPR14 void restart()
void restart()
{ {
reset_input_buffer(); reset_input_buffer();
reset_output_buffer(); reset_output_buffer();
@ -199,19 +193,16 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns the beginning of the output buffer. /// Returns the beginning of the output buffer.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14 const char* begin() const
ETL_CONSTEXPR14
const char* begin() const
{ {
return p_output_buffer; return p_output_buffer;
} }
//************************************************************************* //*************************************************************************
/// This only returns a useful value if a callback has not been set or called. /// This only returns a useful value if a callback has not been set or
/// called.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14 const char* end() const
ETL_CONSTEXPR14
const char* end() const
{ {
return p_output_buffer + output_buffer_length; return p_output_buffer + output_buffer_length;
} }
@ -219,30 +210,26 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns the beginning of the output buffer. /// Returns the beginning of the output buffer.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14 const char* cbegin() const
ETL_CONSTEXPR14
const char* cbegin() const
{ {
return p_output_buffer; return p_output_buffer;
} }
//************************************************************************* //*************************************************************************
/// This only returns a useful value if a callback has not been set or called. /// This only returns a useful value if a callback has not been set or
/// called.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14 const char* cend() const
ETL_CONSTEXPR14
const char* cend() const
{ {
return p_output_buffer + output_buffer_length; return p_output_buffer + output_buffer_length;
} }
//************************************************************************* //*************************************************************************
/// Returns the size of the output buffer. /// Returns the size of the output buffer.
/// This only returns a useful value if a callback has not been set or called. /// This only returns a useful value if a callback has not been set or
/// called.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14 size_t size() const
ETL_CONSTEXPR14
size_t size() const
{ {
return output_buffer_length; return output_buffer_length;
} }
@ -250,20 +237,17 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns the maximum size of the output buffer. /// Returns the maximum size of the output buffer.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14 size_t max_size() const
ETL_CONSTEXPR14
size_t max_size() const
{ {
return output_buffer_max_size; return output_buffer_max_size;
} }
//************************************************************************* //*************************************************************************
/// Get a span of the output data. /// Get a span of the output data.
/// This only returns a useful span if a callback has not been set or called. /// This only returns a useful span if a callback has not been set or
/// called.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14 span_type span() const
ETL_CONSTEXPR14
span_type span() const
{ {
return span_type(begin(), end()); return span_type(begin(), end());
} }
@ -271,9 +255,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns true if the output buffer has overflowed /// Returns true if the output buffer has overflowed
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14 bool overflow() const
ETL_CONSTEXPR14
bool overflow() const
{ {
return overflowed; return overflowed;
} }
@ -281,9 +263,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Returns true if an error was detected. /// Returns true if an error was detected.
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14 bool error() const
ETL_CONSTEXPR14
bool error() const
{ {
return overflow(); return overflow();
} }
@ -293,12 +273,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Constructor /// Constructor
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 ETL_CONSTEXPR14 ibase64_encoder(const char* encoder_table_, bool use_padding_, char* p_output_buffer_, size_t ouput_buffer_max_size_,
ibase64_encoder(const char* encoder_table_, callback_type callback_)
bool use_padding_,
char* p_output_buffer_,
size_t ouput_buffer_max_size_,
callback_type callback_)
: base64(encoder_table_, use_padding_) : base64(encoder_table_, use_padding_)
, input_buffer() , input_buffer()
, input_buffer_length(0) , input_buffer_length(0)
@ -313,64 +289,65 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Encode one block of data. /// Encode one block of data.
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 ETL_CONSTEXPR14 bool encode_block()
bool encode_block()
{ {
switch (input_buffer_length) switch (input_buffer_length)
{ {
// Only triggered on call to flush(). // Only triggered on call to flush().
case 1: case 1:
{
uint32_t octets = input_buffer[0];
octets = octets << 4; // Adjust one octet (8 bits) for two sextets worth of data (12 bits)
// Write out two sextets + optional padding.
push_to_output_buffer(encoder_table[(octets >> 6) & 0x3F]);
push_to_output_buffer(encoder_table[(octets >> 0) & 0x3F]);
if (use_padding)
{ {
push_to_output_buffer('='); uint32_t octets = input_buffer[0];
push_to_output_buffer('='); octets = octets << 4; // Adjust one octet (8 bits) for two sextets
} // worth of data (12 bits)
break;
} // Write out two sextets + optional padding.
push_to_output_buffer(encoder_table[(octets >> 6) & 0x3F]);
push_to_output_buffer(encoder_table[(octets >> 0) & 0x3F]);
if (use_padding)
{
push_to_output_buffer('=');
push_to_output_buffer('=');
}
break;
}
// Only triggered on call to flush(). // Only triggered on call to flush().
case 2: case 2:
{
uint32_t octets = (static_cast<uint32_t>(input_buffer[0]) << 8) | input_buffer[1];
octets <<= 2; // Adjust two octets (16 bits) for three sextets worth of data (18 bits)
// Write out three sextets + optional padding.
push_to_output_buffer(encoder_table[(octets >> 12) & 0x3F]);
push_to_output_buffer(encoder_table[(octets >> 6) & 0x3F]);
push_to_output_buffer(encoder_table[(octets >> 0) & 0x3F]);
if (use_padding)
{ {
push_to_output_buffer('='); uint32_t octets = (static_cast<uint32_t>(input_buffer[0]) << 8) | input_buffer[1];
octets <<= 2; // Adjust two octets (16 bits) for three sextets worth
// of data (18 bits)
// Write out three sextets + optional padding.
push_to_output_buffer(encoder_table[(octets >> 12) & 0x3F]);
push_to_output_buffer(encoder_table[(octets >> 6) & 0x3F]);
push_to_output_buffer(encoder_table[(octets >> 0) & 0x3F]);
if (use_padding)
{
push_to_output_buffer('=');
}
break;
} }
break;
}
// Only triggered on call to encode(). // Only triggered on call to encode().
case 3: case 3:
{ {
uint32_t octets = (static_cast<uint32_t>(input_buffer[0]) << 16) | (static_cast<uint32_t>(input_buffer[1]) << 8) | input_buffer[2]; uint32_t octets = (static_cast<uint32_t>(input_buffer[0]) << 16) | (static_cast<uint32_t>(input_buffer[1]) << 8) | input_buffer[2];
// Write out four sextets // Write out four sextets
push_to_output_buffer(encoder_table[(octets >> 18) & 0x3F]); push_to_output_buffer(encoder_table[(octets >> 18) & 0x3F]);
push_to_output_buffer(encoder_table[(octets >> 12) & 0x3F]); push_to_output_buffer(encoder_table[(octets >> 12) & 0x3F]);
push_to_output_buffer(encoder_table[(octets >> 6) & 0x3F]); push_to_output_buffer(encoder_table[(octets >> 6) & 0x3F]);
push_to_output_buffer(encoder_table[(octets >> 0) & 0x3F]); push_to_output_buffer(encoder_table[(octets >> 0) & 0x3F]);
break; break;
} }
default: default:
{ {
break; break;
} }
} }
ETL_ASSERT(!overflowed, ETL_ERROR(etl::base64_overflow)); ETL_ASSERT(!overflowed, ETL_ERROR(etl::base64_overflow));
@ -383,8 +360,7 @@ namespace etl
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD
static static
ETL_CONSTEXPR14 ETL_CONSTEXPR14 size_t encoded_size(size_t input_length, bool use_padding)
size_t encoded_size(size_t input_length, bool use_padding)
{ {
size_t required_output_length = 0; size_t required_output_length = 0;
@ -420,8 +396,7 @@ namespace etl
//************************************************************************* //*************************************************************************
// Push to the output buffer. // Push to the output buffer.
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 ETL_CONSTEXPR14 void push_to_output_buffer(char c)
void push_to_output_buffer(char c)
{ {
if (output_buffer_length < output_buffer_max_size) if (output_buffer_length < output_buffer_max_size)
{ {
@ -434,28 +409,25 @@ namespace etl
} }
//************************************************************************* //*************************************************************************
// //
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 ETL_CONSTEXPR14 bool output_buffer_is_full() const
bool output_buffer_is_full() const
{ {
return output_buffer_length == output_buffer_max_size; return output_buffer_length == output_buffer_max_size;
} }
//************************************************************************* //*************************************************************************
// //
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 ETL_CONSTEXPR14 bool output_buffer_is_empty() const
bool output_buffer_is_empty() const
{ {
return output_buffer_length == 0; return output_buffer_length == 0;
} }
//************************************************************************* //*************************************************************************
// //
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 ETL_CONSTEXPR14 void reset_output_buffer()
void reset_output_buffer()
{ {
output_buffer_length = 0; output_buffer_length = 0;
} }
@ -464,26 +436,23 @@ namespace etl
// Push to the input buffer. // Push to the input buffer.
//************************************************************************* //*************************************************************************
template <typename T> template <typename T>
ETL_CONSTEXPR14 ETL_CONSTEXPR14 void push_to_input_buffer(T value)
void push_to_input_buffer(T value)
{ {
input_buffer[input_buffer_length++] = static_cast<uint8_t>(value); input_buffer[input_buffer_length++] = static_cast<uint8_t>(value);
} }
//************************************************************************* //*************************************************************************
// //
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 ETL_CONSTEXPR14 bool input_buffer_is_full() const
bool input_buffer_is_full() const
{ {
return input_buffer_length == 3U; return input_buffer_length == 3U;
} }
//************************************************************************* //*************************************************************************
// //
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 ETL_CONSTEXPR14 void reset_input_buffer()
void reset_input_buffer()
{ {
input_buffer_length = 0; input_buffer_length = 0;
} }
@ -496,7 +465,7 @@ namespace etl
const size_t output_buffer_max_size; const size_t output_buffer_max_size;
callback_type callback; callback_type callback;
bool overflowed; bool overflowed;
}; };
@ -508,19 +477,15 @@ namespace etl
{ {
public: public:
ETL_STATIC_ASSERT((Buffer_Size >= etl::base64::Min_Encode_Buffer_Size), "Buffer size must be greater than etl::base64::Min_Encode_Buffer_Size"); ETL_STATIC_ASSERT((Buffer_Size >= etl::base64::Min_Encode_Buffer_Size), "Buffer size must be greater than etl::base64::Min_Encode_Buffer_Size");
ETL_STATIC_ASSERT(((Buffer_Size % etl::base64::Min_Encode_Buffer_Size) == 0), "Buffer size must be a multiple of etl::base64::Min_Encode_Buffer_Size"); ETL_STATIC_ASSERT(((Buffer_Size % etl::base64::Min_Encode_Buffer_Size) == 0),
"Buffer size must be a multiple of etl::base64::Min_Encode_Buffer_Size");
//************************************************************************* //*************************************************************************
/// Base64 RFC-2152 constructor. /// Base64 RFC-2152 constructor.
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 ETL_CONSTEXPR14 base64_rfc2152_encoder()
base64_rfc2152_encoder() : ibase64_encoder(etl::base64::character_set_1(), etl::base64::Padding::No_Padding, output_buffer, Buffer_Size, callback_type())
: ibase64_encoder(etl::base64::character_set_1(),
etl::base64::Padding::No_Padding,
output_buffer,
Buffer_Size,
callback_type())
, output_buffer() , output_buffer()
{ {
} }
@ -528,13 +493,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Base64 RFC-2152 constructor. /// Base64 RFC-2152 constructor.
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 ETL_CONSTEXPR14 base64_rfc2152_encoder(callback_type callback_)
base64_rfc2152_encoder(callback_type callback_) : ibase64_encoder(etl::base64::character_set_1(), etl::base64::Padding::No_Padding, output_buffer, Buffer_Size, callback_)
: ibase64_encoder(etl::base64::character_set_1(),
etl::base64::Padding::No_Padding,
output_buffer,
Buffer_Size,
callback_)
, output_buffer() , output_buffer()
{ {
} }
@ -544,8 +504,7 @@ namespace etl
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD
static static
ETL_CONSTEXPR14 ETL_CONSTEXPR14 size_t safe_output_buffer_size(size_t input_length)
size_t safe_output_buffer_size(size_t input_length)
{ {
return ibase64_encoder::encoded_size(input_length, etl::base64::Padding::No_Padding); return ibase64_encoder::encoded_size(input_length, etl::base64::Padding::No_Padding);
} }
@ -564,19 +523,15 @@ namespace etl
{ {
public: public:
ETL_STATIC_ASSERT((Buffer_Size >= etl::base64::Min_Encode_Buffer_Size), "Buffer size must be greater than etl::base64::Min_Encode_Buffer_Size"); ETL_STATIC_ASSERT((Buffer_Size >= etl::base64::Min_Encode_Buffer_Size), "Buffer size must be greater than etl::base64::Min_Encode_Buffer_Size");
ETL_STATIC_ASSERT(((Buffer_Size% etl::base64::Min_Encode_Buffer_Size) == 0), "Buffer size must be a multiple of etl::base64::Min_Encode_Buffer_Size"); ETL_STATIC_ASSERT(((Buffer_Size % etl::base64::Min_Encode_Buffer_Size) == 0),
"Buffer size must be a multiple of etl::base64::Min_Encode_Buffer_Size");
//************************************************************************* //*************************************************************************
/// Base64 RFC-3501 constructor. /// Base64 RFC-3501 constructor.
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 ETL_CONSTEXPR14 base64_rfc3501_encoder()
base64_rfc3501_encoder() : ibase64_encoder(etl::base64::character_set_3(), etl::base64::Padding::No_Padding, output_buffer, Buffer_Size, callback_type())
: ibase64_encoder(etl::base64::character_set_3(),
etl::base64::Padding::No_Padding,
output_buffer,
Buffer_Size,
callback_type())
, output_buffer() , output_buffer()
{ {
} }
@ -584,13 +539,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Base64 RFC-3501 constructor. /// Base64 RFC-3501 constructor.
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 ETL_CONSTEXPR14 base64_rfc3501_encoder(callback_type callback_)
base64_rfc3501_encoder(callback_type callback_) : ibase64_encoder(etl::base64::character_set_3(), etl::base64::Padding::No_Padding, output_buffer, Buffer_Size, callback_)
: ibase64_encoder(etl::base64::character_set_3(),
etl::base64::Padding::No_Padding,
output_buffer,
Buffer_Size,
callback_)
, output_buffer() , output_buffer()
{ {
} }
@ -600,8 +550,7 @@ namespace etl
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD
static static
ETL_CONSTEXPR14 ETL_CONSTEXPR14 size_t safe_output_buffer_size(size_t input_length)
size_t safe_output_buffer_size(size_t input_length)
{ {
return ibase64_encoder::encoded_size(input_length, etl::base64::Padding::No_Padding); return ibase64_encoder::encoded_size(input_length, etl::base64::Padding::No_Padding);
} }
@ -620,19 +569,15 @@ namespace etl
{ {
public: public:
ETL_STATIC_ASSERT((Buffer_Size >= etl::base64::Min_Encode_Buffer_Size), "Buffer size must be greater than etl::base64::Min_Encode_Buffer_Size"); ETL_STATIC_ASSERT((Buffer_Size >= etl::base64::Min_Encode_Buffer_Size), "Buffer size must be greater than etl::base64::Min_Encode_Buffer_Size");
ETL_STATIC_ASSERT(((Buffer_Size % etl::base64::Min_Encode_Buffer_Size) == 0), "Buffer size must be a multiple of etl::base64::Min_Encode_Buffer_Size"); ETL_STATIC_ASSERT(((Buffer_Size % etl::base64::Min_Encode_Buffer_Size) == 0),
"Buffer size must be a multiple of etl::base64::Min_Encode_Buffer_Size");
//************************************************************************* //*************************************************************************
/// Base64 RFC-4648 constructor. /// Base64 RFC-4648 constructor.
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 ETL_CONSTEXPR14 base64_rfc4648_encoder()
base64_rfc4648_encoder() : ibase64_encoder(etl::base64::character_set_1(), etl::base64::Padding::No_Padding, output_buffer, Buffer_Size, callback_type())
: ibase64_encoder(etl::base64::character_set_1(),
etl::base64::Padding::No_Padding,
output_buffer,
Buffer_Size,
callback_type())
, output_buffer() , output_buffer()
{ {
} }
@ -640,13 +585,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Base64 RFC-4648 constructor. /// Base64 RFC-4648 constructor.
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 ETL_CONSTEXPR14 base64_rfc4648_encoder(callback_type callback_)
base64_rfc4648_encoder(callback_type callback_) : ibase64_encoder(etl::base64::character_set_1(), etl::base64::Padding::No_Padding, output_buffer, Buffer_Size, callback_)
: ibase64_encoder(etl::base64::character_set_1(),
etl::base64::Padding::No_Padding,
output_buffer,
Buffer_Size,
callback_)
, output_buffer() , output_buffer()
{ {
} }
@ -656,8 +596,7 @@ namespace etl
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD
static static
ETL_CONSTEXPR14 ETL_CONSTEXPR14 size_t safe_output_buffer_size(size_t input_length)
size_t safe_output_buffer_size(size_t input_length)
{ {
return ibase64_encoder::encoded_size(input_length, etl::base64::Padding::No_Padding); return ibase64_encoder::encoded_size(input_length, etl::base64::Padding::No_Padding);
} }
@ -676,19 +615,15 @@ namespace etl
{ {
public: public:
ETL_STATIC_ASSERT((Buffer_Size >= etl::base64::Min_Encode_Buffer_Size), "Buffer size must be greater than etl::base64::Min_Encode_Buffer_Size"); ETL_STATIC_ASSERT((Buffer_Size >= etl::base64::Min_Encode_Buffer_Size), "Buffer size must be greater than etl::base64::Min_Encode_Buffer_Size");
ETL_STATIC_ASSERT(((Buffer_Size% etl::base64::Min_Encode_Buffer_Size) == 0), "Buffer size must be a multiple of etl::base64::Min_Encode_Buffer_Size"); ETL_STATIC_ASSERT(((Buffer_Size % etl::base64::Min_Encode_Buffer_Size) == 0),
"Buffer size must be a multiple of etl::base64::Min_Encode_Buffer_Size");
//************************************************************************* //*************************************************************************
/// Base64 RFC-4648-Padding constructor. /// Base64 RFC-4648-Padding constructor.
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 ETL_CONSTEXPR14 base64_rfc4648_padding_encoder()
base64_rfc4648_padding_encoder() : ibase64_encoder(etl::base64::character_set_1(), etl::base64::Padding::Use_Padding, output_buffer, Buffer_Size, callback_type())
: ibase64_encoder(etl::base64::character_set_1(),
etl::base64::Padding::Use_Padding,
output_buffer,
Buffer_Size,
callback_type())
, output_buffer() , output_buffer()
{ {
} }
@ -696,13 +631,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Base64 RFC-4648-Padding constructor. /// Base64 RFC-4648-Padding constructor.
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 ETL_CONSTEXPR14 base64_rfc4648_padding_encoder(callback_type callback_)
base64_rfc4648_padding_encoder(callback_type callback_) : ibase64_encoder(etl::base64::character_set_1(), etl::base64::Padding::Use_Padding, output_buffer, Buffer_Size, callback_)
: ibase64_encoder(etl::base64::character_set_1(),
etl::base64::Padding::Use_Padding,
output_buffer,
Buffer_Size,
callback_)
, output_buffer() , output_buffer()
{ {
} }
@ -712,8 +642,7 @@ namespace etl
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD
static static
ETL_CONSTEXPR14 ETL_CONSTEXPR14 size_t safe_output_buffer_size(size_t input_length)
size_t safe_output_buffer_size(size_t input_length)
{ {
return ibase64_encoder::encoded_size(input_length, etl::base64::Padding::Use_Padding); return ibase64_encoder::encoded_size(input_length, etl::base64::Padding::Use_Padding);
} }
@ -732,19 +661,15 @@ namespace etl
{ {
public: public:
ETL_STATIC_ASSERT((Buffer_Size >= etl::base64::Min_Encode_Buffer_Size), "Buffer size must be greater than etl::base64::Min_Encode_Buffer_Size"); ETL_STATIC_ASSERT((Buffer_Size >= etl::base64::Min_Encode_Buffer_Size), "Buffer size must be greater than etl::base64::Min_Encode_Buffer_Size");
ETL_STATIC_ASSERT(((Buffer_Size % etl::base64::Min_Encode_Buffer_Size) == 0), "Buffer size must be a multiple of etl::base64::Min_Encode_Buffer_Size"); ETL_STATIC_ASSERT(((Buffer_Size % etl::base64::Min_Encode_Buffer_Size) == 0),
"Buffer size must be a multiple of etl::base64::Min_Encode_Buffer_Size");
//************************************************************************* //*************************************************************************
/// Base64 RFC-4648-URL constructor. /// Base64 RFC-4648-URL constructor.
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 ETL_CONSTEXPR14 base64_rfc4648_url_encoder()
base64_rfc4648_url_encoder() : ibase64_encoder(etl::base64::character_set_2(), etl::base64::Padding::No_Padding, output_buffer, Buffer_Size, callback_type())
: ibase64_encoder(etl::base64::character_set_2(),
etl::base64::Padding::No_Padding,
output_buffer,
Buffer_Size,
callback_type())
, output_buffer() , output_buffer()
{ {
} }
@ -752,13 +677,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Base64 RFC-4648-URL constructor. /// Base64 RFC-4648-URL constructor.
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 ETL_CONSTEXPR14 base64_rfc4648_url_encoder(callback_type callback_)
base64_rfc4648_url_encoder(callback_type callback_) : ibase64_encoder(etl::base64::character_set_2(), etl::base64::Padding::No_Padding, output_buffer, Buffer_Size, callback_)
: ibase64_encoder(etl::base64::character_set_2(),
etl::base64::Padding::No_Padding,
output_buffer,
Buffer_Size,
callback_)
, output_buffer() , output_buffer()
{ {
} }
@ -768,8 +688,7 @@ namespace etl
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD
static static
ETL_CONSTEXPR14 ETL_CONSTEXPR14 size_t safe_output_buffer_size(size_t input_length)
size_t safe_output_buffer_size(size_t input_length)
{ {
return ibase64_encoder::encoded_size(input_length, etl::base64::Padding::No_Padding); return ibase64_encoder::encoded_size(input_length, etl::base64::Padding::No_Padding);
} }
@ -788,19 +707,15 @@ namespace etl
{ {
public: public:
ETL_STATIC_ASSERT((Buffer_Size >= etl::base64::Min_Encode_Buffer_Size), "Buffer size must be greater than etl::base64::Min_Encode_Buffer_Size"); ETL_STATIC_ASSERT((Buffer_Size >= etl::base64::Min_Encode_Buffer_Size), "Buffer size must be greater than etl::base64::Min_Encode_Buffer_Size");
ETL_STATIC_ASSERT(((Buffer_Size% etl::base64::Min_Encode_Buffer_Size) == 0), "Buffer size must be a multiple of etl::base64::Min_Encode_Buffer_Size"); ETL_STATIC_ASSERT(((Buffer_Size % etl::base64::Min_Encode_Buffer_Size) == 0),
"Buffer size must be a multiple of etl::base64::Min_Encode_Buffer_Size");
//************************************************************************* //*************************************************************************
/// Base64 RFC-4648-URL constructor. /// Base64 RFC-4648-URL constructor.
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 ETL_CONSTEXPR14 base64_rfc4648_url_padding_encoder()
base64_rfc4648_url_padding_encoder() : ibase64_encoder(etl::base64::character_set_2(), etl::base64::Padding::Use_Padding, output_buffer, Buffer_Size, callback_type())
: ibase64_encoder(etl::base64::character_set_2(),
etl::base64::Padding::Use_Padding,
output_buffer,
Buffer_Size,
callback_type())
, output_buffer() , output_buffer()
{ {
} }
@ -808,13 +723,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Base64 RFC-4648-URL constructor. /// Base64 RFC-4648-URL constructor.
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 ETL_CONSTEXPR14 base64_rfc4648_url_padding_encoder(callback_type callback_)
base64_rfc4648_url_padding_encoder(callback_type callback_) : ibase64_encoder(etl::base64::character_set_2(), etl::base64::Padding::Use_Padding, output_buffer, Buffer_Size, callback_)
: ibase64_encoder(etl::base64::character_set_2(),
etl::base64::Padding::Use_Padding,
output_buffer,
Buffer_Size,
callback_)
, output_buffer() , output_buffer()
{ {
} }
@ -824,8 +734,7 @@ namespace etl
//************************************************************************* //*************************************************************************
ETL_NODISCARD ETL_NODISCARD
static static
ETL_CONSTEXPR14 ETL_CONSTEXPR14 size_t safe_output_buffer_size(size_t input_length)
size_t safe_output_buffer_size(size_t input_length)
{ {
return ibase64_encoder::encoded_size(input_length, etl::base64::Padding::Use_Padding); return ibase64_encoder::encoded_size(input_length, etl::base64::Padding::Use_Padding);
} }
@ -835,7 +744,7 @@ namespace etl
/// The internal output buffer. /// The internal output buffer.
char output_buffer[Buffer_Size]; char output_buffer[Buffer_Size];
}; };
} } // namespace etl
#undef ETL_IS_TYPE_8_BIT_INTEGRAL #undef ETL_IS_TYPE_8_BIT_INTEGRAL
#undef ETL_IS_ITERATOR_TYPE_8_BIT_INTEGRAL #undef ETL_IS_ITERATOR_TYPE_8_BIT_INTEGRAL

View File

@ -34,8 +34,8 @@ SOFTWARE.
///\ingroup string ///\ingroup string
#include "platform.h" #include "platform.h"
#include "type_traits.h"
#include "static_assert.h" #include "static_assert.h"
#include "type_traits.h"
#include "utility.h" #include "utility.h"
namespace etl namespace etl
@ -131,7 +131,7 @@ namespace etl
struct right_spec struct right_spec
{ {
}; };
} } // namespace private_basic_format_spec
//*************************************************************************** //***************************************************************************
// Stream formatting manipulators. // Stream formatting manipulators.
@ -222,14 +222,8 @@ namespace etl
//*************************************************************************** //***************************************************************************
/// Constructor. /// Constructor.
//*************************************************************************** //***************************************************************************
ETL_CONSTEXPR basic_format_spec(uint_least8_t base__, ETL_CONSTEXPR basic_format_spec(uint_least8_t base__, uint_least8_t width__, uint_least8_t precision__, bool upper_case__, bool left_justified__,
uint_least8_t width__, bool boolalpha__, bool show_base__, typename TString::value_type fill__) ETL_NOEXCEPT
uint_least8_t precision__,
bool upper_case__,
bool left_justified__,
bool boolalpha__,
bool show_base__,
typename TString::value_type fill__) ETL_NOEXCEPT
: base_(base__) : base_(base__)
, width_(width__) , width_(width__)
, precision_(precision__) , precision_(precision__)
@ -400,7 +394,7 @@ namespace etl
//*************************************************************************** //***************************************************************************
/// Gets the width. /// Gets the width.
//*************************************************************************** //***************************************************************************
ETL_CONSTEXPR uint32_t get_width() const ETL_NOEXCEPT ETL_CONSTEXPR uint32_t get_width() const ETL_NOEXCEPT
{ {
return width_; return width_;
} }
@ -570,36 +564,32 @@ namespace etl
//*************************************************************************** //***************************************************************************
/// Equality operator. /// Equality operator.
//*************************************************************************** //***************************************************************************
ETL_CONSTEXPR friend bool operator ==(const basic_format_spec& lhs, const basic_format_spec& rhs) ETL_CONSTEXPR friend bool operator==(const basic_format_spec& lhs, const basic_format_spec& rhs)
{ {
return (lhs.base_ == rhs.base_) && return (lhs.base_ == rhs.base_) && (lhs.width_ == rhs.width_) && (lhs.precision_ == rhs.precision_) && (lhs.upper_case_ == rhs.upper_case_)
(lhs.width_ == rhs.width_) && && (lhs.left_justified_ == rhs.left_justified_) && (lhs.boolalpha_ == rhs.boolalpha_) && (lhs.show_base_ == rhs.show_base_)
(lhs.precision_ == rhs.precision_) && && (lhs.fill_ == rhs.fill_);
(lhs.upper_case_ == rhs.upper_case_) &&
(lhs.left_justified_ == rhs.left_justified_) &&
(lhs.boolalpha_ == rhs.boolalpha_) &&
(lhs.show_base_ == rhs.show_base_) &&
(lhs.fill_ == rhs.fill_);
} }
//*************************************************************************** //***************************************************************************
/// Inequality operator. /// Inequality operator.
//*************************************************************************** //***************************************************************************
ETL_CONSTEXPR friend bool operator !=(const basic_format_spec& lhs, const basic_format_spec& rhs) ETL_CONSTEXPR friend bool operator!=(const basic_format_spec& lhs, const basic_format_spec& rhs)
{ {
return !(lhs == rhs); return !(lhs == rhs);
} }
private: private:
uint_least8_t base_;
uint_least8_t width_; uint_least8_t base_;
uint_least8_t precision_; uint_least8_t width_;
bool upper_case_; uint_least8_t precision_;
bool left_justified_; bool upper_case_;
bool boolalpha_; bool left_justified_;
bool show_base_; bool boolalpha_;
bool show_base_;
typename TString::value_type fill_; typename TString::value_type fill_;
}; };
} } // namespace etl
#endif #endif

File diff suppressed because it is too large Load Diff

View File

@ -35,9 +35,9 @@ SOFTWARE.
#include "platform.h" #include "platform.h"
#include "to_string.h" #include "to_string.h"
#include "to_u8string.h"
#include "to_u16string.h" #include "to_u16string.h"
#include "to_u32string.h" #include "to_u32string.h"
#include "to_u8string.h"
#include "to_wstring.h" #include "to_wstring.h"
namespace etl namespace etl
@ -125,16 +125,17 @@ namespace etl
//********************************* //*********************************
/// TFormat /// TFormat
//********************************* //*********************************
friend basic_string_stream& operator <<(basic_string_stream& ss, const TFormat& fmt) friend basic_string_stream& operator<<(basic_string_stream& ss, const TFormat& fmt)
{ {
ss.format = fmt; ss.format = fmt;
return ss; return ss;
} }
//********************************* //*********************************
/// etl::base_spec from etl::setbase, etl::bin, etl::oct, etl::dec & etl::hex stream manipulators /// etl::base_spec from etl::setbase, etl::bin, etl::oct, etl::dec &
/// etl::hex stream manipulators
//********************************* //*********************************
friend basic_string_stream& operator <<(basic_string_stream& ss, etl::private_basic_format_spec::base_spec fmt) friend basic_string_stream& operator<<(basic_string_stream& ss, etl::private_basic_format_spec::base_spec fmt)
{ {
ss.format.base(fmt.base); ss.format.base(fmt.base);
return ss; return ss;
@ -143,7 +144,7 @@ namespace etl
//********************************* //*********************************
/// etl::width_spec from etl::setw stream manipulator /// etl::width_spec from etl::setw stream manipulator
//********************************* //*********************************
friend basic_string_stream& operator <<(basic_string_stream& ss, etl::private_basic_format_spec::width_spec fmt) friend basic_string_stream& operator<<(basic_string_stream& ss, etl::private_basic_format_spec::width_spec fmt)
{ {
ss.format.width(fmt.width); ss.format.width(fmt.width);
return ss; return ss;
@ -153,7 +154,7 @@ namespace etl
/// etl::fill_spec from etl::setfill stream manipulator /// etl::fill_spec from etl::setfill stream manipulator
//********************************* //*********************************
template <typename TChar> template <typename TChar>
friend basic_string_stream& operator <<(basic_string_stream& ss, etl::private_basic_format_spec::fill_spec<TChar> fmt) friend basic_string_stream& operator<<(basic_string_stream& ss, etl::private_basic_format_spec::fill_spec<TChar> fmt)
{ {
ss.format.fill(fmt.fill); ss.format.fill(fmt.fill);
return ss; return ss;
@ -162,34 +163,37 @@ namespace etl
//********************************* //*********************************
/// etl::precision_spec from etl::setprecision stream manipulator /// etl::precision_spec from etl::setprecision stream manipulator
//********************************* //*********************************
friend basic_string_stream& operator <<(basic_string_stream& ss, etl::private_basic_format_spec::precision_spec fmt) friend basic_string_stream& operator<<(basic_string_stream& ss, etl::private_basic_format_spec::precision_spec fmt)
{ {
ss.format.precision(fmt.precision); ss.format.precision(fmt.precision);
return ss; return ss;
} }
//********************************* //*********************************
/// etl::boolalpha_spec from etl::boolalpha & etl::noboolalpha stream manipulators /// etl::boolalpha_spec from etl::boolalpha & etl::noboolalpha stream
/// manipulators
//********************************* //*********************************
friend basic_string_stream& operator <<(basic_string_stream& ss, etl::private_basic_format_spec::boolalpha_spec fmt) friend basic_string_stream& operator<<(basic_string_stream& ss, etl::private_basic_format_spec::boolalpha_spec fmt)
{ {
ss.format.boolalpha(fmt.boolalpha); ss.format.boolalpha(fmt.boolalpha);
return ss; return ss;
} }
//********************************* //*********************************
/// etl::uppercase_spec from etl::uppercase & etl::nouppercase stream manipulators /// etl::uppercase_spec from etl::uppercase & etl::nouppercase stream
/// manipulators
//********************************* //*********************************
friend basic_string_stream& operator <<(basic_string_stream& ss, etl::private_basic_format_spec::uppercase_spec fmt) friend basic_string_stream& operator<<(basic_string_stream& ss, etl::private_basic_format_spec::uppercase_spec fmt)
{ {
ss.format.upper_case(fmt.upper_case); ss.format.upper_case(fmt.upper_case);
return ss; return ss;
} }
//********************************* //*********************************
/// etl::showbase_spec from etl::showbase & etl::noshowbase stream manipulators /// etl::showbase_spec from etl::showbase & etl::noshowbase stream
/// manipulators
//********************************* //*********************************
friend basic_string_stream& operator <<(basic_string_stream& ss, etl::private_basic_format_spec::showbase_spec fmt) friend basic_string_stream& operator<<(basic_string_stream& ss, etl::private_basic_format_spec::showbase_spec fmt)
{ {
ss.format.show_base(fmt.show_base); ss.format.show_base(fmt.show_base);
return ss; return ss;
@ -198,7 +202,7 @@ namespace etl
//********************************* //*********************************
/// etl::left_spec from etl::left stream manipulator /// etl::left_spec from etl::left stream manipulator
//********************************* //*********************************
friend basic_string_stream& operator <<(basic_string_stream& ss, etl::private_basic_format_spec::left_spec /*fmt*/) friend basic_string_stream& operator<<(basic_string_stream& ss, etl::private_basic_format_spec::left_spec /*fmt*/)
{ {
ss.format.left(); ss.format.left();
return ss; return ss;
@ -207,7 +211,7 @@ namespace etl
//********************************* //*********************************
/// etl::right_spec from etl::left stream manipulator /// etl::right_spec from etl::left stream manipulator
//********************************* //*********************************
friend basic_string_stream& operator <<(basic_string_stream& ss, etl::private_basic_format_spec::right_spec /*fmt*/) friend basic_string_stream& operator<<(basic_string_stream& ss, etl::private_basic_format_spec::right_spec /*fmt*/)
{ {
ss.format.right(); ss.format.right();
return ss; return ss;
@ -216,7 +220,7 @@ namespace etl
//********************************* //*********************************
/// From a string view /// From a string view
//********************************* //*********************************
friend basic_string_stream& operator <<(basic_string_stream& ss, TStringView view) friend basic_string_stream& operator<<(basic_string_stream& ss, TStringView view)
{ {
etl::to_string(view, ss.text, ss.format, true); etl::to_string(view, ss.text, ss.format, true);
return ss; return ss;
@ -225,7 +229,7 @@ namespace etl
//********************************* //*********************************
/// From a character pointer to a string /// From a character pointer to a string
//********************************* //*********************************
friend basic_string_stream& operator <<(basic_string_stream& ss, pointer p) friend basic_string_stream& operator<<(basic_string_stream& ss, pointer p)
{ {
TStringView view(p); TStringView view(p);
ss << view; ss << view;
@ -235,7 +239,7 @@ namespace etl
//********************************* //*********************************
/// From a const character pointer to a string /// From a const character pointer to a string
//********************************* //*********************************
friend basic_string_stream& operator <<(basic_string_stream& ss, const_pointer p) friend basic_string_stream& operator<<(basic_string_stream& ss, const_pointer p)
{ {
TStringView view(p); TStringView view(p);
ss << view; ss << view;
@ -245,7 +249,7 @@ namespace etl
//********************************* //*********************************
/// From a string interface /// From a string interface
//********************************* //*********************************
friend basic_string_stream& operator <<(basic_string_stream& ss, const TIString& t) friend basic_string_stream& operator<<(basic_string_stream& ss, const TIString& t)
{ {
etl::to_string(t, ss.text, ss.format, true); etl::to_string(t, ss.text, ss.format, true);
return ss; return ss;
@ -255,7 +259,7 @@ namespace etl
/// From a string /// From a string
//********************************* //*********************************
template <template <size_t> class TString, size_t SIZE> template <template <size_t> class TString, size_t SIZE>
friend basic_string_stream& operator <<(basic_string_stream& ss, const TString<SIZE>& t) friend basic_string_stream& operator<<(basic_string_stream& ss, const TString<SIZE>& t)
{ {
const TIString& itext = t; const TIString& itext = t;
etl::to_string(itext, ss.str(), ss.get_format(), true); etl::to_string(itext, ss.str(), ss.get_format(), true);
@ -266,7 +270,7 @@ namespace etl
/// From anything else /// From anything else
//********************************* //*********************************
template <typename T> template <typename T>
friend basic_string_stream& operator <<(basic_string_stream& ss, const T& value) friend basic_string_stream& operator<<(basic_string_stream& ss, const T& value)
{ {
etl::to_string(value, ss.text, ss.format, true); etl::to_string(value, ss.text, ss.format, true);
return ss; return ss;
@ -278,8 +282,8 @@ namespace etl
TFormat format; TFormat format;
basic_string_stream(const basic_string_stream&) ETL_DELETE; basic_string_stream(const basic_string_stream&) ETL_DELETE;
basic_string_stream& operator =(const basic_string_stream&) ETL_DELETE; basic_string_stream& operator=(const basic_string_stream&) ETL_DELETE;
}; };
} } // namespace etl
#endif #endif

View File

@ -36,16 +36,16 @@ SOFTWARE.
///\ingroup utilities ///\ingroup utilities
#include "platform.h" #include "platform.h"
#include "type_traits.h" #include "error_handler.h"
#include "exception.h"
#include "functional.h"
#include "integral_limits.h" #include "integral_limits.h"
#include "limits.h" #include "limits.h"
#include "static_assert.h"
#include "log.h" #include "log.h"
#include "power.h" #include "power.h"
#include "smallest.h" #include "smallest.h"
#include "exception.h" #include "static_assert.h"
#include "error_handler.h" #include "type_traits.h"
#include "functional.h"
#if ETL_USING_CPP20 && ETL_USING_STL #if ETL_USING_CPP20 && ETL_USING_STL
#include <bit> #include <bit>
@ -90,7 +90,7 @@ namespace etl
struct max_value_for_nbits struct max_value_for_nbits
{ {
typedef typename etl::smallest_uint_for_bits<NBits>::type value_type; typedef typename etl::smallest_uint_for_bits<NBits>::type value_type;
static ETL_CONSTANT value_type value = (value_type(1) << (NBits - 1)) | max_value_for_nbits<NBits - 1>::value; static ETL_CONSTANT value_type value = (value_type(1) << (NBits - 1)) | max_value_for_nbits<NBits - 1>::value;
}; };
/// Specialisation for when NBits == 0. /// Specialisation for when NBits == 0.
@ -98,7 +98,7 @@ namespace etl
struct max_value_for_nbits<0> struct max_value_for_nbits<0>
{ {
typedef etl::smallest_uint_for_bits<0>::type value_type; typedef etl::smallest_uint_for_bits<0>::type value_type;
static ETL_CONSTANT value_type value = 0; static ETL_CONSTANT value_type value = 0;
}; };
template <size_t NBits> template <size_t NBits>
@ -244,7 +244,7 @@ namespace etl
{ {
ETL_STATIC_ASSERT(integral_limits<TReturn>::bits >= NBits, "Return type too small to hold result"); ETL_STATIC_ASSERT(integral_limits<TReturn>::bits >= NBits, "Return type too small to hold result");
ETL_CONSTANT TValue mask = etl::power<2, NBits>::value - 1U; ETL_CONSTANT TValue mask = etl::power<2, NBits>::value - 1U;
ETL_CONSTANT size_t shift = NBits; ETL_CONSTANT size_t shift = NBits;
// Fold the value down to fit the width. // Fold the value down to fit the width.
@ -265,13 +265,14 @@ namespace etl
//*************************************************************************** //***************************************************************************
/// Sign extend. /// Sign extend.
/// Converts an N bit binary number, where bit N-1 is the sign bit, to a signed integral type. /// Converts an N bit binary number, where bit N-1 is the sign bit, to a
/// signed integral type.
///\ingroup binary ///\ingroup binary
//*************************************************************************** //***************************************************************************
template <typename TReturn, size_t NBits, typename TValue> template <typename TReturn, size_t NBits, typename TValue>
ETL_CONSTEXPR14 TReturn sign_extend(TValue value) ETL_CONSTEXPR14 TReturn sign_extend(TValue value)
{ {
ETL_STATIC_ASSERT(etl::is_integral<TValue>::value, "TValue not an integral type"); ETL_STATIC_ASSERT(etl::is_integral<TValue>::value, "TValue not an integral type");
ETL_STATIC_ASSERT(etl::is_integral<TReturn>::value, "TReturn not an integral type"); ETL_STATIC_ASSERT(etl::is_integral<TReturn>::value, "TReturn not an integral type");
ETL_STATIC_ASSERT(NBits <= etl::integral_limits<TReturn>::bits, "NBits too large for return type"); ETL_STATIC_ASSERT(NBits <= etl::integral_limits<TReturn>::bits, "NBits too large for return type");
@ -292,7 +293,7 @@ namespace etl
template <typename TReturn, size_t NBits, size_t SHIFT, typename TValue> template <typename TReturn, size_t NBits, size_t SHIFT, typename TValue>
ETL_CONSTEXPR14 TReturn sign_extend(TValue value) ETL_CONSTEXPR14 TReturn sign_extend(TValue value)
{ {
ETL_STATIC_ASSERT(etl::is_integral<TValue>::value, "TValue not an integral type"); ETL_STATIC_ASSERT(etl::is_integral<TValue>::value, "TValue not an integral type");
ETL_STATIC_ASSERT(etl::is_integral<TReturn>::value, "TReturn not an integral type"); ETL_STATIC_ASSERT(etl::is_integral<TReturn>::value, "TReturn not an integral type");
ETL_STATIC_ASSERT(NBits <= etl::integral_limits<TReturn>::bits, "NBits too large for return type"); ETL_STATIC_ASSERT(NBits <= etl::integral_limits<TReturn>::bits, "NBits too large for return type");
ETL_STATIC_ASSERT(SHIFT <= etl::integral_limits<TReturn>::bits, "SHIFT too large"); ETL_STATIC_ASSERT(SHIFT <= etl::integral_limits<TReturn>::bits, "SHIFT too large");
@ -307,19 +308,20 @@ namespace etl
//*************************************************************************** //***************************************************************************
/// Sign extend. /// Sign extend.
/// Converts an N bit binary number, where bit N-1 is the sign bit, to a signed integral type. /// Converts an N bit binary number, where bit N-1 is the sign bit, to a
/// signed integral type.
///\ingroup binary ///\ingroup binary
//*************************************************************************** //***************************************************************************
template <typename TReturn, typename TValue> template <typename TReturn, typename TValue>
ETL_CONSTEXPR14 TReturn sign_extend(TValue value, size_t NBits) ETL_CONSTEXPR14 TReturn sign_extend(TValue value, size_t NBits)
{ {
ETL_STATIC_ASSERT(etl::is_integral<TValue>::value, "TValue not an integral type"); ETL_STATIC_ASSERT(etl::is_integral<TValue>::value, "TValue not an integral type");
ETL_STATIC_ASSERT(etl::is_integral<TReturn>::value, "TReturn not an integral type"); ETL_STATIC_ASSERT(etl::is_integral<TReturn>::value, "TReturn not an integral type");
ETL_ASSERT((NBits <= etl::integral_limits<TReturn>::bits), ETL_ERROR(binary_out_of_range)); ETL_ASSERT((NBits <= etl::integral_limits<TReturn>::bits), ETL_ERROR(binary_out_of_range));
TReturn mask = TReturn(1) << (NBits - 1); TReturn mask = TReturn(1) << (NBits - 1);
value = value & TValue((TValue(1) << NBits) - 1); value = value & TValue((TValue(1) << NBits) - 1);
return static_cast<TReturn>(static_cast<TReturn>(value ^ static_cast<TValue>(mask)) - mask); return static_cast<TReturn>(static_cast<TReturn>(value ^ static_cast<TValue>(mask)) - mask);
} }
@ -333,13 +335,13 @@ namespace etl
template <typename TReturn, typename TValue> template <typename TReturn, typename TValue>
ETL_CONSTEXPR14 TReturn sign_extend(TValue value, size_t NBits, size_t SHIFT) ETL_CONSTEXPR14 TReturn sign_extend(TValue value, size_t NBits, size_t SHIFT)
{ {
ETL_STATIC_ASSERT(etl::is_integral<TValue>::value, "TValue not an integral type"); ETL_STATIC_ASSERT(etl::is_integral<TValue>::value, "TValue not an integral type");
ETL_STATIC_ASSERT(etl::is_integral<TReturn>::value, "TReturn not an integral type"); ETL_STATIC_ASSERT(etl::is_integral<TReturn>::value, "TReturn not an integral type");
ETL_ASSERT((NBits <= etl::integral_limits<TReturn>::bits), ETL_ERROR(binary_out_of_range)); ETL_ASSERT((NBits <= etl::integral_limits<TReturn>::bits), ETL_ERROR(binary_out_of_range));
TReturn mask = TReturn(1) << (NBits - 1); TReturn mask = TReturn(1) << (NBits - 1);
value = (value >> SHIFT) & TValue((TValue(1) << NBits) - 1); value = (value >> SHIFT) & TValue((TValue(1) << NBits) - 1);
return static_cast<TReturn>(static_cast<TReturn>(value ^ static_cast<TValue>(mask)) - mask); return static_cast<TReturn>(static_cast<TReturn>(value ^ static_cast<TValue>(mask)) - mask);
} }
@ -353,7 +355,7 @@ namespace etl
struct bit struct bit
{ {
typedef typename etl::smallest_uint_for_bits<POSITION + 1U>::type value_type; typedef typename etl::smallest_uint_for_bits<POSITION + 1U>::type value_type;
static ETL_CONSTANT value_type value = value_type(1) << POSITION; static ETL_CONSTANT value_type value = value_type(1) << POSITION;
}; };
template <size_t POSITION> template <size_t POSITION>
@ -409,7 +411,7 @@ namespace etl
{ {
typedef typename etl::make_unsigned<TValue>::type unsigned_t; typedef typename etl::make_unsigned<TValue>::type unsigned_t;
ETL_CONSTEXPR14 const unsigned_t mask = etl::binary_fill<unsigned_t, uint8_t>(0x7FU); ETL_CONSTEXPR14 const unsigned_t mask = etl::binary_fill<unsigned_t, uint8_t>(0x7FU);
const unsigned_t temp = unsigned_t(~((((unsigned_t(value) & mask) + mask) | unsigned_t(value)) | mask)); const unsigned_t temp = unsigned_t(~((((unsigned_t(value) & mask) + mask) | unsigned_t(value)) | mask));
return (temp != 0U); return (temp != 0U);
} }
@ -423,7 +425,7 @@ namespace etl
{ {
typedef typename etl::make_unsigned<TValue>::type unsigned_t; typedef typename etl::make_unsigned<TValue>::type unsigned_t;
ETL_CONSTEXPR14 const unsigned_t mask = etl::binary_fill<unsigned_t, uint8_t>(0x7FU); ETL_CONSTEXPR14 const unsigned_t mask = etl::binary_fill<unsigned_t, uint8_t>(0x7FU);
const unsigned_t temp = unsigned_t(~((((unsigned_t(Value) & mask) + mask) | unsigned_t(Value)) | mask)); const unsigned_t temp = unsigned_t(~((((unsigned_t(Value) & mask) + mask) | unsigned_t(Value)) | mask));
return (temp != 0U); return (temp != 0U);
} }
@ -486,8 +488,7 @@ namespace etl
///\ingroup binary ///\ingroup binary
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
ETL_CONSTEXPR14 ETL_CONSTEXPR14 typename etl::enable_if< etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 8U), T>::type
typename etl::enable_if<etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 8U), T>::type
reverse_bits(T value) reverse_bits(T value)
{ {
value = ((value & 0xAAU) >> 1U) | ((value & 0x55U) << 1U); value = ((value & 0xAAU) >> 1U) | ((value & 0x55U) << 1U);
@ -503,7 +504,7 @@ namespace etl
{ {
private: private:
static ETL_CONSTANT uint8_t value1 = uint8_t(((Value & 0xAAU) >> 1U) | ((Value & 0x55U) << 1U)); static ETL_CONSTANT uint8_t value1 = uint8_t(((Value & 0xAAU) >> 1U) | ((Value & 0x55U) << 1U));
static ETL_CONSTANT uint8_t value2 = uint8_t(((value1 & 0xCCU) >> 2U) | ((value1 & 0x33U) << 2U)); static ETL_CONSTANT uint8_t value2 = uint8_t(((value1 & 0xCCU) >> 2U) | ((value1 & 0x33U) << 2U));
public: public:
@ -537,8 +538,7 @@ namespace etl
///\ingroup binary ///\ingroup binary
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
ETL_CONSTEXPR14 ETL_CONSTEXPR14 typename etl::enable_if< etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 16U), T>::type
typename etl::enable_if<etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 16U), T>::type
reverse_bits(T value) reverse_bits(T value)
{ {
value = ((value & 0xAAAAU) >> 1U) | ((value & 0x5555U) << 1U); value = ((value & 0xAAAAU) >> 1U) | ((value & 0x5555U) << 1U);
@ -555,7 +555,7 @@ namespace etl
{ {
private: private:
static ETL_CONSTANT uint16_t value1 = uint16_t(((Value & 0xAAAAU) >> 1U) | ((Value & 0x5555U) << 1U)); static ETL_CONSTANT uint16_t value1 = uint16_t(((Value & 0xAAAAU) >> 1U) | ((Value & 0x5555U) << 1U));
static ETL_CONSTANT uint16_t value2 = uint16_t(((value1 & 0xCCCCU) >> 2U) | ((value1 & 0x3333U) << 2U)); static ETL_CONSTANT uint16_t value2 = uint16_t(((value1 & 0xCCCCU) >> 2U) | ((value1 & 0x3333U) << 2U));
static ETL_CONSTANT uint16_t value3 = uint16_t(((value2 & 0xF0F0U) >> 4U) | ((value2 & 0x0F0FU) << 4U)); static ETL_CONSTANT uint16_t value3 = uint16_t(((value2 & 0xF0F0U) >> 4U) | ((value2 & 0x0F0FU) << 4U));
@ -574,8 +574,10 @@ namespace etl
private: private:
static ETL_CONSTANT int16_t value1 = int16_t(((static_cast<uint16_t>(Value) & 0xAAAAU) >> 1U) | ((static_cast<uint16_t>(Value) & 0x5555U) << 1U)); static ETL_CONSTANT int16_t value1 = int16_t(((static_cast<uint16_t>(Value) & 0xAAAAU) >> 1U) | ((static_cast<uint16_t>(Value) & 0x5555U) << 1U));
static ETL_CONSTANT int16_t value2 = int16_t(((static_cast<uint16_t>(value1) & 0xCCCCU) >> 2U) | ((static_cast<uint16_t>(value1) & 0x3333U) << 2U)); static
static ETL_CONSTANT int16_t value3 = int16_t(((static_cast<uint16_t>(value2) & 0xF0F0U) >> 4U) | ((static_cast<uint16_t>(value2) & 0x0F0FU) << 4U)); ETL_CONSTANT int16_t value2 = int16_t(((static_cast<uint16_t>(value1) & 0xCCCCU) >> 2U) | ((static_cast<uint16_t>(value1) & 0x3333U) << 2U));
static
ETL_CONSTANT int16_t value3 = int16_t(((static_cast<uint16_t>(value2) & 0xF0F0U) >> 4U) | ((static_cast<uint16_t>(value2) & 0x0F0FU) << 4U));
public: public:
@ -590,14 +592,13 @@ namespace etl
///\ingroup binary ///\ingroup binary
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
ETL_CONSTEXPR14 ETL_CONSTEXPR14 typename etl::enable_if< etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 32U), T>::type
typename etl::enable_if<etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 32U), T>::type
reverse_bits(T value) reverse_bits(T value)
{ {
value = ((value & 0xAAAAAAAAUL) >> 1U) | ((value & 0x55555555UL) << 1U); value = ((value & 0xAAAAAAAAUL) >> 1U) | ((value & 0x55555555UL) << 1U);
value = ((value & 0xCCCCCCCCUL) >> 2U) | ((value & 0x33333333UL) << 2U); value = ((value & 0xCCCCCCCCUL) >> 2U) | ((value & 0x33333333UL) << 2U);
value = ((value & 0xF0F0F0F0UL) >> 4U) | ((value & 0x0F0F0F0FUL) << 4U); value = ((value & 0xF0F0F0F0UL) >> 4U) | ((value & 0x0F0F0F0FUL) << 4U);
value = ((value & 0xFF00FF00UL) >> 8U) | ((value & 0x00FF00FFUL) << 8U); value = ((value & 0xFF00FF00UL) >> 8U) | ((value & 0x00FF00FFUL) << 8U);
value = (value >> 16U) | ((value & 0xFFFFU) << 16U); value = (value >> 16U) | ((value & 0xFFFFU) << 16U);
return value; return value;
@ -609,10 +610,10 @@ namespace etl
{ {
private: private:
static ETL_CONSTANT uint32_t value1 = uint32_t(((Value & 0xAAAAAAAAUL) >> 1U) | ((Value & 0x55555555UL) << 1U)); static ETL_CONSTANT uint32_t value1 = uint32_t(((Value & 0xAAAAAAAAUL) >> 1U) | ((Value & 0x55555555UL) << 1U));
static ETL_CONSTANT uint32_t value2 = uint32_t(((value1 & 0xCCCCCCCCUL) >> 2U) | ((value1 & 0x33333333UL) << 2U)); static ETL_CONSTANT uint32_t value2 = uint32_t(((value1 & 0xCCCCCCCCUL) >> 2U) | ((value1 & 0x33333333UL) << 2U));
static ETL_CONSTANT uint32_t value3 = uint32_t(((value2 & 0xF0F0F0F0UL) >> 4U) | ((value2 & 0x0F0F0F0FUL) << 4U)); static ETL_CONSTANT uint32_t value3 = uint32_t(((value2 & 0xF0F0F0F0UL) >> 4U) | ((value2 & 0x0F0F0F0FUL) << 4U));
static ETL_CONSTANT uint32_t value4 = uint32_t(((value3 & 0xFF00FF00UL) >> 8U) | ((value3 & 0x00FF00FFUL) << 8U)); static ETL_CONSTANT uint32_t value4 = uint32_t(((value3 & 0xFF00FF00UL) >> 8U) | ((value3 & 0x00FF00FFUL) << 8U));
public: public:
@ -628,10 +629,14 @@ namespace etl
{ {
private: private:
static ETL_CONSTANT int32_t value1 = int32_t(((static_cast<uint32_t>(Value) & 0xAAAAAAAAUL) >> 1U) | ((static_cast<uint32_t>(Value) & 0x55555555UL) << 1U)); static ETL_CONSTANT int32_t value1 =
static ETL_CONSTANT int32_t value2 = int32_t(((static_cast<uint32_t>(value1) & 0xCCCCCCCCUL) >> 2U) | ((static_cast<uint32_t>(value1) & 0x33333333UL) << 2U)); int32_t(((static_cast<uint32_t>(Value) & 0xAAAAAAAAUL) >> 1U) | ((static_cast<uint32_t>(Value) & 0x55555555UL) << 1U));
static ETL_CONSTANT int32_t value3 = int32_t(((static_cast<uint32_t>(value2) & 0xF0F0F0F0UL) >> 4U) | ((static_cast<uint32_t>(value2) & 0x0F0F0F0FUL) << 4U)); static ETL_CONSTANT int32_t value2 =
static ETL_CONSTANT int32_t value4 = int32_t(((static_cast<uint32_t>(value3) & 0xFF00FF00UL) >> 8U) | ((static_cast<uint32_t>(value3) & 0x00FF00FFUL) << 8U)); int32_t(((static_cast<uint32_t>(value1) & 0xCCCCCCCCUL) >> 2U) | ((static_cast<uint32_t>(value1) & 0x33333333UL) << 2U));
static ETL_CONSTANT int32_t value3 =
int32_t(((static_cast<uint32_t>(value2) & 0xF0F0F0F0UL) >> 4U) | ((static_cast<uint32_t>(value2) & 0x0F0F0F0FUL) << 4U));
static ETL_CONSTANT int32_t value4 =
int32_t(((static_cast<uint32_t>(value3) & 0xFF00FF00UL) >> 8U) | ((static_cast<uint32_t>(value3) & 0x00FF00FFUL) << 8U));
public: public:
@ -647,14 +652,13 @@ namespace etl
///\ingroup binary ///\ingroup binary
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
ETL_CONSTEXPR14 ETL_CONSTEXPR14 typename etl::enable_if< etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 64U), T>::type
typename etl::enable_if<etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 64U), T>::type
reverse_bits(T value) reverse_bits(T value)
{ {
value = ((value & 0xAAAAAAAAAAAAAAAAULL) >> 1U) | ((value & 0x5555555555555555ULL) << 1U); value = ((value & 0xAAAAAAAAAAAAAAAAULL) >> 1U) | ((value & 0x5555555555555555ULL) << 1U);
value = ((value & 0xCCCCCCCCCCCCCCCCULL) >> 2U) | ((value & 0x3333333333333333ULL) << 2U); value = ((value & 0xCCCCCCCCCCCCCCCCULL) >> 2U) | ((value & 0x3333333333333333ULL) << 2U);
value = ((value & 0xF0F0F0F0F0F0F0F0ULL) >> 4U) | ((value & 0x0F0F0F0F0F0F0F0FULL) << 4U); value = ((value & 0xF0F0F0F0F0F0F0F0ULL) >> 4U) | ((value & 0x0F0F0F0F0F0F0F0FULL) << 4U);
value = ((value & 0xFF00FF00FF00FF00ULL) >> 8U) | ((value & 0x00FF00FF00FF00FFULL) << 8U); value = ((value & 0xFF00FF00FF00FF00ULL) >> 8U) | ((value & 0x00FF00FF00FF00FFULL) << 8U);
value = ((value & 0xFFFF0000FFFF0000ULL) >> 16U) | ((value & 0x0000FFFF0000FFFFULL) << 16U); value = ((value & 0xFFFF0000FFFF0000ULL) >> 16U) | ((value & 0x0000FFFF0000FFFFULL) << 16U);
value = (value >> 32U) | ((value & 0xFFFFFFFFULL) << 32U); value = (value >> 32U) | ((value & 0xFFFFFFFFULL) << 32U);
@ -667,10 +671,10 @@ namespace etl
{ {
private: private:
static ETL_CONSTANT uint64_t value1 = uint64_t(((Value & 0xAAAAAAAAAAAAAAAAULL) >> 1U) | ((Value & 0x5555555555555555ULL) << 1U)); static ETL_CONSTANT uint64_t value1 = uint64_t(((Value & 0xAAAAAAAAAAAAAAAAULL) >> 1U) | ((Value & 0x5555555555555555ULL) << 1U));
static ETL_CONSTANT uint64_t value2 = uint64_t(((value1 & 0xCCCCCCCCCCCCCCCCULL) >> 2U) | ((value1 & 0x3333333333333333ULL) << 2U)); static ETL_CONSTANT uint64_t value2 = uint64_t(((value1 & 0xCCCCCCCCCCCCCCCCULL) >> 2U) | ((value1 & 0x3333333333333333ULL) << 2U));
static ETL_CONSTANT uint64_t value3 = uint64_t(((value2 & 0xF0F0F0F0F0F0F0F0ULL) >> 4U) | ((value2 & 0x0F0F0F0F0F0F0F0FULL) << 4U)); static ETL_CONSTANT uint64_t value3 = uint64_t(((value2 & 0xF0F0F0F0F0F0F0F0ULL) >> 4U) | ((value2 & 0x0F0F0F0F0F0F0F0FULL) << 4U));
static ETL_CONSTANT uint64_t value4 = uint64_t(((value3 & 0xFF00FF00FF00FF00ULL) >> 8U) | ((value3 & 0x00FF00FF00FF00FFULL) << 8U)); static ETL_CONSTANT uint64_t value4 = uint64_t(((value3 & 0xFF00FF00FF00FF00ULL) >> 8U) | ((value3 & 0x00FF00FF00FF00FFULL) << 8U));
static ETL_CONSTANT uint64_t value5 = uint64_t(((value4 & 0xFFFF0000FFFF0000ULL) >> 16U) | ((value4 & 0x0000FFFF0000FFFFULL) << 16U)); static ETL_CONSTANT uint64_t value5 = uint64_t(((value4 & 0xFFFF0000FFFF0000ULL) >> 16U) | ((value4 & 0x0000FFFF0000FFFFULL) << 16U));
public: public:
@ -687,11 +691,16 @@ namespace etl
{ {
private: private:
static ETL_CONSTANT int64_t value1 = int64_t(((static_cast<uint64_t>(Value) & 0xAAAAAAAAAAAAAAAAULL) >> 1U) | ((static_cast<uint64_t>(Value) & 0x5555555555555555ULL) << 1U)); static ETL_CONSTANT int64_t value1 =
static ETL_CONSTANT int64_t value2 = int64_t(((static_cast<uint64_t>(value1) & 0xCCCCCCCCCCCCCCCCULL) >> 2U) | ((static_cast<uint64_t>(value1) & 0x3333333333333333ULL) << 2U)); int64_t(((static_cast<uint64_t>(Value) & 0xAAAAAAAAAAAAAAAAULL) >> 1U) | ((static_cast<uint64_t>(Value) & 0x5555555555555555ULL) << 1U));
static ETL_CONSTANT int64_t value3 = int64_t(((static_cast<uint64_t>(value2) & 0xF0F0F0F0F0F0F0F0ULL) >> 4U) | ((static_cast<uint64_t>(value2) & 0x0F0F0F0F0F0F0F0FULL) << 4U)); static ETL_CONSTANT int64_t value2 =
static ETL_CONSTANT int64_t value4 = int64_t(((static_cast<uint64_t>(value3) & 0xFF00FF00FF00FF00ULL) >> 8U) | ((static_cast<uint64_t>(value3) & 0x00FF00FF00FF00FFULL) << 8U)); int64_t(((static_cast<uint64_t>(value1) & 0xCCCCCCCCCCCCCCCCULL) >> 2U) | ((static_cast<uint64_t>(value1) & 0x3333333333333333ULL) << 2U));
static ETL_CONSTANT int64_t value5 = int64_t(((static_cast<uint64_t>(value4) & 0xFFFF0000FFFF0000ULL) >> 16U) | ((static_cast<uint64_t>(value4) & 0x0000FFFF0000FFFFULL) << 16U)); static ETL_CONSTANT int64_t value3 =
int64_t(((static_cast<uint64_t>(value2) & 0xF0F0F0F0F0F0F0F0ULL) >> 4U) | ((static_cast<uint64_t>(value2) & 0x0F0F0F0F0F0F0F0FULL) << 4U));
static ETL_CONSTANT int64_t value4 =
int64_t(((static_cast<uint64_t>(value3) & 0xFF00FF00FF00FF00ULL) >> 8U) | ((static_cast<uint64_t>(value3) & 0x00FF00FF00FF00FFULL) << 8U));
static ETL_CONSTANT int64_t value5 =
int64_t(((static_cast<uint64_t>(value4) & 0xFFFF0000FFFF0000ULL) >> 16U) | ((static_cast<uint64_t>(value4) & 0x0000FFFF0000FFFFULL) << 16U));
public: public:
@ -707,9 +716,7 @@ namespace etl
///\ingroup binary ///\ingroup binary
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
ETL_CONSTEXPR14 ETL_CONSTEXPR14 typename etl::enable_if< etl::is_integral<T>::value && etl::is_signed<T>::value, T>::type reverse_bits(T value)
typename etl::enable_if<etl::is_integral<T>::value && etl::is_signed<T>::value, T>::type
reverse_bits(T value)
{ {
typedef typename etl::make_unsigned<T>::type unsigned_t; typedef typename etl::make_unsigned<T>::type unsigned_t;
@ -722,8 +729,7 @@ namespace etl
//*************************************************************************** //***************************************************************************
#if ETL_USING_8BIT_TYPES #if ETL_USING_8BIT_TYPES
template <typename T> template <typename T>
ETL_CONSTEXPR14 ETL_CONSTEXPR14 typename etl::enable_if< etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 8U), T>::type
typename etl::enable_if<etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 8U), T>::type
reverse_bytes(T value) reverse_bytes(T value)
{ {
return value; return value;
@ -735,8 +741,7 @@ namespace etl
///\ingroup binary ///\ingroup binary
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
ETL_CONSTEXPR14 ETL_CONSTEXPR14 typename etl::enable_if< etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 16U), T>::type
typename etl::enable_if<etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 16U), T>::type
reverse_bytes(T value) reverse_bytes(T value)
{ {
#if ETL_CPP23_SUPPORTED && ETL_USING_STL && ETL_HAS_STD_BYTESWAP #if ETL_CPP23_SUPPORTED && ETL_USING_STL && ETL_HAS_STD_BYTESWAP
@ -751,8 +756,7 @@ namespace etl
///\ingroup binary ///\ingroup binary
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
ETL_CONSTEXPR14 ETL_CONSTEXPR14 typename etl::enable_if< etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 32U), T>::type
typename etl::enable_if<etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 32U), T>::type
reverse_bytes(T value) reverse_bytes(T value)
{ {
#if ETL_CPP23_SUPPORTED && ETL_USING_STL && ETL_HAS_STD_BYTESWAP #if ETL_CPP23_SUPPORTED && ETL_USING_STL && ETL_HAS_STD_BYTESWAP
@ -771,19 +775,18 @@ namespace etl
///\ingroup binary ///\ingroup binary
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
ETL_CONSTEXPR14 ETL_CONSTEXPR14 typename etl::enable_if< etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 64U), T>::type
typename etl::enable_if<etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 64U), T>::type
reverse_bytes(T value) reverse_bytes(T value)
{ {
#if ETL_CPP23_SUPPORTED && ETL_USING_STL && ETL_HAS_STD_BYTESWAP #if ETL_CPP23_SUPPORTED && ETL_USING_STL && ETL_HAS_STD_BYTESWAP
return std::byteswap(value); return std::byteswap(value);
#else #else
value = ((value & 0xFF00FF00FF00FF00ULL) >> 8U) | ((value & 0x00FF00FF00FF00FFULL) << 8U); value = ((value & 0xFF00FF00FF00FF00ULL) >> 8U) | ((value & 0x00FF00FF00FF00FFULL) << 8U);
value = ((value & 0xFFFF0000FFFF0000ULL) >> 16U) | ((value & 0x0000FFFF0000FFFFULL) << 16U); value = ((value & 0xFFFF0000FFFF0000ULL) >> 16U) | ((value & 0x0000FFFF0000FFFFULL) << 16U);
value = (value >> 32U) | (value << 32U); value = (value >> 32U) | (value << 32U);
return value; return value;
#endif #endif
} }
#endif #endif
@ -792,9 +795,7 @@ namespace etl
///\ingroup binary ///\ingroup binary
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
ETL_CONSTEXPR14 ETL_CONSTEXPR14 typename etl::enable_if< etl::is_integral<T>::value && etl::is_signed<T>::value, T>::type reverse_bytes(T value)
typename etl::enable_if<etl::is_integral<T>::value && etl::is_signed<T>::value, T>::type
reverse_bytes(T value)
{ {
typedef typename etl::make_unsigned<T>::type unsigned_t; typedef typename etl::make_unsigned<T>::type unsigned_t;
@ -807,8 +808,7 @@ namespace etl
///\ingroup binary ///\ingroup binary
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
ETL_CONSTEXPR14 ETL_CONSTEXPR14 typename etl::enable_if< etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 8U), T>::type
typename etl::enable_if<etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 8U), T>::type
gray_to_binary(T value) gray_to_binary(T value)
{ {
value ^= (value >> 4U); value ^= (value >> 4U);
@ -824,8 +824,7 @@ namespace etl
///\ingroup binary ///\ingroup binary
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
ETL_CONSTEXPR14 ETL_CONSTEXPR14 typename etl::enable_if< etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 16U), T>::type
typename etl::enable_if<etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 16U), T>::type
gray_to_binary(T value) gray_to_binary(T value)
{ {
value ^= (value >> 8U); value ^= (value >> 8U);
@ -841,8 +840,7 @@ namespace etl
///\ingroup binary ///\ingroup binary
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
ETL_CONSTEXPR14 ETL_CONSTEXPR14 typename etl::enable_if< etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 32U), T>::type
typename etl::enable_if<etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 32U), T>::type
gray_to_binary(T value) gray_to_binary(T value)
{ {
value ^= (value >> 16U); value ^= (value >> 16U);
@ -860,8 +858,7 @@ namespace etl
///\ingroup binary ///\ingroup binary
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
ETL_CONSTEXPR14 ETL_CONSTEXPR14 typename etl::enable_if< etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 64U), T>::type
typename etl::enable_if<etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 64U), T>::type
gray_to_binary(T value) gray_to_binary(T value)
{ {
value ^= (value >> 32U); value ^= (value >> 32U);
@ -880,9 +877,7 @@ namespace etl
///\ingroup binary ///\ingroup binary
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
ETL_CONSTEXPR14 ETL_CONSTEXPR14 typename etl::enable_if< etl::is_integral<T>::value && etl::is_signed<T>::value, T>::type gray_to_binary(T value)
typename etl::enable_if<etl::is_integral<T>::value && etl::is_signed<T>::value, T>::type
gray_to_binary(T value)
{ {
typedef typename etl::make_unsigned<T>::type unsigned_t; typedef typename etl::make_unsigned<T>::type unsigned_t;
@ -899,9 +894,9 @@ namespace etl
typename etl::enable_if<etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 8U), uint_least8_t>::type typename etl::enable_if<etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 8U), uint_least8_t>::type
count_bits(T value) count_bits(T value)
{ {
#if ETL_CPP23_SUPPORTED && ETL_USING_STL #if ETL_CPP23_SUPPORTED && ETL_USING_STL
return std::popcount(value); return std::popcount(value);
#else #else
uint32_t count = 0U; uint32_t count = 0U;
count = value - ((value >> 1U) & 0x55U); count = value - ((value >> 1U) & 0x55U);
@ -909,7 +904,7 @@ namespace etl
count = ((count >> 4U) + count) & 0x0FU; count = ((count >> 4U) + count) & 0x0FU;
return uint_least8_t(count); return uint_least8_t(count);
#endif #endif
} }
#endif #endif
@ -952,8 +947,8 @@ namespace etl
count = value - ((value >> 1U) & 0x55555555UL); count = value - ((value >> 1U) & 0x55555555UL);
count = ((count >> 2U) & 0x33333333UL) + (count & 0x33333333UL); count = ((count >> 2U) & 0x33333333UL) + (count & 0x33333333UL);
count = ((count >> 4U) + count) & 0x0F0F0F0FUL; count = ((count >> 4U) + count) & 0x0F0F0F0FUL;
count = ((count >> 8U) + count) & 0x00FF00FFUL; count = ((count >> 8U) + count) & 0x00FF00FFUL;
count = ((count >> 16U) + count) & 0x0000FFUL; count = ((count >> 16U) + count) & 0x0000FFUL;
return static_cast<uint_least8_t>(count); return static_cast<uint_least8_t>(count);
@ -970,20 +965,20 @@ namespace etl
typename etl::enable_if<etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 64U), uint_least8_t>::type typename etl::enable_if<etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 64U), uint_least8_t>::type
count_bits(T value) count_bits(T value)
{ {
#if ETL_USING_CPP20 && ETL_USING_STL #if ETL_USING_CPP20 && ETL_USING_STL
return std::popcount(value); return std::popcount(value);
#else #else
uint64_t count = 0U; uint64_t count = 0U;
count = value - ((value >> 1U) & 0x5555555555555555ULL); count = value - ((value >> 1U) & 0x5555555555555555ULL);
count = ((count >> 2U) & 0x3333333333333333ULL) + (count & 0x3333333333333333ULL); count = ((count >> 2U) & 0x3333333333333333ULL) + (count & 0x3333333333333333ULL);
count = ((count >> 4U) + count) & 0x0F0F0F0F0F0F0F0FULL; count = ((count >> 4U) + count) & 0x0F0F0F0F0F0F0F0FULL;
count = ((count >> 8U) + count) & 0x00FF00FF00FF00FFULL; count = ((count >> 8U) + count) & 0x00FF00FF00FF00FFULL;
count = ((count >> 16U) + count) & 0x0000FFFF0000FFFFULL; count = ((count >> 16U) + count) & 0x0000FFFF0000FFFFULL;
count = ((count >> 32U) + count) & 0x00000000FFFFFFFFULL; count = ((count >> 32U) + count) & 0x00000000FFFFFFFFULL;
return static_cast<uint_least8_t>(count); return static_cast<uint_least8_t>(count);
#endif #endif
} }
#endif #endif
@ -992,9 +987,7 @@ namespace etl
///\ingroup binary ///\ingroup binary
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
ETL_CONSTEXPR14 ETL_CONSTEXPR14 typename etl::enable_if< etl::is_integral<T>::value && etl::is_signed<T>::value, uint_least8_t>::type count_bits(T value)
typename etl::enable_if<etl::is_integral<T>::value && etl::is_signed<T>::value, uint_least8_t>::type
count_bits(T value)
{ {
typedef typename etl::make_unsigned<T>::type unsigned_t; typedef typename etl::make_unsigned<T>::type unsigned_t;
@ -1072,9 +1065,7 @@ namespace etl
///\ingroup binary ///\ingroup binary
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
ETL_CONSTEXPR14 ETL_CONSTEXPR14 typename etl::enable_if< etl::is_integral<T>::value && etl::is_signed<T>::value, uint_least8_t>::type parity(T value)
typename etl::enable_if<etl::is_integral<T>::value && etl::is_signed<T>::value, uint_least8_t>::type
parity(T value)
{ {
typedef typename etl::make_unsigned<T>::type unsigned_t; typedef typename etl::make_unsigned<T>::type unsigned_t;
@ -1092,9 +1083,9 @@ namespace etl
typename etl::enable_if<etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 8U), uint_least8_t>::type typename etl::enable_if<etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 8U), uint_least8_t>::type
count_trailing_zeros(T value) count_trailing_zeros(T value)
{ {
#if ETL_USING_CPP20 && ETL_USING_STL #if ETL_USING_CPP20 && ETL_USING_STL
return std::countr_zero(value); return std::countr_zero(value);
#else #else
uint_least8_t count = 0U; uint_least8_t count = 0U;
if (value & 0x1U) if (value & 0x1U)
@ -1127,7 +1118,7 @@ namespace etl
} }
return count; return count;
#endif #endif
} }
#endif #endif
@ -1256,60 +1247,60 @@ namespace etl
typename etl::enable_if<etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 64U), uint_least8_t>::type typename etl::enable_if<etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 64U), uint_least8_t>::type
count_trailing_zeros(T value) count_trailing_zeros(T value)
{ {
#if ETL_USING_CPP20 && ETL_USING_STL #if ETL_USING_CPP20 && ETL_USING_STL
return std::countr_zero(value); return std::countr_zero(value);
#else #else
uint_least8_t count = 0U; uint_least8_t count = 0U;
if (value & 0x1ULL) if (value & 0x1ULL)
{
count = 0U;
}
else
{
count = 1U;
if ((value & 0xFFFFFFFFULL) == 0ULL)
{ {
count = 0U; value >>= 32U;
} count += 32U;
else
{
count = 1U;
if ((value & 0xFFFFFFFFULL) == 0ULL)
{
value >>= 32U;
count += 32U;
}
if ((value & 0xFFFFULL) == 0ULL)
{
value >>= 16U;
count += 16U;
}
if ((value & 0xFFULL) == 0ULL)
{
value >>= 8U;
count += 8U;
}
if ((value & 0xFULL) == 0ULL)
{
value >>= 4U;
count += 4U;
}
if ((value & 0x3ULL) == 0ULL)
{
value >>= 2U;
count += 2U;
}
if ((value & 0x1U) == 0U)
{
value >>= 1U;
count += 1U;
}
count -= value & 0x1ULL;
} }
return count; if ((value & 0xFFFFULL) == 0ULL)
#endif {
value >>= 16U;
count += 16U;
}
if ((value & 0xFFULL) == 0ULL)
{
value >>= 8U;
count += 8U;
}
if ((value & 0xFULL) == 0ULL)
{
value >>= 4U;
count += 4U;
}
if ((value & 0x3ULL) == 0ULL)
{
value >>= 2U;
count += 2U;
}
if ((value & 0x1U) == 0U)
{
value >>= 1U;
count += 1U;
}
count -= value & 0x1ULL;
}
return count;
#endif
} }
#endif #endif
@ -1318,9 +1309,7 @@ namespace etl
///\ingroup binary ///\ingroup binary
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
ETL_CONSTEXPR14 ETL_CONSTEXPR14 typename etl::enable_if< etl::is_integral<T>::value && etl::is_signed<T>::value, uint_least8_t>::type count_trailing_zeros(T value)
typename etl::enable_if<etl::is_integral<T>::value && etl::is_signed<T>::value, uint_least8_t>::type
count_trailing_zeros(T value)
{ {
typedef typename etl::make_unsigned<T>::type unsigned_t; typedef typename etl::make_unsigned<T>::type unsigned_t;
@ -1338,9 +1327,9 @@ namespace etl
typename etl::enable_if<etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 8U), uint_least8_t>::type typename etl::enable_if<etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 8U), uint_least8_t>::type
count_trailing_ones(T value) count_trailing_ones(T value)
{ {
#if ETL_USING_CPP20 && ETL_USING_STL #if ETL_USING_CPP20 && ETL_USING_STL
return std::countr_one(value); return std::countr_one(value);
#else #else
uint_least8_t count = 0U; uint_least8_t count = 0U;
if ((value & 0x1U) == 0x0U) if ((value & 0x1U) == 0x0U)
@ -1373,7 +1362,7 @@ namespace etl
} }
return count; return count;
#endif #endif
} }
#endif #endif
@ -1502,9 +1491,9 @@ namespace etl
typename etl::enable_if<etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 64U), uint_least8_t>::type typename etl::enable_if<etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 64U), uint_least8_t>::type
count_trailing_ones(T value) count_trailing_ones(T value)
{ {
#if ETL_USING_CPP20 && ETL_USING_STL #if ETL_USING_CPP20 && ETL_USING_STL
return std::countr_one(value); return std::countr_one(value);
#else #else
uint_least8_t count = 0U; uint_least8_t count = 0U;
if ((value & 0x1ULL) == 0x0ULL) if ((value & 0x1ULL) == 0x0ULL)
@ -1549,7 +1538,7 @@ namespace etl
} }
return count; return count;
#endif #endif
} }
#endif #endif
@ -1558,9 +1547,7 @@ namespace etl
///\ingroup binary ///\ingroup binary
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
ETL_CONSTEXPR14 ETL_CONSTEXPR14 typename etl::enable_if< etl::is_integral<T>::value && etl::is_signed<T>::value, uint_least8_t>::type count_trailing_ones(T value)
typename etl::enable_if<etl::is_integral<T>::value&& etl::is_signed<T>::value, uint_least8_t>::type
count_trailing_ones(T value)
{ {
typedef typename etl::make_unsigned<T>::type unsigned_t; typedef typename etl::make_unsigned<T>::type unsigned_t;
@ -1578,9 +1565,9 @@ namespace etl
typename etl::enable_if<etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 8U), uint_least8_t>::type typename etl::enable_if<etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 8U), uint_least8_t>::type
count_leading_zeros(T value) count_leading_zeros(T value)
{ {
#if ETL_USING_CPP20 && ETL_USING_STL #if ETL_USING_CPP20 && ETL_USING_STL
return std::countl_zero(value); return std::countl_zero(value);
#else #else
uint_least8_t count = 0U; uint_least8_t count = 0U;
if (value & 0x80U) if (value & 0x80U)
@ -1613,7 +1600,7 @@ namespace etl
} }
return count; return count;
#endif #endif
} }
#endif #endif
@ -1742,9 +1729,9 @@ namespace etl
typename etl::enable_if<etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 64U), uint_least8_t>::type typename etl::enable_if<etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 64U), uint_least8_t>::type
count_leading_zeros(T value) count_leading_zeros(T value)
{ {
#if ETL_USING_CPP20 && ETL_USING_STL #if ETL_USING_CPP20 && ETL_USING_STL
return std::countl_zero(value); return std::countl_zero(value);
#else #else
uint_least8_t count = 0U; uint_least8_t count = 0U;
if (value & 0x8000000000000000ULL) if (value & 0x8000000000000000ULL)
@ -1795,7 +1782,7 @@ namespace etl
} }
return count; return count;
#endif #endif
} }
#endif #endif
@ -1804,9 +1791,7 @@ namespace etl
///\ingroup binary ///\ingroup binary
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
ETL_CONSTEXPR14 ETL_CONSTEXPR14 typename etl::enable_if< etl::is_integral<T>::value && etl::is_signed<T>::value, uint_least8_t>::type count_leading_zeros(T value)
typename etl::enable_if<etl::is_integral<T>::value && etl::is_signed<T>::value, uint_least8_t>::type
count_leading_zeros(T value)
{ {
typedef typename etl::make_unsigned<T>::type unsigned_t; typedef typename etl::make_unsigned<T>::type unsigned_t;
@ -1824,9 +1809,9 @@ namespace etl
typename etl::enable_if<etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 8U), uint_least8_t>::type typename etl::enable_if<etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 8U), uint_least8_t>::type
count_leading_ones(T value) count_leading_ones(T value)
{ {
#if ETL_USING_CPP20 && ETL_USING_STL #if ETL_USING_CPP20 && ETL_USING_STL
return std::countl_one(value); return std::countl_one(value);
#else #else
uint_least8_t count = 0U; uint_least8_t count = 0U;
if ((value & 0x80U) == 0U) if ((value & 0x80U) == 0U)
@ -1859,7 +1844,7 @@ namespace etl
} }
return count; return count;
#endif #endif
} }
#endif #endif
@ -1988,9 +1973,9 @@ namespace etl
typename etl::enable_if<etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 64U), uint_least8_t>::type typename etl::enable_if<etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 64U), uint_least8_t>::type
count_leading_ones(T value) count_leading_ones(T value)
{ {
#if ETL_USING_CPP20 && ETL_USING_STL #if ETL_USING_CPP20 && ETL_USING_STL
return std::countl_one(value); return std::countl_one(value);
#else #else
uint_least8_t count = 0U; uint_least8_t count = 0U;
if ((value & 0x8000000000000000ULL) == 0ULL) if ((value & 0x8000000000000000ULL) == 0ULL)
@ -2041,7 +2026,7 @@ namespace etl
} }
return count; return count;
#endif #endif
} }
#endif #endif
@ -2050,9 +2035,7 @@ namespace etl
///\ingroup binary ///\ingroup binary
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
ETL_CONSTEXPR14 ETL_CONSTEXPR14 typename etl::enable_if< etl::is_integral<T>::value && etl::is_signed<T>::value, uint_least8_t>::type count_leading_ones(T value)
typename etl::enable_if<etl::is_integral<T>::value && etl::is_signed<T>::value, uint_least8_t>::type
count_leading_ones(T value)
{ {
typedef typename etl::make_unsigned<T>::type unsigned_t; typedef typename etl::make_unsigned<T>::type unsigned_t;
@ -2105,21 +2088,21 @@ namespace etl
//***************************************************************************** //*****************************************************************************
template <typename T> template <typename T>
ETL_CONSTEXPR14 ETL_CONSTEXPR14
typename etl::enable_if<etl::is_integral<T>::value&& etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 8U), uint16_t>::type typename etl::enable_if< etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 8U), uint16_t>::type
binary_interleave(T first, T second) binary_interleave(T first, T second)
{ {
uint16_t f = uint16_t(first); uint16_t f = uint16_t(first);
uint16_t s = uint16_t(second); uint16_t s = uint16_t(second);
f = static_cast<uint16_t>((static_cast<uint32_t>(f) | (static_cast<uint32_t>(f) << 4U)) & 0x0F0FU); f = static_cast<uint16_t>((static_cast<uint32_t>(f) | (static_cast<uint32_t>(f) << 4U)) & 0x0F0FU);
f = static_cast<uint16_t>((static_cast<uint32_t>(f) | (static_cast<uint32_t>(f) << 2U)) & 0x3333U); f = static_cast<uint16_t>((static_cast<uint32_t>(f) | (static_cast<uint32_t>(f) << 2U)) & 0x3333U);
f = static_cast<uint16_t>((static_cast<uint32_t>(f) | (static_cast<uint32_t>(f) << 1U)) & 0x5555U); f = static_cast<uint16_t>((static_cast<uint32_t>(f) | (static_cast<uint32_t>(f) << 1U)) & 0x5555U);
s = static_cast<uint16_t>((static_cast<uint32_t>(s) | (static_cast<uint32_t>(s) << 4U)) & 0x0F0FU); s = static_cast<uint16_t>((static_cast<uint32_t>(s) | (static_cast<uint32_t>(s) << 4U)) & 0x0F0FU);
s = static_cast<uint16_t>((static_cast<uint32_t>(s) | (static_cast<uint32_t>(s) << 2U)) & 0x3333U); s = static_cast<uint16_t>((static_cast<uint32_t>(s) | (static_cast<uint32_t>(s) << 2U)) & 0x3333U);
s = static_cast<uint16_t>((static_cast<uint32_t>(s) | (static_cast<uint32_t>(s) << 1U)) & 0x5555U); s = static_cast<uint16_t>((static_cast<uint32_t>(s) | (static_cast<uint32_t>(s) << 1U)) & 0x5555U);
return (f | (s << 1U)); return (f | (s << 1U));
} }
#endif #endif
@ -2129,23 +2112,23 @@ namespace etl
//***************************************************************************** //*****************************************************************************
template <typename T> template <typename T>
ETL_CONSTEXPR14 ETL_CONSTEXPR14
typename etl::enable_if<etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 16U), uint32_t>::type typename etl::enable_if< etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 16U), uint32_t>::type
binary_interleave(T first, T second) binary_interleave(T first, T second)
{ {
uint32_t f = uint32_t(first); uint32_t f = uint32_t(first);
uint32_t s = uint32_t(second); uint32_t s = uint32_t(second);
f = (f | (f << 8U)) & 0x00FF00FFUL; f = (f | (f << 8U)) & 0x00FF00FFUL;
f = (f | (f << 4U)) & 0x0F0F0F0FUL; f = (f | (f << 4U)) & 0x0F0F0F0FUL;
f = (f | (f << 2U)) & 0x33333333UL; f = (f | (f << 2U)) & 0x33333333UL;
f = (f | (f << 1U)) & 0x55555555UL; f = (f | (f << 1U)) & 0x55555555UL;
s = (s | (s << 8U)) & 0x00FF00FFUL; s = (s | (s << 8U)) & 0x00FF00FFUL;
s = (s | (s << 4U)) & 0x0F0F0F0FUL; s = (s | (s << 4U)) & 0x0F0F0F0FUL;
s = (s | (s << 2U)) & 0x33333333UL; s = (s | (s << 2U)) & 0x33333333UL;
s = (s | (s << 1U)) & 0x55555555UL; s = (s | (s << 1U)) & 0x55555555UL;
return (f | (s << 1U)); return (f | (s << 1U));
} }
#if ETL_USING_64BIT_TYPES #if ETL_USING_64BIT_TYPES
@ -2155,25 +2138,25 @@ namespace etl
//***************************************************************************** //*****************************************************************************
template <typename T> template <typename T>
ETL_CONSTEXPR14 ETL_CONSTEXPR14
typename etl::enable_if<etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 32U), uint64_t>::type typename etl::enable_if< etl::is_integral<T>::value && etl::is_unsigned<T>::value && (etl::integral_limits<T>::bits == 32U), uint64_t>::type
binary_interleave(T first, T second) binary_interleave(T first, T second)
{ {
uint64_t f = uint64_t(first); uint64_t f = uint64_t(first);
uint64_t s = uint64_t(second); uint64_t s = uint64_t(second);
f = (f | (f << 16U)) & 0x0000FFFF0000FFFFULL; f = (f | (f << 16U)) & 0x0000FFFF0000FFFFULL;
f = (f | (f << 8U)) & 0x00FF00FF00FF00FFULL; f = (f | (f << 8U)) & 0x00FF00FF00FF00FFULL;
f = (f | (f << 4U)) & 0x0F0F0F0F0F0F0F0FULL; f = (f | (f << 4U)) & 0x0F0F0F0F0F0F0F0FULL;
f = (f | (f << 2U)) & 0x3333333333333333ULL; f = (f | (f << 2U)) & 0x3333333333333333ULL;
f = (f | (f << 1U)) & 0x5555555555555555ULL; f = (f | (f << 1U)) & 0x5555555555555555ULL;
s = (s | (s << 16U)) & 0x0000FFFF0000FFFFULL; s = (s | (s << 16U)) & 0x0000FFFF0000FFFFULL;
s = (s | (s << 8U)) & 0x00FF00FF00FF00FFULL; s = (s | (s << 8U)) & 0x00FF00FF00FF00FFULL;
s = (s | (s << 4U)) & 0x0F0F0F0F0F0F0F0FULL; s = (s | (s << 4U)) & 0x0F0F0F0F0F0F0F0FULL;
s = (s | (s << 2U)) & 0x3333333333333333ULL; s = (s | (s << 2U)) & 0x3333333333333333ULL;
s = (s | (s << 1U)) & 0x5555555555555555ULL; s = (s | (s << 1U)) & 0x5555555555555555ULL;
return (f | (s << 1U)); return (f | (s << 1U));
} }
#endif #endif
@ -2182,9 +2165,7 @@ namespace etl
///\ingroup binary ///\ingroup binary
//***************************************************************************** //*****************************************************************************
template <typename T> template <typename T>
ETL_CONSTEXPR14 ETL_CONSTEXPR14 typename etl::enable_if< etl::is_integral<T>::value && etl::is_signed<T>::value, T>::type binary_interleave(T first, T second)
typename etl::enable_if<etl::is_integral<T>::value && etl::is_signed<T>::value, T>::type
binary_interleave(T first, T second)
{ {
return int64_t(binary_interleave(uint16_t(first), uint16_t(second))); return int64_t(binary_interleave(uint16_t(first), uint16_t(second)));
} }
@ -2194,10 +2175,9 @@ namespace etl
///\ingroup binary ///\ingroup binary
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
ETL_CONSTEXPR typename etl::enable_if<etl::is_integral<T>::value, bool>::type ETL_CONSTEXPR typename etl::enable_if<etl::is_integral<T>::value, bool>::type is_odd(T value)
is_odd(T value)
{ {
return ((static_cast<typename etl::make_unsigned<T>::type>(value) & 1U) != 0U); return ((static_cast<typename etl::make_unsigned<T>::type>(value) & 1U) != 0U);
} }
//*************************************************************************** //***************************************************************************
@ -2205,8 +2185,7 @@ namespace etl
///\ingroup binary ///\ingroup binary
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
ETL_CONSTEXPR typename etl::enable_if<etl::is_integral<T>::value, bool>::type ETL_CONSTEXPR typename etl::enable_if<etl::is_integral<T>::value, bool>::type is_even(T value)
is_even(T value)
{ {
return ((static_cast<typename etl::make_unsigned<T>::type>(value) & 1U) == 0U); return ((static_cast<typename etl::make_unsigned<T>::type>(value) & 1U) == 0U);
} }
@ -2240,8 +2219,7 @@ namespace etl
{ {
typedef typename etl::make_unsigned<T>::type type; typedef typename etl::make_unsigned<T>::type type;
return (nbits == 0U) ? static_cast<T>(0) return (nbits == 0U) ? static_cast<T>(0) : static_cast<T>(static_cast<type>(~0) >> (etl::integral_limits<type>::bits - nbits));
: static_cast<T>(static_cast<type>(~0) >> (etl::integral_limits<type>::bits - nbits));
} }
//*********************************** //***********************************
@ -2264,8 +2242,7 @@ namespace etl
{ {
typedef typename etl::make_unsigned<T>::type type; typedef typename etl::make_unsigned<T>::type type;
return (nbits == 0U) ? static_cast<T>(0) return (nbits == 0U) ? static_cast<T>(0) : static_cast<T>(static_cast<type>(~0) << (etl::integral_limits<type>::bits - nbits));
: static_cast<T>(static_cast<type>(~0) << (etl::integral_limits<type>::bits - nbits));
} }
//*********************************** //***********************************
@ -2285,9 +2262,7 @@ namespace etl
struct binary_not : public etl::unary_function<T, T> struct binary_not : public etl::unary_function<T, T>
{ {
//*********************************** //***********************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR T operator()(T value) const ETL_NOEXCEPT
ETL_CONSTEXPR
T operator ()(T value) const ETL_NOEXCEPT
{ {
ETL_STATIC_ASSERT(etl::is_integral<T>::value, "Not an integral type"); ETL_STATIC_ASSERT(etl::is_integral<T>::value, "Not an integral type");
@ -2303,16 +2278,13 @@ namespace etl
struct binary_and : public etl::unary_function<T, T> struct binary_and : public etl::unary_function<T, T>
{ {
//*********************************** //***********************************
ETL_CONSTEXPR ETL_CONSTEXPR explicit binary_and(T parameter_) ETL_NOEXCEPT
explicit binary_and(T parameter_) ETL_NOEXCEPT
: parameter(parameter_) : parameter(parameter_)
{ {
} }
//*********************************** //***********************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR T operator()(T value) const ETL_NOEXCEPT
ETL_CONSTEXPR
T operator ()(T value) const ETL_NOEXCEPT
{ {
ETL_STATIC_ASSERT(etl::is_integral<T>::value, "Not an integral type"); ETL_STATIC_ASSERT(etl::is_integral<T>::value, "Not an integral type");
@ -2332,16 +2304,13 @@ namespace etl
struct binary_or : public etl::unary_function<T, T> struct binary_or : public etl::unary_function<T, T>
{ {
//*********************************** //***********************************
ETL_CONSTEXPR ETL_CONSTEXPR explicit binary_or(T parameter_) ETL_NOEXCEPT
explicit binary_or(T parameter_) ETL_NOEXCEPT
: parameter(parameter_) : parameter(parameter_)
{ {
} }
//*********************************** //***********************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR T operator()(T value) const ETL_NOEXCEPT
ETL_CONSTEXPR
T operator ()(T value) const ETL_NOEXCEPT
{ {
ETL_STATIC_ASSERT(etl::is_integral<T>::value, "Not an integral type"); ETL_STATIC_ASSERT(etl::is_integral<T>::value, "Not an integral type");
@ -2361,16 +2330,13 @@ namespace etl
struct binary_xor : public etl::unary_function<T, T> struct binary_xor : public etl::unary_function<T, T>
{ {
//*********************************** //***********************************
ETL_CONSTEXPR ETL_CONSTEXPR explicit binary_xor(T parameter_) ETL_NOEXCEPT
explicit binary_xor(T parameter_) ETL_NOEXCEPT
: parameter(parameter_) : parameter(parameter_)
{ {
} }
//*********************************** //***********************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR T operator()(T value) const ETL_NOEXCEPT
ETL_CONSTEXPR
T operator ()(T value) const ETL_NOEXCEPT
{ {
ETL_STATIC_ASSERT(etl::is_integral<T>::value, "Not an integral type"); ETL_STATIC_ASSERT(etl::is_integral<T>::value, "Not an integral type");
@ -2685,6 +2651,6 @@ namespace etl
b30 = 0x40000000UL, b30 = 0x40000000UL,
b31 = 0x80000000UL b31 = 0x80000000UL
}; };
} } // namespace etl
#endif #endif

View File

@ -40,15 +40,15 @@ SOFTWARE.
#include "platform.h" #include "platform.h"
#include "alignment.h" #include "alignment.h"
#include "parameter_type.h"
#include "atomic.h" #include "atomic.h"
#include "error_handler.h"
#include "file_error_numbers.h"
#include "integral_limits.h"
#include "memory.h" #include "memory.h"
#include "memory_model.h" #include "memory_model.h"
#include "integral_limits.h" #include "parameter_type.h"
#include "utility.h"
#include "error_handler.h"
#include "span.h" #include "span.h"
#include "file_error_numbers.h" #include "utility.h"
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
@ -60,12 +60,12 @@ namespace etl
//*************************************************************************** //***************************************************************************
/// Base exception for a bip buffer. /// Base exception for a bip buffer.
//*************************************************************************** //***************************************************************************
class bip_buffer_exception: public exception class bip_buffer_exception : public exception
{ {
public: public:
bip_buffer_exception(string_type reason_, string_type file_name_, numeric_type line_number_) bip_buffer_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
: exception(reason_, file_name_, line_number_) : exception(reason_, file_name_, line_number_)
{ {
} }
}; };
@ -73,7 +73,7 @@ namespace etl
//*************************************************************************** //***************************************************************************
/// Exception for an invalid reserve. /// Exception for an invalid reserve.
//*************************************************************************** //***************************************************************************
class bip_buffer_reserve_invalid: public bip_buffer_exception class bip_buffer_reserve_invalid : public bip_buffer_exception
{ {
public: public:
@ -117,7 +117,7 @@ namespace etl
size_type size() const size_type size() const
{ {
size_type write_index = write.load(etl::memory_order_acquire); size_type write_index = write.load(etl::memory_order_acquire);
size_type read_index = read.load(etl::memory_order_acquire); size_type read_index = read.load(etl::memory_order_acquire);
// no wraparound // no wraparound
if (write_index >= read_index) if (write_index >= read_index)
@ -140,7 +140,7 @@ namespace etl
size_type available() const size_type available() const
{ {
size_type write_index = write.load(etl::memory_order_acquire); size_type write_index = write.load(etl::memory_order_acquire);
size_type read_index = read.load(etl::memory_order_acquire); size_type read_index = read.load(etl::memory_order_acquire);
// no wraparound // no wraparound
if (write_index >= read_index) if (write_index >= read_index)
@ -185,10 +185,10 @@ namespace etl
/// Constructs the buffer. /// Constructs the buffer.
//************************************************************************* //*************************************************************************
bip_buffer_spsc_atomic_base(size_type reserved_) bip_buffer_spsc_atomic_base(size_type reserved_)
: read(0) : read(0)
, write(0) , write(0)
, last(0) , last(0)
, Reserved(reserved_) , Reserved(reserved_)
{ {
} }
@ -204,7 +204,7 @@ namespace etl
size_type get_write_reserve(size_type* psize, size_type fallback_size = numeric_limits<size_type>::max()) size_type get_write_reserve(size_type* psize, size_type fallback_size = numeric_limits<size_type>::max())
{ {
size_type write_index = write.load(etl::memory_order_relaxed); size_type write_index = write.load(etl::memory_order_relaxed);
size_type read_index = read.load(etl::memory_order_acquire); size_type read_index = read.load(etl::memory_order_acquire);
// No wraparound // No wraparound
if (write_index >= read_index) if (write_index >= read_index)
@ -262,7 +262,7 @@ namespace etl
if (wsize > 0) if (wsize > 0)
{ {
size_type write_index = write.load(etl::memory_order_relaxed); size_type write_index = write.load(etl::memory_order_relaxed);
size_type read_index = read.load(etl::memory_order_acquire); size_type read_index = read.load(etl::memory_order_acquire);
// Wrapped around already // Wrapped around already
if (write_index < read_index) if (write_index < read_index)
@ -285,7 +285,7 @@ namespace etl
// Correct wrapping point // Correct wrapping point
last.store(write_index, etl::memory_order_release); last.store(write_index, etl::memory_order_release);
} }
// Always update write index // Always update write index
write.store(windex + wsize, etl::memory_order_release); write.store(windex + wsize, etl::memory_order_release);
} }
@ -294,7 +294,7 @@ namespace etl
//************************************************************************* //*************************************************************************
size_type get_read_reserve(size_type* psize) size_type get_read_reserve(size_type* psize)
{ {
size_type read_index = read.load(etl::memory_order_relaxed); size_type read_index = read.load(etl::memory_order_relaxed);
size_type write_index = write.load(etl::memory_order_acquire); size_type write_index = write.load(etl::memory_order_acquire);
if (read_index > write_index) if (read_index > write_index)
@ -344,21 +344,19 @@ namespace etl
etl::atomic<size_type> read; etl::atomic<size_type> read;
etl::atomic<size_type> write; etl::atomic<size_type> write;
etl::atomic<size_type> last; etl::atomic<size_type> last;
const size_type Reserved; const size_type Reserved;
#if defined(ETL_POLYMORPHIC_SPSC_BIP_BUFFER_ATOMIC) || defined(ETL_POLYMORPHIC_CONTAINERS)
#if defined(ETL_POLYMORPHIC_SPSC_BIP_BUFFER_ATOMIC) || defined(ETL_POLYMORPHIC_CONTAINERS)
public: public:
virtual ~bip_buffer_spsc_atomic_base() virtual ~bip_buffer_spsc_atomic_base() {}
{ #else
}
#else
protected: protected:
~bip_buffer_spsc_atomic_base() ~bip_buffer_spsc_atomic_base() {}
{ #endif
}
#endif
}; };
//*************************************************************************** //***************************************************************************
@ -370,21 +368,21 @@ namespace etl
private: private:
typedef typename etl::bip_buffer_spsc_atomic_base<Memory_Model> base_t; typedef typename etl::bip_buffer_spsc_atomic_base<Memory_Model> base_t;
using base_t::reset;
using base_t::get_read_reserve;
using base_t::apply_read_reserve; using base_t::apply_read_reserve;
using base_t::get_write_reserve;
using base_t::apply_write_reserve; using base_t::apply_write_reserve;
using base_t::get_read_reserve;
using base_t::get_write_reserve;
using base_t::reset;
public: public:
typedef T value_type; ///< The type stored in the buffer. typedef T value_type; ///< The type stored in the buffer.
typedef T& reference; ///< A reference to the type used in the buffer. typedef T& reference; ///< A reference to the type used in the buffer.
typedef const T& const_reference; ///< A const reference to the type used in the buffer. typedef const T& const_reference; ///< A const reference to the type used in the buffer.
#if ETL_USING_CPP11 #if ETL_USING_CPP11
typedef T&& rvalue_reference;///< An rvalue_reference to the type used in the buffer. typedef T&& rvalue_reference; ///< An rvalue_reference to the type used in the buffer.
#endif #endif
typedef typename base_t::size_type size_type; ///< The type used for determining the size of the buffer. typedef typename base_t::size_type size_type; ///< The type used for determining the size of the buffer.
using base_t::max_size; using base_t::max_size;
@ -394,8 +392,8 @@ namespace etl
span<T> read_reserve(size_type max_reserve_size = numeric_limits<size_type>::max()) span<T> read_reserve(size_type max_reserve_size = numeric_limits<size_type>::max())
{ {
size_type reserve_size = max_reserve_size; size_type reserve_size = max_reserve_size;
size_type rindex = get_read_reserve(&reserve_size); size_type rindex = get_read_reserve(&reserve_size);
return span<T>(p_buffer + rindex, reserve_size); return span<T>(p_buffer + rindex, reserve_size);
} }
@ -404,7 +402,7 @@ namespace etl
// the reserve can be trimmed at the end before committing. // the reserve can be trimmed at the end before committing.
// Throws bip_buffer_reserve_invalid // Throws bip_buffer_reserve_invalid
//************************************************************************* //*************************************************************************
void read_commit(const span<T> &reserve) void read_commit(const span<T>& reserve)
{ {
size_type rindex = etl::distance(p_buffer, reserve.data()); size_type rindex = etl::distance(p_buffer, reserve.data());
apply_read_reserve(rindex, reserve.size()); apply_read_reserve(rindex, reserve.size());
@ -416,8 +414,8 @@ namespace etl
span<T> write_reserve(size_type max_reserve_size) span<T> write_reserve(size_type max_reserve_size)
{ {
size_type reserve_size = max_reserve_size; size_type reserve_size = max_reserve_size;
size_type windex = get_write_reserve(&reserve_size); size_type windex = get_write_reserve(&reserve_size);
return span<T>(p_buffer + windex, reserve_size); return span<T>(p_buffer + windex, reserve_size);
} }
@ -427,10 +425,10 @@ namespace etl
//************************************************************************* //*************************************************************************
span<T> write_reserve_optimal(size_type min_reserve_size = 1U) span<T> write_reserve_optimal(size_type min_reserve_size = 1U)
{ {
size_type reserve_size = numeric_limits<size_type>::max(); size_type reserve_size = numeric_limits<size_type>::max();
size_type windex = get_write_reserve(&reserve_size, min_reserve_size); size_type windex = get_write_reserve(&reserve_size, min_reserve_size);
return span<T>(p_buffer + windex, reserve_size); return span<T>(p_buffer + windex, reserve_size);
} }
//************************************************************************* //*************************************************************************
@ -438,7 +436,7 @@ namespace etl
// the reserve can be trimmed at the end before committing. // the reserve can be trimmed at the end before committing.
// Throws bip_buffer_reserve_invalid // Throws bip_buffer_reserve_invalid
//************************************************************************* //*************************************************************************
void write_commit(const span<T> &reserve) void write_commit(const span<T>& reserve)
{ {
size_type windex = etl::distance(p_buffer, reserve.data()); size_type windex = etl::distance(p_buffer, reserve.data());
apply_write_reserve(windex, reserve.size()); apply_write_reserve(windex, reserve.size());
@ -475,12 +473,12 @@ namespace etl
// Disable copy construction and assignment. // Disable copy construction and assignment.
ibip_buffer_spsc_atomic(const ibip_buffer_spsc_atomic&) ETL_DELETE; ibip_buffer_spsc_atomic(const ibip_buffer_spsc_atomic&) ETL_DELETE;
ibip_buffer_spsc_atomic& operator =(const ibip_buffer_spsc_atomic&) ETL_DELETE; ibip_buffer_spsc_atomic& operator=(const ibip_buffer_spsc_atomic&) ETL_DELETE;
#if ETL_USING_CPP11 #if ETL_USING_CPP11
ibip_buffer_spsc_atomic(ibip_buffer_spsc_atomic&&) = delete; ibip_buffer_spsc_atomic(ibip_buffer_spsc_atomic&&) = delete;
ibip_buffer_spsc_atomic& operator =(ibip_buffer_spsc_atomic&&) = delete; ibip_buffer_spsc_atomic& operator=(ibip_buffer_spsc_atomic&&) = delete;
#endif #endif
T* const p_buffer; T* const p_buffer;
}; };
@ -490,7 +488,8 @@ namespace etl
/// This buffer supports concurrent access by one producer and one consumer. /// This buffer supports concurrent access by one producer and one consumer.
/// \tparam T The type this buffer should support. /// \tparam T The type this buffer should support.
/// \tparam Size The maximum capacity of the buffer. /// \tparam Size The maximum capacity of the buffer.
/// \tparam Memory_Model The memory model for the buffer. Determines the type of the internal counter variables. /// \tparam Memory_Model The memory model for the buffer. Determines the type
/// of the internal counter variables.
//*************************************************************************** //***************************************************************************
template <typename T, const size_t Size, const size_t Memory_Model = etl::memory_model::MEMORY_MODEL_LARGE> template <typename T, const size_t Size, const size_t Memory_Model = etl::memory_model::MEMORY_MODEL_LARGE>
class bip_buffer_spsc_atomic : public ibip_buffer_spsc_atomic<T, Memory_Model> class bip_buffer_spsc_atomic : public ibip_buffer_spsc_atomic<T, Memory_Model>
@ -529,15 +528,15 @@ namespace etl
base_t::clear(); base_t::clear();
} }
private: private:
/// The uninitialised buffer of T used in the bip_buffer_spsc. /// The uninitialised buffer of T used in the bip_buffer_spsc.
etl::uninitialized_buffer_of<T, Reserved_Size> buffer; etl::uninitialized_buffer_of<T, Reserved_Size> buffer;
}; };
template <typename T, const size_t Size, const size_t Memory_Model> template <typename T, const size_t Size, const size_t Memory_Model>
ETL_CONSTANT typename bip_buffer_spsc_atomic<T, Size, Memory_Model>::size_type bip_buffer_spsc_atomic<T, Size, Memory_Model>::Reserved_Size; ETL_CONSTANT typename bip_buffer_spsc_atomic<T, Size, Memory_Model>::size_type bip_buffer_spsc_atomic<T, Size, Memory_Model>::Reserved_Size;
} } // namespace etl
#endif /* ETL_HAS_ATOMIC && ETL_USING_CPP11 */ #endif /* ETL_HAS_ATOMIC && ETL_USING_CPP11 */

View File

@ -32,10 +32,9 @@ SOFTWARE.
#define ETL_BIT_INCLUDED #define ETL_BIT_INCLUDED
#include "platform.h" #include "platform.h"
#include "type_traits.h"
#include "binary.h" #include "binary.h"
#include "integral_limits.h"
#include "endianness.h" #include "endianness.h"
#include "integral_limits.h"
#include "type_traits.h" #include "type_traits.h"
#include <string.h> #include <string.h>
@ -51,11 +50,9 @@ namespace etl
//*************************************************************************** //***************************************************************************
template <typename TDestination, typename TSource> template <typename TDestination, typename TSource>
ETL_NODISCARD ETL_NODISCARD
typename etl::enable_if<!(etl::is_integral<TDestination>::value&& etl::is_integral<TSource>::value) && typename etl::enable_if< !(etl::is_integral<TDestination>::value && etl::is_integral<TSource>::value) && (sizeof(TDestination) == sizeof(TSource))
(sizeof(TDestination) == sizeof(TSource)) && && etl::is_trivially_copyable<TSource>::value && etl::is_trivially_copyable<TDestination>::value,
etl::is_trivially_copyable<TSource>::value && TDestination>::type bit_cast(const TSource& source) ETL_NOEXCEPT
etl::is_trivially_copyable<TDestination>::value, TDestination>::type
bit_cast(const TSource& source) ETL_NOEXCEPT
{ {
TDestination destination; TDestination destination;
@ -68,11 +65,9 @@ namespace etl
/// bit_cast - Integral to integral /// bit_cast - Integral to integral
//*************************************************************************** //***************************************************************************
template <typename TDestination, typename TSource> template <typename TDestination, typename TSource>
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR14
ETL_CONSTEXPR14 typename etl::enable_if< (etl::is_integral<TDestination>::value && etl::is_integral<TSource>::value) && (sizeof(TDestination) == sizeof(TSource)),
typename etl::enable_if<(etl::is_integral<TDestination>::value && etl::is_integral<TSource>::value) && TDestination>::type bit_cast(const TSource& source) ETL_NOEXCEPT
(sizeof(TDestination) == sizeof(TSource)), TDestination>::type
bit_cast(const TSource& source) ETL_NOEXCEPT
{ {
return static_cast<TDestination>(source); return static_cast<TDestination>(source);
} }
@ -81,9 +76,7 @@ namespace etl
/// byteswap /// byteswap
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
ETL_CONSTEXPR14 ETL_CONSTEXPR14 typename etl::enable_if<etl::is_integral<T>::value, T>::type byteswap(T value) ETL_NOEXCEPT
typename etl::enable_if<etl::is_integral<T>::value, T>::type
byteswap(T value) ETL_NOEXCEPT
{ {
return etl::reverse_bytes(value); return etl::reverse_bytes(value);
} }
@ -92,8 +85,7 @@ namespace etl
/// has_single_bit /// has_single_bit
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
ETL_NODISCARD ETL_CONSTEXPR14 ETL_NODISCARD ETL_CONSTEXPR14 typename etl::enable_if<etl::is_unsigned<T>::value, bool>::type has_single_bit(T value) ETL_NOEXCEPT
typename etl::enable_if<etl::is_unsigned<T>::value, bool>::type has_single_bit(T value) ETL_NOEXCEPT
{ {
return (value & (value - 1)) == 0; return (value & (value - 1)) == 0;
} }
@ -101,9 +93,7 @@ namespace etl
/// countl_zero /// countl_zero
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
ETL_NODISCARD ETL_CONSTEXPR14 ETL_NODISCARD ETL_CONSTEXPR14 typename etl::enable_if<etl::is_unsigned<T>::value, int>::type countl_zero(T value) ETL_NOEXCEPT
typename etl::enable_if<etl::is_unsigned<T>::value, int>::type
countl_zero(T value) ETL_NOEXCEPT
{ {
return etl::count_leading_zeros(value); return etl::count_leading_zeros(value);
} }
@ -112,9 +102,7 @@ namespace etl
/// countl_one /// countl_one
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
ETL_NODISCARD ETL_CONSTEXPR14 ETL_NODISCARD ETL_CONSTEXPR14 typename etl::enable_if<etl::is_unsigned<T>::value, int>::type countl_one(T value) ETL_NOEXCEPT
typename etl::enable_if<etl::is_unsigned<T>::value, int>::type
countl_one(T value) ETL_NOEXCEPT
{ {
return etl::count_leading_ones(value); return etl::count_leading_ones(value);
} }
@ -123,9 +111,7 @@ namespace etl
/// countr_zero /// countr_zero
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
ETL_NODISCARD ETL_CONSTEXPR14 ETL_NODISCARD ETL_CONSTEXPR14 typename etl::enable_if<etl::is_unsigned<T>::value, int>::type countr_zero(T value) ETL_NOEXCEPT
typename etl::enable_if<etl::is_unsigned<T>::value, int>::type
countr_zero(T value) ETL_NOEXCEPT
{ {
return etl::count_trailing_zeros(value); return etl::count_trailing_zeros(value);
} }
@ -134,21 +120,16 @@ namespace etl
/// countr_one /// countr_one
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
ETL_NODISCARD ETL_CONSTEXPR14 ETL_NODISCARD ETL_CONSTEXPR14 typename etl::enable_if<etl::is_unsigned<T>::value, int>::type countr_one(T value) ETL_NOEXCEPT
typename etl::enable_if<etl::is_unsigned<T>::value, int>::type
countr_one(T value) ETL_NOEXCEPT
{ {
return etl::count_trailing_ones(value); return etl::count_trailing_ones(value);
} }
//*************************************************************************** //***************************************************************************
/// bit_width /// bit_width
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
ETL_CONSTEXPR14 ETL_CONSTEXPR14 typename etl::enable_if<etl::is_unsigned<T>::value, T>::type bit_width(T value) ETL_NOEXCEPT
typename etl::enable_if<etl::is_unsigned<T>::value, T>::type
bit_width(T value) ETL_NOEXCEPT
{ {
#if ETL_USING_CPP20 && ETL_USING_STL #if ETL_USING_CPP20 && ETL_USING_STL
return static_cast<T>(std::bit_width(value)); return static_cast<T>(std::bit_width(value));
@ -161,9 +142,7 @@ namespace etl
/// bit_ceil /// bit_ceil
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
ETL_NODISCARD ETL_CONSTEXPR14 ETL_NODISCARD ETL_CONSTEXPR14 typename etl::enable_if<etl::is_unsigned<T>::value, T>::type bit_ceil(T value)
typename etl::enable_if<etl::is_unsigned<T>::value, T>::type
bit_ceil(T value)
{ {
#if ETL_USING_CPP20 && ETL_USING_STL #if ETL_USING_CPP20 && ETL_USING_STL
return std::bit_ceil(value); return std::bit_ceil(value);
@ -183,9 +162,7 @@ namespace etl
/// bit_floor /// bit_floor
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
ETL_NODISCARD ETL_CONSTEXPR14 ETL_NODISCARD ETL_CONSTEXPR14 typename etl::enable_if<etl::is_unsigned<T>::value, T>::type bit_floor(T value) ETL_NOEXCEPT
typename etl::enable_if<etl::is_unsigned<T>::value, T>::type
bit_floor(T value) ETL_NOEXCEPT
{ {
#if ETL_USING_CPP20 && ETL_USING_STL #if ETL_USING_CPP20 && ETL_USING_STL
return std::bit_floor(value); return std::bit_floor(value);
@ -205,9 +182,7 @@ namespace etl
/// rotl /// rotl
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
ETL_NODISCARD ETL_CONSTEXPR14 ETL_NODISCARD ETL_CONSTEXPR14 typename etl::enable_if<etl::is_unsigned<T>::value, T>::type rotl(T value, int n) ETL_NOEXCEPT
typename etl::enable_if<etl::is_unsigned<T>::value, T>::type
rotl(T value, int n) ETL_NOEXCEPT
{ {
if (n < 0) if (n < 0)
{ {
@ -223,9 +198,7 @@ namespace etl
/// rotr /// rotr
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
ETL_NODISCARD ETL_CONSTEXPR14 ETL_NODISCARD ETL_CONSTEXPR14 typename etl::enable_if<etl::is_unsigned<T>::value, T>::type rotr(T value, int n) ETL_NOEXCEPT
typename etl::enable_if<etl::is_unsigned<T>::value, T>::type
rotr(T value, int n) ETL_NOEXCEPT
{ {
if (n < 0) if (n < 0)
{ {
@ -236,17 +209,15 @@ namespace etl
return etl::rotate_right(value, static_cast<size_t>(n)); return etl::rotate_right(value, static_cast<size_t>(n));
} }
} }
//*************************************************************************** //***************************************************************************
/// popcount /// popcount
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
ETL_NODISCARD ETL_CONSTEXPR14 ETL_NODISCARD ETL_CONSTEXPR14 typename etl::enable_if<etl::is_unsigned<T>::value, int>::type popcount(T value) ETL_NOEXCEPT
typename etl::enable_if<etl::is_unsigned<T>::value, int>::type
popcount(T value) ETL_NOEXCEPT
{ {
return etl::count_bits(value); return etl::count_bits(value);
} }
} } // namespace etl
#endif #endif

View File

@ -27,22 +27,22 @@ SOFTWARE.
#define ETL_BIT_STREAM_INCLUDED #define ETL_BIT_STREAM_INCLUDED
#include "platform.h" #include "platform.h"
#include "type_traits.h"
#include "nullptr.h"
#include "endianness.h"
#include "integral_limits.h"
#include "binary.h"
#include "algorithm.h" #include "algorithm.h"
#include "binary.h"
#include "delegate.h"
#include "endianness.h"
#include "error_handler.h"
#include "exception.h"
#include "integral_limits.h"
#include "iterator.h" #include "iterator.h"
#include "memory.h" #include "memory.h"
#include "delegate.h" #include "nullptr.h"
#include "span.h"
#include "optional.h" #include "optional.h"
#include "exception.h" #include "span.h"
#include "error_handler.h" #include "type_traits.h"
#include <stdint.h>
#include <limits.h> #include <limits.h>
#include <stdint.h>
#include "private/minmax_push.h" #include "private/minmax_push.h"
@ -93,7 +93,7 @@ namespace etl
//*************************************************************************** //***************************************************************************
void set_stream(void* begin_, size_t length_) void set_stream(void* begin_, size_t length_)
{ {
pdata = reinterpret_cast<unsigned char*>(begin_); pdata = reinterpret_cast<unsigned char*>(begin_);
length_chars = length_; length_chars = length_;
restart(); restart();
} }
@ -112,8 +112,8 @@ namespace etl
void restart() void restart()
{ {
bits_available_in_char = CHAR_BIT; bits_available_in_char = CHAR_BIT;
char_index = 0U; char_index = 0U;
bits_available = CHAR_BIT * length_chars; bits_available = CHAR_BIT * length_chars;
} }
//*************************************************************************** //***************************************************************************
@ -148,8 +148,7 @@ namespace etl
/// For integral types /// For integral types
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
typename etl::enable_if<etl::is_integral<T>::value, bool>::type typename etl::enable_if<etl::is_integral<T>::value, bool>::type put(T value, uint_least8_t nbits = CHAR_BIT * sizeof(T))
put(T value, uint_least8_t nbits = CHAR_BIT * sizeof(T))
{ {
return put_integral(static_cast<uint32_t>(value), nbits); return put_integral(static_cast<uint32_t>(value), nbits);
} }
@ -176,8 +175,7 @@ namespace etl
/// For floating point types /// For floating point types
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
typename etl::enable_if<etl::is_floating_point<T>::value, bool>::type typename etl::enable_if<etl::is_floating_point<T>::value, bool>::type put(T value)
put(T value)
{ {
bool success = true; bool success = true;
@ -207,7 +205,7 @@ namespace etl
// Do we have enough bits? // Do we have enough bits?
if (bits_available > 0U) if (bits_available > 0U)
{ {
value = get_bit(); value = get_bit();
success = true; success = true;
} }
} }
@ -219,11 +217,10 @@ namespace etl
/// For integral types /// For integral types
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
typename etl::enable_if<etl::is_integral<T>::value, bool>::type typename etl::enable_if<etl::is_integral<T>::value, bool>::type get(T& value, uint_least8_t nbits = CHAR_BIT * sizeof(T))
get(T& value, uint_least8_t nbits = CHAR_BIT * sizeof(T))
{ {
bool success = false; bool success = false;
uint_least8_t bits = nbits; uint_least8_t bits = nbits;
if (pdata != ETL_NULLPTR) if (pdata != ETL_NULLPTR)
{ {
@ -238,7 +235,7 @@ namespace etl
unsigned char mask_width = static_cast<unsigned char>(etl::min(nbits, bits_available_in_char)); unsigned char mask_width = static_cast<unsigned char>(etl::min(nbits, bits_available_in_char));
typedef typename etl::make_unsigned<T>::type chunk_t; typedef typename etl::make_unsigned<T>::type chunk_t;
chunk_t chunk = get_chunk(mask_width); chunk_t chunk = get_chunk(mask_width);
nbits -= mask_width; nbits -= mask_width;
value |= static_cast<T>(chunk << nbits); value |= static_cast<T>(chunk << nbits);
@ -262,8 +259,7 @@ namespace etl
/// For floating point types /// For floating point types
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
typename etl::enable_if<etl::is_floating_point<T>::value, bool>::type typename etl::enable_if<etl::is_floating_point<T>::value, bool>::type get(T& value)
get(T& value)
{ {
bool success = false; bool success = false;
@ -279,7 +275,7 @@ namespace etl
for (size_t i = 0UL; i < sizeof(T); ++i) for (size_t i = 0UL; i < sizeof(T); ++i)
{ {
get(data.raw[i], CHAR_BIT); get(data.raw[i], CHAR_BIT);
} }
from_bytes(reinterpret_cast<const unsigned char*>(data.raw), value); from_bytes(reinterpret_cast<const unsigned char*>(data.raw), value);
@ -351,7 +347,7 @@ namespace etl
unsigned char mask_width = static_cast<unsigned char>(etl::min(nbits, bits_available_in_char)); unsigned char mask_width = static_cast<unsigned char>(etl::min(nbits, bits_available_in_char));
nbits -= mask_width; nbits -= mask_width;
uint32_t mask = ((1U << mask_width) - 1U) << nbits; uint32_t mask = ((1U << mask_width) - 1U) << nbits;
//uint32_t mask = ((uint32_t(1U) << mask_width) - 1U) << nbits; // uint32_t mask = ((uint32_t(1U) << mask_width) - 1U) << nbits;
// Move chunk to lowest char bits. // Move chunk to lowest char bits.
// Chunks are never larger than one char. // Chunks are never larger than one char.
@ -513,11 +509,13 @@ namespace etl
bits_available -= nbits; bits_available -= nbits;
} }
unsigned char *pdata; ///< The start of the bitstream buffer. unsigned char* pdata; ///< The start of the bitstream buffer.
size_t length_chars; ///< The length, in char, of the bitstream buffer. size_t length_chars; ///< The length, in char, of the bitstream buffer.
unsigned char bits_available_in_char; ///< The number of available bits in the current char. unsigned char bits_available_in_char; ///< The number of available bits in
size_t char_index; ///< The index of the char in the bitstream buffer. ///< the current char.
size_t bits_available; ///< The number of bits still available in the bitstream buffer. size_t char_index; ///< The index of the char in the bitstream buffer.
size_t bits_available; ///< The number of bits still available in the
///< bitstream buffer.
}; };
//*************************************************************************** //***************************************************************************
@ -527,10 +525,10 @@ namespace etl
{ {
public: public:
typedef char value_type; typedef char value_type;
typedef value_type* iterator; typedef value_type* iterator;
typedef const value_type* const_iterator; typedef const value_type* const_iterator;
typedef etl::span<value_type> callback_parameter_type; typedef etl::span<value_type> callback_parameter_type;
typedef etl::delegate<void(callback_parameter_type)> callback_type; typedef etl::delegate<void(callback_parameter_type)> callback_type;
//*************************************************************************** //***************************************************************************
@ -589,8 +587,8 @@ namespace etl
void restart() void restart()
{ {
bits_available_in_char = CHAR_BIT; bits_available_in_char = CHAR_BIT;
char_index = 0U; char_index = 0U;
bits_available = capacity_bits(); bits_available = capacity_bits();
} }
//*************************************************************************** //***************************************************************************
@ -653,8 +651,7 @@ namespace etl
/// For integral types /// For integral types
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
typename etl::enable_if<etl::is_integral<T>::value, void>::type typename etl::enable_if<etl::is_integral<T>::value, void>::type write_unchecked(T value, uint_least8_t nbits = CHAR_BIT * sizeof(T))
write_unchecked(T value, uint_least8_t nbits = CHAR_BIT * sizeof(T))
{ {
typedef typename etl::unsigned_type<T>::type unsigned_t; typedef typename etl::unsigned_type<T>::type unsigned_t;
@ -665,8 +662,7 @@ namespace etl
/// For integral types /// For integral types
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
typename etl::enable_if<etl::is_integral<T>::value, bool>::type typename etl::enable_if<etl::is_integral<T>::value, bool>::type write(T value, uint_least8_t nbits = CHAR_BIT * sizeof(T))
write(T value, uint_least8_t nbits = CHAR_BIT * sizeof(T))
{ {
bool success = (available(nbits) > 0U); bool success = (available(nbits) > 0U);
@ -975,10 +971,12 @@ namespace etl
char* const pdata; ///< The start of the bitstream buffer. char* const pdata; ///< The start of the bitstream buffer.
const size_t length_chars; ///< The length of the bitstream buffer. const size_t length_chars; ///< The length of the bitstream buffer.
const etl::endian stream_endianness; ///< The endianness of the stream data. const etl::endian stream_endianness; ///< The endianness of the stream data.
unsigned char bits_available_in_char; ///< The number of available bits in the current char. unsigned char bits_available_in_char; ///< The number of available bits in
size_t char_index; ///< The index of the current char in the bitstream buffer. ///< the current char.
size_t bits_available; ///< The number of bits still available in the bitstream buffer. size_t char_index; ///< The index of the current char in the bitstream buffer.
callback_type callback; ///< An optional callback on every filled byte in buffer. size_t bits_available; ///< The number of bits still available in the
///< bitstream buffer.
callback_type callback; ///< An optional callback on every filled byte in buffer.
}; };
//*************************************************************************** //***************************************************************************
@ -1005,8 +1003,8 @@ namespace etl
/// Overload this to support custom types. /// Overload this to support custom types.
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
typename etl::enable_if<etl::is_integral<T>::value, void>::type typename etl::enable_if<etl::is_integral<T>::value, void>::type write_unchecked(etl::bit_stream_writer& stream, const T& value,
write_unchecked(etl::bit_stream_writer& stream, const T& value, uint_least8_t nbits = CHAR_BIT * sizeof(T)) uint_least8_t nbits = CHAR_BIT * sizeof(T))
{ {
stream.write_unchecked(value, nbits); stream.write_unchecked(value, nbits);
} }
@ -1017,8 +1015,8 @@ namespace etl
/// Overload this to support custom types. /// Overload this to support custom types.
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
typename etl::enable_if<etl::is_integral<T>::value, bool>::type typename etl::enable_if<etl::is_integral<T>::value, bool>::type write(etl::bit_stream_writer& stream, const T& value,
write(etl::bit_stream_writer& stream, const T& value, uint_least8_t nbits = CHAR_BIT * sizeof(T)) uint_least8_t nbits = CHAR_BIT * sizeof(T))
{ {
return stream.write(value, nbits); return stream.write(value, nbits);
} }
@ -1030,7 +1028,7 @@ namespace etl
{ {
public: public:
typedef char value_type; typedef char value_type;
typedef const char* const_iterator; typedef const char* const_iterator;
//*************************************************************************** //***************************************************************************
@ -1109,16 +1107,15 @@ namespace etl
void restart() void restart()
{ {
bits_available_in_char = CHAR_BIT; bits_available_in_char = CHAR_BIT;
char_index = 0U; char_index = 0U;
bits_available = CHAR_BIT * length_chars; bits_available = CHAR_BIT * length_chars;
} }
//*************************************************************************** //***************************************************************************
/// For bool types /// For bool types
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
typename etl::enable_if<etl::is_same<bool, T>::value, bool>::type typename etl::enable_if<etl::is_same<bool, T>::value, bool>::type read_unchecked()
read_unchecked()
{ {
return get_bit(); return get_bit();
} }
@ -1127,8 +1124,7 @@ namespace etl
/// For bool types /// For bool types
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
typename etl::enable_if<etl::is_same<bool, T>::value, etl::optional<bool> >::type typename etl::enable_if<etl::is_same<bool, T>::value, etl::optional<bool> >::type read()
read()
{ {
etl::optional<bool> result; etl::optional<bool> result;
@ -1144,8 +1140,8 @@ namespace etl
/// For integral types /// For integral types
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
typename etl::enable_if<etl::is_integral<T>::value && !etl::is_same<bool, T>::value, T>::type typename etl::enable_if< etl::is_integral<T>::value && !etl::is_same<bool, T>::value, T>::type read_unchecked(uint_least8_t nbits = CHAR_BIT
read_unchecked(uint_least8_t nbits = CHAR_BIT * sizeof(T)) * sizeof(T))
{ {
typedef typename etl::unsigned_type<T>::type unsigned_t; typedef typename etl::unsigned_type<T>::type unsigned_t;
@ -1166,7 +1162,7 @@ namespace etl
// Do we have enough bits? // Do we have enough bits?
if (bits_available >= nbits) if (bits_available >= nbits)
{ {
result = read_unchecked<T>(nbits); result = read_unchecked<T>(nbits);
} }
return result; return result;
@ -1266,8 +1262,8 @@ namespace etl
// Make sure that we are not reading more bits than should be available. // Make sure that we are not reading more bits than should be available.
nbits = (nbits > (CHAR_BIT * sizeof(T))) ? (CHAR_BIT * sizeof(T)) : nbits; nbits = (nbits > (CHAR_BIT * sizeof(T))) ? (CHAR_BIT * sizeof(T)) : nbits;
T value = 0; T value = 0;
uint_least8_t bits = nbits; uint_least8_t bits = nbits;
// Get the bits from the stream. // Get the bits from the stream.
while (nbits != 0) while (nbits != 0)
@ -1352,9 +1348,11 @@ namespace etl
const char* pdata; ///< The start of the bitstream buffer. const char* pdata; ///< The start of the bitstream buffer.
size_t length_chars; ///< The length, in char, of the bitstream buffer. size_t length_chars; ///< The length, in char, of the bitstream buffer.
const etl::endian stream_endianness; ///< The endianness of the stream data. const etl::endian stream_endianness; ///< The endianness of the stream data.
unsigned char bits_available_in_char; ///< The number of available bits in the current char. unsigned char bits_available_in_char; ///< The number of available bits in
size_t char_index; ///< The index of the char in the bitstream buffer. ///< the current char.
size_t bits_available; ///< The number of bits still available in the bitstream buffer. size_t char_index; ///< The index of the char in the bitstream buffer.
size_t bits_available; ///< The number of bits still available in the
///< bitstream buffer.
}; };
//*************************************************************************** //***************************************************************************
@ -1404,7 +1402,7 @@ namespace etl
{ {
return stream.read<bool>(); return stream.read<bool>();
} }
} } // namespace etl
#include "private/minmax_pop.h" #include "private/minmax_pop.h"

View File

@ -32,12 +32,12 @@ SOFTWARE.
#define ETL_BLOOM_FILTER_INCLUDED #define ETL_BLOOM_FILTER_INCLUDED
#include "platform.h" #include "platform.h"
#include "parameter_type.h"
#include "bitset.h"
#include "type_traits.h"
#include "binary.h" #include "binary.h"
#include "bitset.h"
#include "log.h" #include "log.h"
#include "parameter_type.h"
#include "power.h" #include "power.h"
#include "type_traits.h"
///\defgroup bloom_filter bloom_filter ///\defgroup bloom_filter bloom_filter
/// A Bloom filter /// A Bloom filter
@ -51,34 +51,33 @@ namespace etl
struct null_hash struct null_hash
{ {
template <typename T> template <typename T>
size_t operator ()(T) size_t operator()(T)
{ {
return 0; return 0;
} }
}; };
} } // namespace private_bloom_filter
//*************************************************************************** //***************************************************************************
/// An implementation of a bloom filter. /// An implementation of a bloom filter.
/// Allows up to three hashes to be defined. /// Allows up to three hashes to be defined.
/// Hashes must support the () operator and define 'argument_type'. /// Hashes must support the () operator and define 'argument_type'.
///\tparam Desired_Width The desired number of hash results that can be stored. Rounded up to best fit the underlying bitset. ///\tparam Desired_Width The desired number of hash results that can be
///\tparam THash1 The first hash generator class. /// stored. Rounded up to best fit the underlying
///\tparam THash2 The second hash generator class. If omitted, uses the null hash. /// bitset. \tparam THash1 The first hash generator class. \tparam
///\tparam THash3 The third hash generator class. If omitted, uses the null hash. /// THash2 The second hash generator class. If omitted, uses the null
/// The hash classes must define <b>argument_type</b>. /// hash. \tparam THash3 The third hash generator class. If omitted,
/// uses the null hash. The hash classes must define <b>argument_type</b>.
///\ingroup bloom_filter ///\ingroup bloom_filter
//*************************************************************************** //***************************************************************************
template <size_t Desired_Width, template <size_t Desired_Width, typename THash1, typename THash2 = private_bloom_filter::null_hash,
typename THash1,
typename THash2 = private_bloom_filter::null_hash,
typename THash3 = private_bloom_filter::null_hash> typename THash3 = private_bloom_filter::null_hash>
class bloom_filter class bloom_filter
{ {
private: private:
typedef typename etl::parameter_type<typename THash1::argument_type>::type parameter_t; typedef typename etl::parameter_type<typename THash1::argument_type>::type parameter_t;
typedef private_bloom_filter::null_hash null_hash; typedef private_bloom_filter::null_hash null_hash;
public: public:
@ -90,11 +89,11 @@ namespace etl
//*************************************************************************** //***************************************************************************
/// Clears the bloom filter of all entries. /// Clears the bloom filter of all entries.
//*************************************************************************** //***************************************************************************
void clear() void clear()
{ {
flags.reset(); flags.reset();
} }
//*************************************************************************** //***************************************************************************
/// Adds a key to the filter. /// Adds a key to the filter.
@ -184,7 +183,6 @@ namespace etl
/// The Bloom filter flags. /// The Bloom filter flags.
etl::bitset<WIDTH> flags; etl::bitset<WIDTH> flags;
}; };
} } // namespace etl
#endif #endif

View File

@ -91,7 +91,7 @@ namespace etl
//*************************************************** //***************************************************
/// Assignment operator /// Assignment operator
//*************************************************** //***************************************************
const_iterator& operator =(const const_iterator& rhs) const_iterator& operator=(const const_iterator& rhs)
{ {
p_bresenham_line = rhs.p_bresenham_line; p_bresenham_line = rhs.p_bresenham_line;
@ -101,7 +101,7 @@ namespace etl
//*************************************************** //***************************************************
/// Pre-increment operator /// Pre-increment operator
//*************************************************** //***************************************************
const_iterator& operator ++() const_iterator& operator++()
{ {
// Has the end of the series has been reached? // Has the end of the series has been reached?
if (p_bresenham_line->get_coordinate() == p_bresenham_line->back()) if (p_bresenham_line->get_coordinate() == p_bresenham_line->back())
@ -120,7 +120,7 @@ namespace etl
//*************************************************** //***************************************************
/// De-reference operator /// De-reference operator
//*************************************************** //***************************************************
value_type operator *() const value_type operator*() const
{ {
return p_bresenham_line->get_coordinate(); return p_bresenham_line->get_coordinate();
} }
@ -128,7 +128,7 @@ namespace etl
//*************************************************** //***************************************************
/// Equality operator /// Equality operator
//*************************************************** //***************************************************
friend bool operator ==(const const_iterator& lhs, const const_iterator& rhs) friend bool operator==(const const_iterator& lhs, const const_iterator& rhs)
{ {
return lhs.p_bresenham_line == rhs.p_bresenham_line; return lhs.p_bresenham_line == rhs.p_bresenham_line;
} }
@ -136,7 +136,7 @@ namespace etl
//*************************************************** //***************************************************
/// Inequality operator /// Inequality operator
//*************************************************** //***************************************************
friend bool operator !=(const const_iterator& lhs, const const_iterator& rhs) friend bool operator!=(const const_iterator& lhs, const const_iterator& rhs)
{ {
return !(lhs == rhs); return !(lhs == rhs);
} }
@ -251,7 +251,7 @@ namespace etl
//*************************************************** //***************************************************
/// Equality operator /// Equality operator
//*************************************************** //***************************************************
friend bool operator ==(const bresenham_line& lhs, const bresenham_line& rhs) friend bool operator==(const bresenham_line& lhs, const bresenham_line& rhs)
{ {
return (lhs.front() == rhs.front()) && (lhs.back() == rhs.back()); return (lhs.front() == rhs.front()) && (lhs.back() == rhs.back());
} }
@ -259,7 +259,7 @@ namespace etl
//*************************************************** //***************************************************
/// Inequality operator /// Inequality operator
//*************************************************** //***************************************************
friend bool operator !=(const bresenham_line& lhs, const bresenham_line& rhs) friend bool operator!=(const bresenham_line& lhs, const bresenham_line& rhs)
{ {
return !(lhs == rhs); return !(lhs == rhs);
} }
@ -272,7 +272,7 @@ namespace etl
void initialise(T first_x, T first_y, T last_x, T last_y) void initialise(T first_x, T first_y, T last_x, T last_y)
{ {
first = value_type(first_x, first_y); first = value_type(first_x, first_y);
last = value_type(last_x, last_y); last = value_type(last_x, last_y);
coordinate = first; coordinate = first;
x_increment = (last_x < first_x) ? -1 : 1; x_increment = (last_x < first_x) ? -1 : 1;
y_increment = (last_y < first_y) ? -1 : 1; y_increment = (last_y < first_y) ? -1 : 1;
@ -355,7 +355,6 @@ namespace etl
work_t balance; work_t balance;
bool do_minor_increment; bool do_minor_increment;
}; };
} } // namespace etl
#endif #endif

View File

@ -32,12 +32,12 @@ SOFTWARE.
#define ETL_BUFFER_DESCRIPTORS_INCLUDED #define ETL_BUFFER_DESCRIPTORS_INCLUDED
#include "platform.h" #include "platform.h"
#include "array.h"
#include "delegate.h"
#include "type_traits.h"
#include "static_assert.h"
#include "cyclic_value.h"
#include "algorithm.h" #include "algorithm.h"
#include "array.h"
#include "cyclic_value.h"
#include "delegate.h"
#include "static_assert.h"
#include "type_traits.h"
#include <cstring> #include <cstring>
@ -89,7 +89,7 @@ namespace etl
} }
//********************************* //*********************************
descriptor& operator =(const descriptor& other) descriptor& operator=(const descriptor& other)
{ {
pdesc_item = other.pdesc_item; pdesc_item = other.pdesc_item;
return *this; return *this;
@ -99,14 +99,13 @@ namespace etl
pointer data() const pointer data() const
{ {
assert(pdesc_item != ETL_NULLPTR); assert(pdesc_item != ETL_NULLPTR);
#include "private/diagnostic_null_dereference_push.h" #include "private/diagnostic_null_dereference_push.h"
return pdesc_item->pbuffer; return pdesc_item->pbuffer;
#include "private/diagnostic_pop.h" #include "private/diagnostic_pop.h"
} }
//********************************* //*********************************
ETL_NODISCARD ETL_NODISCARD ETL_CONSTEXPR size_type max_size() const
ETL_CONSTEXPR size_type max_size() const
{ {
return BUFFER_SIZE; return BUFFER_SIZE;
} }
@ -284,23 +283,26 @@ namespace etl
//********************************* //*********************************
struct descriptor_item struct descriptor_item
{ {
pointer pbuffer; pointer pbuffer;
volatile flag_type in_use; volatile flag_type in_use;
}; };
callback_type callback; callback_type callback;
etl::array<descriptor_item, N_BUFFERS> descriptor_items; etl::array<descriptor_item, N_BUFFERS> descriptor_items;
etl::cyclic_value<uint_least8_t, 0U, N_BUFFERS - 1> next; etl::cyclic_value<uint_least8_t, 0U, N_BUFFERS - 1> next;
}; };
template <typename TBuffer, size_t BUFFER_SIZE_, size_t N_BUFFERS_, typename TFlag> template <typename TBuffer, size_t BUFFER_SIZE_, size_t N_BUFFERS_, typename TFlag>
ETL_CONSTANT typename buffer_descriptors<TBuffer, BUFFER_SIZE_, N_BUFFERS_, TFlag>::size_type buffer_descriptors<TBuffer, BUFFER_SIZE_, N_BUFFERS_, TFlag>::N_BUFFERS; ETL_CONSTANT typename buffer_descriptors<TBuffer, BUFFER_SIZE_, N_BUFFERS_, TFlag>::size_type
buffer_descriptors<TBuffer, BUFFER_SIZE_, N_BUFFERS_, TFlag>::N_BUFFERS;
template <typename TBuffer, size_t BUFFER_SIZE_, size_t N_BUFFERS_, typename TFlag> template <typename TBuffer, size_t BUFFER_SIZE_, size_t N_BUFFERS_, typename TFlag>
ETL_CONSTANT typename buffer_descriptors<TBuffer, BUFFER_SIZE_, N_BUFFERS_, TFlag>::size_type buffer_descriptors<TBuffer, BUFFER_SIZE_, N_BUFFERS_, TFlag>::BUFFER_SIZE; ETL_CONSTANT typename buffer_descriptors<TBuffer, BUFFER_SIZE_, N_BUFFERS_, TFlag>::size_type
buffer_descriptors<TBuffer, BUFFER_SIZE_, N_BUFFERS_, TFlag>::BUFFER_SIZE;
template <typename TBuffer, size_t BUFFER_SIZE_, size_t N_BUFFERS_, typename TFlag> template <typename TBuffer, size_t BUFFER_SIZE_, size_t N_BUFFERS_, typename TFlag>
ETL_CONSTANT typename buffer_descriptors<TBuffer, BUFFER_SIZE_, N_BUFFERS_, TFlag>::size_type buffer_descriptors<TBuffer, BUFFER_SIZE_, N_BUFFERS_, TFlag>::descriptor::MAX_SIZE; ETL_CONSTANT typename buffer_descriptors<TBuffer, BUFFER_SIZE_, N_BUFFERS_, TFlag>::size_type
} buffer_descriptors<TBuffer, BUFFER_SIZE_, N_BUFFERS_, TFlag>::descriptor::MAX_SIZE;
} // namespace etl
#endif #endif
#endif #endif

View File

@ -33,15 +33,15 @@ namespace etl
{ {
#if ETL_USING_CPP11 && !defined(ETL_BYTE_FORCE_CPP03_IMPLEMENTATION) #if ETL_USING_CPP11 && !defined(ETL_BYTE_FORCE_CPP03_IMPLEMENTATION)
enum class byte : unsigned char {}; enum class byte : unsigned char
{
};
//************************************************************************* //*************************************************************************
/// To integer. /// To integer.
//************************************************************************* //*************************************************************************
template <typename TInteger> template <typename TInteger>
constexpr constexpr typename etl::enable_if<etl::is_integral<TInteger>::value, TInteger>::type to_integer(etl::byte b) ETL_NOEXCEPT
typename etl::enable_if<etl::is_integral<TInteger>::value, TInteger>::type
to_integer(etl::byte b) ETL_NOEXCEPT
{ {
return TInteger(b); return TInteger(b);
} }
@ -50,31 +50,25 @@ namespace etl
/// Shift left. /// Shift left.
//************************************************************************* //*************************************************************************
template <typename TInteger> template <typename TInteger>
constexpr constexpr typename etl::enable_if<etl::is_integral<TInteger>::value, etl::byte>::type operator<<(etl::byte b, TInteger shift) ETL_NOEXCEPT
typename etl::enable_if<etl::is_integral<TInteger>::value, etl::byte>::type
operator <<(etl::byte b, TInteger shift) ETL_NOEXCEPT
{ {
return etl::byte(static_cast<unsigned int>(b) << shift); return etl::byte(static_cast<unsigned int>(b) << shift);
} }
//************************************************************************* //*************************************************************************
/// Shift right /// Shift right
//************************************************************************* //*************************************************************************
template <typename TInteger> template <typename TInteger>
constexpr constexpr typename etl::enable_if<etl::is_integral<TInteger>::value, etl::byte>::type operator>>(etl::byte b, TInteger shift) ETL_NOEXCEPT
typename etl::enable_if<etl::is_integral<TInteger>::value, etl::byte>::type
operator >>(etl::byte b, TInteger shift) ETL_NOEXCEPT
{ {
return etl::byte(static_cast<unsigned int>(b) >> shift); return etl::byte(static_cast<unsigned int>(b) >> shift);
} }
//************************************************************************* //*************************************************************************
/// Shift left equals. /// Shift left equals.
//************************************************************************* //*************************************************************************
template <typename TInteger> template <typename TInteger>
constexpr constexpr typename etl::enable_if<etl::is_integral<TInteger>::value, etl::byte&>::type operator<<=(etl::byte& b, TInteger shift) ETL_NOEXCEPT
typename etl::enable_if<etl::is_integral<TInteger>::value, etl::byte&>::type
operator <<=(etl::byte& b, TInteger shift) ETL_NOEXCEPT
{ {
return b = b << shift; return b = b << shift;
} }
@ -83,9 +77,7 @@ namespace etl
/// Shift right equals. /// Shift right equals.
//************************************************************************* //*************************************************************************
template <typename TInteger> template <typename TInteger>
constexpr constexpr typename etl::enable_if<etl::is_integral<TInteger>::value, etl::byte&>::type operator>>=(etl::byte& b, TInteger shift) ETL_NOEXCEPT
typename etl::enable_if<etl::is_integral<TInteger>::value, etl::byte&>::type
operator >>=(etl::byte& b, TInteger shift) ETL_NOEXCEPT
{ {
return b = b >> shift; return b = b >> shift;
} }
@ -93,7 +85,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Or. /// Or.
//************************************************************************* //*************************************************************************
inline constexpr etl::byte operator |(etl::byte lhs, etl::byte rhs) ETL_NOEXCEPT inline constexpr etl::byte operator|(etl::byte lhs, etl::byte rhs) ETL_NOEXCEPT
{ {
return etl::byte(static_cast<unsigned int>(lhs) | static_cast<unsigned int>(rhs)); return etl::byte(static_cast<unsigned int>(lhs) | static_cast<unsigned int>(rhs));
} }
@ -101,7 +93,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// And. /// And.
//************************************************************************* //*************************************************************************
inline constexpr etl::byte operator &(etl::byte lhs, etl::byte rhs) ETL_NOEXCEPT inline constexpr etl::byte operator&(etl::byte lhs, etl::byte rhs) ETL_NOEXCEPT
{ {
return etl::byte(static_cast<unsigned int>(lhs) & static_cast<unsigned int>(rhs)); return etl::byte(static_cast<unsigned int>(lhs) & static_cast<unsigned int>(rhs));
} }
@ -109,7 +101,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Exclusive Or. /// Exclusive Or.
//************************************************************************* //*************************************************************************
inline constexpr etl::byte operator ^(etl::byte lhs, etl::byte rhs) ETL_NOEXCEPT inline constexpr etl::byte operator^(etl::byte lhs, etl::byte rhs) ETL_NOEXCEPT
{ {
return etl::byte(static_cast<unsigned int>(lhs) ^ static_cast<unsigned int>(rhs)); return etl::byte(static_cast<unsigned int>(lhs) ^ static_cast<unsigned int>(rhs));
} }
@ -117,7 +109,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Or equals. /// Or equals.
//************************************************************************* //*************************************************************************
inline ETL_CONSTEXPR14 etl::byte& operator |=(etl::byte& lhs, etl::byte rhs) ETL_NOEXCEPT inline ETL_CONSTEXPR14 etl::byte& operator|=(etl::byte& lhs, etl::byte rhs) ETL_NOEXCEPT
{ {
return lhs = lhs | rhs; return lhs = lhs | rhs;
} }
@ -125,7 +117,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// And equals /// And equals
//************************************************************************* //*************************************************************************
inline ETL_CONSTEXPR14 etl::byte& operator &=(etl::byte& lhs, etl::byte rhs) ETL_NOEXCEPT inline ETL_CONSTEXPR14 etl::byte& operator&=(etl::byte& lhs, etl::byte rhs) ETL_NOEXCEPT
{ {
return lhs = lhs & rhs; return lhs = lhs & rhs;
} }
@ -133,7 +125,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Exclusive or equals. /// Exclusive or equals.
//************************************************************************* //*************************************************************************
inline ETL_CONSTEXPR14 etl::byte& operator ^=(etl::byte& lhs, etl::byte rhs) ETL_NOEXCEPT inline ETL_CONSTEXPR14 etl::byte& operator^=(etl::byte& lhs, etl::byte rhs) ETL_NOEXCEPT
{ {
return lhs = lhs ^ rhs; return lhs = lhs ^ rhs;
} }
@ -141,7 +133,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Not. /// Not.
//************************************************************************* //*************************************************************************
inline constexpr etl::byte operator ~(etl::byte b) ETL_NOEXCEPT inline constexpr etl::byte operator~(etl::byte b) ETL_NOEXCEPT
{ {
return etl::byte(~static_cast<unsigned int>(b)); return etl::byte(~static_cast<unsigned int>(b));
} }
@ -157,11 +149,9 @@ namespace etl
// Friend functions // Friend functions
template <typename TInteger> template <typename TInteger>
friend friend typename etl::enable_if<etl::is_integral<TInteger>::value, TInteger>::type to_integer(etl::byte b);
typename etl::enable_if<etl::is_integral<TInteger>::value, TInteger>::type
to_integer(etl::byte b);
friend bool operator ==(etl::byte lhs, etl::byte rhs); friend bool operator==(etl::byte lhs, etl::byte rhs);
// Default constructor // Default constructor
byte() byte()
@ -192,7 +182,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Equality test /// Equality test
//************************************************************************* //*************************************************************************
inline bool operator ==(etl::byte lhs, etl::byte rhs) inline bool operator==(etl::byte lhs, etl::byte rhs)
{ {
return (lhs.value == rhs.value); return (lhs.value == rhs.value);
} }
@ -200,7 +190,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Inequality test /// Inequality test
//************************************************************************* //*************************************************************************
inline bool operator !=(etl::byte lhs, etl::byte rhs) inline bool operator!=(etl::byte lhs, etl::byte rhs)
{ {
return !(lhs == rhs); return !(lhs == rhs);
} }
@ -208,9 +198,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// To integer. /// To integer.
//************************************************************************* //*************************************************************************
template <typename TInteger> template <typename TInteger>
typename etl::enable_if<etl::is_integral<TInteger>::value, TInteger>::type typename etl::enable_if<etl::is_integral<TInteger>::value, TInteger>::type to_integer(etl::byte b)
to_integer(etl::byte b)
{ {
return TInteger(b); return TInteger(b);
} }
@ -219,28 +208,25 @@ namespace etl
/// Shift left. /// Shift left.
//************************************************************************* //*************************************************************************
template <typename TInteger> template <typename TInteger>
typename etl::enable_if<etl::is_integral<TInteger>::value, etl::byte>::type typename etl::enable_if<etl::is_integral<TInteger>::value, etl::byte>::type operator<<(etl::byte b, TInteger shift)
operator <<(etl::byte b, TInteger shift)
{ {
return etl::byte(to_integer<unsigned int>(b) << shift); return etl::byte(to_integer<unsigned int>(b) << shift);
} }
//************************************************************************* //*************************************************************************
/// Shift right /// Shift right
//************************************************************************* //*************************************************************************
template <typename TInteger> template <typename TInteger>
typename etl::enable_if<etl::is_integral<TInteger>::value, etl::byte>::type typename etl::enable_if<etl::is_integral<TInteger>::value, etl::byte>::type operator>>(etl::byte b, TInteger shift)
operator >>(etl::byte b, TInteger shift)
{ {
return etl::byte(to_integer<unsigned int>(b) >> shift); return etl::byte(to_integer<unsigned int>(b) >> shift);
} }
//************************************************************************* //*************************************************************************
/// Shift left equals. /// Shift left equals.
//************************************************************************* //*************************************************************************
template <typename TInteger> template <typename TInteger>
typename etl::enable_if<etl::is_integral<TInteger>::value, etl::byte&>::type typename etl::enable_if<etl::is_integral<TInteger>::value, etl::byte&>::type operator<<=(etl::byte& b, TInteger shift)
operator <<=(etl::byte& b, TInteger shift)
{ {
b = b << shift; b = b << shift;
@ -251,8 +237,7 @@ namespace etl
/// Shift right equals. /// Shift right equals.
//************************************************************************* //*************************************************************************
template <typename TInteger> template <typename TInteger>
typename etl::enable_if<etl::is_integral<TInteger>::value, etl::byte&>::type typename etl::enable_if<etl::is_integral<TInteger>::value, etl::byte&>::type operator>>=(etl::byte& b, TInteger shift)
operator >>=(etl::byte& b, TInteger shift)
{ {
b = b >> shift; b = b >> shift;
@ -262,7 +247,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Or. /// Or.
//************************************************************************* //*************************************************************************
inline etl::byte operator |(etl::byte lhs, etl::byte rhs) inline etl::byte operator|(etl::byte lhs, etl::byte rhs)
{ {
return etl::byte(to_integer<unsigned int>(lhs) | to_integer<unsigned int>(rhs)); return etl::byte(to_integer<unsigned int>(lhs) | to_integer<unsigned int>(rhs));
} }
@ -270,7 +255,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// And. /// And.
//************************************************************************* //*************************************************************************
inline etl::byte operator &(etl::byte lhs, etl::byte rhs) inline etl::byte operator&(etl::byte lhs, etl::byte rhs)
{ {
return etl::byte(to_integer<unsigned int>(lhs) & to_integer<unsigned int>(rhs)); return etl::byte(to_integer<unsigned int>(lhs) & to_integer<unsigned int>(rhs));
} }
@ -278,15 +263,15 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Exclusive Or. /// Exclusive Or.
//************************************************************************* //*************************************************************************
inline etl::byte operator ^(etl::byte lhs, etl::byte rhs) inline etl::byte operator^(etl::byte lhs, etl::byte rhs)
{ {
return etl::byte(to_integer<unsigned int>(lhs) ^ to_integer<unsigned int>(rhs)); return etl::byte(to_integer<unsigned int>(lhs) ^ to_integer<unsigned int>(rhs));
} }
//************************************************************************* //*************************************************************************
/// Or equals. /// Or equals.
//************************************************************************* //*************************************************************************
inline etl::byte& operator |=(etl::byte& lhs, etl::byte rhs) inline etl::byte& operator|=(etl::byte& lhs, etl::byte rhs)
{ {
return lhs = lhs | rhs; return lhs = lhs | rhs;
} }
@ -294,7 +279,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// And equals /// And equals
//************************************************************************* //*************************************************************************
inline etl::byte& operator &=(etl::byte& lhs, etl::byte rhs) inline etl::byte& operator&=(etl::byte& lhs, etl::byte rhs)
{ {
return lhs = lhs & rhs; return lhs = lhs & rhs;
} }
@ -302,7 +287,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Exclusive or equals. /// Exclusive or equals.
//************************************************************************* //*************************************************************************
inline etl::byte& operator ^=(etl::byte& lhs, etl::byte rhs) inline etl::byte& operator^=(etl::byte& lhs, etl::byte rhs)
{ {
return lhs = lhs ^ rhs; return lhs = lhs ^ rhs;
} }
@ -310,14 +295,13 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Not. /// Not.
//************************************************************************* //*************************************************************************
inline etl::byte operator ~(etl::byte b) inline etl::byte operator~(etl::byte b)
{ {
return etl::byte(~to_integer<unsigned char>(b)); return etl::byte(~to_integer<unsigned char>(b));
} }
#endif #endif
} // namespace etl
}
#endif #endif

View File

@ -32,22 +32,21 @@ SOFTWARE.
#define ETL_BYTE_STREAM_INCLUDED #define ETL_BYTE_STREAM_INCLUDED
#include "platform.h" #include "platform.h"
#include "type_traits.h"
#include "nullptr.h"
#include "endianness.h"
#include "integral_limits.h"
#include "algorithm.h" #include "algorithm.h"
#include "delegate.h"
#include "endianness.h"
#include "error_handler.h"
#include "exception.h"
#include "integral_limits.h"
#include "iterator.h" #include "iterator.h"
#include "memory.h" #include "memory.h"
#include "span.h" #include "nullptr.h"
#include "iterator.h"
#include "optional.h" #include "optional.h"
#include "delegate.h" #include "span.h"
#include "exception.h" #include "type_traits.h"
#include "error_handler.h"
#include <stdint.h>
#include <limits.h> #include <limits.h>
#include <stdint.h>
namespace etl namespace etl
{ {
@ -58,9 +57,9 @@ namespace etl
{ {
public: public:
typedef char* iterator; typedef char* iterator;
typedef const char* const_iterator; typedef const char* const_iterator;
typedef etl::span<char> callback_parameter_type; typedef etl::span<char> callback_parameter_type;
typedef etl::delegate<void(callback_parameter_type)> callback_type; typedef etl::delegate<void(callback_parameter_type)> callback_type;
//*************************************************************************** //***************************************************************************
@ -115,7 +114,7 @@ namespace etl
/// Construct from array. /// Construct from array.
//*************************************************************************** //***************************************************************************
template <typename T, size_t Size> template <typename T, size_t Size>
byte_stream_writer(T(&begin_)[Size], etl::endian stream_endianness_, callback_type callback_ = callback_type()) byte_stream_writer(T (&begin_)[Size], etl::endian stream_endianness_, callback_type callback_ = callback_type())
: pdata(begin_) : pdata(begin_)
, pcurrent(begin_) , pcurrent(begin_)
, stream_length(begin_ + (Size * sizeof(T))) , stream_length(begin_ + (Size * sizeof(T)))
@ -151,8 +150,7 @@ namespace etl
/// Write a value to the stream. /// Write a value to the stream.
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, void>::type typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, void>::type write_unchecked(T value)
write_unchecked(T value)
{ {
to_bytes<T>(value); to_bytes<T>(value);
} }
@ -161,8 +159,7 @@ namespace etl
/// Write a value to the stream. /// Write a value to the stream.
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, bool>::type typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, bool>::type write(T value)
write(T value)
{ {
bool success = (available<T>() > 0U); bool success = (available<T>() > 0U);
@ -178,8 +175,7 @@ namespace etl
/// Write a range of T to the stream. /// Write a range of T to the stream.
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, void>::type typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, void>::type write_unchecked(const etl::span<T>& range)
write_unchecked(const etl::span<T>& range)
{ {
typename etl::span<T>::iterator itr = range.begin(); typename etl::span<T>::iterator itr = range.begin();
@ -194,8 +190,7 @@ namespace etl
/// Write a range of T to the stream. /// Write a range of T to the stream.
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, bool>::type typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, bool>::type write(const etl::span<T>& range)
write(const etl::span<T>& range)
{ {
bool success = (available<T>() >= range.size()); bool success = (available<T>() >= range.size());
@ -211,8 +206,7 @@ namespace etl
/// Write a range of T to the stream. /// Write a range of T to the stream.
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, void>::type typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, void>::type write_unchecked(const T* start, size_t length)
write_unchecked(const T* start, size_t length)
{ {
while (length-- != 0U) while (length-- != 0U)
{ {
@ -225,8 +219,7 @@ namespace etl
/// Write a range of T to the stream. /// Write a range of T to the stream.
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, bool>::type typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, bool>::type write(const T* start, size_t length)
write(const T* start, size_t length)
{ {
bool success = (available<T>() >= length); bool success = (available<T>() >= length);
@ -439,8 +432,7 @@ namespace etl
/// to_bytes /// to_bytes
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
typename etl::enable_if<sizeof(T) == 1U, void>::type typename etl::enable_if<sizeof(T) == 1U, void>::type to_bytes(const T value)
to_bytes(const T value)
{ {
*pcurrent = static_cast<char>(value); *pcurrent = static_cast<char>(value);
step(1U); step(1U);
@ -448,8 +440,7 @@ namespace etl
//********************************* //*********************************
template <typename T> template <typename T>
typename etl::enable_if<sizeof(T) != 1U, void>::type typename etl::enable_if<sizeof(T) != 1U, void>::type to_bytes(const T value)
to_bytes(const T value)
{ {
const char* pv = reinterpret_cast<const char*>(&value); const char* pv = reinterpret_cast<const char*>(&value);
copy_value(pv, pcurrent, sizeof(T)); copy_value(pv, pcurrent, sizeof(T));
@ -494,7 +485,7 @@ namespace etl
{ {
public: public:
typedef char* iterator; typedef char* iterator;
typedef const char* const_iterator; typedef const char* const_iterator;
//*************************************************************************** //***************************************************************************
@ -545,7 +536,7 @@ namespace etl
/// Construct from array. /// Construct from array.
//*************************************************************************** //***************************************************************************
template <typename T, size_t Size> template <typename T, size_t Size>
byte_stream_reader(T(&begin_)[Size], etl::endian stream_endianness_) byte_stream_reader(T (&begin_)[Size], etl::endian stream_endianness_)
: pdata(begin_) : pdata(begin_)
, pcurrent(begin_) , pcurrent(begin_)
, stream_length(begin_ + (Size * sizeof(T))) , stream_length(begin_ + (Size * sizeof(T)))
@ -557,7 +548,7 @@ namespace etl
/// Construct from const array. /// Construct from const array.
//*************************************************************************** //***************************************************************************
template <typename T, size_t Size> template <typename T, size_t Size>
byte_stream_reader(const T(&begin_)[Size], etl::endian stream_endianness_) byte_stream_reader(const T (&begin_)[Size], etl::endian stream_endianness_)
: pdata(begin_) : pdata(begin_)
, pcurrent(begin_) , pcurrent(begin_)
, stream_length(begin_ + (Size * sizeof(T))) , stream_length(begin_ + (Size * sizeof(T)))
@ -569,8 +560,7 @@ namespace etl
/// Read a value from the stream. /// Read a value from the stream.
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, T>::type typename etl::enable_if< etl::is_integral<T>::value || etl::is_floating_point<T>::value, T>::type read_unchecked()
read_unchecked()
{ {
return from_bytes<T>(); return from_bytes<T>();
} }
@ -579,8 +569,7 @@ namespace etl
/// Read a value from the stream. /// Read a value from the stream.
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, etl::optional<T> >::type typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, etl::optional<T> >::type read()
read()
{ {
etl::optional<T> result; etl::optional<T> result;
@ -597,14 +586,13 @@ namespace etl
/// Read a byte range from the stream. /// Read a byte range from the stream.
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
typename etl::enable_if<sizeof(T) == 1U, etl::span<const T> >::type typename etl::enable_if<sizeof(T) == 1U, etl::span<const T> >::type read_unchecked(size_t n)
read_unchecked(size_t n)
{ {
etl::span<const T> result; etl::span<const T> result;
const char* pend = pcurrent + (n * sizeof(T)); const char* pend = pcurrent + (n * sizeof(T));
result = etl::span<const T>(reinterpret_cast<const T*>(pcurrent), reinterpret_cast<const T*>(pend)); result = etl::span<const T>(reinterpret_cast<const T*>(pcurrent), reinterpret_cast<const T*>(pend));
pcurrent = pend; pcurrent = pend;
return result; return result;
@ -614,8 +602,7 @@ namespace etl
/// Read a byte range from the stream. /// Read a byte range from the stream.
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
typename etl::enable_if<sizeof(T) == 1U, etl::optional<etl::span<const T> > >::type typename etl::enable_if<sizeof(T) == 1U, etl::optional<etl::span<const T> > >::type read(size_t n)
read(size_t n)
{ {
etl::optional<etl::span<const T> > result; etl::optional<etl::span<const T> > result;
@ -665,8 +652,8 @@ namespace etl
/// Read a range of T from the stream. /// Read a range of T from the stream.
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, etl::span<const T> >::type typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, etl::span<const T> >::type read_unchecked(T* start,
read_unchecked(T* start, size_t length) size_t length)
{ {
T* destination = start; T* destination = start;
@ -826,16 +813,14 @@ namespace etl
/// from_bytes /// from_bytes
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
typename etl::enable_if<sizeof(T) == 1U, T>::type typename etl::enable_if<sizeof(T) == 1U, T>::type from_bytes()
from_bytes()
{ {
return static_cast<T>(*pcurrent++); return static_cast<T>(*pcurrent++);
} }
//********************************* //*********************************
template <typename T> template <typename T>
typename etl::enable_if<sizeof(T) != 1U, T>::type typename etl::enable_if<sizeof(T) != 1U, T>::type from_bytes()
from_bytes()
{ {
T value; T value;
@ -893,7 +878,7 @@ namespace etl
/// Overload this to support custom types. /// Overload this to support custom types.
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
T read_unchecked(etl::byte_stream_reader& stream) T read_unchecked(etl::byte_stream_reader& stream)
{ {
return stream.read_unchecked<T>(); return stream.read_unchecked<T>();
} }
@ -906,6 +891,6 @@ namespace etl
{ {
return stream.read<T>(); return stream.read<T>();
} }
} } // namespace etl
#endif #endif

View File

@ -34,9 +34,10 @@ SOFTWARE.
namespace etl namespace etl
{ {
//*************************************************************************** //***************************************************************************
/// A callback class designed to be multiply inherited by other client classes. /// A callback class designed to be multiply inherited by other client
/// The class is parametrised with a callback parameter type and a unique id. /// classes. The class is parametrised with a callback parameter type and a
/// The unique id allows multiple callbacks with the same parameter type. /// unique id. The unique id allows multiple callbacks with the same parameter
/// type.
///\tparam TParameter The callback parameter type. ///\tparam TParameter The callback parameter type.
///\tparam ID The unique id for this callback. ///\tparam ID The unique id for this callback.
//*************************************************************************** //***************************************************************************
@ -49,25 +50,25 @@ namespace etl
template <typename T, const int I> template <typename T, const int I>
struct parameter struct parameter
{ {
parameter(T value_) parameter(T value_)
: value(value_) : value(value_)
{ {
} }
typedef T value_type; typedef T value_type;
T value; T value;
private: private:
parameter(); parameter();
}; };
// Specialisation for void. // Specialisation for void.
template <const int I> template <const int I>
struct parameter<void, I> struct parameter<void, I>
{ {
typedef void value_type; typedef void value_type;
}; };
public: public:
@ -76,6 +77,6 @@ namespace etl
virtual void etl_callback(type p = type()) = 0; virtual void etl_callback(type p = type()) = 0;
}; };
} } // namespace etl
#endif #endif

View File

@ -32,10 +32,10 @@ SOFTWARE.
#define ETL_CALLBACK_SERVICE_INCLUDED #define ETL_CALLBACK_SERVICE_INCLUDED
#include "platform.h" #include "platform.h"
#include "array.h"
#include "function.h"
#include "nullptr.h" #include "nullptr.h"
#include "static_assert.h" #include "static_assert.h"
#include "function.h"
#include "array.h"
namespace etl namespace etl
{ {
@ -55,8 +55,8 @@ namespace etl
/// Sets all callbacks to the internal default. /// Sets all callbacks to the internal default.
//************************************************************************* //*************************************************************************
callback_service() callback_service()
: unhandled_callback(*this), : unhandled_callback(*this)
p_unhandled(ETL_NULLPTR) , p_unhandled(ETL_NULLPTR)
{ {
lookup.fill(&unhandled_callback); lookup.fill(&unhandled_callback);
} }
@ -71,7 +71,7 @@ namespace etl
void register_callback(etl::ifunction<size_t>& callback) void register_callback(etl::ifunction<size_t>& callback)
{ {
ETL_STATIC_ASSERT(Id < (Offset + Range), "Callback Id out of range"); ETL_STATIC_ASSERT(Id < (Offset + Range), "Callback Id out of range");
ETL_STATIC_ASSERT(Id >= Offset, "Callback Id out of range"); ETL_STATIC_ASSERT(Id >= Offset, "Callback Id out of range");
lookup[Id - Offset] = &callback; lookup[Id - Offset] = &callback;
} }
@ -108,7 +108,7 @@ namespace etl
void callback() void callback()
{ {
ETL_STATIC_ASSERT(Id < (Offset + Range), "Callback Id out of range"); ETL_STATIC_ASSERT(Id < (Offset + Range), "Callback Id out of range");
ETL_STATIC_ASSERT(Id >= Offset, "Callback Id out of range"); ETL_STATIC_ASSERT(Id >= Offset, "Callback Id out of range");
(*lookup[Id - Offset])(Id); (*lookup[Id - Offset])(Id);
} }
@ -144,9 +144,7 @@ namespace etl
} }
/// The default callback for unhandled ids. /// The default callback for unhandled ids.
etl::function_mp<callback_service<Range, Offset>, etl::function_mp<callback_service<Range, Offset>, size_t, &callback_service<Range, Offset>::unhandled> unhandled_callback;
size_t,
&callback_service<Range, Offset>::unhandled> unhandled_callback;
/// Pointer to the user defined 'unhandled' callback. /// Pointer to the user defined 'unhandled' callback.
etl::ifunction<size_t>* p_unhandled; etl::ifunction<size_t>* p_unhandled;
@ -154,6 +152,6 @@ namespace etl
/// Lookup table of callbacks. /// Lookup table of callbacks.
etl::array<etl::ifunction<size_t>*, Range> lookup; etl::array<etl::ifunction<size_t>*, Range> lookup;
}; };
} } // namespace etl
#endif #endif

View File

@ -31,14 +31,14 @@ SOFTWARE.
#include "platform.h" #include "platform.h"
#include "algorithm.h" #include "algorithm.h"
#include "nullptr.h" #include "atomic.h"
#include "delegate.h"
#include "error_handler.h"
#include "function.h" #include "function.h"
#include "nullptr.h"
#include "placement_new.h"
#include "static_assert.h" #include "static_assert.h"
#include "timer.h" #include "timer.h"
#include "atomic.h"
#include "error_handler.h"
#include "placement_new.h"
#include "delegate.h"
#include <stdint.h> #include <stdint.h>
@ -91,9 +91,7 @@ namespace etl
//******************************************* //*******************************************
/// Register a timer. /// Register a timer.
//******************************************* //*******************************************
etl::timer::id::type register_timer(void (*p_callback_)(), etl::timer::id::type register_timer(void (*p_callback_)(), uint32_t period_, bool repeating_)
uint32_t period_,
bool repeating_)
{ {
etl::timer::id::type id = etl::timer::id::NO_TIMER; etl::timer::id::type id = etl::timer::id::NO_TIMER;
@ -123,9 +121,7 @@ namespace etl
//******************************************* //*******************************************
/// Register a timer. /// Register a timer.
//******************************************* //*******************************************
etl::timer::id::type register_timer(etl::ifunction<void>& callback_, etl::timer::id::type register_timer(etl::ifunction<void>& callback_, uint32_t period_, bool repeating_)
uint32_t period_,
bool repeating_)
{ {
etl::timer::id::type id = etl::timer::id::NO_TIMER; etl::timer::id::type id = etl::timer::id::NO_TIMER;
@ -152,38 +148,36 @@ namespace etl
return id; return id;
} }
//******************************************* //*******************************************
/// Register a timer. /// Register a timer.
//******************************************* //*******************************************
#if ETL_USING_CPP11 #if ETL_USING_CPP11
etl::timer::id::type register_timer(callback_type& callback_, etl::timer::id::type register_timer(callback_type& callback_, uint32_t period_, bool repeating_)
uint32_t period_, {
bool repeating_) etl::timer::id::type id = etl::timer::id::NO_TIMER;
bool is_space = (registered_timers < MAX_TIMERS);
if (is_space)
{ {
etl::timer::id::type id = etl::timer::id::NO_TIMER; // Search for the free space.
for (uint_least8_t i = 0U; i < MAX_TIMERS; ++i)
{
timer_data& timer = timer_array[i];
bool is_space = (registered_timers < MAX_TIMERS); if (timer.id == etl::timer::id::NO_TIMER)
if (is_space)
{ {
// Search for the free space. // Create in-place.
for (uint_least8_t i = 0U; i < MAX_TIMERS; ++i) new (&timer) timer_data(i, callback_, period_, repeating_);
{ ++registered_timers;
timer_data& timer = timer_array[i]; id = i;
break;
if (timer.id == etl::timer::id::NO_TIMER)
{
// Create in-place.
new (&timer) timer_data(i, callback_, period_, repeating_);
++registered_timers;
id = i;
break;
}
}
} }
}
return id;
} }
return id;
}
#endif #endif
//******************************************* //*******************************************
@ -290,17 +284,17 @@ namespace etl
if (timer.cbk_type == timer_data::C_CALLBACK) if (timer.cbk_type == timer_data::C_CALLBACK)
{ {
// Call the C callback. // Call the C callback.
reinterpret_cast<void(*)()>(timer.p_callback)(); reinterpret_cast<void (*)()>(timer.p_callback)();
} }
else if(timer.cbk_type == timer_data::IFUNCTION) else if (timer.cbk_type == timer_data::IFUNCTION)
{ {
// Call the function wrapper callback. // Call the function wrapper callback.
(*reinterpret_cast<etl::ifunction<void>*>(timer.p_callback))(); (*reinterpret_cast<etl::ifunction<void>*>(timer.p_callback))();
} }
else if(timer.cbk_type == timer_data::DELEGATE) else if (timer.cbk_type == timer_data::DELEGATE)
{ {
// Call the delegate callback. // Call the delegate callback.
(*reinterpret_cast<callback_type*>(timer.p_callback))(); (*reinterpret_cast<callback_type*>(timer.p_callback))();
} }
} }
@ -427,7 +421,8 @@ namespace etl
//******************************************* //*******************************************
/// Get the time to the next timer event. /// Get the time to the next timer event.
/// Returns etl::timer::interval::No_Active_Interval if there is no active timer. /// Returns etl::timer::interval::No_Active_Interval if there is no active
/// timer.
//******************************************* //*******************************************
uint32_t time_to_next() const uint32_t time_to_next() const
{ {
@ -524,10 +519,7 @@ namespace etl
//******************************************* //*******************************************
/// C function callback /// C function callback
//******************************************* //*******************************************
timer_data(etl::timer::id::type id_, timer_data(etl::timer::id::type id_, void (*p_callback_)(), uint32_t period_, bool repeating_)
void (*p_callback_)(),
uint32_t period_,
bool repeating_)
: p_callback(reinterpret_cast<void*>(p_callback_)) : p_callback(reinterpret_cast<void*>(p_callback_))
, period(period_) , period(period_)
, delta(etl::timer::state::Inactive) , delta(etl::timer::state::Inactive)
@ -542,10 +534,7 @@ namespace etl
//******************************************* //*******************************************
/// ETL function callback /// ETL function callback
//******************************************* //*******************************************
timer_data(etl::timer::id::type id_, timer_data(etl::timer::id::type id_, etl::ifunction<void>& callback_, uint32_t period_, bool repeating_)
etl::ifunction<void>& callback_,
uint32_t period_,
bool repeating_)
: p_callback(reinterpret_cast<void*>(&callback_)) : p_callback(reinterpret_cast<void*>(&callback_))
, period(period_) , period(period_)
, delta(etl::timer::state::Inactive) , delta(etl::timer::state::Inactive)
@ -560,18 +549,15 @@ namespace etl
//******************************************* //*******************************************
/// ETL delegate callback /// ETL delegate callback
//******************************************* //*******************************************
timer_data(etl::timer::id::type id_, timer_data(etl::timer::id::type id_, callback_type& callback_, uint32_t period_, bool repeating_)
callback_type& callback_, : p_callback(reinterpret_cast<void*>(&callback_))
uint32_t period_, , period(period_)
bool repeating_) , delta(etl::timer::state::Inactive)
: p_callback(reinterpret_cast<void*>(&callback_)), , id(id_)
period(period_), , previous(etl::timer::id::NO_TIMER)
delta(etl::timer::state::Inactive), , next(etl::timer::id::NO_TIMER)
id(id_), , repeating(repeating_)
previous(etl::timer::id::NO_TIMER), , cbk_type(DELEGATE)
next(etl::timer::id::NO_TIMER),
repeating(repeating_),
cbk_type(DELEGATE)
{ {
} }
@ -591,34 +577,36 @@ namespace etl
delta = etl::timer::state::Inactive; delta = etl::timer::state::Inactive;
} }
void* p_callback; void* p_callback;
uint32_t period; uint32_t period;
uint32_t delta; uint32_t delta;
etl::timer::id::type id; etl::timer::id::type id;
uint_least8_t previous; uint_least8_t previous;
uint_least8_t next; uint_least8_t next;
bool repeating; bool repeating;
callback_type_id cbk_type; callback_type_id cbk_type;
private: private:
// Disabled. // Disabled.
timer_data(const timer_data& other); timer_data(const timer_data& other);
timer_data& operator =(const timer_data& other); timer_data& operator=(const timer_data& other);
}; };
//******************************************* //*******************************************
/// Constructor. /// Constructor.
//******************************************* //*******************************************
icallback_timer(timer_data* const timer_array_, const uint_least8_t Max_Timers_) icallback_timer(timer_data* const timer_array_, const uint_least8_t Max_Timers_)
: timer_array(timer_array_), : timer_array(timer_array_)
active_list(timer_array_), , active_list(timer_array_)
enabled(false), , enabled(false)
,
#if defined(ETL_CALLBACK_TIMER_USE_ATOMIC_LOCK) #if defined(ETL_CALLBACK_TIMER_USE_ATOMIC_LOCK)
process_semaphore(0), process_semaphore(0)
,
#endif #endif
registered_timers(0), registered_timers(0)
MAX_TIMERS(Max_Timers_) , MAX_TIMERS(Max_Timers_)
{ {
} }
@ -662,10 +650,10 @@ namespace etl
if (head == etl::timer::id::NO_TIMER) if (head == etl::timer::id::NO_TIMER)
{ {
// No entries yet. // No entries yet.
head = id_; head = id_;
tail = id_; tail = id_;
timer.previous = etl::timer::id::NO_TIMER; timer.previous = etl::timer::id::NO_TIMER;
timer.next = etl::timer::id::NO_TIMER; timer.next = etl::timer::id::NO_TIMER;
} }
else else
{ {
@ -686,8 +674,8 @@ namespace etl
// Insert before test. // Insert before test.
timer.previous = test.previous; timer.previous = test.previous;
test.previous = timer.id; test.previous = timer.id;
timer.next = test.id; timer.next = test.id;
// Adjust the next delta to compensate. // Adjust the next delta to compensate.
test.delta -= timer.delta; test.delta -= timer.delta;
@ -711,9 +699,9 @@ namespace etl
{ {
// Tag on to the tail. // Tag on to the tail.
ptimers[tail].next = timer.id; ptimers[tail].next = timer.id;
timer.previous = tail; timer.previous = tail;
timer.next = etl::timer::id::NO_TIMER; timer.next = etl::timer::id::NO_TIMER;
tail = timer.id; tail = timer.id;
} }
} }
} }
@ -751,8 +739,8 @@ namespace etl
} }
timer.previous = etl::timer::id::NO_TIMER; timer.previous = etl::timer::id::NO_TIMER;
timer.next = etl::timer::id::NO_TIMER; timer.next = etl::timer::id::NO_TIMER;
timer.delta = etl::timer::state::Inactive; timer.delta = etl::timer::state::Inactive;
} }
//******************************* //*******************************
@ -796,12 +784,12 @@ namespace etl
while (id != etl::timer::id::NO_TIMER) while (id != etl::timer::id::NO_TIMER)
{ {
timer_data& timer = ptimers[id]; timer_data& timer = ptimers[id];
id = next(id); id = next(id);
timer.next = etl::timer::id::NO_TIMER; timer.next = etl::timer::id::NO_TIMER;
} }
head = etl::timer::id::NO_TIMER; head = etl::timer::id::NO_TIMER;
tail = etl::timer::id::NO_TIMER; tail = etl::timer::id::NO_TIMER;
current = etl::timer::id::NO_TIMER; current = etl::timer::id::NO_TIMER;
} }
@ -823,15 +811,15 @@ namespace etl
volatile bool enabled; volatile bool enabled;
#if defined(ETL_CALLBACK_TIMER_USE_ATOMIC_LOCK) #if defined(ETL_CALLBACK_TIMER_USE_ATOMIC_LOCK)
#if defined(ETL_TIMER_SEMAPHORE_TYPE) #if defined(ETL_TIMER_SEMAPHORE_TYPE)
typedef ETL_TIMER_SEMAPHORE_TYPE timer_semaphore_t; typedef ETL_TIMER_SEMAPHORE_TYPE timer_semaphore_t;
#else
#if ETL_HAS_ATOMIC
typedef etl::atomic_uint16_t timer_semaphore_t;
#else #else
#error No atomic type available #if ETL_HAS_ATOMIC
typedef etl::atomic_uint16_t timer_semaphore_t;
#else
#error No atomic type available
#endif
#endif #endif
#endif
mutable etl::timer_semaphore_t process_semaphore; mutable etl::timer_semaphore_t process_semaphore;
#endif #endif
@ -867,7 +855,7 @@ namespace etl
timer_data timer_array[Max_Timers_]; timer_data timer_array[Max_Timers_];
}; };
} } // namespace etl
#undef ETL_DISABLE_TIMER_UPDATES #undef ETL_DISABLE_TIMER_UPDATES
#undef ETL_ENABLE_TIMER_UPDATES #undef ETL_ENABLE_TIMER_UPDATES

View File

@ -31,13 +31,13 @@ SOFTWARE.
#include "platform.h" #include "platform.h"
#include "algorithm.h" #include "algorithm.h"
#include "nullptr.h" #include "delegate.h"
#include "error_handler.h"
#include "function.h" #include "function.h"
#include "nullptr.h"
#include "placement_new.h"
#include "static_assert.h" #include "static_assert.h"
#include "timer.h" #include "timer.h"
#include "error_handler.h"
#include "placement_new.h"
#include "delegate.h"
#include <stdint.h> #include <stdint.h>
@ -58,35 +58,33 @@ namespace etl
//******************************************* //*******************************************
/// Register a timer. /// Register a timer.
//******************************************* //*******************************************
etl::timer::id::type register_timer(callback_type callback_, etl::timer::id::type register_timer(callback_type callback_, uint32_t period_, bool repeating_)
uint32_t period_,
bool repeating_)
{ {
etl::timer::id::type id = etl::timer::id::NO_TIMER; etl::timer::id::type id = etl::timer::id::NO_TIMER;
bool is_space = (number_of_registered_timers < Max_Timers);
if (is_space) bool is_space = (number_of_registered_timers < Max_Timers);
if (is_space)
{
// Search for the free space.
for (uint_least8_t i = 0U; i < Max_Timers; ++i)
{ {
// Search for the free space. timer_data& timer = timer_array[i];
for (uint_least8_t i = 0U; i < Max_Timers; ++i)
{ if (timer.id == etl::timer::id::NO_TIMER)
timer_data& timer = timer_array[i]; {
// Create in-place.
if (timer.id == etl::timer::id::NO_TIMER) new (&timer) timer_data(i, callback_, period_, repeating_);
{ ++number_of_registered_timers;
// Create in-place. id = i;
new (&timer) timer_data(i, callback_, period_, repeating_); break;
++number_of_registered_timers;
id = i;
break;
}
} }
} }
return id;
} }
return id;
}
//******************************************* //*******************************************
/// Unregister a timer. /// Unregister a timer.
//******************************************* //*******************************************
@ -319,7 +317,8 @@ namespace etl
//******************************************* //*******************************************
/// Get the time to the next timer event. /// Get the time to the next timer event.
/// Returns etl::timer::interval::No_Active_Interval if there is no active timer. /// Returns etl::timer::interval::No_Active_Interval if there is no active
/// timer.
//******************************************* //*******************************************
uint32_t time_to_next() const uint32_t time_to_next() const
{ {
@ -412,10 +411,7 @@ namespace etl
//******************************************* //*******************************************
/// ETL delegate callback /// ETL delegate callback
//******************************************* //*******************************************
timer_data(etl::timer::id::type id_, timer_data(etl::timer::id::type id_, callback_type callback_, uint32_t period_, bool repeating_)
callback_type callback_,
uint32_t period_,
bool repeating_)
: callback(callback_) : callback(callback_)
, period(period_) , period(period_)
, delta(etl::timer::state::Inactive) , delta(etl::timer::state::Inactive)
@ -454,13 +450,13 @@ namespace etl
// Disabled. // Disabled.
timer_data(const timer_data& other) ETL_DELETE; timer_data(const timer_data& other) ETL_DELETE;
timer_data& operator =(const timer_data& other) ETL_DELETE; timer_data& operator=(const timer_data& other) ETL_DELETE;
}; };
//******************************************* //*******************************************
/// Constructor. /// Constructor.
//******************************************* //*******************************************
icallback_timer_atomic(timer_data* const timer_array_, const uint_least8_t Max_Timers_) icallback_timer_atomic(timer_data* const timer_array_, const uint_least8_t Max_Timers_)
: timer_array(timer_array_) : timer_array(timer_array_)
, active_list(timer_array_) , active_list(timer_array_)
, enabled(false) , enabled(false)
@ -512,10 +508,10 @@ namespace etl
if (head == etl::timer::id::NO_TIMER) if (head == etl::timer::id::NO_TIMER)
{ {
// No entries yet. // No entries yet.
head = id_; head = id_;
tail = id_; tail = id_;
timer.previous = etl::timer::id::NO_TIMER; timer.previous = etl::timer::id::NO_TIMER;
timer.next = etl::timer::id::NO_TIMER; timer.next = etl::timer::id::NO_TIMER;
} }
else else
{ {
@ -536,8 +532,8 @@ namespace etl
// Insert before test. // Insert before test.
timer.previous = test.previous; timer.previous = test.previous;
test.previous = timer.id; test.previous = timer.id;
timer.next = test.id; timer.next = test.id;
// Adjust the next delta to compensate. // Adjust the next delta to compensate.
test.delta -= timer.delta; test.delta -= timer.delta;
@ -561,9 +557,9 @@ namespace etl
{ {
// Tag on to the tail. // Tag on to the tail.
ptimers[tail].next = timer.id; ptimers[tail].next = timer.id;
timer.previous = tail; timer.previous = tail;
timer.next = etl::timer::id::NO_TIMER; timer.next = etl::timer::id::NO_TIMER;
tail = timer.id; tail = timer.id;
} }
} }
} }
@ -601,8 +597,8 @@ namespace etl
} }
timer.previous = etl::timer::id::NO_TIMER; timer.previous = etl::timer::id::NO_TIMER;
timer.next = etl::timer::id::NO_TIMER; timer.next = etl::timer::id::NO_TIMER;
timer.delta = etl::timer::state::Inactive; timer.delta = etl::timer::state::Inactive;
} }
//******************************* //*******************************
@ -646,12 +642,12 @@ namespace etl
while (id != etl::timer::id::NO_TIMER) while (id != etl::timer::id::NO_TIMER)
{ {
timer_data& timer = ptimers[id]; timer_data& timer = ptimers[id];
id = next(id); id = next(id);
timer.next = etl::timer::id::NO_TIMER; timer.next = etl::timer::id::NO_TIMER;
} }
head = etl::timer::id::NO_TIMER; head = etl::timer::id::NO_TIMER;
tail = etl::timer::id::NO_TIMER; tail = etl::timer::id::NO_TIMER;
current = etl::timer::id::NO_TIMER; current = etl::timer::id::NO_TIMER;
} }
@ -670,9 +666,9 @@ namespace etl
// The list of active timers. // The list of active timers.
timer_list active_list; timer_list active_list;
bool enabled; bool enabled;
mutable TSemaphore process_semaphore; mutable TSemaphore process_semaphore;
uint_least8_t number_of_registered_timers; uint_least8_t number_of_registered_timers;
event_callback_type insert_callback; event_callback_type insert_callback;
event_callback_type remove_callback; event_callback_type remove_callback;
@ -704,6 +700,6 @@ namespace etl
typename etl::icallback_timer_atomic<TSemaphore>::timer_data timer_array[Max_Timers_]; typename etl::icallback_timer_atomic<TSemaphore>::timer_data timer_array[Max_Timers_];
}; };
} } // namespace etl
#endif #endif

View File

@ -31,10 +31,10 @@ SOFTWARE.
#include "platform.h" #include "platform.h"
#include "callback_timer_locked.h" #include "callback_timer_locked.h"
#include "delegate.h"
#include "etl/nullptr.h" #include "etl/nullptr.h"
#include "etl/optional.h" #include "etl/optional.h"
#include "priority_queue.h" #include "priority_queue.h"
#include "delegate.h"
namespace etl namespace etl
{ {
@ -103,7 +103,7 @@ namespace etl
{ {
if (!handler_queue.full()) if (!handler_queue.full())
{ {
handler_queue.push(callback_node(timer.callback, timer_priorities[timer.id])); handler_queue.push(callback_node(timer.callback, timer_priorities[timer.id]));
} }
} }
@ -143,18 +143,17 @@ namespace etl
{ {
callback_type work_todo_callback; callback_type work_todo_callback;
do do {
{
lock(); lock();
if (handler_queue.empty()) if (handler_queue.empty())
{ {
work_todo_callback.clear(); work_todo_callback.clear();
} }
else else
{ {
callback_node &work_todo_callback_node = handler_queue.top(); callback_node& work_todo_callback_node = handler_queue.top();
work_todo_callback = work_todo_callback_node.callback; work_todo_callback = work_todo_callback_node.callback;
handler_queue.pop(); handler_queue.pop();
} }
@ -169,11 +168,9 @@ namespace etl
//******************************************* //*******************************************
/// Register a timer. /// Register a timer.
//******************************************* //*******************************************
etl::timer::id::type register_timer(const callback_type& callback_, etl::timer::id::type register_timer(const callback_type& callback_, uint32_t period_, bool repeating_)
uint32_t period_,
bool repeating_)
{ {
return register_timer(callback_, period_, repeating_, 0); return register_timer(callback_, period_, repeating_, 0);
} }
//******************************************* //*******************************************
@ -182,27 +179,24 @@ namespace etl
/// Suggestion: this could be used as amonth of work to do and /// Suggestion: this could be used as amonth of work to do and
/// less work will be done in first place. /// less work will be done in first place.
//******************************************* //*******************************************
etl::timer::id::type register_timer(const callback_type& callback_, etl::timer::id::type register_timer(const callback_type& callback_, uint32_t period_, bool repeating_, uint_least8_t priority_)
uint32_t period_,
bool repeating_,
uint_least8_t priority_)
{ {
etl::timer::id::type id = icallback_timer_locked::register_timer(callback_, period_, repeating_); etl::timer::id::type id = icallback_timer_locked::register_timer(callback_, period_, repeating_);
if (id != etl::timer::id::NO_TIMER) if (id != etl::timer::id::NO_TIMER)
{ {
timer_priorities[id] = priority_; timer_priorities[id] = priority_;
} }
return id; return id;
} }
private: private:
priority_queue<callback_node, Max_Handlers_> handler_queue; priority_queue<callback_node, Max_Handlers_> handler_queue;
uint_least8_t timer_priorities[Max_Timers_]; uint_least8_t timer_priorities[Max_Timers_];
timer_data timer_array[Max_Timers_]; timer_data timer_array[Max_Timers_];
}; };
} } // namespace etl
#endif #endif

View File

@ -1,4 +1,4 @@
/****************************************************************************** /******************************************************************************
The MIT License(MIT) The MIT License(MIT)
Embedded Template Library. Embedded Template Library.
@ -31,12 +31,12 @@ SOFTWARE.
#include "platform.h" #include "platform.h"
#include "algorithm.h" #include "algorithm.h"
#include "nullptr.h"
#include "delegate.h" #include "delegate.h"
#include "error_handler.h"
#include "nullptr.h"
#include "placement_new.h"
#include "static_assert.h" #include "static_assert.h"
#include "timer.h" #include "timer.h"
#include "error_handler.h"
#include "placement_new.h"
#include <stdint.h> #include <stdint.h>
@ -57,9 +57,7 @@ namespace etl
//******************************************* //*******************************************
/// Register a timer. /// Register a timer.
//******************************************* //*******************************************
etl::timer::id::type register_timer(const callback_type& callback_, etl::timer::id::type register_timer(const callback_type& callback_, uint32_t period_, bool repeating_)
uint32_t period_,
bool repeating_)
{ {
etl::timer::id::type id = etl::timer::id::NO_TIMER; etl::timer::id::type id = etl::timer::id::NO_TIMER;
@ -168,7 +166,7 @@ namespace etl
if (enabled) if (enabled)
{ {
// We have something to do? // We have something to do?
bool has_active = !active_list.empty(); bool has_active = !active_list.empty();
if (has_active) if (has_active)
{ {
@ -320,7 +318,8 @@ namespace etl
//******************************************* //*******************************************
/// Get the time to the next timer event. /// Get the time to the next timer event.
/// Returns etl::timer::interval::No_Active_Interval if there is no active timer. /// Returns etl::timer::interval::No_Active_Interval if there is no active
/// timer.
//******************************************* //*******************************************
uint32_t time_to_next() const uint32_t time_to_next() const
{ {
@ -349,7 +348,7 @@ namespace etl
if (has_active_timer()) if (has_active_timer())
{ {
TInterruptGuard guard; TInterruptGuard guard;
(void)guard; // Silence 'unused variable warnings. (void)guard; // Silence 'unused variable warnings.
const timer_data& timer = timer_array[id_]; const timer_data& timer = timer_array[id_];
@ -413,10 +412,7 @@ namespace etl
//******************************************* //*******************************************
/// ETL delegate callback /// ETL delegate callback
//******************************************* //*******************************************
timer_data(etl::timer::id::type id_, timer_data(etl::timer::id::type id_, callback_type callback_, uint32_t period_, bool repeating_)
callback_type callback_,
uint32_t period_,
bool repeating_)
: callback(callback_) : callback(callback_)
, period(period_) , period(period_)
, delta(etl::timer::state::Inactive) , delta(etl::timer::state::Inactive)
@ -455,13 +451,13 @@ namespace etl
// Disabled. // Disabled.
timer_data(const timer_data& other) ETL_DELETE; timer_data(const timer_data& other) ETL_DELETE;
timer_data& operator =(const timer_data& other) ETL_DELETE; timer_data& operator=(const timer_data& other) ETL_DELETE;
}; };
//******************************************* //*******************************************
/// Constructor. /// Constructor.
//******************************************* //*******************************************
icallback_timer_interrupt(timer_data* const timer_array_, const uint_least8_t Max_Timers_) icallback_timer_interrupt(timer_data* const timer_array_, const uint_least8_t Max_Timers_)
: timer_array(timer_array_) : timer_array(timer_array_)
, active_list(timer_array_) , active_list(timer_array_)
, enabled(false) , enabled(false)
@ -512,10 +508,10 @@ namespace etl
if (head == etl::timer::id::NO_TIMER) if (head == etl::timer::id::NO_TIMER)
{ {
// No entries yet. // No entries yet.
head = id_; head = id_;
tail = id_; tail = id_;
timer.previous = etl::timer::id::NO_TIMER; timer.previous = etl::timer::id::NO_TIMER;
timer.next = etl::timer::id::NO_TIMER; timer.next = etl::timer::id::NO_TIMER;
} }
else else
{ {
@ -536,8 +532,8 @@ namespace etl
// Insert before test. // Insert before test.
timer.previous = test.previous; timer.previous = test.previous;
test.previous = timer.id; test.previous = timer.id;
timer.next = test.id; timer.next = test.id;
// Adjust the next delta to compensate. // Adjust the next delta to compensate.
test.delta -= timer.delta; test.delta -= timer.delta;
@ -561,9 +557,9 @@ namespace etl
{ {
// Tag on to the tail. // Tag on to the tail.
ptimers[tail].next = timer.id; ptimers[tail].next = timer.id;
timer.previous = tail; timer.previous = tail;
timer.next = etl::timer::id::NO_TIMER; timer.next = etl::timer::id::NO_TIMER;
tail = timer.id; tail = timer.id;
} }
} }
} }
@ -646,8 +642,8 @@ namespace etl
while (id != etl::timer::id::NO_TIMER) while (id != etl::timer::id::NO_TIMER)
{ {
timer_data& timer = ptimers[id]; timer_data& timer = ptimers[id];
id = next(id); id = next(id);
timer.next = etl::timer::id::NO_TIMER; timer.next = etl::timer::id::NO_TIMER;
} }
head = etl::timer::id::NO_TIMER; head = etl::timer::id::NO_TIMER;
@ -670,7 +666,7 @@ namespace etl
// The list of active timers. // The list of active timers.
timer_list active_list; timer_list active_list;
bool enabled; bool enabled;
uint_least8_t number_of_registered_timers; uint_least8_t number_of_registered_timers;
event_callback_type insert_callback; event_callback_type insert_callback;
@ -705,6 +701,6 @@ namespace etl
typename icallback_timer_interrupt<TInterruptGuard>::timer_data timer_array[Max_Timers_]; typename icallback_timer_interrupt<TInterruptGuard>::timer_data timer_array[Max_Timers_];
}; };
} } // namespace etl
#endif #endif

View File

@ -31,12 +31,12 @@ SOFTWARE.
#include "platform.h" #include "platform.h"
#include "algorithm.h" #include "algorithm.h"
#include "nullptr.h"
#include "delegate.h" #include "delegate.h"
#include "error_handler.h"
#include "nullptr.h"
#include "placement_new.h"
#include "static_assert.h" #include "static_assert.h"
#include "timer.h" #include "timer.h"
#include "error_handler.h"
#include "placement_new.h"
#include <stdint.h> #include <stdint.h>
@ -59,9 +59,7 @@ namespace etl
//******************************************* //*******************************************
/// Register a timer. /// Register a timer.
//******************************************* //*******************************************
etl::timer::id::type register_timer(const callback_type& callback_, etl::timer::id::type register_timer(const callback_type& callback_, uint32_t period_, bool repeating_)
uint32_t period_,
bool repeating_)
{ {
etl::timer::id::type id = etl::timer::id::NO_TIMER; etl::timer::id::type id = etl::timer::id::NO_TIMER;
@ -281,7 +279,8 @@ namespace etl
//******************************************* //*******************************************
/// Get the time to the next timer event. /// Get the time to the next timer event.
/// Returns etl::timer::interval::No_Active_Interval if there is no active timer. /// Returns etl::timer::interval::No_Active_Interval if there is no active
/// timer.
//******************************************* //*******************************************
uint32_t time_to_next() const uint32_t time_to_next() const
{ {
@ -355,17 +354,20 @@ namespace etl
protected: protected:
class callback_node class callback_node
{ {
public: public:
callback_node(callback_type &callback_,uint_least8_t priority_) : callback(callback_), priority(priority_) callback_node(callback_type& callback_, uint_least8_t priority_)
: callback(callback_)
, priority(priority_)
{ {
} }
bool operator < (const callback_node& p) const bool operator<(const callback_node& p) const
{ {
return this->priority > p.priority; // comparison was inverted here to easy the code design return this->priority > p.priority; // comparison was inverted here to
// easy the code design
} }
callback_type callback; callback_type callback;
@ -391,10 +393,7 @@ namespace etl
//******************************************* //*******************************************
/// ETL delegate callback /// ETL delegate callback
//******************************************* //*******************************************
timer_data(etl::timer::id::type id_, timer_data(etl::timer::id::type id_, callback_type callback_, uint32_t period_, bool repeating_)
callback_type callback_,
uint32_t period_,
bool repeating_)
: callback(callback_) : callback(callback_)
, period(period_) , period(period_)
, delta(etl::timer::state::Inactive) , delta(etl::timer::state::Inactive)
@ -433,18 +432,18 @@ namespace etl
// Disabled. // Disabled.
timer_data(const timer_data& other) ETL_DELETE; timer_data(const timer_data& other) ETL_DELETE;
timer_data& operator =(const timer_data& other) ETL_DELETE; timer_data& operator=(const timer_data& other) ETL_DELETE;
}; };
//******************************************* //*******************************************
/// Constructor. /// Constructor.
//******************************************* //*******************************************
icallback_timer_locked(timer_data* const timer_array_, const uint_least8_t Max_Timers_) icallback_timer_locked(timer_data* const timer_array_, const uint_least8_t Max_Timers_)
: timer_array(timer_array_), : timer_array(timer_array_)
active_list(timer_array_), , active_list(timer_array_)
enabled(false), , enabled(false)
number_of_registered_timers(0U), , number_of_registered_timers(0U)
Max_Timers(Max_Timers_) , Max_Timers(Max_Timers_)
{ {
} }
@ -482,10 +481,10 @@ namespace etl
if (head == etl::timer::id::NO_TIMER) if (head == etl::timer::id::NO_TIMER)
{ {
// No entries yet. // No entries yet.
head = id_; head = id_;
tail = id_; tail = id_;
timer.previous = etl::timer::id::NO_TIMER; timer.previous = etl::timer::id::NO_TIMER;
timer.next = etl::timer::id::NO_TIMER; timer.next = etl::timer::id::NO_TIMER;
} }
else else
{ {
@ -506,8 +505,8 @@ namespace etl
// Insert before test. // Insert before test.
timer.previous = test.previous; timer.previous = test.previous;
test.previous = timer.id; test.previous = timer.id;
timer.next = test.id; timer.next = test.id;
// Adjust the next delta to compensate. // Adjust the next delta to compensate.
test.delta -= timer.delta; test.delta -= timer.delta;
@ -531,9 +530,9 @@ namespace etl
{ {
// Tag on to the tail. // Tag on to the tail.
ptimers[tail].next = timer.id; ptimers[tail].next = timer.id;
timer.previous = tail; timer.previous = tail;
timer.next = etl::timer::id::NO_TIMER; timer.next = etl::timer::id::NO_TIMER;
tail = timer.id; tail = timer.id;
} }
} }
} }
@ -571,8 +570,8 @@ namespace etl
} }
timer.previous = etl::timer::id::NO_TIMER; timer.previous = etl::timer::id::NO_TIMER;
timer.next = etl::timer::id::NO_TIMER; timer.next = etl::timer::id::NO_TIMER;
timer.delta = etl::timer::state::Inactive; timer.delta = etl::timer::state::Inactive;
} }
//******************************* //*******************************
@ -616,12 +615,12 @@ namespace etl
while (id != etl::timer::id::NO_TIMER) while (id != etl::timer::id::NO_TIMER)
{ {
timer_data& timer = ptimers[id]; timer_data& timer = ptimers[id];
id = next(id); id = next(id);
timer.next = etl::timer::id::NO_TIMER; timer.next = etl::timer::id::NO_TIMER;
} }
head = etl::timer::id::NO_TIMER; head = etl::timer::id::NO_TIMER;
tail = etl::timer::id::NO_TIMER; tail = etl::timer::id::NO_TIMER;
current = etl::timer::id::NO_TIMER; current = etl::timer::id::NO_TIMER;
} }
@ -648,7 +647,7 @@ namespace etl
// The list of active timers. // The list of active timers.
timer_list active_list; timer_list active_list;
bool enabled; bool enabled;
uint_least8_t number_of_registered_timers; uint_least8_t number_of_registered_timers;
try_lock_type try_lock; ///< The callback that tries to lock. try_lock_type try_lock; ///< The callback that tries to lock.
@ -766,6 +765,6 @@ namespace etl
timer_data timer_array[Max_Timers_]; timer_data timer_array[Max_Timers_];
}; };
} } // namespace etl
#endif #endif

View File

@ -45,9 +45,11 @@ SOFTWARE.
namespace etl namespace etl
{ {
template<typename T> struct char_traits_types; template <typename T>
struct char_traits_types;
template<> struct char_traits_types<char> template <>
struct char_traits_types<char>
{ {
typedef char char_type; typedef char char_type;
typedef int int_type; typedef int int_type;
@ -56,7 +58,8 @@ namespace etl
typedef char state_type; typedef char state_type;
}; };
template<> struct char_traits_types<signed char> template <>
struct char_traits_types<signed char>
{ {
typedef signed char char_type; typedef signed char char_type;
typedef int int_type; typedef int int_type;
@ -65,7 +68,8 @@ namespace etl
typedef signed char state_type; typedef signed char state_type;
}; };
template<> struct char_traits_types<unsigned char> template <>
struct char_traits_types<unsigned char>
{ {
typedef unsigned char char_type; typedef unsigned char char_type;
typedef int int_type; typedef int int_type;
@ -74,7 +78,8 @@ namespace etl
typedef unsigned char state_type; typedef unsigned char state_type;
}; };
template<> struct char_traits_types<wchar_t> template <>
struct char_traits_types<wchar_t>
{ {
typedef wchar_t char_type; typedef wchar_t char_type;
typedef uint_least16_t int_type; typedef uint_least16_t int_type;
@ -84,17 +89,19 @@ namespace etl
}; };
#if ETL_USING_CPP20 #if ETL_USING_CPP20
template<> struct char_traits_types<char8_t> template <>
struct char_traits_types<char8_t>
{ {
typedef char8_t char_type; typedef char8_t char_type;
typedef unsigned int int_type; typedef unsigned int int_type;
typedef long long off_type; typedef long long off_type;
typedef size_t pos_type; typedef size_t pos_type;
typedef char state_type; typedef char state_type;
}; };
#endif #endif
template<> struct char_traits_types<char16_t> template <>
struct char_traits_types<char16_t>
{ {
typedef char16_t char_type; typedef char16_t char_type;
typedef uint_least16_t int_type; typedef uint_least16_t int_type;
@ -103,7 +110,8 @@ namespace etl
typedef char state_type; typedef char state_type;
}; };
template<> struct char_traits_types<char32_t> template <>
struct char_traits_types<char32_t>
{ {
typedef char32_t char_type; typedef char32_t char_type;
typedef uint_least32_t int_type; typedef uint_least32_t int_type;
@ -115,7 +123,7 @@ namespace etl
//*************************************************************************** //***************************************************************************
/// Character traits for any character type. /// Character traits for any character type.
//*************************************************************************** //***************************************************************************
template<typename T> template <typename T>
struct char_traits : public char_traits_types<T> struct char_traits : public char_traits_types<T>
{ {
typedef typename char_traits_types<T>::char_type char_type; typedef typename char_traits_types<T>::char_type char_type;
@ -196,9 +204,7 @@ namespace etl
} }
else else
{ {
etl::copy_n(ETL_OR_STD::reverse_iterator<const char_type*>(src + count), etl::copy_n(ETL_OR_STD::reverse_iterator<const char_type*>(src + count), count, ETL_OR_STD::reverse_iterator<char_type*>(dst + count));
count,
ETL_OR_STD::reverse_iterator<char_type*>(dst + count));
} }
return dst; return dst;
@ -310,7 +316,7 @@ namespace etl
{ {
return 1; return 1;
} }
if (*t1 < *t2) if (*t1 < *t2)
{ {
return -1; return -1;
@ -343,7 +349,7 @@ namespace etl
++t1; ++t1;
++t2; ++t2;
--n; --n;
} }
return 0; return 0;
} }
@ -384,6 +390,6 @@ namespace etl
return result; return result;
} }
} } // namespace etl
#endif #endif

View File

@ -179,7 +179,7 @@ namespace etl
/// \param begin Start of the range. /// \param begin Start of the range.
/// \param end End of the range. /// \param end End of the range.
//************************************************************************* //*************************************************************************
template<typename TIterator> template <typename TIterator>
checksum(TIterator begin, const TIterator end) checksum(TIterator begin, const TIterator end)
{ {
this->reset(); this->reset();
@ -208,7 +208,7 @@ namespace etl
/// \param begin Start of the range. /// \param begin Start of the range.
/// \param end End of the range. /// \param end End of the range.
//************************************************************************* //*************************************************************************
template<typename TIterator> template <typename TIterator>
bsd_checksum(TIterator begin, const TIterator end) bsd_checksum(TIterator begin, const TIterator end)
{ {
this->reset(); this->reset();
@ -237,7 +237,7 @@ namespace etl
/// \param begin Start of the range. /// \param begin Start of the range.
/// \param end End of the range. /// \param end End of the range.
//************************************************************************* //*************************************************************************
template<typename TIterator> template <typename TIterator>
xor_checksum(TIterator begin, const TIterator end) xor_checksum(TIterator begin, const TIterator end)
{ {
this->reset(); this->reset();
@ -266,7 +266,7 @@ namespace etl
/// \param begin Start of the range. /// \param begin Start of the range.
/// \param end End of the range. /// \param end End of the range.
//************************************************************************* //*************************************************************************
template<typename TIterator> template <typename TIterator>
xor_rotate_checksum(TIterator begin, const TIterator end) xor_rotate_checksum(TIterator begin, const TIterator end)
{ {
this->reset(); this->reset();
@ -295,13 +295,13 @@ namespace etl
/// \param begin Start of the range. /// \param begin Start of the range.
/// \param end End of the range. /// \param end End of the range.
//************************************************************************* //*************************************************************************
template<typename TIterator> template <typename TIterator>
parity_checksum(TIterator begin, const TIterator end) parity_checksum(TIterator begin, const TIterator end)
{ {
this->reset(); this->reset();
this->add(begin, end); this->add(begin, end);
} }
}; };
} } // namespace etl
#endif #endif

View File

@ -41,12 +41,12 @@ SOFTWARE.
#if ETL_USING_CPP11 #if ETL_USING_CPP11
#include "type_traits.h" #include "hash.h"
#include "integral_limits.h" #include "integral_limits.h"
#include "hash.h" #include "type_traits.h"
#include <stdint.h> #include <stdint.h>
#include <time.h> #include <time.h>
namespace etl namespace etl
{ {
@ -57,17 +57,17 @@ namespace etl
{ {
}; };
#if ETL_USING_CPP17 #if ETL_USING_CPP17
template <typename TRep> template <typename TRep>
constexpr bool treat_as_floating_point_v = treat_as_floating_point<TRep>::value; constexpr bool treat_as_floating_point_v = treat_as_floating_point<TRep>::value;
#endif #endif
} } // namespace chrono
// Use the same type as defined in time.h. // Use the same type as defined in time.h.
using time_t = ::time_t; using time_t = ::time_t;
} } // namespace etl
// clang-format off // clang-format off
// Keeping the order is important here // Keeping the order is important here
#include "private/chrono/last_spec.h" #include "private/chrono/last_spec.h"
#include "private/chrono/duration.h" #include "private/chrono/duration.h"
@ -89,11 +89,11 @@ namespace etl
namespace etl namespace etl
{ {
namespace chrono namespace chrono
{ {
using namespace literals::chrono_literals; using namespace literals::chrono_literals;
} }
} } // namespace etl
#endif #endif

View File

@ -32,15 +32,15 @@ SOFTWARE.
#define ETL_CIRCULAR_BUFFER_INCLUDED #define ETL_CIRCULAR_BUFFER_INCLUDED
#include "platform.h" #include "platform.h"
#include "vector.h"
#include "exception.h"
#include "error_handler.h" #include "error_handler.h"
#include "exception.h"
#include "initializer_list.h"
#include "iterator.h"
#include "memory.h" #include "memory.h"
#include "memory_model.h" #include "memory_model.h"
#include "type_traits.h"
#include "iterator.h"
#include "static_assert.h" #include "static_assert.h"
#include "initializer_list.h" #include "type_traits.h"
#include "vector.h"
namespace etl namespace etl
{ {
@ -170,7 +170,7 @@ namespace etl
size_type buffer_size; size_type buffer_size;
size_type in; ///< Index to the next write. size_type in; ///< Index to the next write.
size_type out; ///< Index to the next read. size_type out; ///< Index to the next read.
ETL_DECLARE_DEBUG_COUNT; ///< Internal debugging. ETL_DECLARE_DEBUG_COUNT; ///< Internal debugging.
}; };
//*************************************************************************** //***************************************************************************
@ -181,14 +181,14 @@ namespace etl
{ {
public: public:
typedef T value_type; typedef T value_type;
typedef T& reference; typedef T& reference;
typedef const T& const_reference; typedef const T& const_reference;
#if ETL_USING_CPP11 #if ETL_USING_CPP11
typedef T&& rvalue_reference; typedef T&& rvalue_reference;
#endif #endif
typedef T* pointer; typedef T* pointer;
typedef const T* const_pointer; typedef const T* const_pointer;
typedef typename etl::iterator_traits<pointer>::difference_type difference_type; typedef typename etl::iterator_traits<pointer>::difference_type difference_type;
@ -222,7 +222,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Assignment operator. /// Assignment operator.
//************************************************************************* //*************************************************************************
iterator& operator =(const iterator& other) iterator& operator=(const iterator& other)
{ {
picb = other.picb; picb = other.picb;
current = other.current; current = other.current;
@ -233,7 +233,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// * operator /// * operator
//************************************************************************* //*************************************************************************
reference operator *() const reference operator*() const
{ {
return picb->pbuffer[current]; return picb->pbuffer[current];
} }
@ -241,7 +241,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// -> operator /// -> operator
//************************************************************************* //*************************************************************************
pointer operator ->() const pointer operator->() const
{ {
return &picb->pbuffer[current]; return &picb->pbuffer[current];
} }
@ -249,7 +249,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// [] operator /// [] operator
//************************************************************************* //*************************************************************************
reference operator [](size_t index) reference operator[](size_t index)
{ {
return picb->pbuffer[(current + index) % picb->buffer_size]; return picb->pbuffer[(current + index) % picb->buffer_size];
} }
@ -257,7 +257,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// [] operator /// [] operator
//************************************************************************* //*************************************************************************
const_reference operator [](size_t index) const const_reference operator[](size_t index) const
{ {
return picb->pbuffer[(current + index) % picb->buffer_size]; return picb->pbuffer[(current + index) % picb->buffer_size];
} }
@ -265,7 +265,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Pre-increment. /// Pre-increment.
//************************************************************************* //*************************************************************************
iterator& operator ++() iterator& operator++()
{ {
++current; ++current;
@ -281,7 +281,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Post increment. /// Post increment.
//************************************************************************* //*************************************************************************
iterator operator ++(int) iterator operator++(int)
{ {
iterator original(*this); iterator original(*this);
@ -293,7 +293,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Pre-decrement. /// Pre-decrement.
//************************************************************************* //*************************************************************************
iterator& operator --() iterator& operator--()
{ {
// Are we at the end of the buffer? // Are we at the end of the buffer?
if (current == 0U) if (current == 0U)
@ -311,7 +311,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Post increment. /// Post increment.
//************************************************************************* //*************************************************************************
iterator operator --(int) iterator operator--(int)
{ {
iterator original(*this); iterator original(*this);
@ -323,7 +323,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Add offset. /// Add offset.
//************************************************************************* //*************************************************************************
iterator& operator +=(int n) iterator& operator+=(int n)
{ {
current += size_type(static_cast<int>(picb->buffer_size) + n); current += size_type(static_cast<int>(picb->buffer_size) + n);
current %= picb->buffer_size; current %= picb->buffer_size;
@ -334,7 +334,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Subtract offset. /// Subtract offset.
//************************************************************************* //*************************************************************************
iterator& operator -=(int n) iterator& operator-=(int n)
{ {
return (this->operator+=(-n)); return (this->operator+=(-n));
} }
@ -342,7 +342,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Add offset. /// Add offset.
//************************************************************************* //*************************************************************************
friend iterator operator +(const iterator& lhs, int n) friend iterator operator+(const iterator& lhs, int n)
{ {
iterator temp = lhs; iterator temp = lhs;
@ -354,7 +354,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Add offset. /// Add offset.
//************************************************************************* //*************************************************************************
friend iterator operator +(int n, const iterator& rhs) friend iterator operator+(int n, const iterator& rhs)
{ {
iterator temp = rhs; iterator temp = rhs;
@ -366,7 +366,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Subtract offset. /// Subtract offset.
//************************************************************************* //*************************************************************************
friend iterator operator -(const iterator& lhs, int n) friend iterator operator-(const iterator& lhs, int n)
{ {
iterator temp = lhs; iterator temp = lhs;
@ -378,7 +378,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Equality operator /// Equality operator
//************************************************************************* //*************************************************************************
friend bool operator == (const iterator& lhs, const iterator& rhs) friend bool operator==(const iterator& lhs, const iterator& rhs)
{ {
return (lhs.current == rhs.current); return (lhs.current == rhs.current);
} }
@ -386,18 +386,18 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Inequality operator /// Inequality operator
//************************************************************************* //*************************************************************************
friend bool operator != (const iterator& lhs, const iterator& rhs) friend bool operator!=(const iterator& lhs, const iterator& rhs)
{ {
return !(lhs == rhs); return !(lhs == rhs);
} }
//*************************************************** //***************************************************
friend bool operator < (const iterator& lhs, const iterator& rhs) friend bool operator<(const iterator& lhs, const iterator& rhs)
{ {
const difference_type lhs_index = lhs.get_index(); const difference_type lhs_index = lhs.get_index();
const difference_type rhs_index = rhs.get_index(); const difference_type rhs_index = rhs.get_index();
const difference_type reference_index = lhs.container().begin().get_index(); const difference_type reference_index = lhs.container().begin().get_index();
const difference_type buffer_size = static_cast<difference_type>(lhs.container().max_size() + 1UL); const difference_type buffer_size = static_cast<difference_type>(lhs.container().max_size() + 1UL);
const difference_type lhs_distance = (lhs_index < reference_index) ? buffer_size + lhs_index - reference_index : lhs_index - reference_index; const difference_type lhs_distance = (lhs_index < reference_index) ? buffer_size + lhs_index - reference_index : lhs_index - reference_index;
const difference_type rhs_distance = (rhs_index < reference_index) ? buffer_size + rhs_index - reference_index : rhs_index - reference_index; const difference_type rhs_distance = (rhs_index < reference_index) ? buffer_size + rhs_index - reference_index : rhs_index - reference_index;
@ -406,19 +406,19 @@ namespace etl
} }
//*************************************************** //***************************************************
friend bool operator <= (const iterator& lhs, const iterator& rhs) friend bool operator<=(const iterator& lhs, const iterator& rhs)
{ {
return !(lhs > rhs); return !(lhs > rhs);
} }
//*************************************************** //***************************************************
friend bool operator > (const iterator& lhs, const iterator& rhs) friend bool operator>(const iterator& lhs, const iterator& rhs)
{ {
return (rhs < lhs); return (rhs < lhs);
} }
//*************************************************** //***************************************************
friend bool operator >= (const iterator& lhs, const iterator& rhs) friend bool operator>=(const iterator& lhs, const iterator& rhs)
{ {
return !(lhs < rhs); return !(lhs < rhs);
} }
@ -468,7 +468,7 @@ namespace etl
private: private:
const icircular_buffer<T>* picb; const icircular_buffer<T>* picb;
size_type current; size_type current;
}; };
//************************************************************************* //*************************************************************************
@ -510,7 +510,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Assignment operator. /// Assignment operator.
//************************************************************************* //*************************************************************************
const_iterator& operator =(const typename icircular_buffer::iterator& other) const_iterator& operator=(const typename icircular_buffer::iterator& other)
{ {
picb = other.picb; picb = other.picb;
current = other.current; current = other.current;
@ -521,7 +521,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Assignment operator. /// Assignment operator.
//************************************************************************* //*************************************************************************
const_iterator& operator =(const const_iterator& other) const_iterator& operator=(const const_iterator& other)
{ {
picb = other.picb; picb = other.picb;
current = other.current; current = other.current;
@ -532,7 +532,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// * operator /// * operator
//************************************************************************* //*************************************************************************
const_reference operator *() const const_reference operator*() const
{ {
return picb->pbuffer[current]; return picb->pbuffer[current];
} }
@ -540,7 +540,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// -> operator /// -> operator
//************************************************************************* //*************************************************************************
const_pointer operator ->() const const_pointer operator->() const
{ {
return &(picb->pbuffer[current]); return &(picb->pbuffer[current]);
} }
@ -548,7 +548,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// [] operator /// [] operator
//************************************************************************* //*************************************************************************
const_reference operator [](size_t index) const const_reference operator[](size_t index) const
{ {
return picb->pbuffer[(current + index) % picb->buffer_size]; return picb->pbuffer[(current + index) % picb->buffer_size];
} }
@ -556,7 +556,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Pre-increment. /// Pre-increment.
//************************************************************************* //*************************************************************************
const_iterator& operator ++() const_iterator& operator++()
{ {
++current; ++current;
@ -572,7 +572,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Post increment. /// Post increment.
//************************************************************************* //*************************************************************************
const_iterator operator ++(int) const_iterator operator++(int)
{ {
const_iterator original(*this); const_iterator original(*this);
@ -584,7 +584,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Pre-decrement. /// Pre-decrement.
//************************************************************************* //*************************************************************************
const_iterator& operator --() const_iterator& operator--()
{ {
// Are we at the end of the buffer? // Are we at the end of the buffer?
if (current == 0U) if (current == 0U)
@ -602,7 +602,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Post increment. /// Post increment.
//************************************************************************* //*************************************************************************
const_iterator operator --(int) const_iterator operator--(int)
{ {
const_iterator original(*this); const_iterator original(*this);
@ -614,7 +614,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Add offset. /// Add offset.
//************************************************************************* //*************************************************************************
const_iterator& operator +=(int n) const_iterator& operator+=(int n)
{ {
current += size_type(static_cast<int>(picb->buffer_size) + n); current += size_type(static_cast<int>(picb->buffer_size) + n);
current %= picb->buffer_size; current %= picb->buffer_size;
@ -625,7 +625,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Subtract offset. /// Subtract offset.
//************************************************************************* //*************************************************************************
const_iterator& operator -=(int n) const_iterator& operator-=(int n)
{ {
return (this->operator+=(-n)); return (this->operator+=(-n));
} }
@ -633,7 +633,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Add offset. /// Add offset.
//************************************************************************* //*************************************************************************
friend const_iterator operator +(const const_iterator& lhs, int n) friend const_iterator operator+(const const_iterator& lhs, int n)
{ {
const_iterator temp = lhs; const_iterator temp = lhs;
@ -645,7 +645,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Subtract offset. /// Subtract offset.
//************************************************************************* //*************************************************************************
friend const_iterator operator -(const const_iterator& lhs, int n) friend const_iterator operator-(const const_iterator& lhs, int n)
{ {
const_iterator temp = lhs; const_iterator temp = lhs;
@ -657,7 +657,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Equality operator /// Equality operator
//************************************************************************* //*************************************************************************
friend bool operator == (const const_iterator& lhs, const const_iterator& rhs) friend bool operator==(const const_iterator& lhs, const const_iterator& rhs)
{ {
return (lhs.current == rhs.current); return (lhs.current == rhs.current);
} }
@ -665,18 +665,18 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Inequality operator /// Inequality operator
//************************************************************************* //*************************************************************************
friend bool operator != (const const_iterator& lhs, const const_iterator& rhs) friend bool operator!=(const const_iterator& lhs, const const_iterator& rhs)
{ {
return !(lhs == rhs); return !(lhs == rhs);
} }
//*************************************************** //***************************************************
friend bool operator < (const const_iterator& lhs, const const_iterator& rhs) friend bool operator<(const const_iterator& lhs, const const_iterator& rhs)
{ {
const difference_type lhs_index = lhs.get_index(); const difference_type lhs_index = lhs.get_index();
const difference_type rhs_index = rhs.get_index(); const difference_type rhs_index = rhs.get_index();
const difference_type reference_index = lhs.container().begin().get_index(); const difference_type reference_index = lhs.container().begin().get_index();
const difference_type buffer_size = static_cast<difference_type>(lhs.container().max_size() + 1UL); const difference_type buffer_size = static_cast<difference_type>(lhs.container().max_size() + 1UL);
const difference_type lhs_distance = (lhs_index < reference_index) ? buffer_size + lhs_index - reference_index : lhs_index - reference_index; const difference_type lhs_distance = (lhs_index < reference_index) ? buffer_size + lhs_index - reference_index : lhs_index - reference_index;
const difference_type rhs_distance = (rhs_index < reference_index) ? buffer_size + rhs_index - reference_index : rhs_index - reference_index; const difference_type rhs_distance = (rhs_index < reference_index) ? buffer_size + rhs_index - reference_index : rhs_index - reference_index;
@ -685,19 +685,19 @@ namespace etl
} }
//*************************************************** //***************************************************
friend bool operator <= (const const_iterator& lhs, const const_iterator& rhs) friend bool operator<=(const const_iterator& lhs, const const_iterator& rhs)
{ {
return !(lhs > rhs); return !(lhs > rhs);
} }
//*************************************************** //***************************************************
friend bool operator > (const const_iterator& lhs, const const_iterator& rhs) friend bool operator>(const const_iterator& lhs, const const_iterator& rhs)
{ {
return (rhs < lhs); return (rhs < lhs);
} }
//*************************************************** //***************************************************
friend bool operator >= (const const_iterator& lhs, const const_iterator& rhs) friend bool operator>=(const const_iterator& lhs, const const_iterator& rhs)
{ {
return !(lhs < rhs); return !(lhs < rhs);
} }
@ -734,7 +734,7 @@ namespace etl
private: private:
const icircular_buffer<T>* picb; const icircular_buffer<T>* picb;
size_type current; size_type current;
}; };
friend class iterator; friend class iterator;
@ -886,7 +886,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Get a reference to the item. /// Get a reference to the item.
//************************************************************************* //*************************************************************************
reference operator [](size_t index) reference operator[](size_t index)
{ {
return pbuffer[(out + index) % buffer_size]; return pbuffer[(out + index) % buffer_size];
} }
@ -895,7 +895,7 @@ namespace etl
/// Get a const reference to the item at the back of the buffer. /// Get a const reference to the item at the back of the buffer.
/// Asserts an error if the buffer is empty. /// Asserts an error if the buffer is empty.
//************************************************************************* //*************************************************************************
const_reference operator [](size_t index) const const_reference operator[](size_t index) const
{ {
return pbuffer[(out + index) % buffer_size]; return pbuffer[(out + index) % buffer_size];
} }
@ -988,7 +988,7 @@ namespace etl
//************************************************************************* //*************************************************************************
void clear() void clear()
{ {
if ETL_IF_CONSTEXPR(etl::is_trivially_destructible<T>::value) if ETL_IF_CONSTEXPR (etl::is_trivially_destructible<T>::value)
{ {
in = 0U; in = 0U;
out = 0U; out = 0U;
@ -1021,7 +1021,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// - operator for iterator /// - operator for iterator
//************************************************************************* //*************************************************************************
friend difference_type operator -(const iterator& lhs, const iterator& rhs) friend difference_type operator-(const iterator& lhs, const iterator& rhs)
{ {
return distance(rhs, lhs); return distance(rhs, lhs);
} }
@ -1029,7 +1029,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// - operator for const_iterator /// - operator for const_iterator
//************************************************************************* //*************************************************************************
friend difference_type operator -(const const_iterator& lhs, const const_iterator& rhs) friend difference_type operator-(const const_iterator& lhs, const const_iterator& rhs)
{ {
return distance(rhs, lhs); return distance(rhs, lhs);
} }
@ -1058,7 +1058,8 @@ namespace etl
} }
//************************************************************************* //*************************************************************************
/// Measures the distance from the _begin iterator to the specified iterator. /// Measures the distance from the _begin iterator to the specified
/// iterator.
//************************************************************************* //*************************************************************************
template <typename TIterator> template <typename TIterator>
static difference_type distance(const TIterator& other) static difference_type distance(const TIterator& other)
@ -1093,15 +1094,15 @@ namespace etl
/// Destructor. /// Destructor.
//************************************************************************* //*************************************************************************
#if defined(ETL_POLYMORPHIC_CIRCULAR_BUFFER) || defined(ETL_POLYMORPHIC_CONTAINERS) #if defined(ETL_POLYMORPHIC_CIRCULAR_BUFFER) || defined(ETL_POLYMORPHIC_CONTAINERS)
public: public:
virtual ~icircular_buffer()
{ virtual ~icircular_buffer() {}
}
#else #else
protected: protected:
~icircular_buffer()
{ ~icircular_buffer() {}
}
#endif #endif
}; };
@ -1167,7 +1168,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Assignment operator /// Assignment operator
//************************************************************************* //*************************************************************************
circular_buffer& operator =(const circular_buffer& other) circular_buffer& operator=(const circular_buffer& other)
{ {
if (this != &other) if (this != &other)
{ {
@ -1199,7 +1200,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Move Assignment operator /// Move Assignment operator
//************************************************************************* //*************************************************************************
circular_buffer& operator =(circular_buffer&& other) circular_buffer& operator=(circular_buffer&& other)
{ {
if (this != &other) if (this != &other)
{ {
@ -1228,9 +1229,9 @@ namespace etl
/// Fix the internal pointers after a low level memory copy. /// Fix the internal pointers after a low level memory copy.
//************************************************************************* //*************************************************************************
#ifdef ETL_ICIRCULAR_BUFFER_REPAIR_ENABLE #ifdef ETL_ICIRCULAR_BUFFER_REPAIR_ENABLE
virtual void repair() ETL_OVERRIDE virtual void repair() ETL_OVERRIDE
#else #else
void repair() void repair()
#endif #endif
{ {
ETL_ASSERT(etl::is_trivially_copyable<T>::value, ETL_ERROR(etl::circular_buffer_incompatible_type)); ETL_ASSERT(etl::is_trivially_copyable<T>::value, ETL_ERROR(etl::circular_buffer_incompatible_type));
@ -1278,7 +1279,8 @@ namespace etl
/// Constructs a buffer from an iterator range. /// Constructs a buffer from an iterator range.
//************************************************************************* //*************************************************************************
template <typename TIterator> template <typename TIterator>
circular_buffer_ext(TIterator first, const TIterator& last, void* buffer, size_t max_size, typename etl::enable_if<!etl::is_integral<TIterator>::value, int>::type = 0) circular_buffer_ext(TIterator first, const TIterator& last, void* buffer, size_t max_size,
typename etl::enable_if<!etl::is_integral<TIterator>::value, int>::type = 0)
: icircular_buffer<T>(reinterpret_cast<T*>(buffer), max_size) : icircular_buffer<T>(reinterpret_cast<T*>(buffer), max_size)
{ {
while (first != last) while (first != last)
@ -1319,9 +1321,8 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Assignment operator /// Assignment operator
//************************************************************************* //*************************************************************************
circular_buffer_ext& operator =(const circular_buffer_ext& other) circular_buffer_ext& operator=(const circular_buffer_ext& other)
{ {
if (this != &other) if (this != &other)
{ {
this->clear(); this->clear();
@ -1352,7 +1353,7 @@ namespace etl
//************************************************************************* //*************************************************************************
/// Move Assignment operator /// Move Assignment operator
//************************************************************************* //*************************************************************************
circular_buffer_ext& operator =(circular_buffer_ext&& other) circular_buffer_ext& operator=(circular_buffer_ext&& other)
{ {
if (this != &other) if (this != &other)
{ {
@ -1398,9 +1399,9 @@ namespace etl
swap(this->pbuffer, other.pbuffer); swap(this->pbuffer, other.pbuffer);
swap(this->buffer_size, other.buffer_size); swap(this->buffer_size, other.buffer_size);
#if defined(ETL_DEBUG_COUNT) #if defined(ETL_DEBUG_COUNT)
this->etl_debug_count.swap(other.etl_debug_count); this->etl_debug_count.swap(other.etl_debug_count);
#endif #endif
} }
#endif #endif
@ -1445,8 +1446,7 @@ namespace etl
//************************************************************************* //*************************************************************************
#if ETL_USING_CPP17 && ETL_HAS_INITIALIZER_LIST #if ETL_USING_CPP17 && ETL_HAS_INITIALIZER_LIST
template <typename T, typename... Ts> template <typename T, typename... Ts>
circular_buffer(T, Ts...) circular_buffer(T, Ts...) -> circular_buffer<etl::enable_if_t<(etl::is_same_v<T, Ts> && ...), T>, 1U + sizeof...(Ts)>;
->circular_buffer<etl::enable_if_t<(etl::is_same_v<T, Ts> && ...), T>, 1U + sizeof...(Ts)>;
#endif #endif
//************************************************************************* //*************************************************************************
@ -1473,7 +1473,7 @@ namespace etl
/// Equality operator /// Equality operator
//************************************************************************* //*************************************************************************
template <typename T> template <typename T>
bool operator ==(const icircular_buffer<T>& lhs, const icircular_buffer<T>& rhs) bool operator==(const icircular_buffer<T>& lhs, const icircular_buffer<T>& rhs)
{ {
return (lhs.size() == rhs.size()) && etl::equal(lhs.begin(), lhs.end(), rhs.begin()); return (lhs.size() == rhs.size()) && etl::equal(lhs.begin(), lhs.end(), rhs.begin());
} }
@ -1482,10 +1482,10 @@ namespace etl
/// Inequality operator /// Inequality operator
//************************************************************************* //*************************************************************************
template <typename T> template <typename T>
bool operator !=(const icircular_buffer<T>& lhs, const icircular_buffer<T>& rhs) bool operator!=(const icircular_buffer<T>& lhs, const icircular_buffer<T>& rhs)
{ {
return !(lhs == rhs); return !(lhs == rhs);
} }
} } // namespace etl
#endif #endif

View File

@ -46,7 +46,7 @@ namespace etl
//*************************************************************************** //***************************************************************************
template <typename TIterator> template <typename TIterator>
class circular_iterator_common class circular_iterator_common
: public etl::iterator<typename etl::iterator_traits<TIterator>::iterator_category, typename etl::iterator_traits<TIterator>::value_type> : public etl::iterator< typename etl::iterator_traits<TIterator>::iterator_category, typename etl::iterator_traits<TIterator>::value_type>
{ {
public: public:
@ -89,11 +89,11 @@ namespace etl
//*************************************************************************** //***************************************************************************
/// Assignment /// Assignment
//*************************************************************************** //***************************************************************************
ETL_CONSTEXPR14 circular_iterator_common& operator =(const circular_iterator_common& other) ETL_CONSTEXPR14 circular_iterator_common& operator=(const circular_iterator_common& other)
{ {
itr_begin = other.itr_begin; itr_begin = other.itr_begin;
itr_end = other.itr_end; itr_end = other.itr_end;
itr = other.itr; itr = other.itr;
return *this; return *this;
} }
@ -133,7 +133,7 @@ namespace etl
//*************************************************************************** //***************************************************************************
/// Dereference operator. /// Dereference operator.
//*************************************************************************** //***************************************************************************
ETL_CONSTEXPR14 value_type operator *() ETL_CONSTEXPR14 value_type operator*()
{ {
return *itr; return *itr;
} }
@ -141,7 +141,7 @@ namespace etl
//*************************************************************************** //***************************************************************************
/// Dereference operator. /// Dereference operator.
//*************************************************************************** //***************************************************************************
ETL_CONSTEXPR14 const value_type operator *() const ETL_CONSTEXPR14 const value_type operator*() const
{ {
return *itr; return *itr;
} }
@ -149,7 +149,7 @@ namespace etl
//*************************************************************************** //***************************************************************************
/// -> operator. /// -> operator.
//*************************************************************************** //***************************************************************************
ETL_CONSTEXPR14 TIterator operator ->() ETL_CONSTEXPR14 TIterator operator->()
{ {
return itr; return itr;
} }
@ -157,7 +157,7 @@ namespace etl
//*************************************************************************** //***************************************************************************
/// -> operator. /// -> operator.
//*************************************************************************** //***************************************************************************
ETL_CONSTEXPR14 const TIterator operator ->() const ETL_CONSTEXPR14 const TIterator operator->() const
{ {
return itr; return itr;
} }
@ -187,14 +187,17 @@ namespace etl
//*************************************************************************** //***************************************************************************
/// A circular iterator class. /// A circular iterator class.
/// This iterator can be given a pair of iterator values, which will loop if the start or end of the range is reached. /// This iterator can be given a pair of iterator values, which will loop if
/// the start or end of the range is reached.
///\ingroup iterator ///\ingroup iterator
//*************************************************************************** //***************************************************************************
template <typename TIterator, typename TTag = typename etl::iterator_traits<TIterator>::iterator_category> template <typename TIterator, typename TTag = typename etl::iterator_traits<TIterator>::iterator_category>
class circular_iterator_impl class circular_iterator_impl
{ {
ETL_STATIC_ASSERT((etl::is_same<TTag, ETL_OR_STD::input_iterator_tag>::value_type), "input_iterator_catagory is not supported by circular_iterator"); ETL_STATIC_ASSERT((etl::is_same<TTag, ETL_OR_STD::input_iterator_tag>::value_type),
ETL_STATIC_ASSERT((etl::is_same<TTag, ETL_OR_STD::output_iterator_tag>::value_type), "output_iterator_catagory is not supported by circular_iterator"); "input_iterator_catagory is not supported by circular_iterator");
ETL_STATIC_ASSERT((etl::is_same<TTag, ETL_OR_STD::output_iterator_tag>::value_type),
"output_iterator_catagory is not supported by circular_iterator");
}; };
//*************************************************************************** //***************************************************************************
@ -203,8 +206,7 @@ namespace etl
///\ingroup iterator ///\ingroup iterator
/// //*************************************************************************** /// //***************************************************************************
template <typename TIterator> template <typename TIterator>
class circular_iterator_impl<TIterator, ETL_OR_STD::forward_iterator_tag> class circular_iterator_impl<TIterator, ETL_OR_STD::forward_iterator_tag> : public circular_iterator_common<TIterator>
: public circular_iterator_common<TIterator>
{ {
private: private:
@ -255,7 +257,7 @@ namespace etl
//*************************************************************************** //***************************************************************************
/// Assignment /// Assignment
//*************************************************************************** //***************************************************************************
ETL_CONSTEXPR14 circular_iterator_impl& operator =(const circular_iterator_impl& other) ETL_CONSTEXPR14 circular_iterator_impl& operator=(const circular_iterator_impl& other)
{ {
common_t::operator=(other); common_t::operator=(other);
@ -265,7 +267,7 @@ namespace etl
//*************************************************************************** //***************************************************************************
/// Increment. /// Increment.
//*************************************************************************** //***************************************************************************
ETL_CONSTEXPR14 circular_iterator_impl& operator ++() ETL_CONSTEXPR14 circular_iterator_impl& operator++()
{ {
if (++this->itr == this->itr_end) if (++this->itr == this->itr_end)
{ {
@ -278,7 +280,7 @@ namespace etl
//*************************************************************************** //***************************************************************************
/// Increment. /// Increment.
//*************************************************************************** //***************************************************************************
ETL_CONSTEXPR14 circular_iterator_impl operator ++(int) ETL_CONSTEXPR14 circular_iterator_impl operator++(int)
{ {
circular_iterator_impl original(*this); circular_iterator_impl original(*this);
@ -294,8 +296,7 @@ namespace etl
///\ingroup iterator ///\ingroup iterator
/// //*************************************************************************** /// //***************************************************************************
template <typename TIterator> template <typename TIterator>
class circular_iterator_impl<TIterator, ETL_OR_STD::bidirectional_iterator_tag> class circular_iterator_impl<TIterator, ETL_OR_STD::bidirectional_iterator_tag> : public circular_iterator_common<TIterator>
: public circular_iterator_common<TIterator>
{ {
private: private:
@ -346,7 +347,7 @@ namespace etl
//*************************************************************************** //***************************************************************************
/// Assignment /// Assignment
//*************************************************************************** //***************************************************************************
ETL_CONSTEXPR14 circular_iterator_impl& operator =(const circular_iterator_impl& other) ETL_CONSTEXPR14 circular_iterator_impl& operator=(const circular_iterator_impl& other)
{ {
common_t::operator=(other); common_t::operator=(other);
@ -356,7 +357,7 @@ namespace etl
//*************************************************************************** //***************************************************************************
/// Increment. /// Increment.
//*************************************************************************** //***************************************************************************
ETL_CONSTEXPR14 circular_iterator_impl& operator ++() ETL_CONSTEXPR14 circular_iterator_impl& operator++()
{ {
if (++this->itr == this->itr_end) if (++this->itr == this->itr_end)
{ {
@ -369,7 +370,7 @@ namespace etl
//*************************************************************************** //***************************************************************************
/// Increment. /// Increment.
//*************************************************************************** //***************************************************************************
ETL_CONSTEXPR14 circular_iterator_impl operator ++(int) ETL_CONSTEXPR14 circular_iterator_impl operator++(int)
{ {
circular_iterator_impl original(*this); circular_iterator_impl original(*this);
@ -381,7 +382,7 @@ namespace etl
//*************************************************************************** //***************************************************************************
/// Decrement. /// Decrement.
//*************************************************************************** //***************************************************************************
ETL_CONSTEXPR14 circular_iterator_impl& operator --() ETL_CONSTEXPR14 circular_iterator_impl& operator--()
{ {
if (this->itr == this->itr_begin) if (this->itr == this->itr_begin)
{ {
@ -400,7 +401,7 @@ namespace etl
//*************************************************************************** //***************************************************************************
/// Decrement. /// Decrement.
//*************************************************************************** //***************************************************************************
ETL_CONSTEXPR14 circular_iterator_impl operator --(int) ETL_CONSTEXPR14 circular_iterator_impl operator--(int)
{ {
circular_iterator_impl original(*this); circular_iterator_impl original(*this);
@ -417,11 +418,11 @@ namespace etl
//*************************************************************************** //***************************************************************************
template <typename TIterator> template <typename TIterator>
class circular_iterator_impl<TIterator, ETL_OR_STD::random_access_iterator_tag> class circular_iterator_impl<TIterator, ETL_OR_STD::random_access_iterator_tag>
: public etl::private_circular_iterator::circular_iterator_common<TIterator> : public etl::private_circular_iterator::circular_iterator_common< TIterator>
{ {
private: private:
typedef etl::private_circular_iterator::circular_iterator_common<TIterator> common_t; typedef etl::private_circular_iterator::circular_iterator_common< TIterator> common_t;
public: public:
@ -468,7 +469,7 @@ namespace etl
//*************************************************************************** //***************************************************************************
/// Assignment /// Assignment
//*************************************************************************** //***************************************************************************
ETL_CONSTEXPR14 circular_iterator_impl& operator =(const circular_iterator_impl& other) ETL_CONSTEXPR14 circular_iterator_impl& operator=(const circular_iterator_impl& other)
{ {
common_t::operator=(other); common_t::operator=(other);
@ -478,7 +479,7 @@ namespace etl
//*************************************************************************** //***************************************************************************
/// Increment. /// Increment.
//*************************************************************************** //***************************************************************************
ETL_CONSTEXPR14 circular_iterator_impl& operator ++() ETL_CONSTEXPR14 circular_iterator_impl& operator++()
{ {
if (++this->itr == this->itr_end) if (++this->itr == this->itr_end)
{ {
@ -491,7 +492,7 @@ namespace etl
//*************************************************************************** //***************************************************************************
/// Increment. /// Increment.
//*************************************************************************** //***************************************************************************
ETL_CONSTEXPR14 circular_iterator_impl operator ++(int) ETL_CONSTEXPR14 circular_iterator_impl operator++(int)
{ {
circular_iterator_impl original(*this); circular_iterator_impl original(*this);
@ -503,7 +504,7 @@ namespace etl
//*************************************************************************** //***************************************************************************
/// Decrement. /// Decrement.
//*************************************************************************** //***************************************************************************
ETL_CONSTEXPR14 circular_iterator_impl& operator --() ETL_CONSTEXPR14 circular_iterator_impl& operator--()
{ {
if (this->itr == this->itr_begin) if (this->itr == this->itr_begin)
{ {
@ -522,7 +523,7 @@ namespace etl
//*************************************************************************** //***************************************************************************
/// Decrement. /// Decrement.
//*************************************************************************** //***************************************************************************
ETL_CONSTEXPR14 circular_iterator_impl operator --(int) ETL_CONSTEXPR14 circular_iterator_impl operator--(int)
{ {
circular_iterator_impl original(*this); circular_iterator_impl original(*this);
@ -534,7 +535,7 @@ namespace etl
//*************************************************************************** //***************************************************************************
/// += operator. /// += operator.
//*************************************************************************** //***************************************************************************
ETL_CONSTEXPR14 circular_iterator_impl& operator +=(difference_type offset) ETL_CONSTEXPR14 circular_iterator_impl& operator+=(difference_type offset)
{ {
const difference_type length = difference_type(this->size()); const difference_type length = difference_type(this->size());
offset %= length; offset %= length;
@ -542,7 +543,7 @@ namespace etl
if (offset != 0) if (offset != 0)
{ {
const difference_type distance_from_begin = etl::distance(this->itr_begin, this->itr); const difference_type distance_from_begin = etl::distance(this->itr_begin, this->itr);
const difference_type distance_to_end = etl::distance(this->itr, this->itr_end); const difference_type distance_to_end = etl::distance(this->itr, this->itr_end);
if (offset > 0) if (offset > 0)
{ {
@ -579,25 +580,27 @@ namespace etl
//*************************************************************************** //***************************************************************************
/// -= operator. /// -= operator.
//*************************************************************************** //***************************************************************************
ETL_CONSTEXPR14 circular_iterator_impl& operator -=(typename etl::iterator_traits<TIterator>::difference_type offset) ETL_CONSTEXPR14 circular_iterator_impl& operator-=(typename etl::iterator_traits<TIterator>::difference_type offset)
{ {
return operator +=(-offset); return operator+=(-offset);
} }
}; };
} } // namespace private_circular_iterator
//*************************************************************************** //***************************************************************************
/// A circular iterator class. /// A circular iterator class.
/// This iterator can be given a pair of iterator values, which will loop if the start or end of the range is reached. /// This iterator can be given a pair of iterator values, which will loop if
/// the start or end of the range is reached.
///\ingroup iterator ///\ingroup iterator
//************************************************************************** //**************************************************************************
template <typename TIterator> template <typename TIterator>
class circular_iterator ETL_FINAL class circular_iterator ETL_FINAL
: public etl::private_circular_iterator::circular_iterator_impl<TIterator, typename etl::iterator_traits<TIterator>::iterator_category> : public etl::private_circular_iterator::circular_iterator_impl< TIterator, typename etl::iterator_traits<TIterator>::iterator_category>
{ {
private: private:
typedef typename etl::private_circular_iterator::circular_iterator_impl<TIterator, typename etl::iterator_traits<TIterator>::iterator_category> impl_t; typedef typename etl::private_circular_iterator::circular_iterator_impl< TIterator, typename etl::iterator_traits<TIterator>::iterator_category>
impl_t;
public: public:
@ -644,7 +647,7 @@ namespace etl
//*************************************************************************** //***************************************************************************
/// Assignment /// Assignment
//*************************************************************************** //***************************************************************************
ETL_CONSTEXPR14 circular_iterator& operator =(const circular_iterator& other) ETL_CONSTEXPR14 circular_iterator& operator=(const circular_iterator& other)
{ {
impl_t::operator=(other); impl_t::operator=(other);
@ -656,12 +659,12 @@ namespace etl
/// + addition operator. /// + addition operator.
//***************************************************************************** //*****************************************************************************
template <typename TIterator> template <typename TIterator>
ETL_CONSTEXPR14 etl::circular_iterator<TIterator> operator +(etl::circular_iterator<TIterator>& lhs, ETL_CONSTEXPR14 etl::circular_iterator<TIterator> operator+(etl::circular_iterator<TIterator>& lhs,
typename etl::iterator_traits<TIterator>::difference_type offset) typename etl::iterator_traits<TIterator>::difference_type offset)
{ {
etl::circular_iterator<TIterator> result(lhs); etl::circular_iterator<TIterator> result(lhs);
result += offset; result += offset;
return result; return result;
} }
@ -669,8 +672,8 @@ namespace etl
/// - offset operator. /// - offset operator.
//***************************************************************************** //*****************************************************************************
template <typename TIterator> template <typename TIterator>
ETL_CONSTEXPR14 etl::circular_iterator<TIterator> operator -(etl::circular_iterator<TIterator>& lhs, ETL_CONSTEXPR14 etl::circular_iterator<TIterator> operator-(etl::circular_iterator<TIterator>& lhs,
typename etl::iterator_traits<TIterator>::difference_type offset) typename etl::iterator_traits<TIterator>::difference_type offset)
{ {
etl::circular_iterator<TIterator> result(lhs); etl::circular_iterator<TIterator> result(lhs);
result -= offset; result -= offset;
@ -682,8 +685,8 @@ namespace etl
/// - circular_iterator difference operator. /// - circular_iterator difference operator.
//***************************************************************************** //*****************************************************************************
template <typename TIterator> template <typename TIterator>
ETL_CONSTEXPR14 typename etl::iterator_traits<TIterator>::difference_type operator -(etl::circular_iterator<TIterator>& lhs, ETL_CONSTEXPR14 typename etl::iterator_traits<TIterator>::difference_type operator-(etl::circular_iterator<TIterator>& lhs,
etl::circular_iterator<TIterator>& rhs) etl::circular_iterator<TIterator>& rhs)
{ {
return TIterator(lhs) - TIterator(rhs); return TIterator(lhs) - TIterator(rhs);
} }
@ -692,8 +695,7 @@ namespace etl
/// Equality operator. circular_iterator == circular_iterator. /// Equality operator. circular_iterator == circular_iterator.
//***************************************************************************** //*****************************************************************************
template <typename TIterator> template <typename TIterator>
ETL_CONSTEXPR14 bool operator ==(const etl::circular_iterator<TIterator>& lhs, ETL_CONSTEXPR14 bool operator==(const etl::circular_iterator<TIterator>& lhs, const etl::circular_iterator<TIterator>& rhs)
const etl::circular_iterator<TIterator>& rhs)
{ {
return TIterator(lhs) == TIterator(rhs); return TIterator(lhs) == TIterator(rhs);
} }
@ -702,8 +704,7 @@ namespace etl
/// Equality operator. circular_iterator == iterator. /// Equality operator. circular_iterator == iterator.
//***************************************************************************** //*****************************************************************************
template <typename TIterator> template <typename TIterator>
ETL_CONSTEXPR14 bool operator ==(const etl::circular_iterator<TIterator>& lhs, ETL_CONSTEXPR14 bool operator==(const etl::circular_iterator<TIterator>& lhs, TIterator rhs)
TIterator rhs)
{ {
return TIterator(lhs) == rhs; return TIterator(lhs) == rhs;
} }
@ -712,19 +713,16 @@ namespace etl
/// Equality operator. iterator == circular_iterator. /// Equality operator. iterator == circular_iterator.
//***************************************************************************** //*****************************************************************************
template <typename TIterator> template <typename TIterator>
ETL_CONSTEXPR14 bool operator ==(TIterator lhs, ETL_CONSTEXPR14 bool operator==(TIterator lhs, const etl::circular_iterator<TIterator>& rhs)
const etl::circular_iterator<TIterator>& rhs)
{ {
return lhs == TIterator(rhs); return lhs == TIterator(rhs);
} }
//***************************************************************************** //*****************************************************************************
/// Inequality operator. circular_iterator == circular_iterator. /// Inequality operator. circular_iterator == circular_iterator.
//***************************************************************************** //*****************************************************************************
template <typename TIterator> template <typename TIterator>
ETL_CONSTEXPR14 bool operator !=(const etl::circular_iterator<TIterator>& lhs, ETL_CONSTEXPR14 bool operator!=(const etl::circular_iterator<TIterator>& lhs, const etl::circular_iterator<TIterator>& rhs)
const etl::circular_iterator<TIterator>& rhs)
{ {
return !(lhs == rhs); return !(lhs == rhs);
} }
@ -733,8 +731,7 @@ namespace etl
/// Inequality operator. circular_iterator == iterator. /// Inequality operator. circular_iterator == iterator.
//***************************************************************************** //*****************************************************************************
template <typename TIterator> template <typename TIterator>
ETL_CONSTEXPR14 bool operator !=(const etl::circular_iterator<TIterator>& lhs, ETL_CONSTEXPR14 bool operator!=(const etl::circular_iterator<TIterator>& lhs, TIterator rhs)
TIterator rhs)
{ {
return !(lhs == rhs); return !(lhs == rhs);
} }
@ -743,11 +740,10 @@ namespace etl
/// Inequality operator. iterator == circular_iterator. /// Inequality operator. iterator == circular_iterator.
//***************************************************************************** //*****************************************************************************
template <typename TIterator> template <typename TIterator>
ETL_CONSTEXPR14 bool operator !=(TIterator& lhs, ETL_CONSTEXPR14 bool operator!=(TIterator& lhs, const etl::circular_iterator<TIterator>& rhs)
const etl::circular_iterator<TIterator>& rhs)
{ {
return !(lhs == rhs); return !(lhs == rhs);
} }
} } // namespace etl
#endif #endif

View File

@ -34,8 +34,8 @@ SOFTWARE.
#include "platform.h" #include "platform.h"
#include "delegate.h" #include "delegate.h"
#include "tuple.h" #include "tuple.h"
#include "utility.h"
#include "type_list.h" #include "type_list.h"
#include "utility.h"
namespace etl namespace etl
{ {
@ -62,10 +62,10 @@ namespace etl
class closure<TReturn(TArgs...)> class closure<TReturn(TArgs...)>
{ {
public: public:
using delegate_type = etl::delegate<TReturn(TArgs...)>; ///< The delegate type to be invoked. using delegate_type = etl::delegate<TReturn(TArgs...)>; ///< The delegate type to be invoked.
using argument_types = etl::type_list<TArgs...>; ///< The type list of arguments. using argument_types = etl::type_list<TArgs...>; ///< The type list of arguments.
//********************************************************************* //*********************************************************************
/// Construct a closure with a delegate and its arguments. /// Construct a closure with a delegate and its arguments.
/// \param f The delegate to be invoked. /// \param f The delegate to be invoked.
@ -96,7 +96,7 @@ namespace etl
template <size_t Index, typename UArg> template <size_t Index, typename UArg>
ETL_CONSTEXPR14 void bind(UArg arg) ETL_CONSTEXPR14 void bind(UArg arg)
{ {
static_assert(etl::is_convertible<UArg, etl::type_list_type_at_index_t<argument_types, Index>>::value, "Argument is not convertible"); static_assert(etl::is_convertible< UArg, etl::type_list_type_at_index_t<argument_types, Index>>::value, "Argument is not convertible");
static_assert(!etl::is_reference<UArg>::value, "Cannot bind reference arguments"); static_assert(!etl::is_reference<UArg>::value, "Cannot bind reference arguments");
etl::get<Index>(m_args) = arg; etl::get<Index>(m_args) = arg;
@ -133,13 +133,13 @@ namespace etl
/// \tparam idx Index sequence for tuple unpacking. /// \tparam idx Index sequence for tuple unpacking.
/// \return The result of the delegate invocation. /// \return The result of the delegate invocation.
//********************************************************************* //*********************************************************************
template<size_t... Indexes> template <size_t... Indexes>
ETL_CONSTEXPR14 TReturn execute(etl::index_sequence<Indexes...>) const ETL_CONSTEXPR14 TReturn execute(etl::index_sequence<Indexes...>) const
{ {
return m_f(etl::get<Indexes>(m_args)...); return m_f(etl::get<Indexes>(m_args)...);
} }
delegate_type m_f; ///< The delegate to invoke. delegate_type m_f; ///< The delegate to invoke.
etl::tuple<TArgs...> m_args; ///< The bound arguments. etl::tuple<TArgs...> m_args; ///< The bound arguments.
}; };
#else #else
@ -154,7 +154,7 @@ namespace etl
/// \tparam TReturn The return type of the delegate. /// \tparam TReturn The return type of the delegate.
/// \tparam TArg0 The type of the argument. /// \tparam TArg0 The type of the argument.
//************************************************************************* //*************************************************************************
template<typename TReturn, typename TArg0> template <typename TReturn, typename TArg0>
class closure<TReturn(TArg0)> class closure<TReturn(TArg0)>
{ {
public: public:
@ -177,7 +177,7 @@ namespace etl
/// Invoke the stored delegate with the bound argument. /// Invoke the stored delegate with the bound argument.
/// \return The result of the delegate invocation. /// \return The result of the delegate invocation.
//********************************************************************* //*********************************************************************
TReturn operator()() const TReturn operator()() const
{ {
return m_f(m_arg0); return m_f(m_arg0);
} }
@ -185,7 +185,7 @@ namespace etl
private: private:
delegate_type m_f; ///< The delegate to invoke. delegate_type m_f; ///< The delegate to invoke.
TArg0 m_arg0; TArg0 m_arg0;
}; };
//************************************************************************* //*************************************************************************
@ -194,7 +194,7 @@ namespace etl
/// \tparam TArg0 The type of the first argument. /// \tparam TArg0 The type of the first argument.
/// \tparam TArg1 The type of the second argument. /// \tparam TArg1 The type of the second argument.
//************************************************************************* //*************************************************************************
template<typename TReturn, typename TArg0, typename TArg1> template <typename TReturn, typename TArg0, typename TArg1>
class closure<TReturn(TArg0, TArg1)> class closure<TReturn(TArg0, TArg1)>
{ {
public: public:
@ -218,7 +218,7 @@ namespace etl
/// Invoke the stored delegate with the bound arguments. /// Invoke the stored delegate with the bound arguments.
/// \return The result of the delegate invocation. /// \return The result of the delegate invocation.
//********************************************************************* //*********************************************************************
TReturn operator()() const TReturn operator()() const
{ {
return m_f(m_arg0, m_arg1); return m_f(m_arg0, m_arg1);
} }
@ -226,8 +226,8 @@ namespace etl
private: private:
delegate_type m_f; ///< The delegate to invoke. delegate_type m_f; ///< The delegate to invoke.
TArg0 m_arg0; TArg0 m_arg0;
TArg1 m_arg1; TArg1 m_arg1;
}; };
//************************************************************************* //*************************************************************************
@ -237,7 +237,7 @@ namespace etl
/// \tparam TArg1 The type of the second argument. /// \tparam TArg1 The type of the second argument.
/// \tparam TArg2 The type of the third argument. /// \tparam TArg2 The type of the third argument.
//************************************************************************* //*************************************************************************
template<typename TReturn, typename TArg0, typename TArg1, typename TArg2> template <typename TReturn, typename TArg0, typename TArg1, typename TArg2>
class closure<TReturn(TArg0, TArg1, TArg2)> class closure<TReturn(TArg0, TArg1, TArg2)>
{ {
public: public:
@ -263,7 +263,7 @@ namespace etl
/// Invoke the stored delegate with the bound arguments. /// Invoke the stored delegate with the bound arguments.
/// \return The result of the delegate invocation. /// \return The result of the delegate invocation.
//********************************************************************* //*********************************************************************
TReturn operator()() const TReturn operator()() const
{ {
return m_f(m_arg0, m_arg1, m_arg2); return m_f(m_arg0, m_arg1, m_arg2);
} }
@ -271,9 +271,9 @@ namespace etl
private: private:
delegate_type m_f; ///< The delegate to invoke. delegate_type m_f; ///< The delegate to invoke.
TArg0 m_arg0; TArg0 m_arg0;
TArg1 m_arg1; TArg1 m_arg1;
TArg2 m_arg2; TArg2 m_arg2;
}; };
//************************************************************************* //*************************************************************************
@ -284,7 +284,7 @@ namespace etl
/// \tparam TArg2 The type of the third argument. /// \tparam TArg2 The type of the third argument.
/// \tparam TArg3 The type of the fourth argument. /// \tparam TArg3 The type of the fourth argument.
//************************************************************************* //*************************************************************************
template<typename TReturn, typename TArg0, typename TArg1, typename TArg2, typename TArg3> template <typename TReturn, typename TArg0, typename TArg1, typename TArg2, typename TArg3>
class closure<TReturn(TArg0, TArg1, TArg2, TArg3)> class closure<TReturn(TArg0, TArg1, TArg2, TArg3)>
{ {
public: public:
@ -312,7 +312,7 @@ namespace etl
/// Invoke the stored delegate with the bound arguments. /// Invoke the stored delegate with the bound arguments.
/// \return The result of the delegate invocation. /// \return The result of the delegate invocation.
//********************************************************************* //*********************************************************************
TReturn operator()() const TReturn operator()() const
{ {
return m_f(m_arg0, m_arg1, m_arg2, m_arg3); return m_f(m_arg0, m_arg1, m_arg2, m_arg3);
} }
@ -320,10 +320,10 @@ namespace etl
private: private:
delegate_type m_f; ///< The delegate to invoke. delegate_type m_f; ///< The delegate to invoke.
TArg0 m_arg0; TArg0 m_arg0;
TArg1 m_arg1; TArg1 m_arg1;
TArg2 m_arg2; TArg2 m_arg2;
TArg3 m_arg3; TArg3 m_arg3;
}; };
//************************************************************************* //*************************************************************************
@ -335,7 +335,7 @@ namespace etl
/// \tparam TArg3 The type of the fourth argument. /// \tparam TArg3 The type of the fourth argument.
/// \tparam TArg4 The type of the fifth argument. /// \tparam TArg4 The type of the fifth argument.
//************************************************************************* //*************************************************************************
template<typename TReturn, typename TArg0, typename TArg1, typename TArg2, typename TArg3, typename TArg4> template <typename TReturn, typename TArg0, typename TArg1, typename TArg2, typename TArg3, typename TArg4>
class closure<TReturn(TArg0, TArg1, TArg2, TArg3, TArg4)> class closure<TReturn(TArg0, TArg1, TArg2, TArg3, TArg4)>
{ {
public: public:
@ -365,7 +365,7 @@ namespace etl
/// Invoke the stored delegate with the bound arguments. /// Invoke the stored delegate with the bound arguments.
/// \return The result of the delegate invocation. /// \return The result of the delegate invocation.
//********************************************************************* //*********************************************************************
TReturn operator()() const TReturn operator()() const
{ {
return m_f(m_arg0, m_arg1, m_arg2, m_arg3, m_arg4); return m_f(m_arg0, m_arg1, m_arg2, m_arg3, m_arg4);
} }
@ -373,13 +373,13 @@ namespace etl
private: private:
delegate_type m_f; ///< The delegate to invoke. delegate_type m_f; ///< The delegate to invoke.
TArg0 m_arg0; TArg0 m_arg0;
TArg1 m_arg1; TArg1 m_arg1;
TArg2 m_arg2; TArg2 m_arg2;
TArg3 m_arg3; TArg3 m_arg3;
TArg4 m_arg4; TArg4 m_arg4;
}; };
#endif #endif
} } // namespace etl
#endif #endif

View File

@ -32,8 +32,8 @@ SOFTWARE.
#define ETL_COMBINATIONS_INCLUDED #define ETL_COMBINATIONS_INCLUDED
#include "platform.h" #include "platform.h"
#include "permutations.h"
#include "factorial.h" #include "factorial.h"
#include "permutations.h"
///\defgroup combinations combinations ///\defgroup combinations combinations
/// combinations<N, K> : Calculates K combinations from N. /// combinations<N, K> : Calculates K combinations from N.
@ -58,6 +58,6 @@ namespace etl
template <size_t Value, size_t KV> template <size_t Value, size_t KV>
inline constexpr size_t combinations_v = combinations<Value, KV>::value; inline constexpr size_t combinations_v = combinations<Value, KV>::value;
#endif #endif
} } // namespace etl
#endif #endif

View File

@ -32,8 +32,8 @@ SOFTWARE.
#define ETL_COMPARE_INCLUDED #define ETL_COMPARE_INCLUDED
#include "platform.h" #include "platform.h"
#include "parameter_type.h"
#include "functional.h" #include "functional.h"
#include "parameter_type.h"
//***************************************************************************** //*****************************************************************************
///\defgroup compare compare ///\defgroup compare compare
@ -107,6 +107,6 @@ namespace etl
{ {
return etl::compare<T>::cmp(lhs, rhs); return etl::compare<T>::cmp(lhs, rhs);
} }
} } // namespace etl
#endif #endif

View File

@ -33,8 +33,8 @@ SOFTWARE.
#include "platform.h" #include "platform.h"
#include "utility.h"
#include "type_traits.h" #include "type_traits.h"
#include "utility.h"
#if ETL_NOT_USING_CPP20 && !defined(ETL_IN_UNIT_TEST) #if ETL_NOT_USING_CPP20 && !defined(ETL_IN_UNIT_TEST)
#error NOT SUPPORTED FOR BELOW C++20 #error NOT SUPPORTED FOR BELOW C++20
@ -42,27 +42,27 @@ SOFTWARE.
#if ETL_USING_CPP20 #if ETL_USING_CPP20
#if ETL_USING_STL #if ETL_USING_STL
#include <concepts> #include <concepts>
#endif #endif
namespace etl namespace etl
{ {
#if ETL_USING_STL #if ETL_USING_STL
using std::same_as; using std::assignable_from;
using std::derived_from;
using std::convertible_to;
using std::common_reference_with; using std::common_reference_with;
using std::common_with; using std::common_with;
using std::convertible_to;
using std::derived_from;
using std::floating_point;
using std::integral; using std::integral;
using std::same_as;
using std::signed_integral; using std::signed_integral;
using std::unsigned_integral; using std::unsigned_integral;
using std::floating_point;
using std::assignable_from;
#else // not ETL_USING_STL #else // not ETL_USING_STL
namespace private_concepts namespace private_concepts
{ {
@ -76,41 +76,23 @@ namespace etl
//*************************************************************************** //***************************************************************************
template <typename Derived, typename Base> template <typename Derived, typename Base>
concept derived_from = concept derived_from = etl::is_base_of_v<Base, Derived> && etl::is_convertible_v<const volatile Derived*, const volatile Base*>;
etl::is_base_of_v<Base, Derived> &&
etl::is_convertible_v<const volatile Derived*, const volatile Base*>;
//*************************************************************************** //***************************************************************************
template <typename From, typename To> template <typename From, typename To>
concept convertible_to = concept convertible_to = etl::is_convertible_v<From, To> && requires { static_cast<To>(etl::declval<From>()); };
etl::is_convertible_v<From, To> &&
requires {
static_cast<To>(etl::declval<From>());
};
//*************************************************************************** //***************************************************************************
template< class T, typename U > template < class T, typename U >
concept common_reference_with = concept common_reference_with = etl::same_as<etl::common_reference_t<T, U>, etl::common_reference_t<U, T> >
etl::same_as<etl::common_reference_t<T, U>, etl::common_reference_t<U, T>> && && etl::convertible_to<T, etl::common_reference_t<T, U> > && etl::convertible_to<U, etl::common_reference_t<T, U> >;
etl::convertible_to<T, etl::common_reference_t<T, U>> &&
etl::convertible_to<U, etl::common_reference_t<T, U>>;
//*************************************************************************** //***************************************************************************
template <typename T, typename U> template <typename T, typename U>
concept common_with = concept common_with = etl::same_as<etl::common_type_t<T, U>, etl::common_type_t<U, T> > && requires {
etl::same_as<etl::common_type_t<T, U>, etl::common_type_t<U, T>> && static_cast<etl::common_type_t<T, U> >(etl::declval<T>());
requires { static_cast<etl::common_type_t<T, U> >(etl::declval<U>());
static_cast<etl::common_type_t<T, U>>(etl::declval<T>()); } && etl::common_reference_with< etl::add_lvalue_reference_t<const T>, etl::add_lvalue_reference_t<const U> > && etl::common_reference_with< etl::add_lvalue_reference_t<etl::common_type_t<T, U> >, etl::common_reference_t< etl::add_lvalue_reference_t<const T>, etl::add_lvalue_reference_t<const U> > >;
static_cast<etl::common_type_t<T, U>>(etl::declval<U>());
} &&
etl::common_reference_with<
etl::add_lvalue_reference_t<const T>,
etl::add_lvalue_reference_t<const U>> &&
etl::common_reference_with<
etl::add_lvalue_reference_t<etl::common_type_t<T, U>>,
etl::common_reference_t<
etl::add_lvalue_reference_t<const T>,
etl::add_lvalue_reference_t<const U>>>;
//*************************************************************************** //***************************************************************************
template <typename T> template <typename T>
@ -131,15 +113,12 @@ namespace etl
//*************************************************************************** //***************************************************************************
template <typename LHS, typename RHS> template <typename LHS, typename RHS>
concept assignable_from = concept assignable_from =
etl::is_lvalue_reference_v<LHS> && etl::is_lvalue_reference_v<LHS> && etl::common_reference_with< const etl::remove_reference_t<LHS>&, const etl::remove_reference_t<RHS>&>
etl::common_reference_with< && requires(LHS lhs, RHS&& rhs) {
const etl::remove_reference_t<LHS>&, { lhs = etl::forward<RHS>(rhs) } -> etl::same_as<LHS>;
const etl::remove_reference_t<RHS>&> && };
requires(LHS lhs, RHS&& rhs) {
{ lhs = etl::forward<RHS>(rhs) } -> etl::same_as<LHS>;
};
#endif #endif
} } // namespace etl
#endif #endif
#endif #endif

View File

@ -38,10 +38,10 @@ SOFTWARE.
#endif #endif
#include "algorithm.h" #include "algorithm.h"
#include "type_traits.h"
#include "functional.h" #include "functional.h"
#include "nth_type.h" #include "nth_type.h"
#include "span.h" #include "span.h"
#include "type_traits.h"
#include "private/comparator_is_transparent.h" #include "private/comparator_is_transparent.h"
@ -57,7 +57,7 @@ namespace etl
using key_type = TKey; using key_type = TKey;
using value_type = ETL_OR_STD::pair<const TKey, TMapped>; using value_type = ETL_OR_STD::pair<const TKey, TMapped>;
using mapped_type = TMapped ; using mapped_type = TMapped;
using key_compare = TKeyCompare; using key_compare = TKeyCompare;
using const_reference = const value_type&; using const_reference = const value_type&;
using const_pointer = const value_type*; using const_pointer = const value_type*;
@ -72,13 +72,13 @@ namespace etl
public: public:
// Compare two value types. // Compare two value types.
ETL_CONSTEXPR14 bool operator ()(const value_type& element1, const value_type& element2) const ETL_NOEXCEPT ETL_CONSTEXPR14 bool operator()(const value_type& element1, const value_type& element2) const ETL_NOEXCEPT
{ {
return kcompare(element1.first, element2.first); return kcompare(element1.first, element2.first);
} }
// Compare value type and key. // Compare value type and key.
ETL_CONSTEXPR14 bool operator ()(const value_type& element, const key_type& key) const ETL_NOEXCEPT ETL_CONSTEXPR14 bool operator()(const value_type& element, const key_type& key) const ETL_NOEXCEPT
{ {
return kcompare(element.first, key); return kcompare(element.first, key);
} }
@ -86,13 +86,13 @@ namespace etl
// Compare value types and key. // Compare value types and key.
// Enabled for transparent comparators. // Enabled for transparent comparators.
template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0> template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
ETL_CONSTEXPR14 bool operator ()(const value_type& element, const K& key) const ETL_NOEXCEPT ETL_CONSTEXPR14 bool operator()(const value_type& element, const K& key) const ETL_NOEXCEPT
{ {
return kcompare(element.first, key); return kcompare(element.first, key);
} }
// Compare key and value type. // Compare key and value type.
ETL_CONSTEXPR14 bool operator ()(const key_type& key, const value_type& element) const ETL_NOEXCEPT ETL_CONSTEXPR14 bool operator()(const key_type& key, const value_type& element) const ETL_NOEXCEPT
{ {
return kcompare(key, element.first); return kcompare(key, element.first);
} }
@ -100,7 +100,7 @@ namespace etl
// Compare key and value type. // Compare key and value type.
// Enabled for transparent comparators. // Enabled for transparent comparators.
template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0> template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
ETL_CONSTEXPR14 bool operator ()(const K& key, const value_type& element) const ETL_NOEXCEPT ETL_CONSTEXPR14 bool operator()(const K& key, const value_type& element) const ETL_NOEXCEPT
{ {
return kcompare(key, element.first); return kcompare(key, element.first);
} }
@ -161,13 +161,14 @@ namespace etl
//************************************************************************* //*************************************************************************
///\brief Index operator. ///\brief Index operator.
///\param key The key of the element to return. ///\param key The key of the element to return.
///\return A <code>const mapped_type&</code> to the mapped value at the index. ///\return A <code>const mapped_type&</code> to the mapped value at the
/// index.
/// Undefined behaviour if the key is not in the map. /// Undefined behaviour if the key is not in the map.
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 const mapped_type& operator[](const key_type& key) const ETL_NOEXCEPT ETL_CONSTEXPR14 const mapped_type& operator[](const key_type& key) const ETL_NOEXCEPT
{ {
const_iterator itr = find(key); const_iterator itr = find(key);
return itr->second; return itr->second;
} }
@ -175,7 +176,8 @@ namespace etl
///\brief Key index operator. ///\brief Key index operator.
/// Enabled for transparent comparators. /// Enabled for transparent comparators.
///\param key The key of the element to return. ///\param key The key of the element to return.
///\return A <code>const mapped_type&</code> to the mapped value at the key index. ///\return A <code>const mapped_type&</code> to the mapped value at the key
/// index.
/// Undefined behaviour if the key is not in the map. /// Undefined behaviour if the key is not in the map.
//************************************************************************* //*************************************************************************
template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0> template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
@ -189,7 +191,8 @@ namespace etl
//************************************************************************* //*************************************************************************
///\brief Gets the mapped value at the key index. ///\brief Gets the mapped value at the key index.
///\param key The key of the element to return. ///\param key The key of the element to return.
///\return A <code>const mapped_type&</code> to the mapped value at the index. ///\return A <code>const mapped_type&</code> to the mapped value at the
/// index.
/// Undefined behaviour if the key is not in the map. /// Undefined behaviour if the key is not in the map.
//************************************************************************* //*************************************************************************
ETL_CONSTEXPR14 const mapped_type& at(const key_type& key) const ETL_NOEXCEPT ETL_CONSTEXPR14 const mapped_type& at(const key_type& key) const ETL_NOEXCEPT
@ -203,7 +206,8 @@ namespace etl
///\brief Gets the mapped value at the key index. ///\brief Gets the mapped value at the key index.
/// Enabled if the comparator is transparent. /// Enabled if the comparator is transparent.
///\param key The key of the element to return. ///\param key The key of the element to return.
///\return A <code>const mapped_type&</code> to the mapped value at the index. ///\return A <code>const mapped_type&</code> to the mapped value at the
/// index.
/// Undefined behaviour if the key is not in the map. /// Undefined behaviour if the key is not in the map.
//************************************************************************* //*************************************************************************
template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0> template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
@ -283,7 +287,7 @@ namespace etl
{ {
return contains(key) ? 1 : 0; return contains(key) ? 1 : 0;
} }
//************************************************************************* //*************************************************************************
///\brief Counts the numbeer elements with key. ///\brief Counts the numbeer elements with key.
/// Enabled if the comparator is transparent. /// Enabled if the comparator is transparent.
@ -297,9 +301,9 @@ namespace etl
} }
//************************************************************************* //*************************************************************************
///\brief Returns a range containing all elements with the key. ///\brief Returns a range containing all elements with the key.
/// The range is defined by a pair of two iterators, one to the /// The range is defined by a pair of two iterators, one to the
/// first element that is not less than the key and second to the first /// first element that is not less than the key and second to the first
/// element greater than the key. /// element greater than the key.
///\param key The key of the element ///\param key The key of the element
///\return etl::pair or std::pair containing a pair of iterators. ///\return etl::pair or std::pair containing a pair of iterators.
@ -310,9 +314,9 @@ namespace etl
} }
//************************************************************************* //*************************************************************************
///\brief Returns a range containing all elements with the key. ///\brief Returns a range containing all elements with the key.
/// The range is defined by a pair of two iterators, one to the /// The range is defined by a pair of two iterators, one to the
/// first element that is not less than the key and second to the first /// first element that is not less than the key and second to the first
/// element greater than the key. /// element greater than the key.
/// Enabled if the comparator is transparent. /// Enabled if the comparator is transparent.
///\param key The key of the element ///\param key The key of the element
@ -325,8 +329,10 @@ namespace etl
} }
//************************************************************************* //*************************************************************************
///\brief Returns a const_iterator to the first element that is not less than the key. ///\brief Returns a const_iterator to the first element that is not less
/// Returns a const_iterator to the first element that is not less than the key. /// than the key.
/// Returns a const_iterator to the first element that is not less than the
/// key.
///\param key The key of the element ///\param key The key of the element
///\return const_iterator to the element or end() ///\return const_iterator to the element or end()
//************************************************************************* //*************************************************************************
@ -336,9 +342,10 @@ namespace etl
} }
//************************************************************************* //*************************************************************************
///\brief Returns a const_iterator to the first element that is not less than the key. ///\brief Returns a const_iterator to the first element that is not less
/// Returns a const_iterator to the first element that is not less than the key. /// than the key.
/// Enabled if the comparator is transparent. /// Returns a const_iterator to the first element that is not less than the
/// key. Enabled if the comparator is transparent.
///\param key The key of the element ///\param key The key of the element
///\return const_iterator to the element or end() ///\return const_iterator to the element or end()
//************************************************************************* //*************************************************************************
@ -349,8 +356,10 @@ namespace etl
} }
//************************************************************************* //*************************************************************************
///\brief Returns a const_iterator to the first element that is greater than the key. ///\brief Returns a const_iterator to the first element that is greater than
/// Returns a const_iterator to the first element that is greater than the key. /// the key.
/// Returns a const_iterator to the first element that is greater than the
/// key.
///\param key The key of the element ///\param key The key of the element
///\return const_iterator to the element or end() ///\return const_iterator to the element or end()
//************************************************************************* //*************************************************************************
@ -360,9 +369,10 @@ namespace etl
} }
//************************************************************************* //*************************************************************************
///\brief Returns a const_iterator to the first element that is greater than the key. ///\brief Returns a const_iterator to the first element that is greater than
/// Returns a const_iterator to the first element that is greater than the key. /// the key.
/// Enabled if the comparator is transparent. /// Returns a const_iterator to the first element that is greater than the
/// key. Enabled if the comparator is transparent.
///\param key The key of the element ///\param key The key of the element
///\return const_iterator to the element or end() ///\return const_iterator to the element or end()
//************************************************************************* //*************************************************************************
@ -488,20 +498,21 @@ namespace etl
using key_type = typename base_t::key_type; using key_type = typename base_t::key_type;
using value_type = typename base_t::value_type; using value_type = typename base_t::value_type;
using mapped_type = typename base_t::mapped_type ; using mapped_type = typename base_t::mapped_type;
using key_compare = typename base_t::key_compare; using key_compare = typename base_t::key_compare;
using const_reference = typename base_t::const_reference; using const_reference = typename base_t::const_reference;
using const_pointer = typename base_t::const_pointer; using const_pointer = typename base_t::const_pointer;
using const_iterator = typename base_t::const_iterator; using const_iterator = typename base_t::const_iterator;
using size_type = typename base_t::size_type; using size_type = typename base_t::size_type;
static_assert((etl::is_default_constructible<key_type>::value), "key_type must be default constructible"); static_assert((etl::is_default_constructible<key_type>::value), "key_type must be default constructible");
static_assert((etl::is_default_constructible<mapped_type>::value), "mapped_type must be default constructible"); static_assert((etl::is_default_constructible<mapped_type>::value), "mapped_type must be default constructible");
//************************************************************************* //*************************************************************************
///\brief Construct a const_map from a variadic list of elements. ///\brief Construct a const_map from a variadic list of elements.
/// Static asserts if the elements are not of type <code>value_type</code>. /// Static asserts if the elements are not of type <code>value_type</code>.
/// Static asserts if the number of elements is greater than the capacity of the const_map. /// Static asserts if the number of elements is greater than the capacity of
/// the const_map.
//************************************************************************* //*************************************************************************
template <typename... TElements> template <typename... TElements>
ETL_CONSTEXPR14 explicit const_map(TElements&&... elements) ETL_NOEXCEPT ETL_CONSTEXPR14 explicit const_map(TElements&&... elements) ETL_NOEXCEPT
@ -509,7 +520,7 @@ namespace etl
, element_list{etl::forward<TElements>(elements)...} , element_list{etl::forward<TElements>(elements)...}
{ {
static_assert((etl::are_all_same<value_type, etl::decay_t<TElements>...>::value), "All elements must be value_type"); static_assert((etl::are_all_same<value_type, etl::decay_t<TElements>...>::value), "All elements must be value_type");
static_assert(sizeof...(elements) <= Size, "Number of elements exceeds capacity"); static_assert(sizeof...(elements) <= Size, "Number of elements exceeds capacity");
} }
private: private:
@ -522,9 +533,8 @@ namespace etl
//************************************************************************* //*************************************************************************
#if ETL_USING_CPP17 #if ETL_USING_CPP17
template <typename... TElements> template <typename... TElements>
const_map(TElements...) -> const_map<typename etl::nth_type_t<0, TElements...>::first_type, const_map(TElements...)
typename etl::nth_type_t<0, TElements...>::second_type, -> const_map<typename etl::nth_type_t<0, TElements...>::first_type, typename etl::nth_type_t<0, TElements...>::second_type, sizeof...(TElements)>;
sizeof...(TElements)>;
#endif #endif
//********************************************************************* //*********************************************************************
@ -539,14 +549,14 @@ namespace etl
using key_type = typename base_t::key_type; using key_type = typename base_t::key_type;
using value_type = typename base_t::value_type; using value_type = typename base_t::value_type;
using mapped_type = typename base_t::mapped_type ; using mapped_type = typename base_t::mapped_type;
using key_compare = typename base_t::key_compare; using key_compare = typename base_t::key_compare;
using const_reference = typename base_t::const_reference; using const_reference = typename base_t::const_reference;
using const_pointer = typename base_t::const_pointer; using const_pointer = typename base_t::const_pointer;
using const_iterator = typename base_t::const_iterator; using const_iterator = typename base_t::const_iterator;
using size_type = typename base_t::size_type; using size_type = typename base_t::size_type;
static_assert((etl::is_default_constructible<key_type>::value), "key_type must be default constructible"); static_assert((etl::is_default_constructible<key_type>::value), "key_type must be default constructible");
static_assert((etl::is_default_constructible<mapped_type>::value), "mapped_type must be default constructible"); static_assert((etl::is_default_constructible<mapped_type>::value), "mapped_type must be default constructible");
//************************************************************************* //*************************************************************************
@ -570,7 +580,7 @@ namespace etl
///\brief Construct a const_map from an array. ///\brief Construct a const_map from an array.
//************************************************************************* //*************************************************************************
template <size_type Size> template <size_type Size>
ETL_CONSTEXPR14 explicit const_map_ext(const value_type(&begin_)[Size]) ETL_NOEXCEPT ETL_CONSTEXPR14 explicit const_map_ext(const value_type (&begin_)[Size]) ETL_NOEXCEPT
: iconst_map<TKey, TMapped, TKeyCompare>(begin_, Size, Size) : iconst_map<TKey, TMapped, TKeyCompare>(begin_, Size, Size)
{ {
} }
@ -584,15 +594,15 @@ namespace etl
const_map_ext(const etl::span<TElements, Size>&) -> const_map_ext<typename TElements::first_type, typename TElements::second_type>; const_map_ext(const etl::span<TElements, Size>&) -> const_map_ext<typename TElements::first_type, typename TElements::second_type>;
template <typename TElements, size_t Size> template <typename TElements, size_t Size>
const_map_ext(const TElements(&)[Size]) -> const_map_ext<typename TElements::first_type, typename TElements::second_type>; const_map_ext(const TElements (&)[Size]) -> const_map_ext<typename TElements::first_type, typename TElements::second_type>;
#endif #endif
//************************************************************************* //*************************************************************************
/// Equality test. /// Equality test.
//************************************************************************* //*************************************************************************
template <typename TKey, typename TMapped, typename TKeyCompare> template <typename TKey, typename TMapped, typename TKeyCompare>
ETL_CONSTEXPR14 bool operator ==(const etl::iconst_map<TKey, TMapped, TKeyCompare>& lhs, ETL_CONSTEXPR14 bool operator==(const etl::iconst_map<TKey, TMapped, TKeyCompare>& lhs, const etl::iconst_map<TKey, TMapped, TKeyCompare>& rhs)
const etl::iconst_map<TKey, TMapped, TKeyCompare>& rhs) ETL_NOEXCEPT ETL_NOEXCEPT
{ {
return (lhs.size() == rhs.size()) && etl::equal(lhs.begin(), lhs.end(), rhs.begin()); return (lhs.size() == rhs.size()) && etl::equal(lhs.begin(), lhs.end(), rhs.begin());
} }
@ -601,8 +611,8 @@ namespace etl
/// Inequality test. /// Inequality test.
//************************************************************************* //*************************************************************************
template <typename TKey, typename TMapped, typename TKeyCompare> template <typename TKey, typename TMapped, typename TKeyCompare>
ETL_CONSTEXPR14 bool operator !=(const etl::iconst_map<TKey, TMapped, TKeyCompare>& lhs, ETL_CONSTEXPR14 bool operator!=(const etl::iconst_map<TKey, TMapped, TKeyCompare>& lhs, const etl::iconst_map<TKey, TMapped, TKeyCompare>& rhs)
const etl::iconst_map<TKey, TMapped, TKeyCompare>& rhs) ETL_NOEXCEPT ETL_NOEXCEPT
{ {
return !(lhs == rhs); return !(lhs == rhs);
} }
@ -611,20 +621,18 @@ namespace etl
/// Less-than. /// Less-than.
//************************************************************************* //*************************************************************************
template <typename TKey, typename TMapped, typename TKeyCompare> template <typename TKey, typename TMapped, typename TKeyCompare>
ETL_CONSTEXPR14 bool operator <(const etl::iconst_map<TKey, TMapped, TKeyCompare>& lhs, ETL_CONSTEXPR14 bool operator<(const etl::iconst_map<TKey, TMapped, TKeyCompare>& lhs, const etl::iconst_map<TKey, TMapped, TKeyCompare>& rhs)
const etl::iconst_map<TKey, TMapped, TKeyCompare>& rhs) ETL_NOEXCEPT ETL_NOEXCEPT
{ {
return etl::lexicographical_compare(lhs.begin(), lhs.end(), return etl::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end(), lhs.value_comp());
rhs.begin(), rhs.end(),
lhs.value_comp());
} }
//************************************************************************* //*************************************************************************
/// Greater-than. /// Greater-than.
//************************************************************************* //*************************************************************************
template <typename TKey, typename TMapped, typename TKeyCompare> template <typename TKey, typename TMapped, typename TKeyCompare>
ETL_CONSTEXPR14 bool operator >(const etl::iconst_map<TKey, TMapped, TKeyCompare>& lhs, ETL_CONSTEXPR14 bool operator>(const etl::iconst_map<TKey, TMapped, TKeyCompare>& lhs, const etl::iconst_map<TKey, TMapped, TKeyCompare>& rhs)
const etl::iconst_map<TKey, TMapped, TKeyCompare>& rhs) ETL_NOEXCEPT ETL_NOEXCEPT
{ {
return (rhs < lhs); return (rhs < lhs);
} }
@ -633,8 +641,8 @@ namespace etl
/// Less-than-equal. /// Less-than-equal.
//************************************************************************* //*************************************************************************
template <typename TKey, typename TMapped, typename TKeyCompare> template <typename TKey, typename TMapped, typename TKeyCompare>
ETL_CONSTEXPR14 bool operator <=(const etl::iconst_map<TKey, TMapped, TKeyCompare>& lhs, ETL_CONSTEXPR14 bool operator<=(const etl::iconst_map<TKey, TMapped, TKeyCompare>& lhs, const etl::iconst_map<TKey, TMapped, TKeyCompare>& rhs)
const etl::iconst_map<TKey, TMapped, TKeyCompare>& rhs) ETL_NOEXCEPT ETL_NOEXCEPT
{ {
return !(rhs < lhs); return !(rhs < lhs);
} }
@ -643,11 +651,11 @@ namespace etl
/// Greater-than-equal. /// Greater-than-equal.
//************************************************************************* //*************************************************************************
template <typename TKey, typename TMapped, typename TKeyCompare> template <typename TKey, typename TMapped, typename TKeyCompare>
ETL_CONSTEXPR14 bool operator >=(const etl::iconst_map<TKey, TMapped, TKeyCompare>& lhs, ETL_CONSTEXPR14 bool operator>=(const etl::iconst_map<TKey, TMapped, TKeyCompare>& lhs, const etl::iconst_map<TKey, TMapped, TKeyCompare>& rhs)
const etl::iconst_map<TKey, TMapped, TKeyCompare>& rhs) ETL_NOEXCEPT ETL_NOEXCEPT
{ {
return !(lhs < rhs); return !(lhs < rhs);
} }
} } // namespace etl
#endif #endif

View File

@ -31,17 +31,17 @@ SOFTWARE.
#ifndef ETL_CONST_MULTIMAP_INCLUDED #ifndef ETL_CONST_MULTIMAP_INCLUDED
#define ETL_CONST_MULTIMAP_INCLUDED #define ETL_CONST_MULTIMAP_INCLUDED
#include "platform.h" #include "platform.h"
#if ETL_NOT_USING_CPP11 #if ETL_NOT_USING_CPP11
#error NOT SUPPORTED FOR C++03 OR BELOW #error NOT SUPPORTED FOR C++03 OR BELOW
#endif #endif
#include "algorithm.h" #include "algorithm.h"
#include "type_traits.h"
#include "functional.h" #include "functional.h"
#include "nth_type.h" #include "nth_type.h"
#include "span.h" #include "span.h"
#include "type_traits.h"
#include "private/comparator_is_transparent.h" #include "private/comparator_is_transparent.h"
@ -57,7 +57,7 @@ namespace etl
using key_type = TKey; using key_type = TKey;
using value_type = ETL_OR_STD::pair<const TKey, TMapped>; using value_type = ETL_OR_STD::pair<const TKey, TMapped>;
using mapped_type = TMapped ; using mapped_type = TMapped;
using key_compare = TKeyCompare; using key_compare = TKeyCompare;
using const_reference = const value_type&; using const_reference = const value_type&;
using const_pointer = const value_type*; using const_pointer = const value_type*;
@ -72,13 +72,13 @@ namespace etl
public: public:
// Compare two value types. // Compare two value types.
ETL_CONSTEXPR14 bool operator ()(const value_type& element1, const value_type& element2) const ETL_NOEXCEPT ETL_CONSTEXPR14 bool operator()(const value_type& element1, const value_type& element2) const ETL_NOEXCEPT
{ {
return kcompare(element1.first, element2.first); return kcompare(element1.first, element2.first);
} }
// Compare value type and key. // Compare value type and key.
ETL_CONSTEXPR14 bool operator ()(const value_type& element, const key_type& key) const ETL_NOEXCEPT ETL_CONSTEXPR14 bool operator()(const value_type& element, const key_type& key) const ETL_NOEXCEPT
{ {
return kcompare(element.first, key); return kcompare(element.first, key);
} }
@ -86,13 +86,13 @@ namespace etl
// Compare value types and key. // Compare value types and key.
// Enabled for transparent comparators. // Enabled for transparent comparators.
template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0> template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
ETL_CONSTEXPR14 bool operator ()(const value_type& element, const K& key) const ETL_NOEXCEPT ETL_CONSTEXPR14 bool operator()(const value_type& element, const K& key) const ETL_NOEXCEPT
{ {
return kcompare(element.first, key); return kcompare(element.first, key);
} }
// Compare key and value type. // Compare key and value type.
ETL_CONSTEXPR14 bool operator ()(const key_type& key, const value_type& element) const ETL_NOEXCEPT ETL_CONSTEXPR14 bool operator()(const key_type& key, const value_type& element) const ETL_NOEXCEPT
{ {
return kcompare(key, element.first); return kcompare(key, element.first);
} }
@ -100,7 +100,7 @@ namespace etl
// Compare key and value type. // Compare key and value type.
// Enabled for transparent comparators. // Enabled for transparent comparators.
template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0> template <typename K, typename KC = TKeyCompare, etl::enable_if_t<comparator_is_transparent<KC>::value, int> = 0>
ETL_CONSTEXPR14 bool operator ()(const K& key, const value_type& element) const ETL_NOEXCEPT ETL_CONSTEXPR14 bool operator()(const K& key, const value_type& element) const ETL_NOEXCEPT
{ {
return kcompare(key, element.first); return kcompare(key, element.first);
} }
@ -234,7 +234,7 @@ namespace etl
return size_type(etl::distance(range.first, range.second)); return size_type(etl::distance(range.first, range.second));
} }
//************************************************************************* //*************************************************************************
///\brief Counts the numbeer elements with key. ///\brief Counts the numbeer elements with key.
/// Enabled if the comparator is transparent. /// Enabled if the comparator is transparent.
@ -250,9 +250,9 @@ namespace etl
} }
//************************************************************************* //*************************************************************************
///\brief Returns a range containing all elements with the key. ///\brief Returns a range containing all elements with the key.
/// The range is defined by a pair of two iterators, one to the /// The range is defined by a pair of two iterators, one to the
/// first element that is not less than the key and second to the first /// first element that is not less than the key and second to the first
/// element greater than the key. /// element greater than the key.
///\param key The key of the element ///\param key The key of the element
///\return etl::pair or std::pair containing a pair of iterators. ///\return etl::pair or std::pair containing a pair of iterators.
@ -263,9 +263,9 @@ namespace etl
} }
//************************************************************************* //*************************************************************************
///\brief Returns a range containing all elements with the key. ///\brief Returns a range containing all elements with the key.
/// The range is defined by a pair of two iterators, one to the /// The range is defined by a pair of two iterators, one to the
/// first element that is not less than the key and second to the first /// first element that is not less than the key and second to the first
/// element greater than the key. /// element greater than the key.
/// Enabled if the comparator is transparent. /// Enabled if the comparator is transparent.
///\param key The key of the element ///\param key The key of the element
@ -278,8 +278,10 @@ namespace etl
} }
//************************************************************************* //*************************************************************************
///\brief Returns a const_iterator to the first element that is not less than the key. ///\brief Returns a const_iterator to the first element that is not less
/// Returns a const_iterator to the first element that is not less than the key. /// than the key.
/// Returns a const_iterator to the first element that is not less than the
/// key.
///\param key The key of the element ///\param key The key of the element
///\return const_iterator to the element or end() ///\return const_iterator to the element or end()
//************************************************************************* //*************************************************************************
@ -289,9 +291,10 @@ namespace etl
} }
//************************************************************************* //*************************************************************************
///\brief Returns a const_iterator to the first element that is not less than the key. ///\brief Returns a const_iterator to the first element that is not less
/// Returns a const_iterator to the first element that is not less than the key. /// than the key.
/// Enabled if the comparator is transparent. /// Returns a const_iterator to the first element that is not less than the
/// key. Enabled if the comparator is transparent.
///\param key The key of the element ///\param key The key of the element
///\return const_iterator to the element or end() ///\return const_iterator to the element or end()
//************************************************************************* //*************************************************************************
@ -302,8 +305,10 @@ namespace etl
} }
//************************************************************************* //*************************************************************************
///\brief Returns a const_iterator to the first element that is greater than the key. ///\brief Returns a const_iterator to the first element that is greater than
/// Returns a const_iterator to the first element that is greater than the key. /// the key.
/// Returns a const_iterator to the first element that is greater than the
/// key.
///\param key The key of the element ///\param key The key of the element
///\return const_iterator to the element or end() ///\return const_iterator to the element or end()
//************************************************************************* //*************************************************************************
@ -313,9 +318,10 @@ namespace etl
} }
//************************************************************************* //*************************************************************************
///\brief Returns a const_iterator to the first element that is greater than the key. ///\brief Returns a const_iterator to the first element that is greater than
/// Returns a const_iterator to the first element that is greater than the key. /// the key.
/// Enabled if the comparator is transparent. /// Returns a const_iterator to the first element that is greater than the
/// key. Enabled if the comparator is transparent.
///\param key The key of the element ///\param key The key of the element
///\return const_iterator to the element or end() ///\return const_iterator to the element or end()
//************************************************************************* //*************************************************************************
@ -426,7 +432,7 @@ namespace etl
const value_type* element_list; const value_type* element_list;
const value_type* element_list_end; const value_type* element_list_end;
size_type max_elements; size_type max_elements;
}; };
//************************************************************************* //*************************************************************************
@ -448,14 +454,15 @@ namespace etl
using const_iterator = typename base_t::const_iterator; using const_iterator = typename base_t::const_iterator;
using size_type = typename base_t::size_type; using size_type = typename base_t::size_type;
static_assert((etl::is_default_constructible<key_type>::value), "key_type must be default constructible"); static_assert((etl::is_default_constructible<key_type>::value), "key_type must be default constructible");
static_assert((etl::is_default_constructible<mapped_type>::value), "mapped_type must be default constructible"); static_assert((etl::is_default_constructible<mapped_type>::value), "mapped_type must be default constructible");
//************************************************************************* //*************************************************************************
///\brief Construct a const_map from a variadic list of elements. ///\brief Construct a const_map from a variadic list of elements.
/// Static asserts if the element type is not constructible. /// Static asserts if the element type is not constructible.
/// Static asserts if the elements are not of type <code>value_type</code>. /// Static asserts if the elements are not of type <code>value_type</code>.
/// Static asserts if the number of elements is greater than the capacity of the const_map. /// Static asserts if the number of elements is greater than the capacity of
/// the const_map.
//************************************************************************* //*************************************************************************
template <typename... TElements> template <typename... TElements>
ETL_CONSTEXPR14 explicit const_multimap(TElements&&... elements) ETL_NOEXCEPT ETL_CONSTEXPR14 explicit const_multimap(TElements&&... elements) ETL_NOEXCEPT
@ -463,7 +470,7 @@ namespace etl
, element_list{etl::forward<TElements>(elements)...} , element_list{etl::forward<TElements>(elements)...}
{ {
static_assert((etl::are_all_same<value_type, etl::decay_t<TElements>...>::value), "All elements must be value_type"); static_assert((etl::are_all_same<value_type, etl::decay_t<TElements>...>::value), "All elements must be value_type");
static_assert(sizeof...(elements) <= Size, "Number of elements exceeds capacity"); static_assert(sizeof...(elements) <= Size, "Number of elements exceeds capacity");
} }
private: private:
@ -476,9 +483,8 @@ namespace etl
//************************************************************************* //*************************************************************************
#if ETL_USING_CPP17 #if ETL_USING_CPP17
template <typename... TPairs> template <typename... TPairs>
const_multimap(TPairs...) -> const_multimap<typename etl::nth_type_t<0, TPairs...>::first_type, const_multimap(TPairs...)
typename etl::nth_type_t<0, TPairs...>::second_type, -> const_multimap<typename etl::nth_type_t<0, TPairs...>::first_type, typename etl::nth_type_t<0, TPairs...>::second_type, sizeof...(TPairs)>;
sizeof...(TPairs)>;
#endif #endif
//********************************************************************* //*********************************************************************
@ -493,14 +499,14 @@ namespace etl
using key_type = typename base_t::key_type; using key_type = typename base_t::key_type;
using value_type = typename base_t::value_type; using value_type = typename base_t::value_type;
using mapped_type = typename base_t::mapped_type ; using mapped_type = typename base_t::mapped_type;
using key_compare = typename base_t::key_compare; using key_compare = typename base_t::key_compare;
using const_reference = typename base_t::const_reference; using const_reference = typename base_t::const_reference;
using const_pointer = typename base_t::const_pointer; using const_pointer = typename base_t::const_pointer;
using const_iterator = typename base_t::const_iterator; using const_iterator = typename base_t::const_iterator;
using size_type = typename base_t::size_type; using size_type = typename base_t::size_type;
static_assert((etl::is_default_constructible<key_type>::value), "key_type must be default constructible"); static_assert((etl::is_default_constructible<key_type>::value), "key_type must be default constructible");
static_assert((etl::is_default_constructible<mapped_type>::value), "mapped_type must be default constructible"); static_assert((etl::is_default_constructible<mapped_type>::value), "mapped_type must be default constructible");
//************************************************************************* //*************************************************************************
@ -524,7 +530,7 @@ namespace etl
///\brief Construct a const_map from an array. ///\brief Construct a const_map from an array.
//************************************************************************* //*************************************************************************
template <size_type Size> template <size_type Size>
ETL_CONSTEXPR14 explicit const_multimap_ext(const value_type(&begin_)[Size]) ETL_NOEXCEPT ETL_CONSTEXPR14 explicit const_multimap_ext(const value_type (&begin_)[Size]) ETL_NOEXCEPT
: iconst_multimap<TKey, TMapped, TKeyCompare>(begin_, Size, Size) : iconst_multimap<TKey, TMapped, TKeyCompare>(begin_, Size, Size)
{ {
} }
@ -538,15 +544,15 @@ namespace etl
const_multimap_ext(const etl::span<TElements, Size>&) -> const_multimap_ext<typename TElements::first_type, typename TElements::second_type>; const_multimap_ext(const etl::span<TElements, Size>&) -> const_multimap_ext<typename TElements::first_type, typename TElements::second_type>;
template <typename TElements, size_t Size> template <typename TElements, size_t Size>
const_multimap_ext(const TElements(&)[Size]) -> const_multimap_ext<typename TElements::first_type, typename TElements::second_type>; const_multimap_ext(const TElements (&)[Size]) -> const_multimap_ext<typename TElements::first_type, typename TElements::second_type>;
#endif #endif
//************************************************************************* //*************************************************************************
/// Equality test. /// Equality test.
//************************************************************************* //*************************************************************************
template <typename TKey, typename TMapped, typename TKeyCompare> template <typename TKey, typename TMapped, typename TKeyCompare>
ETL_CONSTEXPR14 bool operator ==(const etl::iconst_multimap<TKey, TMapped, TKeyCompare>& lhs, ETL_CONSTEXPR14 bool operator==(const etl::iconst_multimap<TKey, TMapped, TKeyCompare>& lhs,
const etl::iconst_multimap<TKey, TMapped, TKeyCompare>& rhs) ETL_NOEXCEPT const etl::iconst_multimap<TKey, TMapped, TKeyCompare>& rhs) ETL_NOEXCEPT
{ {
return etl::equal(lhs.begin(), lhs.end(), rhs.begin()); return etl::equal(lhs.begin(), lhs.end(), rhs.begin());
} }
@ -555,8 +561,8 @@ namespace etl
/// Inequality test. /// Inequality test.
//************************************************************************* //*************************************************************************
template <typename TKey, typename TMapped, typename TKeyCompare> template <typename TKey, typename TMapped, typename TKeyCompare>
ETL_CONSTEXPR14 bool operator !=(const etl::iconst_multimap<TKey, TMapped, TKeyCompare>& lhs, ETL_CONSTEXPR14 bool operator!=(const etl::iconst_multimap<TKey, TMapped, TKeyCompare>& lhs,
const etl::iconst_multimap<TKey, TMapped, TKeyCompare>& rhs) ETL_NOEXCEPT const etl::iconst_multimap<TKey, TMapped, TKeyCompare>& rhs) ETL_NOEXCEPT
{ {
return !(lhs == rhs); return !(lhs == rhs);
} }
@ -569,12 +575,10 @@ namespace etl
/// second, otherwise <b>false</b>. /// second, otherwise <b>false</b>.
//************************************************************************* //*************************************************************************
template <typename TKey, typename TMapped, typename TKeyCompare> template <typename TKey, typename TMapped, typename TKeyCompare>
ETL_CONSTEXPR14 bool operator <(const etl::iconst_multimap<TKey, TMapped, TKeyCompare>& lhs, ETL_CONSTEXPR14 bool operator<(const etl::iconst_multimap<TKey, TMapped, TKeyCompare>& lhs,
const etl::iconst_multimap<TKey, TMapped, TKeyCompare>& rhs) ETL_NOEXCEPT const etl::iconst_multimap<TKey, TMapped, TKeyCompare>& rhs) ETL_NOEXCEPT
{ {
return etl::lexicographical_compare(lhs.begin(), lhs.end(), return etl::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end(), lhs.value_comp());
rhs.begin(), rhs.end(),
lhs.value_comp());
} }
//************************************************************************* //*************************************************************************
@ -585,8 +589,8 @@ namespace etl
/// second, otherwise <b>false</b>. /// second, otherwise <b>false</b>.
//************************************************************************* //*************************************************************************
template <typename TKey, typename TMapped, typename TKeyCompare> template <typename TKey, typename TMapped, typename TKeyCompare>
ETL_CONSTEXPR14 bool operator >(const etl::iconst_multimap<TKey, TMapped, TKeyCompare>& lhs, ETL_CONSTEXPR14 bool operator>(const etl::iconst_multimap<TKey, TMapped, TKeyCompare>& lhs,
const etl::iconst_multimap<TKey, TMapped, TKeyCompare>& rhs) ETL_NOEXCEPT const etl::iconst_multimap<TKey, TMapped, TKeyCompare>& rhs) ETL_NOEXCEPT
{ {
return (rhs < lhs); return (rhs < lhs);
} }
@ -595,12 +599,13 @@ namespace etl
/// Less than or equal operator. /// Less than or equal operator.
///\param lhs Reference to the first list. ///\param lhs Reference to the first list.
///\param rhs Reference to the second list. ///\param rhs Reference to the second list.
///\return <b>true</b> if the first list is lexicographically less than or equal ///\return <b>true</b> if the first list is lexicographically less than or
/// equal
/// to the second, otherwise <b>false</b>. /// to the second, otherwise <b>false</b>.
//************************************************************************* //*************************************************************************
template <typename TKey, typename TMapped, typename TKeyCompare> template <typename TKey, typename TMapped, typename TKeyCompare>
ETL_CONSTEXPR14 bool operator <=(const etl::iconst_multimap<TKey, TMapped, TKeyCompare>& lhs, ETL_CONSTEXPR14 bool operator<=(const etl::iconst_multimap<TKey, TMapped, TKeyCompare>& lhs,
const etl::iconst_multimap<TKey, TMapped, TKeyCompare>& rhs) ETL_NOEXCEPT const etl::iconst_multimap<TKey, TMapped, TKeyCompare>& rhs) ETL_NOEXCEPT
{ {
return !(rhs < lhs); return !(rhs < lhs);
} }
@ -613,11 +618,11 @@ namespace etl
/// equal to the second, otherwise <b>false</b>. /// equal to the second, otherwise <b>false</b>.
//************************************************************************* //*************************************************************************
template <typename TKey, typename TMapped, typename TKeyCompare> template <typename TKey, typename TMapped, typename TKeyCompare>
ETL_CONSTEXPR14 bool operator >=(const etl::iconst_multimap<TKey, TMapped, TKeyCompare>& lhs, ETL_CONSTEXPR14 bool operator>=(const etl::iconst_multimap<TKey, TMapped, TKeyCompare>& lhs,
const etl::iconst_multimap<TKey, TMapped, TKeyCompare>& rhs) ETL_NOEXCEPT const etl::iconst_multimap<TKey, TMapped, TKeyCompare>& rhs) ETL_NOEXCEPT
{ {
return !(lhs < rhs); return !(lhs < rhs);
} }
} } // namespace etl
#endif #endif

View File

@ -31,17 +31,17 @@ SOFTWARE.
#ifndef ETL_CONST_MULTISET_INCLUDED #ifndef ETL_CONST_MULTISET_INCLUDED
#define ETL_CONST_MULTISET_INCLUDED #define ETL_CONST_MULTISET_INCLUDED
#include "platform.h" #include "platform.h"
#if ETL_NOT_USING_CPP11 #if ETL_NOT_USING_CPP11
#error NOT SUPPORTED FOR C++03 OR BELOW #error NOT SUPPORTED FOR C++03 OR BELOW
#endif #endif
#include "algorithm.h" #include "algorithm.h"
#include "type_traits.h"
#include "functional.h" #include "functional.h"
#include "nth_type.h" #include "nth_type.h"
#include "span.h" #include "span.h"
#include "type_traits.h"
#include "private/comparator_is_transparent.h" #include "private/comparator_is_transparent.h"
@ -190,7 +190,7 @@ namespace etl
return size_type(etl::distance(range.first, range.second)); return size_type(etl::distance(range.first, range.second));
} }
//************************************************************************* //*************************************************************************
///\brief Counts the numbeer elements with key. ///\brief Counts the numbeer elements with key.
/// Enabled if the comparator is transparent. /// Enabled if the comparator is transparent.
@ -206,9 +206,9 @@ namespace etl
} }
//************************************************************************* //*************************************************************************
///\brief Returns a range containing all elements with the key. ///\brief Returns a range containing all elements with the key.
/// The range is defined by a pair of two iterators, one to the /// The range is defined by a pair of two iterators, one to the
/// first element that is not less than the key and second to the first /// first element that is not less than the key and second to the first
/// element greater than the key. /// element greater than the key.
///\param key The key of the element ///\param key The key of the element
///\return etl::pair or std::pair containing a pair of iterators. ///\return etl::pair or std::pair containing a pair of iterators.
@ -219,9 +219,9 @@ namespace etl
} }
//************************************************************************* //*************************************************************************
///\brief Returns a range containing all elements with the key. ///\brief Returns a range containing all elements with the key.
/// The range is defined by a pair of two iterators, one to the /// The range is defined by a pair of two iterators, one to the
/// first element that is not less than the key and second to the first /// first element that is not less than the key and second to the first
/// element greater than the key. /// element greater than the key.
/// Enabled if the comparator is transparent. /// Enabled if the comparator is transparent.
///\param key The key of the element ///\param key The key of the element
@ -234,8 +234,10 @@ namespace etl
} }
//************************************************************************* //*************************************************************************
///\brief Returns a const_iterator to the first element that is not less than the key. ///\brief Returns a const_iterator to the first element that is not less
/// Returns a const_iterator to the first element that is not less than the key. /// than the key.
/// Returns a const_iterator to the first element that is not less than the
/// key.
///\param key The key of the element ///\param key The key of the element
///\return const_iterator to the element or end() ///\return const_iterator to the element or end()
//************************************************************************* //*************************************************************************
@ -245,9 +247,10 @@ namespace etl
} }
//************************************************************************* //*************************************************************************
///\brief Returns a const_iterator to the first element that is not less than the key. ///\brief Returns a const_iterator to the first element that is not less
/// Returns a const_iterator to the first element that is not less than the key. /// than the key.
/// Enabled if the comparator is transparent. /// Returns a const_iterator to the first element that is not less than the
/// key. Enabled if the comparator is transparent.
///\param key The key of the element ///\param key The key of the element
///\return const_iterator to the element or end() ///\return const_iterator to the element or end()
//************************************************************************* //*************************************************************************
@ -258,8 +261,10 @@ namespace etl
} }
//************************************************************************* //*************************************************************************
///\brief Returns a const_iterator to the first element that is greater than the key. ///\brief Returns a const_iterator to the first element that is greater than
/// Returns a const_iterator to the first element that is greater than the key. /// the key.
/// Returns a const_iterator to the first element that is greater than the
/// key.
///\param key The key of the element ///\param key The key of the element
///\return const_iterator to the element or end() ///\return const_iterator to the element or end()
//************************************************************************* //*************************************************************************
@ -269,9 +274,10 @@ namespace etl
} }
//************************************************************************* //*************************************************************************
///\brief Returns a const_iterator to the first element that is greater than the key. ///\brief Returns a const_iterator to the first element that is greater than
/// Returns a const_iterator to the first element that is greater than the key. /// the key.
/// Enabled if the comparator is transparent. /// Returns a const_iterator to the first element that is greater than the
/// key. Enabled if the comparator is transparent.
///\param key The key of the element ///\param key The key of the element
///\return const_iterator to the element or end() ///\return const_iterator to the element or end()
//************************************************************************* //*************************************************************************
@ -383,7 +389,7 @@ namespace etl
const value_type* element_list; const value_type* element_list;
const value_type* element_list_end; const value_type* element_list_end;
size_type max_elements; size_type max_elements;
}; };
//************************************************************************* //*************************************************************************
@ -410,7 +416,8 @@ namespace etl
///\brief Construct a const_set from a variadic list of elements. ///\brief Construct a const_set from a variadic list of elements.
/// Static asserts if the element type is not constructible. /// Static asserts if the element type is not constructible.
/// Static asserts if the elements are not of type <code>value_type</code>. /// Static asserts if the elements are not of type <code>value_type</code>.
/// Static asserts if the number of elements is greater than the capacity of the const_set. /// Static asserts if the number of elements is greater than the capacity of
/// the const_set.
//************************************************************************* //*************************************************************************
template <typename... TElements> template <typename... TElements>
ETL_CONSTEXPR14 explicit const_multiset(TElements&&... elements) ETL_NOEXCEPT ETL_CONSTEXPR14 explicit const_multiset(TElements&&... elements) ETL_NOEXCEPT
@ -418,7 +425,7 @@ namespace etl
, element_list{etl::forward<TElements>(elements)...} , element_list{etl::forward<TElements>(elements)...}
{ {
static_assert((etl::are_all_same<value_type, etl::decay_t<TElements>...>::value), "All elements must be value_type"); static_assert((etl::are_all_same<value_type, etl::decay_t<TElements>...>::value), "All elements must be value_type");
static_assert(sizeof...(elements) <= Size, "Number of elements exceeds capacity"); static_assert(sizeof...(elements) <= Size, "Number of elements exceeds capacity");
} }
private: private:
@ -475,7 +482,7 @@ namespace etl
///\brief Construct a const_multiset from an array. ///\brief Construct a const_multiset from an array.
//************************************************************************* //*************************************************************************
template <size_type Size> template <size_type Size>
ETL_CONSTEXPR14 explicit const_multiset_ext(const value_type(&begin_)[Size]) ETL_NOEXCEPT ETL_CONSTEXPR14 explicit const_multiset_ext(const value_type (&begin_)[Size]) ETL_NOEXCEPT
: iconst_multiset<TKey, TKeyCompare>(begin_, Size, Size) : iconst_multiset<TKey, TKeyCompare>(begin_, Size, Size)
{ {
} }
@ -489,15 +496,14 @@ namespace etl
const_multiset_ext(const etl::span<TElements, Size>&) -> const_multiset_ext<TElements>; const_multiset_ext(const etl::span<TElements, Size>&) -> const_multiset_ext<TElements>;
template <typename TElements, size_t Size> template <typename TElements, size_t Size>
const_multiset_ext(const TElements(&)[Size]) -> const_multiset_ext<TElements>; const_multiset_ext(const TElements (&)[Size]) -> const_multiset_ext<TElements>;
#endif #endif
//************************************************************************* //*************************************************************************
/// Equality test. /// Equality test.
//************************************************************************* //*************************************************************************
template <typename TKey, typename TKeyCompare> template <typename TKey, typename TKeyCompare>
ETL_CONSTEXPR14 bool operator ==(const etl::iconst_multiset<TKey, TKeyCompare>& lhs, ETL_CONSTEXPR14 bool operator==(const etl::iconst_multiset<TKey, TKeyCompare>& lhs, const etl::iconst_multiset<TKey, TKeyCompare>& rhs) ETL_NOEXCEPT
const etl::iconst_multiset<TKey, TKeyCompare>& rhs) ETL_NOEXCEPT
{ {
return (lhs.size() == rhs.size()) && etl::equal(lhs.begin(), lhs.end(), rhs.begin()); return (lhs.size() == rhs.size()) && etl::equal(lhs.begin(), lhs.end(), rhs.begin());
} }
@ -506,8 +512,7 @@ namespace etl
/// Inequality test. /// Inequality test.
//************************************************************************* //*************************************************************************
template <typename TKey, typename TKeyCompare> template <typename TKey, typename TKeyCompare>
ETL_CONSTEXPR14 bool operator !=(const etl::iconst_multiset<TKey, TKeyCompare>& lhs, ETL_CONSTEXPR14 bool operator!=(const etl::iconst_multiset<TKey, TKeyCompare>& lhs, const etl::iconst_multiset<TKey, TKeyCompare>& rhs) ETL_NOEXCEPT
const etl::iconst_multiset<TKey, TKeyCompare>& rhs) ETL_NOEXCEPT
{ {
return !(lhs == rhs); return !(lhs == rhs);
} }
@ -520,12 +525,9 @@ namespace etl
/// second, otherwise <b>false</b>. /// second, otherwise <b>false</b>.
//************************************************************************* //*************************************************************************
template <typename TKey, typename TKeyCompare> template <typename TKey, typename TKeyCompare>
ETL_CONSTEXPR14 bool operator <(const etl::iconst_multiset<TKey, TKeyCompare>& lhs, ETL_CONSTEXPR14 bool operator<(const etl::iconst_multiset<TKey, TKeyCompare>& lhs, const etl::iconst_multiset<TKey, TKeyCompare>& rhs) ETL_NOEXCEPT
const etl::iconst_multiset<TKey, TKeyCompare>& rhs) ETL_NOEXCEPT
{ {
return etl::lexicographical_compare(lhs.begin(), lhs.end(), return etl::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end(), lhs.value_comp());
rhs.begin(), rhs.end(),
lhs.value_comp());
} }
//************************************************************************* //*************************************************************************
@ -536,8 +538,7 @@ namespace etl
/// second, otherwise <b>false</b>. /// second, otherwise <b>false</b>.
//************************************************************************* //*************************************************************************
template <typename TKey, typename TKeyCompare> template <typename TKey, typename TKeyCompare>
ETL_CONSTEXPR14 bool operator >(const etl::iconst_multiset<TKey, TKeyCompare>& lhs, ETL_CONSTEXPR14 bool operator>(const etl::iconst_multiset<TKey, TKeyCompare>& lhs, const etl::iconst_multiset<TKey, TKeyCompare>& rhs) ETL_NOEXCEPT
const etl::iconst_multiset<TKey, TKeyCompare>& rhs) ETL_NOEXCEPT
{ {
return (rhs < lhs); return (rhs < lhs);
} }
@ -546,12 +547,12 @@ namespace etl
/// Less than or equal operator. /// Less than or equal operator.
///\param lhs Reference to the first list. ///\param lhs Reference to the first list.
///\param rhs Reference to the second list. ///\param rhs Reference to the second list.
///\return <b>true</b> if the first list is lexicographically less than or equal ///\return <b>true</b> if the first list is lexicographically less than or
/// equal
/// to the second, otherwise <b>false</b>. /// to the second, otherwise <b>false</b>.
//************************************************************************* //*************************************************************************
template <typename TKey, typename TKeyCompare> template <typename TKey, typename TKeyCompare>
ETL_CONSTEXPR14 bool operator <=(const etl::iconst_multiset<TKey, TKeyCompare>& lhs, ETL_CONSTEXPR14 bool operator<=(const etl::iconst_multiset<TKey, TKeyCompare>& lhs, const etl::iconst_multiset<TKey, TKeyCompare>& rhs) ETL_NOEXCEPT
const etl::iconst_multiset<TKey, TKeyCompare>& rhs) ETL_NOEXCEPT
{ {
return !(rhs < lhs); return !(rhs < lhs);
} }
@ -564,11 +565,10 @@ namespace etl
/// equal to the second, otherwise <b>false</b>. /// equal to the second, otherwise <b>false</b>.
//************************************************************************* //*************************************************************************
template <typename TKey, typename TKeyCompare> template <typename TKey, typename TKeyCompare>
ETL_CONSTEXPR14 bool operator >=(const etl::iconst_multiset<TKey, TKeyCompare>& lhs, ETL_CONSTEXPR14 bool operator>=(const etl::iconst_multiset<TKey, TKeyCompare>& lhs, const etl::iconst_multiset<TKey, TKeyCompare>& rhs) ETL_NOEXCEPT
const etl::iconst_multiset<TKey, TKeyCompare>& rhs) ETL_NOEXCEPT
{ {
return !(lhs < rhs); return !(lhs < rhs);
} }
} } // namespace etl
#endif #endif

View File

@ -38,10 +38,10 @@ SOFTWARE.
#endif #endif
#include "algorithm.h" #include "algorithm.h"
#include "type_traits.h"
#include "functional.h" #include "functional.h"
#include "nth_type.h" #include "nth_type.h"
#include "span.h" #include "span.h"
#include "type_traits.h"
#include "private/comparator_is_transparent.h" #include "private/comparator_is_transparent.h"
@ -183,7 +183,7 @@ namespace etl
{ {
return contains(key) ? 1 : 0; return contains(key) ? 1 : 0;
} }
//************************************************************************* //*************************************************************************
///\brief Counts the numbeer elements with key. ///\brief Counts the numbeer elements with key.
/// Enabled if the comparator is transparent. /// Enabled if the comparator is transparent.
@ -197,9 +197,9 @@ namespace etl
} }
//************************************************************************* //*************************************************************************
///\brief Returns a range containing all elements with the key. ///\brief Returns a range containing all elements with the key.
/// The range is defined by a pair of two iterators, one to the /// The range is defined by a pair of two iterators, one to the
/// first element that is not less than the key and second to the first /// first element that is not less than the key and second to the first
/// element greater than the key. /// element greater than the key.
///\param key The key of the element ///\param key The key of the element
///\return etl::pair or std::pair containing a pair of iterators. ///\return etl::pair or std::pair containing a pair of iterators.
@ -210,9 +210,9 @@ namespace etl
} }
//************************************************************************* //*************************************************************************
///\brief Returns a range containing all elements with the key. ///\brief Returns a range containing all elements with the key.
/// The range is defined by a pair of two iterators, one to the /// The range is defined by a pair of two iterators, one to the
/// first element that is not less than the key and second to the first /// first element that is not less than the key and second to the first
/// element greater than the key. /// element greater than the key.
/// Enabled if the comparator is transparent. /// Enabled if the comparator is transparent.
///\param key The key of the element ///\param key The key of the element
@ -225,8 +225,10 @@ namespace etl
} }
//************************************************************************* //*************************************************************************
///\brief Returns a const_iterator to the first element that is not less than the key. ///\brief Returns a const_iterator to the first element that is not less
/// Returns a const_iterator to the first element that is not less than the key. /// than the key.
/// Returns a const_iterator to the first element that is not less than the
/// key.
///\param key The key of the element ///\param key The key of the element
///\return const_iterator to the element or end() ///\return const_iterator to the element or end()
//************************************************************************* //*************************************************************************
@ -236,9 +238,10 @@ namespace etl
} }
//************************************************************************* //*************************************************************************
///\brief Returns a const_iterator to the first element that is not less than the key. ///\brief Returns a const_iterator to the first element that is not less
/// Returns a const_iterator to the first element that is not less than the key. /// than the key.
/// Enabled if the comparator is transparent. /// Returns a const_iterator to the first element that is not less than the
/// key. Enabled if the comparator is transparent.
///\param key The key of the element ///\param key The key of the element
///\return const_iterator to the element or end() ///\return const_iterator to the element or end()
//************************************************************************* //*************************************************************************
@ -249,8 +252,10 @@ namespace etl
} }
//************************************************************************* //*************************************************************************
///\brief Returns a const_iterator to the first element that is greater than the key. ///\brief Returns a const_iterator to the first element that is greater than
/// Returns a const_iterator to the first element that is greater than the key. /// the key.
/// Returns a const_iterator to the first element that is greater than the
/// key.
///\param key The key of the element ///\param key The key of the element
///\return const_iterator to the element or end() ///\return const_iterator to the element or end()
//************************************************************************* //*************************************************************************
@ -260,9 +265,10 @@ namespace etl
} }
//************************************************************************* //*************************************************************************
///\brief Returns a const_iterator to the first element that is greater than the key. ///\brief Returns a const_iterator to the first element that is greater than
/// Returns a const_iterator to the first element that is greater than the key. /// the key.
/// Enabled if the comparator is transparent. /// Returns a const_iterator to the first element that is greater than the
/// key. Enabled if the comparator is transparent.
///\param key The key of the element ///\param key The key of the element
///\return const_iterator to the element or end() ///\return const_iterator to the element or end()
//************************************************************************* //*************************************************************************
@ -403,7 +409,8 @@ namespace etl
//************************************************************************* //*************************************************************************
///\brief Construct a const_set from a variadic list of elements. ///\brief Construct a const_set from a variadic list of elements.
/// Static asserts if the elements are not of type <code>value_type</code>. /// Static asserts if the elements are not of type <code>value_type</code>.
/// Static asserts if the number of elements is greater than the capacity of the const_set. /// Static asserts if the number of elements is greater than the capacity of
/// the const_set.
//************************************************************************* //*************************************************************************
template <typename... TElements> template <typename... TElements>
ETL_CONSTEXPR14 explicit const_set(TElements&&... elements) ETL_NOEXCEPT ETL_CONSTEXPR14 explicit const_set(TElements&&... elements) ETL_NOEXCEPT
@ -411,7 +418,7 @@ namespace etl
, element_list{etl::forward<TElements>(elements)...} , element_list{etl::forward<TElements>(elements)...}
{ {
static_assert((etl::are_all_same<value_type, etl::decay_t<TElements>...>::value), "All elements must be key_type"); static_assert((etl::are_all_same<value_type, etl::decay_t<TElements>...>::value), "All elements must be key_type");
static_assert(sizeof...(elements) <= Size, "Number of elements exceeds capacity"); static_assert(sizeof...(elements) <= Size, "Number of elements exceeds capacity");
} }
private: private:
@ -468,7 +475,7 @@ namespace etl
///\brief Construct a const_set from an array. ///\brief Construct a const_set from an array.
//************************************************************************* //*************************************************************************
template <size_type Size> template <size_type Size>
ETL_CONSTEXPR14 explicit const_set_ext(const value_type(&begin_)[Size]) ETL_NOEXCEPT ETL_CONSTEXPR14 explicit const_set_ext(const value_type (&begin_)[Size]) ETL_NOEXCEPT
: iconst_set<TKey, TKeyCompare>(begin_, Size, Size) : iconst_set<TKey, TKeyCompare>(begin_, Size, Size)
{ {
} }
@ -482,15 +489,14 @@ namespace etl
const_set_ext(const etl::span<TElements, Size>&) -> const_set_ext<TElements>; const_set_ext(const etl::span<TElements, Size>&) -> const_set_ext<TElements>;
template <typename TElements, size_t Size> template <typename TElements, size_t Size>
const_set_ext(const TElements(&)[Size]) -> const_set_ext<TElements>; const_set_ext(const TElements (&)[Size]) -> const_set_ext<TElements>;
#endif #endif
//************************************************************************* //*************************************************************************
/// Equality test. /// Equality test.
//************************************************************************* //*************************************************************************
template <typename TKey, typename TKeyCompare> template <typename TKey, typename TKeyCompare>
ETL_CONSTEXPR14 bool operator ==(const etl::iconst_set<TKey, TKeyCompare>& lhs, ETL_CONSTEXPR14 bool operator==(const etl::iconst_set<TKey, TKeyCompare>& lhs, const etl::iconst_set<TKey, TKeyCompare>& rhs) ETL_NOEXCEPT
const etl::iconst_set<TKey, TKeyCompare>& rhs) ETL_NOEXCEPT
{ {
return (lhs.size() == rhs.size()) && etl::equal(lhs.begin(), lhs.end(), rhs.begin()); return (lhs.size() == rhs.size()) && etl::equal(lhs.begin(), lhs.end(), rhs.begin());
} }
@ -499,8 +505,7 @@ namespace etl
/// Inequality test. /// Inequality test.
//************************************************************************* //*************************************************************************
template <typename TKey, typename TKeyCompare> template <typename TKey, typename TKeyCompare>
ETL_CONSTEXPR14 bool operator !=(const etl::iconst_set<TKey, TKeyCompare>& lhs, ETL_CONSTEXPR14 bool operator!=(const etl::iconst_set<TKey, TKeyCompare>& lhs, const etl::iconst_set<TKey, TKeyCompare>& rhs) ETL_NOEXCEPT
const etl::iconst_set<TKey, TKeyCompare>& rhs) ETL_NOEXCEPT
{ {
return !(lhs == rhs); return !(lhs == rhs);
} }
@ -509,20 +514,16 @@ namespace etl
/// Less-than. /// Less-than.
//************************************************************************* //*************************************************************************
template <typename TKey, typename TKeyCompare> template <typename TKey, typename TKeyCompare>
ETL_CONSTEXPR14 bool operator <(const etl::iconst_set<TKey, TKeyCompare>& lhs, ETL_CONSTEXPR14 bool operator<(const etl::iconst_set<TKey, TKeyCompare>& lhs, const etl::iconst_set<TKey, TKeyCompare>& rhs) ETL_NOEXCEPT
const etl::iconst_set<TKey, TKeyCompare>& rhs) ETL_NOEXCEPT
{ {
return etl::lexicographical_compare(lhs.begin(), lhs.end(), return etl::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end(), lhs.value_comp());
rhs.begin(), rhs.end(),
lhs.value_comp());
} }
//************************************************************************* //*************************************************************************
/// Greater-than. /// Greater-than.
//************************************************************************* //*************************************************************************
template <typename TKey, typename TKeyCompare> template <typename TKey, typename TKeyCompare>
ETL_CONSTEXPR14 bool operator >(const etl::iconst_set<TKey, TKeyCompare>& lhs, ETL_CONSTEXPR14 bool operator>(const etl::iconst_set<TKey, TKeyCompare>& lhs, const etl::iconst_set<TKey, TKeyCompare>& rhs) ETL_NOEXCEPT
const etl::iconst_set<TKey, TKeyCompare>& rhs) ETL_NOEXCEPT
{ {
return (rhs < lhs); return (rhs < lhs);
} }
@ -531,8 +532,7 @@ namespace etl
/// Less-than-equal. /// Less-than-equal.
//************************************************************************* //*************************************************************************
template <typename TKey, typename TKeyCompare> template <typename TKey, typename TKeyCompare>
ETL_CONSTEXPR14 bool operator <=(const etl::iconst_set<TKey, TKeyCompare>& lhs, ETL_CONSTEXPR14 bool operator<=(const etl::iconst_set<TKey, TKeyCompare>& lhs, const etl::iconst_set<TKey, TKeyCompare>& rhs) ETL_NOEXCEPT
const etl::iconst_set<TKey, TKeyCompare>& rhs) ETL_NOEXCEPT
{ {
return !(rhs < lhs); return !(rhs < lhs);
} }
@ -541,11 +541,10 @@ namespace etl
/// Greater-than-equal. /// Greater-than-equal.
//************************************************************************* //*************************************************************************
template <typename TKey, typename TKeyCompare> template <typename TKey, typename TKeyCompare>
ETL_CONSTEXPR14 bool operator >=(const etl::iconst_set<TKey, TKeyCompare>& lhs, ETL_CONSTEXPR14 bool operator>=(const etl::iconst_set<TKey, TKeyCompare>& lhs, const etl::iconst_set<TKey, TKeyCompare>& rhs) ETL_NOEXCEPT
const etl::iconst_set<TKey, TKeyCompare>& rhs) ETL_NOEXCEPT
{ {
return !(lhs < rhs); return !(lhs < rhs);
} }
} } // namespace etl
#endif #endif

View File

@ -52,6 +52,6 @@ namespace etl
template <typename T, const T VALUE> template <typename T, const T VALUE>
const T constant<T, VALUE>::value; const T constant<T, VALUE>::value;
} } // namespace etl
#endif #endif

View File

@ -37,4 +37,3 @@ SOFTWARE.
#include <stddef.h> #include <stddef.h>
#endif #endif

View File

@ -68,26 +68,26 @@ namespace etl
{ {
typedef double calc_t; typedef double calc_t;
}; };
} } // namespace private_correlation
//*************************************************************************** //***************************************************************************
/// Correlation Type. /// Correlation Type.
//*************************************************************************** //***************************************************************************
namespace private_correlation namespace private_correlation
{ {
template<typename T = void> template <typename T = void>
struct correlation_type_statics struct correlation_type_statics
{ {
static ETL_CONSTANT bool Sample = false; static ETL_CONSTANT bool Sample = false;
static ETL_CONSTANT bool Population = true; static ETL_CONSTANT bool Population = true;
}; };
template<typename T> template <typename T>
ETL_CONSTANT bool correlation_type_statics<T>::Sample; ETL_CONSTANT bool correlation_type_statics<T>::Sample;
template<typename T> template <typename T>
ETL_CONSTANT bool correlation_type_statics<T>::Population; ETL_CONSTANT bool correlation_type_statics<T>::Population;
} } // namespace private_correlation
struct correlation_type : public private_correlation::correlation_type_statics<> struct correlation_type : public private_correlation::correlation_type_statics<>
{ {
@ -97,7 +97,7 @@ namespace etl
/// Correlation. /// Correlation.
//*************************************************************************** //***************************************************************************
template <bool Correlation_Type, typename TInput, typename TCalc = TInput> template <bool Correlation_Type, typename TInput, typename TCalc = TInput>
class correlation class correlation
: public private_correlation::correlation_traits<TInput, TCalc> : public private_correlation::correlation_traits<TInput, TCalc>
, public etl::binary_function<TInput, TInput, void> , public etl::binary_function<TInput, TInput, void>
{ {
@ -132,11 +132,11 @@ namespace etl
//********************************* //*********************************
void add(TInput value1, TInput value2) void add(TInput value1, TInput value2)
{ {
inner_product += TCalc(value1 * value2); inner_product += TCalc(value1 * value2);
sum_of_squares1 += TCalc(value1 * value1); sum_of_squares1 += TCalc(value1 * value1);
sum_of_squares2 += TCalc(value2 * value2); sum_of_squares2 += TCalc(value2 * value2);
sum1 += TCalc(value1); sum1 += TCalc(value1);
sum2 += TCalc(value2); sum2 += TCalc(value2);
++counter; ++counter;
recalculate = true; recalculate = true;
} }
@ -159,7 +159,7 @@ namespace etl
/// operator () /// operator ()
/// Add a pair of values. /// Add a pair of values.
//********************************* //*********************************
void operator ()(TInput value1, TInput value2) void operator()(TInput value1, TInput value2)
{ {
add(value1, value2); add(value1, value2);
} }
@ -169,7 +169,7 @@ namespace etl
/// Add a range. /// Add a range.
//********************************* //*********************************
template <typename TIterator> template <typename TIterator>
void operator ()(TIterator first1, TIterator last1, TIterator first2) void operator()(TIterator first1, TIterator last1, TIterator first2)
{ {
add(first1, last1, first2); add(first1, last1, first2);
} }
@ -227,7 +227,7 @@ namespace etl
} }
private: private:
//********************************* //*********************************
/// Do the calculation. /// Do the calculation.
//********************************* //*********************************
@ -240,7 +240,7 @@ namespace etl
if (counter != 0) if (counter != 0)
{ {
double n = double(counter); double n = double(counter);
double adjustment = 1.0 / (n * (n - Adjustment)); double adjustment = 1.0 / (n * (n - Adjustment));
double square_of_sum1 = (sum1 * sum1); double square_of_sum1 = (sum1 * sum1);
@ -265,7 +265,7 @@ namespace etl
covariance_value = ((n * inner_product) - (sum1 * sum2)) * adjustment; covariance_value = ((n * inner_product) - (sum1 * sum2)) * adjustment;
if ((stddev1 > 0.0) && (stddev2 > 0.0)) if ((stddev1 > 0.0) && (stddev2 > 0.0))
{ {
correlation_value = covariance_value / (stddev1 * stddev2); correlation_value = covariance_value / (stddev1 * stddev2);
} }
} }
@ -274,12 +274,12 @@ namespace etl
} }
} }
calc_t inner_product; calc_t inner_product;
calc_t sum_of_squares1; calc_t sum_of_squares1;
calc_t sum_of_squares2; calc_t sum_of_squares2;
calc_t sum1; calc_t sum1;
calc_t sum2; calc_t sum2;
uint32_t counter; uint32_t counter;
mutable double covariance_value; mutable double covariance_value;
mutable double correlation_value; mutable double correlation_value;
mutable bool recalculate; mutable bool recalculate;
@ -287,6 +287,6 @@ namespace etl
template <bool Correlation_Type, typename TInput, typename TCalc> template <bool Correlation_Type, typename TInput, typename TCalc>
ETL_CONSTANT int correlation<Correlation_Type, TInput, TCalc>::Adjustment; ETL_CONSTANT int correlation<Correlation_Type, TInput, TCalc>::Adjustment;
} } // namespace etl
#endif #endif

View File

@ -67,26 +67,26 @@ namespace etl
{ {
typedef double calc_t; typedef double calc_t;
}; };
} } // namespace private_covariance
//*************************************************************************** //***************************************************************************
/// Covariance Type. /// Covariance Type.
//*************************************************************************** //***************************************************************************
namespace private_covariance namespace private_covariance
{ {
template<typename T = void> template <typename T = void>
struct covariance_type_statics struct covariance_type_statics
{ {
static ETL_CONSTANT bool Sample = false; static ETL_CONSTANT bool Sample = false;
static ETL_CONSTANT bool Population = true; static ETL_CONSTANT bool Population = true;
}; };
template<typename T> template <typename T>
ETL_CONSTANT bool covariance_type_statics<T>::Sample; ETL_CONSTANT bool covariance_type_statics<T>::Sample;
template<typename T> template <typename T>
ETL_CONSTANT bool covariance_type_statics<T>::Population; ETL_CONSTANT bool covariance_type_statics<T>::Population;
} } // namespace private_covariance
struct covariance_type : public private_covariance::covariance_type_statics<> struct covariance_type : public private_covariance::covariance_type_statics<>
{ {
@ -96,7 +96,7 @@ namespace etl
/// Covariance. /// Covariance.
//*************************************************************************** //***************************************************************************
template <bool Covariance_Type, typename TInput, typename TCalc = TInput> template <bool Covariance_Type, typename TInput, typename TCalc = TInput>
class covariance class covariance
: public private_covariance::covariance_traits<TInput, TCalc> : public private_covariance::covariance_traits<TInput, TCalc>
, public etl::binary_function<TInput, TInput, void> , public etl::binary_function<TInput, TInput, void>
{ {
@ -132,8 +132,8 @@ namespace etl
void add(TInput value1, TInput value2) void add(TInput value1, TInput value2)
{ {
inner_product += TCalc(value1 * value2); inner_product += TCalc(value1 * value2);
sum1 += TCalc(value1); sum1 += TCalc(value1);
sum2 += TCalc(value2); sum2 += TCalc(value2);
++counter; ++counter;
recalculate = true; recalculate = true;
} }
@ -156,7 +156,7 @@ namespace etl
/// operator () /// operator ()
/// Add a pair of values. /// Add a pair of values.
//********************************* //*********************************
void operator ()(TInput value1, TInput value2) void operator()(TInput value1, TInput value2)
{ {
add(value1, value2); add(value1, value2);
} }
@ -166,7 +166,7 @@ namespace etl
/// Add a range. /// Add a range.
//********************************* //*********************************
template <typename TIterator> template <typename TIterator>
void operator ()(TIterator first1, TIterator last1, TIterator first2) void operator()(TIterator first1, TIterator last1, TIterator first2)
{ {
add(first1, last1, first2); add(first1, last1, first2);
} }
@ -182,7 +182,7 @@ namespace etl
if (counter != 0) if (counter != 0)
{ {
double n = double(counter); double n = double(counter);
double adjustment = 1.0 / (n * (n - Adjustment)); double adjustment = 1.0 / (n * (n - Adjustment));
covariance_value = ((n * inner_product) - (sum1 * sum2)) * adjustment; covariance_value = ((n * inner_product) - (sum1 * sum2)) * adjustment;
@ -224,17 +224,17 @@ namespace etl
} }
private: private:
calc_t inner_product; calc_t inner_product;
calc_t sum1; calc_t sum1;
calc_t sum2; calc_t sum2;
uint32_t counter; uint32_t counter;
mutable double covariance_value; mutable double covariance_value;
mutable bool recalculate; mutable bool recalculate;
}; };
template <bool Covariance_Type, typename TInput, typename TCalc> template <bool Covariance_Type, typename TInput, typename TCalc>
ETL_CONSTANT int covariance<Covariance_Type, TInput, TCalc>::Adjustment; ETL_CONSTANT int covariance<Covariance_Type, TInput, TCalc>::Adjustment;
} } // namespace etl
#endif #endif

View File

@ -62,6 +62,7 @@ SOFTWARE.
#include "crc16_en13757.h" #include "crc16_en13757.h"
#include "crc16_genibus.h" #include "crc16_genibus.h"
#include "crc16_kermit.h" #include "crc16_kermit.h"
#include "crc16_m17.h"
#include "crc16_maxim.h" #include "crc16_maxim.h"
#include "crc16_mcrf4xx.h" #include "crc16_mcrf4xx.h"
#include "crc16_modbus.h" #include "crc16_modbus.h"
@ -75,7 +76,6 @@ SOFTWARE.
#include "crc16_usb.h" #include "crc16_usb.h"
#include "crc16_x25.h" #include "crc16_x25.h"
#include "crc16_xmodem.h" #include "crc16_xmodem.h"
#include "crc16_m17.h"
#include "crc32.h" #include "crc32.h"
#include "crc32_bzip2.h" #include "crc32_bzip2.h"

View File

@ -32,8 +32,8 @@ SOFTWARE.
#define ETL_CRC1_INCLUDED #define ETL_CRC1_INCLUDED
#include "platform.h" #include "platform.h"
#include "frame_check_sequence.h"
#include "binary.h" #include "binary.h"
#include "frame_check_sequence.h"
namespace etl namespace etl
{ {
@ -93,13 +93,13 @@ namespace etl
/// \param begin Start of the range. /// \param begin Start of the range.
/// \param end End of the range. /// \param end End of the range.
//************************************************************************* //*************************************************************************
template<typename TIterator> template <typename TIterator>
ETL_CONSTEXPR14 crc1(TIterator begin, const TIterator end) ETL_CONSTEXPR14 crc1(TIterator begin, const TIterator end)
{ {
this->reset(); this->reset();
this->add(begin, end); this->add(begin, end);
} }
}; };
} } // namespace etl
#endif #endif

View File

@ -61,7 +61,7 @@ namespace etl
/// \param begin Start of the range. /// \param begin Start of the range.
/// \param end End of the range. /// \param end End of the range.
//************************************************************************* //*************************************************************************
template<typename TIterator> template <typename TIterator>
crc16_t(TIterator begin, const TIterator end) crc16_t(TIterator begin, const TIterator end)
{ {
this->reset(); this->reset();
@ -74,5 +74,5 @@ namespace etl
typedef etl::crc16_t<16U> crc16_t16; typedef etl::crc16_t<16U> crc16_t16;
typedef etl::crc16_t<4U> crc16_t4; typedef etl::crc16_t<4U> crc16_t4;
typedef crc16_t256 crc16; typedef crc16_t256 crc16;
} } // namespace etl
#endif #endif

View File

@ -61,7 +61,7 @@ namespace etl
/// \param begin Start of the range. /// \param begin Start of the range.
/// \param end End of the range. /// \param end End of the range.
//************************************************************************* //*************************************************************************
template<typename TIterator> template <typename TIterator>
crc16_a_t(TIterator begin, const TIterator end) crc16_a_t(TIterator begin, const TIterator end)
{ {
this->reset(); this->reset();
@ -74,5 +74,5 @@ namespace etl
typedef etl::crc16_a_t<16U> crc16_a_t16; typedef etl::crc16_a_t<16U> crc16_a_t16;
typedef etl::crc16_a_t<4U> crc16_a_t4; typedef etl::crc16_a_t<4U> crc16_a_t4;
typedef crc16_a_t256 crc16_a; typedef crc16_a_t256 crc16_a;
} } // namespace etl
#endif #endif

View File

@ -61,7 +61,7 @@ namespace etl
/// \param begin Start of the range. /// \param begin Start of the range.
/// \param end End of the range. /// \param end End of the range.
//************************************************************************* //*************************************************************************
template<typename TIterator> template <typename TIterator>
crc16_arc_t(TIterator begin, const TIterator end) crc16_arc_t(TIterator begin, const TIterator end)
{ {
this->reset(); this->reset();
@ -74,5 +74,5 @@ namespace etl
typedef etl::crc16_arc_t<16U> crc16_arc_t16; typedef etl::crc16_arc_t<16U> crc16_arc_t16;
typedef etl::crc16_arc_t<4U> crc16_arc_t4; typedef etl::crc16_arc_t<4U> crc16_arc_t4;
typedef crc16_arc_t256 crc16_arc; typedef crc16_arc_t256 crc16_arc;
} } // namespace etl
#endif #endif

View File

@ -43,7 +43,7 @@ namespace etl
template <size_t Table_Size> template <size_t Table_Size>
using crc16_aug_ccitt_t = etl::crc_type<etl::private_crc::crc16_aug_ccitt_parameters, Table_Size>; using crc16_aug_ccitt_t = etl::crc_type<etl::private_crc::crc16_aug_ccitt_parameters, Table_Size>;
#else #else
template <size_t Table_Size> template <size_t Table_Size>
class crc16_aug_ccitt_t : public etl::crc_type<etl::private_crc::crc16_aug_ccitt_parameters, Table_Size> class crc16_aug_ccitt_t : public etl::crc_type<etl::private_crc::crc16_aug_ccitt_parameters, Table_Size>
{ {
public: public:
@ -61,7 +61,7 @@ namespace etl
/// \param begin Start of the range. /// \param begin Start of the range.
/// \param end End of the range. /// \param end End of the range.
//************************************************************************* //*************************************************************************
template<typename TIterator> template <typename TIterator>
crc16_aug_ccitt_t(TIterator begin, const TIterator end) crc16_aug_ccitt_t(TIterator begin, const TIterator end)
{ {
this->reset(); this->reset();
@ -74,5 +74,5 @@ namespace etl
typedef etl::crc16_aug_ccitt_t<16U> crc16_aug_ccitt_t16; typedef etl::crc16_aug_ccitt_t<16U> crc16_aug_ccitt_t16;
typedef etl::crc16_aug_ccitt_t<4U> crc16_aug_ccitt_t4; typedef etl::crc16_aug_ccitt_t<4U> crc16_aug_ccitt_t4;
typedef crc16_aug_ccitt_t256 crc16_aug_ccitt; typedef crc16_aug_ccitt_t256 crc16_aug_ccitt;
} } // namespace etl
#endif #endif

View File

@ -43,7 +43,7 @@ namespace etl
template <size_t Table_Size> template <size_t Table_Size>
using crc16_buypass_t = etl::crc_type<etl::private_crc::crc16_buypass_parameters, Table_Size>; using crc16_buypass_t = etl::crc_type<etl::private_crc::crc16_buypass_parameters, Table_Size>;
#else #else
template <size_t Table_Size> template <size_t Table_Size>
class crc16_buypass_t : public etl::crc_type<etl::private_crc::crc16_buypass_parameters, Table_Size> class crc16_buypass_t : public etl::crc_type<etl::private_crc::crc16_buypass_parameters, Table_Size>
{ {
public: public:
@ -61,7 +61,7 @@ namespace etl
/// \param begin Start of the range. /// \param begin Start of the range.
/// \param end End of the range. /// \param end End of the range.
//************************************************************************* //*************************************************************************
template<typename TIterator> template <typename TIterator>
crc16_buypass_t(TIterator begin, const TIterator end) crc16_buypass_t(TIterator begin, const TIterator end)
{ {
this->reset(); this->reset();
@ -74,5 +74,5 @@ namespace etl
typedef etl::crc16_buypass_t<16U> crc16_buypass_t16; typedef etl::crc16_buypass_t<16U> crc16_buypass_t16;
typedef etl::crc16_buypass_t<4U> crc16_buypass_t4; typedef etl::crc16_buypass_t<4U> crc16_buypass_t4;
typedef crc16_buypass_t256 crc16_buypass; typedef crc16_buypass_t256 crc16_buypass;
} } // namespace etl
#endif #endif

View File

@ -61,7 +61,7 @@ namespace etl
/// \param begin Start of the range. /// \param begin Start of the range.
/// \param end End of the range. /// \param end End of the range.
//************************************************************************* //*************************************************************************
template<typename TIterator> template <typename TIterator>
crc16_ccitt_t(TIterator begin, const TIterator end) crc16_ccitt_t(TIterator begin, const TIterator end)
{ {
this->reset(); this->reset();
@ -74,5 +74,5 @@ namespace etl
typedef etl::crc16_ccitt_t<16U> crc16_ccitt_t16; typedef etl::crc16_ccitt_t<16U> crc16_ccitt_t16;
typedef etl::crc16_ccitt_t<4U> crc16_ccitt_t4; typedef etl::crc16_ccitt_t<4U> crc16_ccitt_t4;
typedef crc16_ccitt_t256 crc16_ccitt; typedef crc16_ccitt_t256 crc16_ccitt;
} } // namespace etl
#endif #endif

View File

@ -61,7 +61,7 @@ namespace etl
/// \param begin Start of the range. /// \param begin Start of the range.
/// \param end End of the range. /// \param end End of the range.
//************************************************************************* //*************************************************************************
template<typename TIterator> template <typename TIterator>
crc16_cdma2000_t(TIterator begin, const TIterator end) crc16_cdma2000_t(TIterator begin, const TIterator end)
{ {
this->reset(); this->reset();
@ -74,5 +74,5 @@ namespace etl
typedef etl::crc16_cdma2000_t<16U> crc16_cdma2000_t16; typedef etl::crc16_cdma2000_t<16U> crc16_cdma2000_t16;
typedef etl::crc16_cdma2000_t<4U> crc16_cdma2000_t4; typedef etl::crc16_cdma2000_t<4U> crc16_cdma2000_t4;
typedef crc16_cdma2000_t256 crc16_cdma2000; typedef crc16_cdma2000_t256 crc16_cdma2000;
} } // namespace etl
#endif #endif

View File

@ -61,7 +61,7 @@ namespace etl
/// \param begin Start of the range. /// \param begin Start of the range.
/// \param end End of the range. /// \param end End of the range.
//************************************************************************* //*************************************************************************
template<typename TIterator> template <typename TIterator>
crc16_dds110_t(TIterator begin, const TIterator end) crc16_dds110_t(TIterator begin, const TIterator end)
{ {
this->reset(); this->reset();
@ -74,5 +74,5 @@ namespace etl
typedef etl::crc16_dds110_t<16U> crc16_dds110_t16; typedef etl::crc16_dds110_t<16U> crc16_dds110_t16;
typedef etl::crc16_dds110_t<4U> crc16_dds110_t4; typedef etl::crc16_dds110_t<4U> crc16_dds110_t4;
typedef crc16_dds110_t256 crc16_dds110; typedef crc16_dds110_t256 crc16_dds110;
} } // namespace etl
#endif #endif

View File

@ -61,7 +61,7 @@ namespace etl
/// \param begin Start of the range. /// \param begin Start of the range.
/// \param end End of the range. /// \param end End of the range.
//************************************************************************* //*************************************************************************
template<typename TIterator> template <typename TIterator>
crc16_dect_r_t(TIterator begin, const TIterator end) crc16_dect_r_t(TIterator begin, const TIterator end)
{ {
this->reset(); this->reset();
@ -74,5 +74,5 @@ namespace etl
typedef etl::crc16_dect_r_t<16U> crc16_dect_r_t16; typedef etl::crc16_dect_r_t<16U> crc16_dect_r_t16;
typedef etl::crc16_dect_r_t<4U> crc16_dect_r_t4; typedef etl::crc16_dect_r_t<4U> crc16_dect_r_t4;
typedef crc16_dect_r_t256 crc16_dectr; typedef crc16_dect_r_t256 crc16_dectr;
} } // namespace etl
#endif #endif

View File

@ -61,7 +61,7 @@ namespace etl
/// \param begin Start of the range. /// \param begin Start of the range.
/// \param end End of the range. /// \param end End of the range.
//************************************************************************* //*************************************************************************
template<typename TIterator> template <typename TIterator>
crc16_dect_x_t(TIterator begin, const TIterator end) crc16_dect_x_t(TIterator begin, const TIterator end)
{ {
this->reset(); this->reset();
@ -74,5 +74,5 @@ namespace etl
typedef etl::crc16_dect_x_t<16U> crc16_dect_x_t16; typedef etl::crc16_dect_x_t<16U> crc16_dect_x_t16;
typedef etl::crc16_dect_x_t<4U> crc16_dect_x_t4; typedef etl::crc16_dect_x_t<4U> crc16_dect_x_t4;
typedef crc16_dect_x_t256 crc16_dectx; typedef crc16_dect_x_t256 crc16_dectx;
} } // namespace etl
#endif #endif

View File

@ -61,7 +61,7 @@ namespace etl
/// \param begin Start of the range. /// \param begin Start of the range.
/// \param end End of the range. /// \param end End of the range.
//************************************************************************* //*************************************************************************
template<typename TIterator> template <typename TIterator>
crc16_dnp_t(TIterator begin, const TIterator end) crc16_dnp_t(TIterator begin, const TIterator end)
{ {
this->reset(); this->reset();
@ -74,5 +74,5 @@ namespace etl
typedef etl::crc16_dnp_t<16U> crc16_dnp_t16; typedef etl::crc16_dnp_t<16U> crc16_dnp_t16;
typedef etl::crc16_dnp_t<4U> crc16_dnp_t4; typedef etl::crc16_dnp_t<4U> crc16_dnp_t4;
typedef crc16_dnp_t256 crc16_dnp; typedef crc16_dnp_t256 crc16_dnp;
} } // namespace etl
#endif #endif

View File

@ -61,7 +61,7 @@ namespace etl
/// \param begin Start of the range. /// \param begin Start of the range.
/// \param end End of the range. /// \param end End of the range.
//************************************************************************* //*************************************************************************
template<typename TIterator> template <typename TIterator>
crc16_en13757_t(TIterator begin, const TIterator end) crc16_en13757_t(TIterator begin, const TIterator end)
{ {
this->reset(); this->reset();
@ -74,5 +74,5 @@ namespace etl
typedef etl::crc16_en13757_t<16U> crc16_en13757_t16; typedef etl::crc16_en13757_t<16U> crc16_en13757_t16;
typedef etl::crc16_en13757_t<4U> crc16_en13757_t4; typedef etl::crc16_en13757_t<4U> crc16_en13757_t4;
typedef crc16_en13757_t256 crc16_en13757; typedef crc16_en13757_t256 crc16_en13757;
} } // namespace etl
#endif #endif

View File

@ -43,7 +43,7 @@ namespace etl
template <size_t Table_Size> template <size_t Table_Size>
using crc16_genibus_t = etl::crc_type<etl::private_crc::crc16_genibus_parameters, Table_Size>; using crc16_genibus_t = etl::crc_type<etl::private_crc::crc16_genibus_parameters, Table_Size>;
#else #else
template <size_t Table_Size> template <size_t Table_Size>
class crc16_genibus_t : public etl::crc_type<etl::private_crc::crc16_genibus_parameters, Table_Size> class crc16_genibus_t : public etl::crc_type<etl::private_crc::crc16_genibus_parameters, Table_Size>
{ {
public: public:
@ -61,7 +61,7 @@ namespace etl
/// \param begin Start of the range. /// \param begin Start of the range.
/// \param end End of the range. /// \param end End of the range.
//************************************************************************* //*************************************************************************
template<typename TIterator> template <typename TIterator>
crc16_genibus_t(TIterator begin, const TIterator end) crc16_genibus_t(TIterator begin, const TIterator end)
{ {
this->reset(); this->reset();
@ -74,5 +74,5 @@ namespace etl
typedef etl::crc16_genibus_t<16U> crc16_genibus_t16; typedef etl::crc16_genibus_t<16U> crc16_genibus_t16;
typedef etl::crc16_genibus_t<4U> crc16_genibus_t4; typedef etl::crc16_genibus_t<4U> crc16_genibus_t4;
typedef crc16_genibus_t256 crc16_genibus; typedef crc16_genibus_t256 crc16_genibus;
} } // namespace etl
#endif #endif

View File

@ -43,7 +43,7 @@ namespace etl
template <size_t Table_Size> template <size_t Table_Size>
using crc16_kermit_t = etl::crc_type<etl::private_crc::crc16_kermit_parameters, Table_Size>; using crc16_kermit_t = etl::crc_type<etl::private_crc::crc16_kermit_parameters, Table_Size>;
#else #else
template <size_t Table_Size> template <size_t Table_Size>
class crc16_kermit_t : public etl::crc_type<etl::private_crc::crc16_kermit_parameters, Table_Size> class crc16_kermit_t : public etl::crc_type<etl::private_crc::crc16_kermit_parameters, Table_Size>
{ {
public: public:
@ -61,7 +61,7 @@ namespace etl
/// \param begin Start of the range. /// \param begin Start of the range.
/// \param end End of the range. /// \param end End of the range.
//************************************************************************* //*************************************************************************
template<typename TIterator> template <typename TIterator>
crc16_kermit_t(TIterator begin, const TIterator end) crc16_kermit_t(TIterator begin, const TIterator end)
{ {
this->reset(); this->reset();
@ -74,5 +74,5 @@ namespace etl
typedef etl::crc16_kermit_t<16U> crc16_kermit_t16; typedef etl::crc16_kermit_t<16U> crc16_kermit_t16;
typedef etl::crc16_kermit_t<4U> crc16_kermit_t4; typedef etl::crc16_kermit_t<4U> crc16_kermit_t4;
typedef crc16_kermit_t256 crc16_kermit; typedef crc16_kermit_t256 crc16_kermit;
} } // namespace etl
#endif #endif

View File

@ -61,7 +61,7 @@ namespace etl
/// \param begin Start of the range. /// \param begin Start of the range.
/// \param end End of the range. /// \param end End of the range.
//************************************************************************* //*************************************************************************
template<typename TIterator> template <typename TIterator>
crc16_m17_t(TIterator begin, const TIterator end) crc16_m17_t(TIterator begin, const TIterator end)
{ {
this->reset(); this->reset();
@ -74,5 +74,5 @@ namespace etl
typedef etl::crc16_m17_t<16U> crc16_m17_t16; typedef etl::crc16_m17_t<16U> crc16_m17_t16;
typedef etl::crc16_m17_t<4U> crc16_m17_t4; typedef etl::crc16_m17_t<4U> crc16_m17_t4;
typedef crc16_m17_t256 crc16_m17; typedef crc16_m17_t256 crc16_m17;
} } // namespace etl
#endif #endif

View File

@ -43,7 +43,7 @@ namespace etl
template <size_t Table_Size> template <size_t Table_Size>
using crc16_maxim_t = etl::crc_type<etl::private_crc::crc16_maxim_parameters, Table_Size>; using crc16_maxim_t = etl::crc_type<etl::private_crc::crc16_maxim_parameters, Table_Size>;
#else #else
template <size_t Table_Size> template <size_t Table_Size>
class crc16_maxim_t : public etl::crc_type<etl::private_crc::crc16_maxim_parameters, Table_Size> class crc16_maxim_t : public etl::crc_type<etl::private_crc::crc16_maxim_parameters, Table_Size>
{ {
public: public:
@ -61,7 +61,7 @@ namespace etl
/// \param begin Start of the range. /// \param begin Start of the range.
/// \param end End of the range. /// \param end End of the range.
//************************************************************************* //*************************************************************************
template<typename TIterator> template <typename TIterator>
crc16_maxim_t(TIterator begin, const TIterator end) crc16_maxim_t(TIterator begin, const TIterator end)
{ {
this->reset(); this->reset();
@ -74,5 +74,5 @@ namespace etl
typedef etl::crc16_maxim_t<16U> crc16_maxim_t16; typedef etl::crc16_maxim_t<16U> crc16_maxim_t16;
typedef etl::crc16_maxim_t<4U> crc16_maxim_t4; typedef etl::crc16_maxim_t<4U> crc16_maxim_t4;
typedef crc16_maxim_t256 crc16_maxim; typedef crc16_maxim_t256 crc16_maxim;
} } // namespace etl
#endif #endif

View File

@ -61,7 +61,7 @@ namespace etl
/// \param begin Start of the range. /// \param begin Start of the range.
/// \param end End of the range. /// \param end End of the range.
//************************************************************************* //*************************************************************************
template<typename TIterator> template <typename TIterator>
crc16_mcrf4xx_t(TIterator begin, const TIterator end) crc16_mcrf4xx_t(TIterator begin, const TIterator end)
{ {
this->reset(); this->reset();
@ -74,5 +74,5 @@ namespace etl
typedef etl::crc16_mcrf4xx_t<16U> crc16_mcrf4xx_t16; typedef etl::crc16_mcrf4xx_t<16U> crc16_mcrf4xx_t16;
typedef etl::crc16_mcrf4xx_t<4U> crc16_mcrf4xx_t4; typedef etl::crc16_mcrf4xx_t<4U> crc16_mcrf4xx_t4;
typedef crc16_mcrf4xx_t256 crc16_mcrf4xx; typedef crc16_mcrf4xx_t256 crc16_mcrf4xx;
} } // namespace etl
#endif #endif

View File

@ -43,7 +43,7 @@ namespace etl
template <size_t Table_Size> template <size_t Table_Size>
using crc16_modbus_t = etl::crc_type<etl::private_crc::crc16_modbus_parameters, Table_Size>; using crc16_modbus_t = etl::crc_type<etl::private_crc::crc16_modbus_parameters, Table_Size>;
#else #else
template <size_t Table_Size> template <size_t Table_Size>
class crc16_modbus_t : public etl::crc_type<etl::private_crc::crc16_modbus_parameters, Table_Size> class crc16_modbus_t : public etl::crc_type<etl::private_crc::crc16_modbus_parameters, Table_Size>
{ {
public: public:
@ -61,7 +61,7 @@ namespace etl
/// \param begin Start of the range. /// \param begin Start of the range.
/// \param end End of the range. /// \param end End of the range.
//************************************************************************* //*************************************************************************
template<typename TIterator> template <typename TIterator>
crc16_modbus_t(TIterator begin, const TIterator end) crc16_modbus_t(TIterator begin, const TIterator end)
{ {
this->reset(); this->reset();
@ -74,5 +74,5 @@ namespace etl
typedef etl::crc16_modbus_t<16U> crc16_modbus_t16; typedef etl::crc16_modbus_t<16U> crc16_modbus_t16;
typedef etl::crc16_modbus_t<4U> crc16_modbus_t4; typedef etl::crc16_modbus_t<4U> crc16_modbus_t4;
typedef crc16_modbus_t256 crc16_modbus; typedef crc16_modbus_t256 crc16_modbus;
} } // namespace etl
#endif #endif

View File

@ -43,7 +43,7 @@ namespace etl
template <size_t Table_Size> template <size_t Table_Size>
using crc16_opensafety_a_t = etl::crc_type<etl::private_crc::crc16_opensafety_a_parameters, Table_Size>; using crc16_opensafety_a_t = etl::crc_type<etl::private_crc::crc16_opensafety_a_parameters, Table_Size>;
#else #else
template <size_t Table_Size> template <size_t Table_Size>
class crc16_opensafety_a_t : public etl::crc_type<etl::private_crc::crc16_opensafety_a_parameters, Table_Size> class crc16_opensafety_a_t : public etl::crc_type<etl::private_crc::crc16_opensafety_a_parameters, Table_Size>
{ {
public: public:
@ -61,7 +61,7 @@ namespace etl
/// \param begin Start of the range. /// \param begin Start of the range.
/// \param end End of the range. /// \param end End of the range.
//************************************************************************* //*************************************************************************
template<typename TIterator> template <typename TIterator>
crc16_opensafety_a_t(TIterator begin, const TIterator end) crc16_opensafety_a_t(TIterator begin, const TIterator end)
{ {
this->reset(); this->reset();
@ -74,5 +74,5 @@ namespace etl
typedef etl::crc16_opensafety_a_t<16U> crc16_opensafety_a_t16; typedef etl::crc16_opensafety_a_t<16U> crc16_opensafety_a_t16;
typedef etl::crc16_opensafety_a_t<4U> crc16_opensafety_a_t4; typedef etl::crc16_opensafety_a_t<4U> crc16_opensafety_a_t4;
typedef crc16_opensafety_a_t256 crc16_opensafety_a; typedef crc16_opensafety_a_t256 crc16_opensafety_a;
} } // namespace etl
#endif #endif

View File

@ -43,10 +43,10 @@ namespace etl
template <size_t Table_Size> template <size_t Table_Size>
using crc16_opensafety_b_t = etl::crc_type<etl::private_crc::crc16_opensafety_b_parameters, Table_Size>; using crc16_opensafety_b_t = etl::crc_type<etl::private_crc::crc16_opensafety_b_parameters, Table_Size>;
#else #else
template <size_t Table_Size> template <size_t Table_Size>
class crc16_opensafety_b_t : public etl::crc_type<etl::private_crc::crc16_opensafety_b_parameters, Table_Size> class crc16_opensafety_b_t : public etl::crc_type<etl::private_crc::crc16_opensafety_b_parameters, Table_Size>
{ {
public: public:
//************************************************************************* //*************************************************************************
/// Default constructor. /// Default constructor.
@ -61,7 +61,7 @@ namespace etl
/// \param begin Start of the range. /// \param begin Start of the range.
/// \param end End of the range. /// \param end End of the range.
//************************************************************************* //*************************************************************************
template<typename TIterator> template <typename TIterator>
crc16_opensafety_b_t(TIterator begin, const TIterator end) crc16_opensafety_b_t(TIterator begin, const TIterator end)
{ {
this->reset(); this->reset();
@ -74,5 +74,5 @@ namespace etl
typedef etl::crc16_opensafety_b_t<16U> crc16_opensafety_b_t16; typedef etl::crc16_opensafety_b_t<16U> crc16_opensafety_b_t16;
typedef etl::crc16_opensafety_b_t<4U> crc16_opensafety_b_t4; typedef etl::crc16_opensafety_b_t<4U> crc16_opensafety_b_t4;
typedef crc16_opensafety_b_t256 crc16_opensafety_b; typedef crc16_opensafety_b_t256 crc16_opensafety_b;
} } // namespace etl
#endif #endif

View File

@ -43,7 +43,7 @@ namespace etl
template <size_t Table_Size> template <size_t Table_Size>
using crc16_profibus_t = etl::crc_type<etl::private_crc::crc16_profibus_parameters, Table_Size>; using crc16_profibus_t = etl::crc_type<etl::private_crc::crc16_profibus_parameters, Table_Size>;
#else #else
template <size_t Table_Size> template <size_t Table_Size>
class crc16_profibus_t : public etl::crc_type<etl::private_crc::crc16_profibus_parameters, Table_Size> class crc16_profibus_t : public etl::crc_type<etl::private_crc::crc16_profibus_parameters, Table_Size>
{ {
public: public:
@ -61,7 +61,7 @@ namespace etl
/// \param begin Start of the range. /// \param begin Start of the range.
/// \param end End of the range. /// \param end End of the range.
//************************************************************************* //*************************************************************************
template<typename TIterator> template <typename TIterator>
crc16_profibus_t(TIterator begin, const TIterator end) crc16_profibus_t(TIterator begin, const TIterator end)
{ {
this->reset(); this->reset();
@ -74,5 +74,5 @@ namespace etl
typedef etl::crc16_profibus_t<16U> crc16_profibus_t16; typedef etl::crc16_profibus_t<16U> crc16_profibus_t16;
typedef etl::crc16_profibus_t<4U> crc16_profibus_t4; typedef etl::crc16_profibus_t<4U> crc16_profibus_t4;
typedef crc16_profibus_t256 crc16_profibus; typedef crc16_profibus_t256 crc16_profibus;
} } // namespace etl
#endif #endif

View File

@ -61,7 +61,7 @@ namespace etl
/// \param begin Start of the range. /// \param begin Start of the range.
/// \param end End of the range. /// \param end End of the range.
//************************************************************************* //*************************************************************************
template<typename TIterator> template <typename TIterator>
crc16_riello_t(TIterator begin, const TIterator end) crc16_riello_t(TIterator begin, const TIterator end)
{ {
this->reset(); this->reset();
@ -74,5 +74,5 @@ namespace etl
typedef etl::crc16_riello_t<16U> crc16_riello_t16; typedef etl::crc16_riello_t<16U> crc16_riello_t16;
typedef etl::crc16_riello_t<4U> crc16_riello_t4; typedef etl::crc16_riello_t<4U> crc16_riello_t4;
typedef crc16_riello_t256 crc16_riello; typedef crc16_riello_t256 crc16_riello;
} } // namespace etl
#endif #endif

View File

@ -61,7 +61,7 @@ namespace etl
/// \param begin Start of the range. /// \param begin Start of the range.
/// \param end End of the range. /// \param end End of the range.
//************************************************************************* //*************************************************************************
template<typename TIterator> template <typename TIterator>
crc16_t10dif_t(TIterator begin, const TIterator end) crc16_t10dif_t(TIterator begin, const TIterator end)
{ {
this->reset(); this->reset();
@ -74,5 +74,5 @@ namespace etl
typedef etl::crc16_t10dif_t<16U> crc16_t10dif_t16; typedef etl::crc16_t10dif_t<16U> crc16_t10dif_t16;
typedef etl::crc16_t10dif_t<4U> crc16_t10dif_t4; typedef etl::crc16_t10dif_t<4U> crc16_t10dif_t4;
typedef crc16_t10dif_t256 crc16_t10dif; typedef crc16_t10dif_t256 crc16_t10dif;
} } // namespace etl
#endif #endif

View File

@ -43,7 +43,7 @@ namespace etl
template <size_t Table_Size> template <size_t Table_Size>
using crc16_teledisk_t = etl::crc_type<etl::private_crc::crc16_teledisk_parameters, Table_Size>; using crc16_teledisk_t = etl::crc_type<etl::private_crc::crc16_teledisk_parameters, Table_Size>;
#else #else
template <size_t Table_Size> template <size_t Table_Size>
class crc16_teledisk_t : public etl::crc_type<etl::private_crc::crc16_teledisk_parameters, Table_Size> class crc16_teledisk_t : public etl::crc_type<etl::private_crc::crc16_teledisk_parameters, Table_Size>
{ {
public: public:
@ -61,7 +61,7 @@ namespace etl
/// \param begin Start of the range. /// \param begin Start of the range.
/// \param end End of the range. /// \param end End of the range.
//************************************************************************* //*************************************************************************
template<typename TIterator> template <typename TIterator>
crc16_teledisk_t(TIterator begin, const TIterator end) crc16_teledisk_t(TIterator begin, const TIterator end)
{ {
this->reset(); this->reset();
@ -74,5 +74,5 @@ namespace etl
typedef etl::crc16_teledisk_t<16U> crc16_teledisk_t16; typedef etl::crc16_teledisk_t<16U> crc16_teledisk_t16;
typedef etl::crc16_teledisk_t<4U> crc16_teledisk_t4; typedef etl::crc16_teledisk_t<4U> crc16_teledisk_t4;
typedef crc16_teledisk_t256 crc16_teledisk; typedef crc16_teledisk_t256 crc16_teledisk;
} } // namespace etl
#endif #endif

View File

@ -43,7 +43,7 @@ namespace etl
template <size_t Table_Size> template <size_t Table_Size>
using crc16_tms37157_t = etl::crc_type<etl::private_crc::crc16_tms37157_parameters, Table_Size>; using crc16_tms37157_t = etl::crc_type<etl::private_crc::crc16_tms37157_parameters, Table_Size>;
#else #else
template <size_t Table_Size> template <size_t Table_Size>
class crc16_tms37157_t : public etl::crc_type<etl::private_crc::crc16_tms37157_parameters, Table_Size> class crc16_tms37157_t : public etl::crc_type<etl::private_crc::crc16_tms37157_parameters, Table_Size>
{ {
public: public:
@ -61,7 +61,7 @@ namespace etl
/// \param begin Start of the range. /// \param begin Start of the range.
/// \param end End of the range. /// \param end End of the range.
//************************************************************************* //*************************************************************************
template<typename TIterator> template <typename TIterator>
crc16_tms37157_t(TIterator begin, const TIterator end) crc16_tms37157_t(TIterator begin, const TIterator end)
{ {
this->reset(); this->reset();
@ -74,5 +74,5 @@ namespace etl
typedef etl::crc16_tms37157_t<16U> crc16_tms37157_t16; typedef etl::crc16_tms37157_t<16U> crc16_tms37157_t16;
typedef etl::crc16_tms37157_t<4U> crc16_tms37157_t4; typedef etl::crc16_tms37157_t<4U> crc16_tms37157_t4;
typedef crc16_tms37157_t256 crc16_tms37157; typedef crc16_tms37157_t256 crc16_tms37157;
} } // namespace etl
#endif #endif

View File

@ -43,7 +43,7 @@ namespace etl
template <size_t Table_Size> template <size_t Table_Size>
using crc16_usb_t = etl::crc_type<etl::private_crc::crc16_usb_parameters, Table_Size>; using crc16_usb_t = etl::crc_type<etl::private_crc::crc16_usb_parameters, Table_Size>;
#else #else
template <size_t Table_Size> template <size_t Table_Size>
class crc16_usb_t : public etl::crc_type<etl::private_crc::crc16_usb_parameters, Table_Size> class crc16_usb_t : public etl::crc_type<etl::private_crc::crc16_usb_parameters, Table_Size>
{ {
public: public:
@ -61,7 +61,7 @@ namespace etl
/// \param begin Start of the range. /// \param begin Start of the range.
/// \param end End of the range. /// \param end End of the range.
//************************************************************************* //*************************************************************************
template<typename TIterator> template <typename TIterator>
crc16_usb_t(TIterator begin, const TIterator end) crc16_usb_t(TIterator begin, const TIterator end)
{ {
this->reset(); this->reset();
@ -74,5 +74,5 @@ namespace etl
typedef etl::crc16_usb_t<16U> crc16_usb_t16; typedef etl::crc16_usb_t<16U> crc16_usb_t16;
typedef etl::crc16_usb_t<4U> crc16_usb_t4; typedef etl::crc16_usb_t<4U> crc16_usb_t4;
typedef crc16_usb_t256 crc16_usb; typedef crc16_usb_t256 crc16_usb;
} } // namespace etl
#endif #endif

View File

@ -43,7 +43,7 @@ namespace etl
template <size_t Table_Size> template <size_t Table_Size>
using crc16_x25_t = etl::crc_type<etl::private_crc::crc16_x25_parameters, Table_Size>; using crc16_x25_t = etl::crc_type<etl::private_crc::crc16_x25_parameters, Table_Size>;
#else #else
template <size_t Table_Size> template <size_t Table_Size>
class crc16_x25_t : public etl::crc_type<etl::private_crc::crc16_x25_parameters, Table_Size> class crc16_x25_t : public etl::crc_type<etl::private_crc::crc16_x25_parameters, Table_Size>
{ {
public: public:
@ -61,7 +61,7 @@ namespace etl
/// \param begin Start of the range. /// \param begin Start of the range.
/// \param end End of the range. /// \param end End of the range.
//************************************************************************* //*************************************************************************
template<typename TIterator> template <typename TIterator>
crc16_x25_t(TIterator begin, const TIterator end) crc16_x25_t(TIterator begin, const TIterator end)
{ {
this->reset(); this->reset();
@ -74,5 +74,5 @@ namespace etl
typedef etl::crc16_x25_t<16U> crc16_x25_t16; typedef etl::crc16_x25_t<16U> crc16_x25_t16;
typedef etl::crc16_x25_t<4U> crc16_x25_t4; typedef etl::crc16_x25_t<4U> crc16_x25_t4;
typedef crc16_x25_t256 crc16_x25; typedef crc16_x25_t256 crc16_x25;
} } // namespace etl
#endif #endif

View File

@ -43,7 +43,7 @@ namespace etl
template <size_t Table_Size> template <size_t Table_Size>
using crc16_xmodem_t = etl::crc_type<etl::private_crc::crc16_xmodem_parameters, Table_Size>; using crc16_xmodem_t = etl::crc_type<etl::private_crc::crc16_xmodem_parameters, Table_Size>;
#else #else
template <size_t Table_Size> template <size_t Table_Size>
class crc16_xmodem_t : public etl::crc_type<etl::private_crc::crc16_xmodem_parameters, Table_Size> class crc16_xmodem_t : public etl::crc_type<etl::private_crc::crc16_xmodem_parameters, Table_Size>
{ {
public: public:
@ -61,7 +61,7 @@ namespace etl
/// \param begin Start of the range. /// \param begin Start of the range.
/// \param end End of the range. /// \param end End of the range.
//************************************************************************* //*************************************************************************
template<typename TIterator> template <typename TIterator>
crc16_xmodem_t(TIterator begin, const TIterator end) crc16_xmodem_t(TIterator begin, const TIterator end)
{ {
this->reset(); this->reset();
@ -74,5 +74,5 @@ namespace etl
typedef etl::crc16_xmodem_t<16U> crc16_xmodem_t16; typedef etl::crc16_xmodem_t<16U> crc16_xmodem_t16;
typedef etl::crc16_xmodem_t<4U> crc16_xmodem_t4; typedef etl::crc16_xmodem_t<4U> crc16_xmodem_t4;
typedef crc16_xmodem_t256 crc16_xmodem; typedef crc16_xmodem_t256 crc16_xmodem;
} } // namespace etl
#endif #endif

View File

@ -61,7 +61,7 @@ namespace etl
/// \param begin Start of the range. /// \param begin Start of the range.
/// \param end End of the range. /// \param end End of the range.
//************************************************************************* //*************************************************************************
template<typename TIterator> template <typename TIterator>
crc32_t(TIterator begin, const TIterator end) crc32_t(TIterator begin, const TIterator end)
{ {
this->reset(); this->reset();
@ -74,5 +74,5 @@ namespace etl
typedef etl::crc32_t<16U> crc32_t16; typedef etl::crc32_t<16U> crc32_t16;
typedef etl::crc32_t<4U> crc32_t4; typedef etl::crc32_t<4U> crc32_t4;
typedef crc32_t256 crc32; typedef crc32_t256 crc32;
} } // namespace etl
#endif #endif

View File

@ -61,7 +61,7 @@ namespace etl
/// \param begin Start of the range. /// \param begin Start of the range.
/// \param end End of the range. /// \param end End of the range.
//************************************************************************* //*************************************************************************
template<typename TIterator> template <typename TIterator>
crc32_bzip2_t(TIterator begin, const TIterator end) crc32_bzip2_t(TIterator begin, const TIterator end)
{ {
this->reset(); this->reset();
@ -74,5 +74,5 @@ namespace etl
typedef etl::crc32_bzip2_t<16U> crc32_bzip2_t16; typedef etl::crc32_bzip2_t<16U> crc32_bzip2_t16;
typedef etl::crc32_bzip2_t<4U> crc32_bzip2_t4; typedef etl::crc32_bzip2_t<4U> crc32_bzip2_t4;
typedef crc32_bzip2_t256 crc32_bzip2; typedef crc32_bzip2_t256 crc32_bzip2;
} } // namespace etl
#endif #endif

View File

@ -61,7 +61,7 @@ namespace etl
/// \param begin Start of the range. /// \param begin Start of the range.
/// \param end End of the range. /// \param end End of the range.
//************************************************************************* //*************************************************************************
template<typename TIterator> template <typename TIterator>
crc32_c_t(TIterator begin, const TIterator end) crc32_c_t(TIterator begin, const TIterator end)
{ {
this->reset(); this->reset();
@ -74,5 +74,5 @@ namespace etl
typedef etl::crc32_c_t<16U> crc32_c_t16; typedef etl::crc32_c_t<16U> crc32_c_t16;
typedef etl::crc32_c_t<4U> crc32_c_t4; typedef etl::crc32_c_t<4U> crc32_c_t4;
typedef crc32_c_t256 crc32_c; typedef crc32_c_t256 crc32_c;
} } // namespace etl
#endif #endif

View File

@ -61,7 +61,7 @@ namespace etl
/// \param begin Start of the range. /// \param begin Start of the range.
/// \param end End of the range. /// \param end End of the range.
//************************************************************************* //*************************************************************************
template<typename TIterator> template <typename TIterator>
crc32_d_t(TIterator begin, const TIterator end) crc32_d_t(TIterator begin, const TIterator end)
{ {
this->reset(); this->reset();
@ -74,5 +74,5 @@ namespace etl
typedef etl::crc32_d_t<16U> crc32_d_t16; typedef etl::crc32_d_t<16U> crc32_d_t16;
typedef etl::crc32_d_t<4U> crc32_d_t4; typedef etl::crc32_d_t<4U> crc32_d_t4;
typedef crc32_d_t256 crc32_d; typedef crc32_d_t256 crc32_d;
} } // namespace etl
#endif #endif

View File

@ -61,7 +61,7 @@ namespace etl
/// \param begin Start of the range. /// \param begin Start of the range.
/// \param end End of the range. /// \param end End of the range.
//************************************************************************* //*************************************************************************
template<typename TIterator> template <typename TIterator>
crc32_jamcrc_t(TIterator begin, const TIterator end) crc32_jamcrc_t(TIterator begin, const TIterator end)
{ {
this->reset(); this->reset();
@ -74,5 +74,5 @@ namespace etl
typedef etl::crc32_jamcrc_t<16U> crc32_jamcrc_t16; typedef etl::crc32_jamcrc_t<16U> crc32_jamcrc_t16;
typedef etl::crc32_jamcrc_t<4U> crc32_jamcrc_t4; typedef etl::crc32_jamcrc_t<4U> crc32_jamcrc_t4;
typedef crc32_jamcrc_t256 crc32_jamcrc; typedef crc32_jamcrc_t256 crc32_jamcrc;
} } // namespace etl
#endif #endif

View File

@ -61,7 +61,7 @@ namespace etl
/// \param begin Start of the range. /// \param begin Start of the range.
/// \param end End of the range. /// \param end End of the range.
//************************************************************************* //*************************************************************************
template<typename TIterator> template <typename TIterator>
crc32_mpeg2_t(TIterator begin, const TIterator end) crc32_mpeg2_t(TIterator begin, const TIterator end)
{ {
this->reset(); this->reset();
@ -74,5 +74,5 @@ namespace etl
typedef etl::crc32_mpeg2_t<16U> crc32_mpeg2_t16; typedef etl::crc32_mpeg2_t<16U> crc32_mpeg2_t16;
typedef etl::crc32_mpeg2_t<4U> crc32_mpeg2_t4; typedef etl::crc32_mpeg2_t<4U> crc32_mpeg2_t4;
typedef crc32_mpeg2_t256 crc32_mpeg2; typedef crc32_mpeg2_t256 crc32_mpeg2;
} } // namespace etl
#endif #endif

View File

@ -61,7 +61,7 @@ namespace etl
/// \param begin Start of the range. /// \param begin Start of the range.
/// \param end End of the range. /// \param end End of the range.
//************************************************************************* //*************************************************************************
template<typename TIterator> template <typename TIterator>
crc32_posix_t(TIterator begin, const TIterator end) crc32_posix_t(TIterator begin, const TIterator end)
{ {
this->reset(); this->reset();
@ -74,5 +74,5 @@ namespace etl
typedef etl::crc32_posix_t<16U> crc32_posix_t16; typedef etl::crc32_posix_t<16U> crc32_posix_t16;
typedef etl::crc32_posix_t<4U> crc32_posix_t4; typedef etl::crc32_posix_t<4U> crc32_posix_t4;
typedef crc32_posix_t256 crc32_posix; typedef crc32_posix_t256 crc32_posix;
} } // namespace etl
#endif #endif

View File

@ -61,7 +61,7 @@ namespace etl
/// \param begin Start of the range. /// \param begin Start of the range.
/// \param end End of the range. /// \param end End of the range.
//************************************************************************* //*************************************************************************
template<typename TIterator> template <typename TIterator>
crc32_q_t(TIterator begin, const TIterator end) crc32_q_t(TIterator begin, const TIterator end)
{ {
this->reset(); this->reset();
@ -74,5 +74,5 @@ namespace etl
typedef etl::crc32_q_t<16U> crc32_q_t16; typedef etl::crc32_q_t<16U> crc32_q_t16;
typedef etl::crc32_q_t<4U> crc32_q_t4; typedef etl::crc32_q_t<4U> crc32_q_t4;
typedef crc32_q_t256 crc32_q; typedef crc32_q_t256 crc32_q;
} } // namespace etl
#endif #endif

View File

@ -61,7 +61,7 @@ namespace etl
/// \param begin Start of the range. /// \param begin Start of the range.
/// \param end End of the range. /// \param end End of the range.
//************************************************************************* //*************************************************************************
template<typename TIterator> template <typename TIterator>
crc32_xfer_t(TIterator begin, const TIterator end) crc32_xfer_t(TIterator begin, const TIterator end)
{ {
this->reset(); this->reset();
@ -74,5 +74,5 @@ namespace etl
typedef etl::crc32_xfer_t<16U> crc32_xfer_t16; typedef etl::crc32_xfer_t<16U> crc32_xfer_t16;
typedef etl::crc32_xfer_t<4U> crc32_xfer_t4; typedef etl::crc32_xfer_t<4U> crc32_xfer_t4;
typedef crc32_xfer_t256 crc32_xfer; typedef crc32_xfer_t256 crc32_xfer;
} } // namespace etl
#endif #endif

Some files were not shown because too many files have changed in this diff Show More