mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
Exported raw text documentation files from the web site editor
This commit is contained in:
parent
129c3091e4
commit
57c3157d9a
49
docs/raw/callbacks/closure.txt
Normal file
49
docs/raw/callbacks/closure.txt
Normal file
@ -0,0 +1,49 @@
|
||||
closure
|
||||
|
||||
etl::closure wraps an etl::delegate and a set of arguments.
|
||||
____________________________________________________________________________________________________
|
||||
C++11 and above.
|
||||
etl::closure<TReturn(TArgs...)>
|
||||
____________________________________________________________________________________________________
|
||||
C++03.
|
||||
etl::delegate<TReturn(TArg0)>
|
||||
etl::delegate<TReturn(TArg0, TArg1)>
|
||||
etl::delegate<TReturn(TArg0, TArg1, TArg2)>
|
||||
etl::delegate<TReturn(TArg0, TArg1, TArg2, TArg3)>
|
||||
etl::delegate<TReturn(TArg0, TArg1, TArg2, TArg3, TArg4)>
|
||||
____________________________________________________________________________________________________
|
||||
Types
|
||||
|
||||
delegate_type The delegate type etl::delegate<TReturn(TArgs...)>
|
||||
____________________________________________________________________________________________________
|
||||
Constructor
|
||||
|
||||
C++11 and above.
|
||||
ETL_CONSTEXPR14 closure(const delegate_type& f, const TArgs... args)
|
||||
____________________________________________________________________________________________________
|
||||
C++03.
|
||||
closure(const delegate_type& f, const TArg0 arg0)
|
||||
closure(const delegate_type& f, const TArg0 arg0, const TArg1 arg1)
|
||||
closure(const delegate_type& f, const TArg0 arg0, const TArg1 arg1, const TArg2 arg2)
|
||||
closure(const delegate_type& f, const TArg0 arg0, const TArg1 arg1, const TArg2 arg2,
|
||||
const TArg3 arg3)
|
||||
closure(const delegate_type& f, const TArg0 arg0, const TArg1 arg1, const TArg2 arg2,
|
||||
const TArg3 arg3, const TArg4 arg4)
|
||||
____________________________________________________________________________________________________
|
||||
Operations
|
||||
template <size_t index, typename UArg>
|
||||
void bind(UArg arg)
|
||||
Bind a new value to the argument at the specified index.
|
||||
UArg must be one of TArgs.
|
||||
Only non-reference types can be rebound.
|
||||
C++11 and above.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename... UArgs>
|
||||
void bind(UArgs&&... args)
|
||||
Bind new values to all of the arguments at once.
|
||||
The number of arguments must match the delegate.
|
||||
C++11 and above.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_CONSTEXPR14 TReturn operator()(TParams... args) const
|
||||
Executes the delegate.
|
||||
|
||||
234
docs/raw/callbacks/delegate.txt
Normal file
234
docs/raw/callbacks/delegate.txt
Normal file
@ -0,0 +1,234 @@
|
||||
delegate
|
||||
|
||||
etl::delegate is a type-safe, generic, and efficient delegate implementation. A delegate is essentially a type-safe function pointer. It can be used to encapsulate a callable unit (like a function, a function pointer, member function, or a callable object like a functor or a lambda function) and call it later.
|
||||
|
||||
etl::delegate is similar in a lot of ways to std::function_ref introduced with C++26.
|
||||
|
||||
The delegate functions may be defined at compile time and/or runtime, depending on the function type.
|
||||
Most delegates can only be constructed via a create function, except lambdas and functors, which can be created by the delegate constructor.
|
||||
|
||||
This may be used to implement a platform abstraction layer that allows an embedded application to interface with multiple hardware platforms.
|
||||
|
||||
Here's a high-level overview of how etl::delegate works:
|
||||
Creation:
|
||||
When you create a delegate, you specify the function signature that it should match. This is done using template parameters. For example, etl::delegate<void(int)> creates a delegate that can hold references to functions that take an integer as an argument and return void.
|
||||
Assignment:
|
||||
You can assign a function to the delegate using the create method. The function you assign must match the delegate's function signature. For example, if you have a delegate of type etl::delegate<void(int)>, you could assign a function void myFunction(int) to it like this:
|
||||
auto myDelegate = etl::delegate<void(int)>::create<myFunction>();
|
||||
Invocation:
|
||||
Once a function has been assigned to the delegate, you can call that function through the delegate just like you would call a regular function. For example, if myDelegate is a delegate that holds a reference to myFunction, you could call myFunction through the delegate like this: myDelegate(123);
|
||||
____________________________________________________________________________________________________
|
||||
Notes:
|
||||
<=20.21.0
|
||||
This class only supports >=C++11.
|
||||
|
||||
>=20.22.0
|
||||
This class is automatically selects C++03 or C++11 versions based on the value of ETL_USING_CPP11
|
||||
The C++03 variant only supports delegates taking 0 or 1 parameter.
|
||||
|
||||
etl::delegate is non-owning. You cannot use lambdas that capture variables that will have gone out of scope when the delegate is called. This would result in dangling references. Lambdas are not copied; The delegate merely keeps pointers to lambdas. This also applies to functors.
|
||||
|
||||
>=20.40.0
|
||||
Move constructors from lambdas or functors are disabled, thereby stopping a delegate being created from a temporary defined in aparameter.
|
||||
|
||||
>=20.42.0
|
||||
etl::delegate is noexcept
|
||||
____________________________________________________________________________________________________
|
||||
etl::delegate<TReturn(TParams…)>
|
||||
|
||||
20.22.0
|
||||
For C++03
|
||||
etl::delegate<TReturn(void)>
|
||||
etl::delegate<TReturn(TParam)>
|
||||
|
||||
For the examples below, assume the following definitions.
|
||||
|
||||
class Test
|
||||
{
|
||||
public:
|
||||
|
||||
int member_function(int);
|
||||
static int member_static(int);
|
||||
int operator()(int);
|
||||
int operator()(int) const;
|
||||
};
|
||||
|
||||
Test test;
|
||||
|
||||
int global(int);
|
||||
|
||||
auto lambda = [](int i){ return i; };
|
||||
____________________________________________________________________________________________________
|
||||
Public types
|
||||
|
||||
return_type TReturn 20.43.0
|
||||
argument_types etl::type_list<TParams...> 20.43.0
|
||||
____________________________________________________________________________________________________
|
||||
Run time construction
|
||||
|
||||
Lambdas
|
||||
etl::delegate<int(int)> d(lambda);
|
||||
etl::delegate<int(int)> d = lambda;
|
||||
etl::delegate<int(int)> d = etl::delegate<int(int)>::create(lambda);
|
||||
|
||||
d.set(lambda);
|
||||
|
||||
Functors
|
||||
etl::delegate<int(int)> d(test);
|
||||
etl::delegate<int(int)> d = test;
|
||||
etl::delegate<int(int)> d = etl::delegate<int(int)>::create(test);
|
||||
|
||||
d.set<test>();
|
||||
|
||||
Member functions
|
||||
etl::delegate<int(int)> d = etl::delegate<int(int)>::create<Test, &Test::member_function>(test);
|
||||
|
||||
d.set<Test, &Test::member_function>(test);
|
||||
d.set<Test, test, &Test::member_function>();
|
||||
____________________________________________________________________________________________________
|
||||
Compile time construction
|
||||
|
||||
Global functions
|
||||
auto d = etl::delegate<int(int)>::create<global>();
|
||||
|
||||
Member functions (if the instance is known at compile time)
|
||||
auto d = etl::delegate<int(int)>::create<Test, test, &Test::member_function>(); // Deprecated
|
||||
auto d = etl::delegate<int(int)>::create<Test, &Test::member_function, test>(); // New
|
||||
|
||||
Functors (if the instance is known at compile time)
|
||||
auto d = etl::delegate<int(int)>::create<Test, test>();
|
||||
auto d = etl::delegate<int(int)>::create<const Test, test>();
|
||||
Note: These are disabled for GCC <= v8.1 as it generates an 'Internal Compiler Error'.
|
||||
|
||||
Static member functions
|
||||
auto d = etl::delegate<int(int)>::create<Test::member_static>();
|
||||
____________________________________________________________________________________________________
|
||||
Constexpr
|
||||
|
||||
Most delegates can be declared as constexpr. (C++11 and above)
|
||||
static Test test;
|
||||
constexpr auto d = etl::delegate<int(int)>::create<Test, test, &Test::member_function>();
|
||||
|
||||
All create functions are constexpr under C++14.
|
||||
All create functions are [[nodiscard]] under C++17.
|
||||
____________________________________________________________________________________________________
|
||||
Calling the delegate
|
||||
|
||||
The delegate may be called as a function with the defined parameter signature.
|
||||
|
||||
etl::delegate<int(int)> d;
|
||||
|
||||
int r = d(3);
|
||||
____________________________________________________________________________________________________
|
||||
Operations
|
||||
|
||||
ETL_CONSTEXPR14 delegate()
|
||||
Constructs an uninitialised delegate.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_CONSTEXPR14 delegate(const delegate& other)
|
||||
Copy constructs a delegate.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_CONSTEXPR14 TReturn operator()(TParams... args) const ETL_NOEXCEPT
|
||||
Executes the delegate.
|
||||
constexpr from 20.42.1
|
||||
____________________________________________________________________________________________________
|
||||
20.17.0
|
||||
ETL_CONSTEXPR14 bool call_if(TParams... args) const ETL_NOEXCEPT
|
||||
For delegates returning void.
|
||||
Calls the delegate if valid.
|
||||
Returns true if valid, otherwise false.
|
||||
constexpr from 20.42.2
|
||||
|
||||
ETL_CONSTEXPR14 etl::optional<TReturn> call_if(TParams... args) const ETL_NOEXCEPT
|
||||
For delegates returning TReturn.
|
||||
Calls the delegate if valid.
|
||||
Returns a valid etl::optional<TReturn> containing the return value, if valid.
|
||||
constexpr from 20.42.2
|
||||
____________________________________________________________________________________________________
|
||||
20.17.0
|
||||
template <typename TAlternative>
|
||||
ETL_CONSTEXPR14 TReturn call_or(TAlternative alternative, TParams... args) const ETL_NOEXCEPT
|
||||
Calls the delegate if valid, otherwise calls alternative.
|
||||
constexpr from 20.42.2
|
||||
|
||||
template <TReturn(*Method)(TParams...)>
|
||||
ETL_CONSTEXPR14 TReturn call_or(TParams... args) const ETL_NOEXCEPT
|
||||
Calls the delegate if valid, otherwise calls Method.
|
||||
____________________________________________________________________________________________________
|
||||
void clear() ETL_NOEXCEPT
|
||||
Sets the delegate back to the uninitialised state.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 bool is_valid() const ETL_NOEXCEPT
|
||||
ETL_CONSTEXPR14 operator bool() const
|
||||
Returns true if the delegate has been initialised, otherwise false.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_CONSTEXPR14 operator =() ETL_NOEXCEPT
|
||||
Assigns from another delegate or lambda.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_CONSTEXPR14 operator ==() ETL_NOEXCEPT
|
||||
ETL_CONSTEXPR14 operator !=() ETL_NOEXCEPT
|
||||
Compares delegates.
|
||||
____________________________________________________________________________________________________
|
||||
make_delegate
|
||||
For C++17 and above.
|
||||
20.39.5
|
||||
____________________________________________________________________________________________________
|
||||
template <auto Function>
|
||||
constexpr auto make_delegate() noexcept
|
||||
Make a delegate from a free function.
|
||||
Returns etl::delegate<function_type>::create<Function>();
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TLambda>
|
||||
constexpr auto make_delegate(TLambda& instance) noexcept
|
||||
Make a delegate from a functor or lambda function.
|
||||
Returns etl::delegate<function_type>(instance);
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T, T& Instance>
|
||||
constexpr auto make_delegate() noexcept
|
||||
Make a delegate from a functor, compile time.
|
||||
Returns etl::delegate<function_type>::create<T, Instance>();
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T, auto Method, T& Instance>
|
||||
constexpr auto make_delegate() noexcept
|
||||
Make a delegate from a member function at compile time.
|
||||
Returns etl::delegate<function_type>::create<T, Method, Instance>();
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T, auto Method, const T& Instance>
|
||||
constexpr auto make_delegate() noexcept
|
||||
Make a delegate from a const member function at compile time.
|
||||
Returns etl::delegate<function_type>::create<T, Method, Instance>();
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T, auto Method>
|
||||
constexpr auto make_delegate(T& instance) noexcept
|
||||
Make a delegate from a member function at run time.
|
||||
Returns etl::delegate<function_type>::create<T, Method>(instance);
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T, auto Method>
|
||||
constexpr auto make_delegate(const T& instance) noexcept
|
||||
Make a delegate from a member function at run time.
|
||||
Returns etl::delegate<function_type>::create<T, Method>(instance);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
79
docs/raw/callbacks/delegate_observable.txt
Normal file
79
docs/raw/callbacks/delegate_observable.txt
Normal file
@ -0,0 +1,79 @@
|
||||
delegate_observable
|
||||
|
||||
etl::delegate_observable is a variation on the observer pattern idea, but using delegates as the callback mechanism.
|
||||
|
||||
template <typename TNotification, size_t Max_Observers>
|
||||
class delegate_observable
|
||||
|
||||
TNotification is the notification type.
|
||||
Max_Observers is the maximum number of observers that can be handled.
|
||||
____________________________________________________________________________________________________
|
||||
Template deduction guide
|
||||
|
||||
template <typename TNotification, typename... TDelegates>
|
||||
delegate_observable(TNotification, TDelegates...)
|
||||
-> delegate_observable<TNotification, sizeof...(TDelegates)>;
|
||||
|
||||
Example
|
||||
etl::delegate<void(int)> delegate1;
|
||||
etl::delegate<void(int)> delegate2;
|
||||
|
||||
etl::delegate_observable observable(int{}, delegate1, delegate2);
|
||||
____________________________________________________________________________________________________
|
||||
Public types
|
||||
|
||||
delegate_type The type of delegate used in this observer.
|
||||
size_type The type used internally for sizes.
|
||||
notification_type The type of the notification.
|
||||
____________________________________________________________________________________________________
|
||||
Construction
|
||||
|
||||
ETL_CONSTEXPR14 delegate_observable()
|
||||
Default constructor.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename... TDelegate>
|
||||
ETL_CONSTEXPR14 delegate_observable(TDelegate&&... delegates)
|
||||
Construct from a collection of observers.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename... TDelegate>
|
||||
ETL_CONSTEXPR14 delegate_observable(notification_type, TDelegate&&... delegates)
|
||||
Construct from notification type and a list of observers.
|
||||
Variant for template deduction guide.
|
||||
The notification value is ignored. It is here to allow deduction of the notification type for the template deduction guide.
|
||||
____________________________________________________________________________________________________
|
||||
Modifiers
|
||||
|
||||
ETL_CONSTEXPR14 bool add_observer(delegate_type observer)
|
||||
Add an observer to the list.
|
||||
Returns true if the observer was removed, false if not.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_CONSTEXPR14 bool remove_observer(const delegate_type& observer)
|
||||
Remove a particular observer from the list.
|
||||
Returns true if the observer was removed, false if not.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_CONSTEXPR14 void clear_observers()
|
||||
Clear all observers.
|
||||
____________________________________________________________________________________________________
|
||||
Status
|
||||
|
||||
ETL_CONSTEXPR14 size_type number_of_observers() const
|
||||
Returns the number of observers.
|
||||
____________________________________________________________________________________________________
|
||||
Notofication
|
||||
|
||||
ETL_CONSTEXPR14 void notify_observers(notification_type n) const
|
||||
Notify all of the observers, sending them the notification.
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
104
docs/raw/callbacks/function.txt
Normal file
104
docs/raw/callbacks/function.txt
Normal file
@ -0,0 +1,104 @@
|
||||
function
|
||||
Note: This class is deprecated. Please use the more versatile etl::delegate class here.
|
||||
|
||||
A set of wrapper templates to allow a member or static function to be called without the caller having to know the specific details of the callee apart from the parameter type. The templates allow the called function to be abstracted.
|
||||
|
||||
This may be used to implement a platform abstraction layer that allows an embedded application to interface with multiple hardware platforms.
|
||||
|
||||
etl::function Callbacks to free or member functions taking zero or one parameter.
|
||||
Function pointer at runtime.
|
||||
|
||||
etl::function_fv Callback to a free function taking no parameters. (Functiion Void)
|
||||
Function pointer at compile time.
|
||||
|
||||
etl::function_fp Callback to a free function taking one parameter. (Functiion Parameter)
|
||||
Function pointer at compile time.
|
||||
|
||||
etl::function_mv Callback to a member function taking no parameters. (Member Void)
|
||||
Function pointer at compile time.
|
||||
|
||||
etl::function_imv Callback to a member function taking no parameters. (Instance Member Void)
|
||||
Instance reference and function pointer at compile time.
|
||||
|
||||
etl::function_mp Callback to a member function taking one parameter. (Member Parameter)
|
||||
Function pointer at compile time.
|
||||
|
||||
etl::function_imp Callback to a member function taking one parameter. (Instance Member Parameter)
|
||||
Instance reference and function pointer at compile time.
|
||||
|
||||
See the tutorial.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
Interface classes.
|
||||
|
||||
template <typename TParameter>
|
||||
class ifunction
|
||||
|
||||
Interface class for a function taking one parameter.
|
||||
____________________________________________________________________________________________________
|
||||
template <>
|
||||
class ifunction<void>
|
||||
|
||||
Interface class for a function taking no parameters.
|
||||
|
||||
All of the following classes are derived from the above.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
Function address at run time.
|
||||
The functions are called indirectly through an internal pointer.
|
||||
|
||||
template <typename TObject, typename TParameter>
|
||||
class function : public ifunction<TParameter>
|
||||
|
||||
Class for a member function taking one parameter.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TObject>
|
||||
class function<TObject, void> : public ifunction<void>
|
||||
|
||||
Class for a member function taking no parameters.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TParameter>
|
||||
class function<void, TParameter> : public ifunction<TParameter>
|
||||
|
||||
Class for a free function taking one parameter.
|
||||
____________________________________________________________________________________________________
|
||||
template <>
|
||||
class function<void, void> : public ifunction<void>
|
||||
|
||||
Class for a free function taking no parameters.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
Function address at compile time.
|
||||
These will be more efficient than the previous definitions, as the one level of indirection is eliminated.
|
||||
|
||||
template <typename TObject, void (TObject::*Function)()>
|
||||
class function_mv : public ifunction<void>
|
||||
|
||||
Class for a member function taking no parameters.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
template <typename TObject, TObject& Instance, void (TObject::*Function)()>
|
||||
class function_imv : public ifunction<void>
|
||||
|
||||
Class for a member function taking no parameters.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TObject, typename TParameter, void (TObject::*Function)(TParameter)>
|
||||
class function_mp : public ifunction<TParameter>
|
||||
|
||||
Class for a member function taking one parameter.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TObject, typename TParameter, TObject& Instance, void (TObject::*Function)(TParameter)>
|
||||
class function_imp : public ifunction<TParameter>
|
||||
|
||||
Class for a member function taking one parameter.
|
||||
____________________________________________________________________________________________________
|
||||
template <void (*Function)()>
|
||||
class function_fv : public ifunction<void>
|
||||
|
||||
Class for a free function taking no parameters.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TParameter, void (*Function)()>
|
||||
class function_fp : public ifunction<TParameter>
|
||||
|
||||
Class for a free function taking one parameter.
|
||||
|
||||
36
docs/raw/chrono/Chrono literals.txt
Normal file
36
docs/raw/chrono/Chrono literals.txt
Normal file
@ -0,0 +1,36 @@
|
||||
Chrono literals
|
||||
Back to chrono
|
||||
|
||||
The ETL Chrono literals are define slightly differently from the STL in that they are user defined, as opposed to language defined.
|
||||
|
||||
Example:-
|
||||
For STL, the literal to define year 2025 would be 2025y.
|
||||
For ETL, the literal is 2025_y.
|
||||
|
||||
By default, the ETL uses the designations of the STL.
|
||||
As this may clash with other user defined literals, the ETL allows more verbose forms to be used, by defining the macro ETL_USE_VERBOSE_CHRONO_LITERALS.
|
||||
If enabled, the example of 2025_y would be written as 2025_year.
|
||||
|
||||
Duration type STL like Verbose
|
||||
etl::chrono::year 2025_y 2025_year
|
||||
etl::chrono::day 10_d 10_day
|
||||
etl::chrono::hours 14_h 14_hours
|
||||
etl::chrono::minutes 30_min 30_minutes
|
||||
etl::chrono::seconds 45_s 45_seconds
|
||||
etl::chrono::milliseconds 500_ms 500_milliseconds
|
||||
etl::chrono::microseconds 500_us 500_microseconds
|
||||
etl::chrono::nanoseconds 500_ns 500_nanoseconds
|
||||
|
||||
Chrono literals may by accessed by using one of the following:-
|
||||
|
||||
using namespace etl::chrono;
|
||||
using namespace etl::literals;
|
||||
using namespace etl::chrono_literals;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
94
docs/raw/chrono/Clocks.txt
Normal file
94
docs/raw/chrono/Clocks.txt
Normal file
@ -0,0 +1,94 @@
|
||||
Clocks
|
||||
Back to chrono
|
||||
____________________________________________________________________________________________________
|
||||
Macros
|
||||
Default macro definitions.
|
||||
Define these in etl_profile.h to set your own duration types for the clocks.
|
||||
|
||||
ETL_CHRONO_SYSTEM_CLOCK_DURATION etl::chrono::nanoseconds
|
||||
ETL_CHRONO_SYSTEM_CLOCK_IS_STEADY true
|
||||
ETL_CHRONO_HIGH_RESOLUTION_CLOCK_DURATION etl::chrono::nanoseconds
|
||||
ETL_CHRONO_HIGH_RESOLUTION_CLOCK_IS_STEADY true
|
||||
ETL_CHRONO_STEADY_CLOCK_DURATION etl::chrono::nanoseconds
|
||||
____________________________________________________________________________________________________
|
||||
Platform clock access
|
||||
Declarations of the functions that must be defined to interface the clocks with the underlying platform.
|
||||
|
||||
extern "C" ETL_CHRONO_SYSTEM_CLOCK_DURATION::rep etl_get_system_clock();
|
||||
extern "C" ETL_CHRONO_HIGH_RESOLUTION_CLOCK_DURATION::rep etl_get_high_resolution_clock();
|
||||
extern "C" ETL_CHRONO_STEADY_CLOCK_DURATION::rep etl_get_steady_clock();
|
||||
|
||||
These functions must return the current count of the underlying clock. The value is in terms of the
|
||||
clock duration defined for that clock.
|
||||
|
||||
Example:
|
||||
If the system_clock duration is set to etl::chrono::nanoseconds, then a return value of 1000 represents 1000ns.
|
||||
____________________________________________________________________________________________________
|
||||
system_clock
|
||||
|
||||
class system_clock
|
||||
|
||||
Member types
|
||||
using duration = ETL_CHRONO_SYSTEM_CLOCK_DURATION
|
||||
using rep = duration::rep
|
||||
using period = duration::period
|
||||
using time_point = time_point<system_clock, duration>
|
||||
|
||||
Member functions
|
||||
static time_point now() ETL_NOEXCEPT
|
||||
static time_t to_time_t(const time_point& t) ETL_NOEXCEPT
|
||||
static time_point from_time_t(time_t t) ETL_NOEXCEPT
|
||||
____________________________________________________________________________________________________
|
||||
high_resolution_clock
|
||||
|
||||
class high_resolution_clock
|
||||
|
||||
Member types
|
||||
using duration = ETL_CHRONO_HIGH_RESOLUTION_CLOCK_DURATION
|
||||
using rep = duration::rep
|
||||
using period = duration::period
|
||||
using time_point = time_point<high_resolution_clock, duration>
|
||||
|
||||
Member functions
|
||||
static time_point now() ETL_NOEXCEPT
|
||||
____________________________________________________________________________________________________
|
||||
steady_clock
|
||||
|
||||
class steady_clock
|
||||
|
||||
Member types
|
||||
using duration = ETL_CHRONO_STEADY_CLOCK_DURATION
|
||||
using rep = duration::rep
|
||||
using period = duration::period
|
||||
using time_point = time_point<steady_clock, duration>
|
||||
|
||||
Member functions
|
||||
static time_point now() ETL_NOEXCEPT
|
||||
____________________________________________________________________________________________________
|
||||
system_time
|
||||
|
||||
template <typename Duration>
|
||||
using sys_time = etl::chrono::time_point<etl::chrono::system_clock, Duration>
|
||||
|
||||
using sys_seconds = sys_time<etl::chrono::seconds>
|
||||
using sys_days = sys_time<etl::chrono::days>
|
||||
____________________________________________________________________________________________________
|
||||
local_time
|
||||
|
||||
struct local_t
|
||||
|
||||
template <typename TDuration>
|
||||
using local_time = etl::chrono::time_point<etl::chrono::local_t, TDuration>
|
||||
|
||||
using local_seconds = local_time<etl::chrono::seconds>
|
||||
using local_days = local_time<etl::chrono::days>
|
||||
____________________________________________________________________________________________________
|
||||
clock_cast
|
||||
|
||||
Cast a time point from one clock to another.
|
||||
This implementation assumes all clock epochs are the same.
|
||||
|
||||
template <typename TToClock, typename TFromClock, typename TFromDuration>
|
||||
ETL_CONSTEXPR14 etl::chrono::time_point<TToClock, typename TToClock::duration>
|
||||
clock_cast(const etl::chrono::time_point<TFromClock, TFromDuration>& from_time_point) ETL_NOEXCEPT
|
||||
|
||||
224
docs/raw/chrono/Operators.txt
Normal file
224
docs/raw/chrono/Operators.txt
Normal file
@ -0,0 +1,224 @@
|
||||
Operators
|
||||
Operators for building dates.
|
||||
Back to chrono
|
||||
____________________________________________________________________________________________________
|
||||
month_day
|
||||
|
||||
Create from month and day.
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::month_day operator /(const etl::chrono::month& m,
|
||||
const etl::chrono::day& d)
|
||||
ETL_NOEXCEPT
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::month_day operator /(const etl::chrono::month& m,
|
||||
int d)
|
||||
ETL_NOEXCEPT
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::month_day operator /(int m,
|
||||
const etl::chrono::day& d)
|
||||
ETL_NOEXCEPT
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::month_day operator /(const etl::chrono::day& d,
|
||||
const etl::chrono::month& m)
|
||||
ETL_NOEXCEPT
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::month_day operator /(const etl::chrono::day& d,
|
||||
int m)
|
||||
ETL_NOEXCEPT
|
||||
____________________________________________________________________________________________________
|
||||
month_day_last
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::month_day_last operator /(const etl::chrono::month& m,
|
||||
etl::chrono::last_spec)
|
||||
ETL_NOEXCEPT
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::month_day_last operator /(int m,
|
||||
etl::chrono::last_spec)
|
||||
ETL_NOEXCEPT
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::month_day_last operator /(etl::chrono::last_spec,
|
||||
const etl::chrono::month& m)
|
||||
ETL_NOEXCEPT
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::month_day_last operator /(etl::chrono::last_spec,
|
||||
int m)
|
||||
ETL_NOEXCEPT
|
||||
____________________________________________________________________________________________________
|
||||
month_weekday
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::month_weekday operator /(const etl::chrono::month& m,
|
||||
const etl::chrono::weekday_indexed& wdi)
|
||||
ETL_NOEXCEPT
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::month_weekday operator /(int m,
|
||||
const etl::chrono::weekday_indexed& wdi)
|
||||
ETL_NOEXCEPT
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::month_weekday operator /(const etl::chrono::weekday_indexed& wdi,
|
||||
const etl::chrono::month& m)
|
||||
ETL_NOEXCEPT
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::month_weekday operator /(const etl::chrono::weekday_indexed& wdi,
|
||||
int m)
|
||||
ETL_NOEXCEPT
|
||||
____________________________________________________________________________________________________
|
||||
month_weekday_last
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::month_weekday_last operator /(const etl::chrono::month& m,
|
||||
const etl::chrono::weekday_last& wdl)
|
||||
ETL_NOEXCEPT
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::month_weekday_last operator /(int m,
|
||||
const etl::chrono::weekday_last& wdl)
|
||||
ETL_NOEXCEPT
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::month_weekday_last operator /(const etl::chrono::weekday_last& wdl,
|
||||
const etl::chrono::month& m)
|
||||
ETL_NOEXCEPT
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::month_weekday_last operator /(const etl::chrono::weekday_last& wdl,
|
||||
int m)
|
||||
ETL_NOEXCEPT
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
year_month
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month operator /(const etl::chrono::year& y,
|
||||
const etl::chrono::month& m)
|
||||
ETL_NOEXCEPT
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month operator /(const etl::chrono::year& y,
|
||||
int m)
|
||||
ETL_NOEXCEPT
|
||||
____________________________________________________________________________________________________
|
||||
year_month_day
|
||||
|
||||
ETL_CONSTEXPR14 etl::chrono::year_month_day operator /(const etl::chrono::year_month& ym,
|
||||
const etl::chrono::day& d)
|
||||
ETL_NOEXCEPT
|
||||
|
||||
ETL_CONSTEXPR14 etl::chrono::year_month_day operator /(const etl::chrono::year_month& ym,
|
||||
int d )
|
||||
ETL_NOEXCEPT
|
||||
____________________________________________________________________________________________________
|
||||
year_month_day
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month_day operator /(const etl::chrono::year& y,
|
||||
const etl::chrono::month_day& md)
|
||||
ETL_NOEXCEPT
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month_day operator /(int y,
|
||||
const etl::chrono::month_day& md)
|
||||
ETL_NOEXCEPT
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month_day operator /(const etl::chrono::month_day& md,
|
||||
const etl::chrono::year& y)
|
||||
ETL_NOEXCEPT
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month_day operator /(const etl::chrono::month_day& md,
|
||||
int y)
|
||||
ETL_NOEXCEPT
|
||||
____________________________________________________________________________________________________
|
||||
year_month_day_last
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month_day_last operator /(const etl::chrono::year_month& ym,
|
||||
etl::chrono::last_spec)
|
||||
ETL_NOEXCEPT
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month_day_last operator /(const etl::chrono::year& y,
|
||||
const etl::chrono::month_day_last& mdl)
|
||||
ETL_NOEXCEPT
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month_day_last operator /(int y,
|
||||
const etl::chrono::month_day_last& mdl)
|
||||
ETL_NOEXCEPT
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month_day_last operator /(const etl::chrono::month_day_last& mdl,
|
||||
const etl::chrono::year& y)
|
||||
ETL_NOEXCEPT
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month_day_last operator /(const etl::chrono::month_day_last& mdl,
|
||||
int y)
|
||||
ETL_NOEXCEPT
|
||||
____________________________________________________________________________________________________
|
||||
year_month_weekday
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month_weekday operator /(const etl::chrono::year_month& ym,
|
||||
const etl::chrono::weekday_indexed& wdi)
|
||||
ETL_NOEXCEPT
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month_weekday operator /(const etl::chrono::year& y,
|
||||
const etl::chrono::month_weekday& mwd)
|
||||
ETL_NOEXCEPT
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month_weekday operator /(int y,
|
||||
const etl::chrono::month_weekday& mwd)
|
||||
ETL_NOEXCEPT
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month_weekday operator /(const etl::chrono::month_weekday& mwd,
|
||||
const etl::chrono::year& y)
|
||||
ETL_NOEXCEPT
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month_weekday operator /(const etl::chrono::month_weekday& mwd,
|
||||
int y)
|
||||
ETL_NOEXCEPT
|
||||
____________________________________________________________________________________________________
|
||||
year_month_weekday_last
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month_weekday_last operator /(const etl::chrono::year_month& ym,
|
||||
const etl::chrono::weekday_last& wdl)
|
||||
ETL_NOEXCEPT
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month_weekday_last operator /(const etl::chrono::year& y,
|
||||
const etl::chrono::month_weekday_last& mwdl)
|
||||
ETL_NOEXCEPT
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month_weekday_last operator /(int y,
|
||||
const etl::chrono::month_weekday_last& mwdl)
|
||||
ETL_NOEXCEPT
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month_weekday_last operator /(const etl::chrono::month_weekday_last& mwdl,
|
||||
const etl::chrono::year& y)
|
||||
ETL_NOEXCEPT
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month_weekday_last operator /(const etl::chrono::month_weekday_last& mwdl,
|
||||
int y)
|
||||
ETL_NOEXCEPT
|
||||
197
docs/raw/chrono/day.txt
Normal file
197
docs/raw/chrono/day.txt
Normal file
@ -0,0 +1,197 @@
|
||||
day
|
||||
A template representing a day.
|
||||
Back to chrono
|
||||
____________________________________________________________________________________________________
|
||||
day
|
||||
|
||||
STL equivalent: std::chrono::day
|
||||
|
||||
class day
|
||||
____________________________________________________________________________________________________
|
||||
Typesdefs
|
||||
rep The internal representation.
|
||||
____________________________________________________________________________________________________
|
||||
Construction
|
||||
|
||||
ETL_CONSTEXPR
|
||||
day()
|
||||
ETL_NOEXCEPT
|
||||
Default constructor.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR
|
||||
explicit day(unsigned value)
|
||||
ETL_NOEXCEPT
|
||||
Construct from unsigned.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
day(const etl::chrono::day& other)
|
||||
ETL_NOEXCEPT
|
||||
Copy constructor.
|
||||
____________________________________________________________________________________________________
|
||||
Tests
|
||||
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
bool ok() const
|
||||
ETL_NOEXCEPT
|
||||
Returns true if the day is within the valid range.
|
||||
______________________________________________
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
int compare(const etl::chrono::day& other) const
|
||||
ETL_NOEXCEPT
|
||||
Compare day with another.
|
||||
if day < other, returns -1
|
||||
else if day > other, returns 1
|
||||
else returns 0
|
||||
____________________________________________________________________________________________________
|
||||
Assignment
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::day& operator =(const etl::chrono::day& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Assignment operator
|
||||
____________________________________________________________________________________________________
|
||||
Increment/decrement
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::day& operator ++()
|
||||
ETL_NOEXCEPT
|
||||
Pre-increment operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::day operator ++(int)
|
||||
ETL_NOEXCEPT
|
||||
Post-increment operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::day& operator --()
|
||||
ETL_NOEXCEPT
|
||||
Pre-decrement operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::day operator --(int)
|
||||
ETL_NOEXCEPT
|
||||
Post-decrement operator.
|
||||
____________________________________________________________________________________________________
|
||||
Mathematical operators
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::day& operator +=(const etl::chrono::days& ms)
|
||||
ETL_NOEXCEPT
|
||||
Plus-equals operator adding etl::chrono::days.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::day& operator -=(const etl::chrono::days& ms)
|
||||
ETL_NOEXCEPT
|
||||
Minus-equals operator subtracting etl::chrono::days.
|
||||
____________________________________________________________________________________________________
|
||||
Conversion
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
operator unsigned() const
|
||||
ETL_NOEXCEPT
|
||||
Conversion operator to unsigned int.
|
||||
____________________________________________________________________________________________________
|
||||
Non-member mathematical operators
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::day operator +(const etl::chrono::day& m,
|
||||
const etl::chrono::days& ms)
|
||||
ETL_NOEXCEPT
|
||||
Add etl::chrono::days to etl::chrono::day.
|
||||
Returns etl::chrono::day.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::day operator +(const etl::chrono::days& ms,
|
||||
const etl::chrono::day& m)
|
||||
ETL_NOEXCEPT
|
||||
Add etl::chrono::day to etl::chrono::days.
|
||||
Returns etl::chrono::day.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::day operator -(const etl::chrono::day& m,
|
||||
const etl::chrono::days& ms)
|
||||
ETL_NOEXCEPT
|
||||
Subtract etl::chrono::days from etl::chrono::day.
|
||||
Returns etl::chrono::day.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::day operator -(const etl::chrono::days& ms,
|
||||
const etl::chrono::day& m)
|
||||
ETL_NOEXCEPT
|
||||
Subtract etl::chrono::day from etl::chrono::days.
|
||||
Returns etl::chrono::days.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::days operator -(const etl::chrono::day& m1,
|
||||
const etl::chrono::day& m2) ETL_NOEXCEPT
|
||||
Subtract etl::chrono::day from etl::chrono::day.
|
||||
Returns etl::chrono::days.
|
||||
____________________________________________________________________________________________________
|
||||
Non-member comparison operators
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
bool operator ==(const etl::chrono::day& m1,
|
||||
const etl::chrono::day& m2)
|
||||
ETL_NOEXCEPT
|
||||
Equality operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
bool operator !=(const etl::chrono::day& m1,
|
||||
const etl::chrono::day& m2)
|
||||
ETL_NOEXCEPT
|
||||
Inequality operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
bool operator <(const etl::chrono::day& m1,
|
||||
const etl::chrono::day& m2)
|
||||
ETL_NOEXCEPT
|
||||
Less-than operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
bool operator <=(const etl::chrono::day& m1,
|
||||
const etl::chrono::day& m2)
|
||||
ETL_NOEXCEPT
|
||||
Less-than-or-equal operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
bool operator >(const etl::chrono::day& m1,
|
||||
const etl::chrono::day& m2)
|
||||
ETL_NOEXCEPT
|
||||
Greater-than operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
bool operator >=(const etl::chrono::day& m1,
|
||||
const etl::chrono::day& m2)
|
||||
ETL_NOEXCEPT
|
||||
Greater-than-or-equal operator.
|
||||
______________________________________________
|
||||
[[nodiscard]] inline constexpr
|
||||
auto operator <=>(const etl::chrono::day& m1,
|
||||
const etl::chrono::day& m2)
|
||||
noexcept
|
||||
Spaceship operator.
|
||||
C++20
|
||||
____________________________________________________________________________________________________
|
||||
Defined days
|
||||
|
||||
etl::chrono::January
|
||||
etl::chrono::February
|
||||
etl::chrono::March
|
||||
etl::chrono::April
|
||||
etl::chrono::May
|
||||
etl::chrono::June
|
||||
etl::chrono::July
|
||||
etl::chrono::August
|
||||
etl::chrono::September
|
||||
etl::chrono::October
|
||||
etl::chrono::November
|
||||
etl::chrono::December
|
||||
____________________________________________________________________________________________________
|
||||
Hash
|
||||
|
||||
template <>
|
||||
struct hash<etl::chrono::day>
|
||||
Hash function for etl::chrono::day
|
||||
|
||||
335
docs/raw/chrono/duration.txt
Normal file
335
docs/raw/chrono/duration.txt
Normal file
@ -0,0 +1,335 @@
|
||||
duration
|
||||
Templates representing a time intervals.
|
||||
Back to chrono
|
||||
____________________________________________________________________________________________________
|
||||
duration_values
|
||||
|
||||
STL equivalent: std::chrono::duration_values
|
||||
|
||||
template <typename TRep>
|
||||
struct duration_values
|
||||
|
||||
ETL_NODISCARD static ETL_CONSTEXPR TRep zero() ETL_NOEXCEPT
|
||||
Returns TRep(0)
|
||||
______________________________________________
|
||||
ETL_NODISCARD static ETL_CONSTEXPR14 TRep min() ETL_NOEXCEPT
|
||||
Returns etl::numeric_limits<TRep>::min()
|
||||
______________________________________________
|
||||
ETL_NODISCARD static ETL_CONSTEXPR14 TRep max() ETL_NOEXCEPT
|
||||
Returns etl::numeric_limits<TRep>::max()
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
duration
|
||||
|
||||
STL equivalent: std::chrono::duration
|
||||
|
||||
template <typename TRep, typename TPeriod = etl::ratio<1>>
|
||||
class duration
|
||||
______________________________________________
|
||||
using rep = TRep
|
||||
using period = typename TPeriod::type;
|
||||
____________________________________________________________________________________________________
|
||||
Construction
|
||||
|
||||
ETL_CONSTEXPR
|
||||
duration()
|
||||
ETL_NOEXCEPT
|
||||
Default constructor.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
duration(const etl::chrono::duration<TRep, TPeriod>& other)
|
||||
ETL_NOEXCEPT
|
||||
______________________________________________
|
||||
template <typename TRep2>
|
||||
ETL_CONSTEXPR14
|
||||
explicit duration(const TRep2& value)
|
||||
ETL_NOEXCEPT
|
||||
______________________________________________
|
||||
template <typename TRep2, typename TPeriod2>
|
||||
ETL_CONSTEXPR14
|
||||
duration(const etl::chrono::duration<TRep2, TPeriod2>& other)
|
||||
ETL_NOEXCEPT
|
||||
Construct from another duration type.
|
||||
Enabled if etl::ratio_divide<TPeriod2, TPeriod>::den == 1
|
||||
____________________________________________________________________________________________________
|
||||
Tests
|
||||
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
int compare(const time_point& other) const
|
||||
ETL_NOEXCEPT
|
||||
Compare day with another.
|
||||
if time_point < other, returns -1
|
||||
else if time_point > other, returns 1
|
||||
else returns 0
|
||||
____________________________________________________________________________________________________
|
||||
Assignment
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::duration<TRep, TPeriod> operator =(const etl::chrono::duration<TRep, TPeriod>& other) ETL_NOEXCEPT
|
||||
______________________________________________
|
||||
template <typename TRep2, typename TPeriod2>
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::duration<TRep, TPeriod> operator =(const etl::chrono::duration<TRep2, TPeriod2>& other) ETL_NOEXCEPT
|
||||
____________________________________________________________________________________________________
|
||||
Convertion
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
TRep count() const
|
||||
ETL_NOEXCEPT
|
||||
Returns the duration count as a numeric.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::common_type_t<duration> operator +() const
|
||||
ETL_NOEXCEPT
|
||||
Implements unary plus.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::common_type_t<duration> operator -() const
|
||||
ETL_NOEXCEPT
|
||||
Implements unary minus.
|
||||
______________________________________________
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::duration<TRep, TPeriod> absolute() const
|
||||
ETL_NOEXCEPT
|
||||
Returns the absolute value of the duration.
|
||||
____________________________________________________________________________________________________
|
||||
Constants
|
||||
|
||||
ETL_NODISCARD
|
||||
static ETL_CONSTEXPR14 etl::chrono::duration<TRep, TPeriod> zero()
|
||||
ETL_NOEXCEPT
|
||||
Returns the duration zero value.
|
||||
______________________________________________
|
||||
ETL_NODISCARD
|
||||
static ETL_CONSTEXPR14 etl::chrono::duration<TRep, TPeriod> min()
|
||||
ETL_NOEXCEPT
|
||||
Returns the minimum duration value.
|
||||
______________________________________________
|
||||
ETL_NODISCARD
|
||||
static ETL_CONSTEXPR14 etl::chrono::duration<TRep, TPeriod> max()
|
||||
ETL_NOEXCEPT
|
||||
Returns the maximum duration value.
|
||||
____________________________________________________________________________________________________
|
||||
Increment/decrement
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
duration& operator ++()
|
||||
ETL_NOEXCEPT
|
||||
Pre-increments the duration count.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
duration operator ++(int)
|
||||
ETL_NOEXCEPT
|
||||
Post-increments the duration count.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
duration& operator --()
|
||||
ETL_NOEXCEPT
|
||||
Pre-decrements the duration count.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
duration operator --(int)
|
||||
ETL_NOEXCEPT
|
||||
Post-decrements the duration count.
|
||||
____________________________________________________________________________________________________
|
||||
Mathematical operators
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
duration& operator +=(const duration<TRep, TPeriod>& d)
|
||||
ETL_NOEXCEPT
|
||||
Adds duration d to this duration.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
duration& operator -=(const duration<TRep, TPeriod>& d)
|
||||
ETL_NOEXCEPT
|
||||
Subtracts duration d to this duration.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
duration& operator *=(const TRep& r)
|
||||
ETL_NOEXCEPT
|
||||
Multiplies this duration by r.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
duration& operator /=(const TRep& r)
|
||||
ETL_NOEXCEPT
|
||||
Divides this duration by r.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
duration& operator %=(const TRep& r)
|
||||
ETL_NOEXCEPT
|
||||
Sets this duration to the modulus of r.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
duration& operator %=(const duration<TRep, TPeriod>& d)
|
||||
ETL_NOEXCEPT
|
||||
Sets this duration to the modulus of duration d.
|
||||
____________________________________________________________________________________________________
|
||||
Comparison
|
||||
|
||||
template <typename TRep2, typename TPeriod2>
|
||||
ETL_CONSTEXPR14
|
||||
int compare(const duration<TRep2, TPeriod2>& other) const
|
||||
ETL_NOEXCEPT
|
||||
Compare duration with another.
|
||||
If duration < other, returns -1
|
||||
else if duration > other, returns 1
|
||||
else returns 0
|
||||
____________________________________________________________________________________________________
|
||||
Non-member mathematical operators
|
||||
|
||||
template <typename TRep1, typename TPeriod1, typename TRep2, typename TPeriod2>
|
||||
ETL_CONSTEXPR14
|
||||
etl::common_type_t<etl::chrono::duration<TRep1, TPeriod1>,
|
||||
etl::chrono::duration<TRep2, TPeriod2>>
|
||||
operator +(const etl::chrono::duration<TRep1, TPeriod1>& lhs,
|
||||
const etl::chrono::duration<TRep2, TPeriod2>& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Operator +
|
||||
______________________________________________
|
||||
template <typename TRep1, typename TPeriod1, typename TRep2, typename TPeriod2>
|
||||
ETL_CONSTEXPR14
|
||||
etl::common_type_t<etl::chrono::duration<TRep1, TPeriod1>,
|
||||
etl::chrono::duration<TRep2, TPeriod2> >::type
|
||||
operator -(const etl::chrono::duration<TRep1, TPeriod1>& lhs,
|
||||
const etl::chrono::duration<TRep2, TPeriod2>& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Operator -
|
||||
______________________________________________
|
||||
template <typename TRep1, typename TPeriod1, typename TRep2>
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::duration<etl::common_type_t<TRep1, TRep2>, TPeriod1>>
|
||||
operator *(const etl::chrono::duration<TRep1, TPeriod1>& lhs,
|
||||
const TRep2& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Operator *
|
||||
Enabled if TRep2 is not a specialization of etl::chrono::duration.
|
||||
______________________________________________
|
||||
template <typename TRep1, typename TRep2, typename TPeriod2>
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::duration<etl::common_type_t<TRep1, TRep2>, TPeriod2>
|
||||
operator *(const TRep1& lhs,
|
||||
const etl::chrono::duration<TRep2, TPeriod2>& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Operator *
|
||||
______________________________________________
|
||||
template <typename TRep1, typename TPeriod1, typename TRep2>
|
||||
ETL_CONSTEXPR14
|
||||
etl::common_type_t<TRep1, TRep2>, TPeriod1>
|
||||
operator /(const etl::chrono::duration<TRep1, TPeriod1>& lhs,
|
||||
const TRep2& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Operator /
|
||||
Enabled if TRep2 is not a specialization of etl::chrono::duration.
|
||||
______________________________________________
|
||||
template <typename TRep1, typename TPeriod1, typename TRep2, typename TPeriod2>
|
||||
ETL_CONSTEXPR14
|
||||
etl::common_type_t<TRep1, TRep2>
|
||||
operator /(const etl::chrono::duration<TRep1, TPeriod1>& lhs,
|
||||
const etl::chrono::duration<TRep2, TPeriod2>& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Operator /
|
||||
______________________________________________
|
||||
template <typename TRep1, typename TPeriod1, typename TRep2>
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::duration<etl::common_type_t<TRep1, TRep2>, TPeriod1>
|
||||
operator %(const etl::chrono::duration<TRep1, TPeriod1>& lhs,
|
||||
const TRep2& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Operator %
|
||||
______________________________________________
|
||||
template <typename TRep1, typename TPeriod1, typename TRep2, typename TPeriod2>
|
||||
ETL_CONSTEXPR14
|
||||
etl::common_type_t<etl::chrono::duration<TRep1, TPeriod1>,
|
||||
etl::chrono::duration<TRep2, TPeriod2>>
|
||||
operator %(const etl::chrono::duration<TRep1, TPeriod1>& lhs,
|
||||
const etl::chrono::duration<TRep2, TPeriod2>& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Operator %
|
||||
____________________________________________________________________________________________________
|
||||
Non-member comparison operators
|
||||
|
||||
template <typename TRep1, typename TPeriod1, typename TRep2, typename TPeriod2>
|
||||
ETL_CONSTEXPR14
|
||||
bool operator ==(const etl::chrono::duration<TRep1, TPeriod1>& lhs,
|
||||
const etl::chrono::duration<TRep2, TPeriod2>& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Checks for equality.
|
||||
______________________________________________
|
||||
template <typename TRep1, typename TPeriod1, typename TRep2, typename TPeriod2>
|
||||
ETL_CONSTEXPR14
|
||||
bool operator !=(const etl::chrono::duration<TRep1, TPeriod1>& lhs,
|
||||
const etl::chrono::duration<TRep2, TPeriod2>& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Checks for inequality.
|
||||
______________________________________________
|
||||
template <typename TRep1, typename TPeriod1, typename TRep2, typename TPeriod2>
|
||||
ETL_CONSTEXPR14
|
||||
bool operator <(const etl::chrono::duration<TRep1, TPeriod1>& lhs,
|
||||
const etl::chrono::duration<TRep2, TPeriod2>& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Checks for less-than.
|
||||
______________________________________________
|
||||
template <typename TRep1, typename TPeriod1, typename TRep2, typename TPeriod2>
|
||||
ETL_CONSTEXPR14
|
||||
bool operator <=(const etl::chrono::duration<TRep1, TPeriod1>& lhs,
|
||||
const etl::chrono::duration<TRep2, TPeriod2>& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Checks for less-than-or-equal.
|
||||
______________________________________________
|
||||
template <typename TRep1, typename TPeriod1, typename TRep2, typename TPeriod2>
|
||||
ETL_CONSTEXPR14
|
||||
bool operator >(const etl::chrono::duration<TRep1, TPeriod1>& lhs,
|
||||
const etl::chrono::duration<TRep2, TPeriod2>& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Checks for greater-than.
|
||||
______________________________________________
|
||||
template <typename TRep1, typename TPeriod1, typename TRep2, typename TPeriod2>
|
||||
ETL_CONSTEXPR14
|
||||
bool operator >=(const etl::chrono::duration<TRep1, TPeriod1>& lhs,
|
||||
const etl::chrono::duration<TRep2, TPeriod2>& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Checks for greater-than-or-equal.
|
||||
______________________________________________
|
||||
template <typename TRep1, typename TPeriod1, typename TRep2, typename TPeriod2>
|
||||
[[nodiscard]]
|
||||
constexpr
|
||||
auto operator <=>(const etl::chrono::duration<TRep1, TPeriod1>& lhs,
|
||||
const etl::chrono::duration<TRep2, TPeriod2>& rhs)
|
||||
noexcept
|
||||
Spaceship operator.
|
||||
C++20
|
||||
____________________________________________________________________________________________________
|
||||
common_type
|
||||
|
||||
template <typename TRep1, typename TPeriod1, typename TRep2, typename TPeriod2>
|
||||
struct common_type<etl::chrono::duration<TRep1, TPeriod1>, etl::chrono::duration<TRep2, TPeriod2>>
|
||||
etl::common_type specialisation for etl::duration.
|
||||
____________________________________________________________________________________________________
|
||||
Hash
|
||||
|
||||
template <typename TRep, typename TPeriod>
|
||||
struct hash<etl::chrono::duration<TRep, TPeriod>>
|
||||
____________________________________________________________________________________________________
|
||||
Pre-defined duration types
|
||||
|
||||
etl::chrono::years
|
||||
etl::chrono::months
|
||||
etl::chrono::weeks
|
||||
etl::chrono::days
|
||||
etl::chrono::hours
|
||||
etl::chrono::minutes
|
||||
etl::chrono::seconds
|
||||
etl::chrono::milliseconds
|
||||
etl::chrono::microseconds
|
||||
etl::chrono::nanoseconds
|
||||
____________________________________________________________________________________________________
|
||||
duration_cast
|
||||
|
||||
template <typename TToDuration, typename TRep, typename TPeriod>
|
||||
ETL_CONSTEXPR14
|
||||
TToDuration duration_cast(const etl::chrono::duration<TRep, TPeriod>& d)
|
||||
ETL_NOEXCEPT
|
||||
Converts from one duration type to another.
|
||||
|
||||
87
docs/raw/chrono/hh_mm_ss.txt
Normal file
87
docs/raw/chrono/hh_mm_ss.txt
Normal file
@ -0,0 +1,87 @@
|
||||
hh_mm_ss
|
||||
A type to hold hous, minutes, and seconds.
|
||||
Back to chrono
|
||||
____________________________________________________________________________________________________
|
||||
absolute
|
||||
|
||||
template <typename TDuration>
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
TDuration absolute(TDuration dur)
|
||||
ETL_NOEXCEPT
|
||||
A specialisation of absolute for etl::chrono::duration.
|
||||
Returns the absolute duration value.
|
||||
____________________________________________________________________________________________________
|
||||
hh_mm_ss
|
||||
|
||||
template <typename TDuration>
|
||||
class hh_mm_ss
|
||||
|
||||
Static asserts if TDuration is not a specialisation of etl::chrono::duration.
|
||||
____________________________________________________________________________________________________
|
||||
Class constant
|
||||
|
||||
static constexpr int fractional_width;
|
||||
The number of fractional digits.
|
||||
____________________________________________________________________________________________________
|
||||
Class type
|
||||
|
||||
precision
|
||||
The return type for to_duration.
|
||||
____________________________________________________________________________________________________
|
||||
Constructors
|
||||
|
||||
ETL_CONSTEXPR
|
||||
hh_mm_ss()
|
||||
ETL_NOEXCEPT
|
||||
Default constructor.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
explicit hh_mm_ss(TDuration d)
|
||||
ETL_NOEXCEPT
|
||||
Construct from duration.
|
||||
____________________________________________________________________________________________________
|
||||
Access
|
||||
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
bool is_negative() const
|
||||
ETL_NOEXCEPT
|
||||
Checks for negative duration.
|
||||
______________________________________________
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::hours hours() const
|
||||
ETL_NOEXCEPT
|
||||
Returns the hours.
|
||||
______________________________________________
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::minutes minutes() const
|
||||
ETL_NOEXCEPT
|
||||
Returns the minutes.
|
||||
______________________________________________
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::seconds seconds() const
|
||||
ETL_NOEXCEPT
|
||||
Returns the seconds.
|
||||
______________________________________________
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
precision subseconds() const
|
||||
ETL_NOEXCEPT
|
||||
Returns the subseconds.
|
||||
______________________________________________
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
explicit operator precision() const
|
||||
ETL_NOEXCEPT
|
||||
Returns the duration.
|
||||
______________________________________________
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
precision to_duration() const
|
||||
ETL_NOEXCEPT
|
||||
Returns the duration.
|
||||
|
||||
17
docs/raw/chrono/last_spec.txt
Normal file
17
docs/raw/chrono/last_spec.txt
Normal file
@ -0,0 +1,17 @@
|
||||
last_spec
|
||||
last_spec is a tag type that is used in conjunction with other calendar types to indicate the last thing in a sequence.
|
||||
Back to chrono
|
||||
____________________________________________________________________________________________________
|
||||
last_spec
|
||||
|
||||
struct last_spec
|
||||
{
|
||||
explicit last_spec() = default;
|
||||
};
|
||||
|
||||
inline constexpr last_spec last{};
|
||||
|
||||
Example:
|
||||
|
||||
2025_y/March/last for last day of March 2025 i.e. 2025-03-31
|
||||
|
||||
213
docs/raw/chrono/month.txt
Normal file
213
docs/raw/chrono/month.txt
Normal file
@ -0,0 +1,213 @@
|
||||
month
|
||||
A template representing a month.
|
||||
Back to chrono
|
||||
____________________________________________________________________________________________________
|
||||
month
|
||||
|
||||
STL equivalent: std::chrono::month
|
||||
|
||||
class month
|
||||
____________________________________________________________________________________________________
|
||||
Typesdefs
|
||||
rep The internal representation.
|
||||
____________________________________________________________________________________________________
|
||||
Construction
|
||||
|
||||
ETL_CONSTEXPR
|
||||
month()
|
||||
ETL_NOEXCEPT
|
||||
Default constructor.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR
|
||||
explicit month(unsigned value)
|
||||
ETL_NOEXCEPT
|
||||
Construct from unsigned.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
month(const etl::chrono::month& other)
|
||||
ETL_NOEXCEPT
|
||||
Copy constructor.
|
||||
____________________________________________________________________________________________________
|
||||
Tests
|
||||
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
bool ok() const
|
||||
ETL_NOEXCEPT
|
||||
Returns true if the month is in range.
|
||||
______________________________________________
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
int compare(const etl::chrono::month& other) const
|
||||
ETL_NOEXCEPT
|
||||
Compare month with another.
|
||||
if month < other, returns -1
|
||||
else if month > other, returns 1
|
||||
else returns 0
|
||||
____________________________________________________________________________________________________
|
||||
Assignment
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::month& operator =(const etl::chrono::month& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Assignment operator
|
||||
____________________________________________________________________________________________________
|
||||
Increment/decrement
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::month& operator ++()
|
||||
ETL_NOEXCEPT
|
||||
Pre-increment operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::month operator ++(int)
|
||||
ETL_NOEXCEPT
|
||||
Post-increment operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::month& operator --()
|
||||
ETL_NOEXCEPT
|
||||
Pre-decrement operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::month operator --(int)
|
||||
ETL_NOEXCEPT
|
||||
Post-decrement operator.
|
||||
____________________________________________________________________________________________________
|
||||
Mathematical operators
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::month& operator +=(const etl::chrono::months& ms)
|
||||
ETL_NOEXCEPT
|
||||
Plus-equals operator adding etl::chrono::months.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::month& operator -=(const etl::chrono::months& ms)
|
||||
ETL_NOEXCEPT
|
||||
Minus-equals operator subtracting etl::chrono::months.
|
||||
____________________________________________________________________________________________________
|
||||
Constants
|
||||
|
||||
ETL_NODISCARD
|
||||
static
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::month min()
|
||||
ETL_NOEXCEPT
|
||||
The minimum month value for which ok() will return true.
|
||||
______________________________________________
|
||||
ETL_NODISCARD
|
||||
static
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::month max()
|
||||
ETL_NOEXCEPT
|
||||
The maximum month value for which ok() will return true.
|
||||
____________________________________________________________________________________________________
|
||||
Conversion
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
operator unsigned() const
|
||||
ETL_NOEXCEPT
|
||||
Conversion operator to unsigned int.
|
||||
____________________________________________________________________________________________________
|
||||
Non-member mathematical operators
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::month operator +(const etl::chrono::month& m,
|
||||
const etl::chrono::months& ms)
|
||||
ETL_NOEXCEPT
|
||||
Add etl::chrono::months to etl::chrono::month.
|
||||
Returns etl::chrono::month.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::month operator +(const etl::chrono::months& ms,
|
||||
const etl::chrono::month& m)
|
||||
ETL_NOEXCEPT
|
||||
Add etl::chrono::month to etl::chrono::months.
|
||||
Returns etl::chrono::month.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::month operator -(const etl::chrono::month& m,
|
||||
const etl::chrono::months& ms)
|
||||
ETL_NOEXCEPT
|
||||
Subtract etl::chrono::months from etl::chrono::month.
|
||||
Returns etl::chrono::month.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::month operator -(const etl::chrono::months& ms,
|
||||
const etl::chrono::month& m)
|
||||
ETL_NOEXCEPT
|
||||
Subtract etl::chrono::month from etl::chrono::months.
|
||||
Returns etl::chrono::months.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::months operator -(const etl::chrono::month& m1,
|
||||
const etl::chrono::month& m2) ETL_NOEXCEPT
|
||||
Subtract etl::chrono::month from etl::chrono::month.
|
||||
Returns etl::chrono::months.
|
||||
____________________________________________________________________________________________________
|
||||
Non-member comparison operators
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
bool operator ==(const etl::chrono::month& m1,
|
||||
const etl::chrono::month& m2)
|
||||
ETL_NOEXCEPT
|
||||
Equality operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
bool operator !=(const etl::chrono::month& m1,
|
||||
const etl::chrono::month& m2)
|
||||
ETL_NOEXCEPT
|
||||
Inequality operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
bool operator <(const etl::chrono::month& m1,
|
||||
const etl::chrono::month& m2)
|
||||
ETL_NOEXCEPT
|
||||
Less-than operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
bool operator <=(const etl::chrono::month& m1,
|
||||
const etl::chrono::month& m2)
|
||||
ETL_NOEXCEPT
|
||||
Less-than-or-equal operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
bool operator >(const etl::chrono::month& m1,
|
||||
const etl::chrono::month& m2)
|
||||
ETL_NOEXCEPT
|
||||
Greater-than operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
bool operator >=(const etl::chrono::month& m1,
|
||||
const etl::chrono::month& m2)
|
||||
ETL_NOEXCEPT
|
||||
Greater-than-or-equal operator.
|
||||
______________________________________________
|
||||
[[nodiscard]] inline constexpr
|
||||
auto operator <=>(const etl::chrono::month& m1,
|
||||
const etl::chrono::month& m2)
|
||||
noexcept
|
||||
Spaceship operator.
|
||||
C++20
|
||||
____________________________________________________________________________________________________
|
||||
Defined months
|
||||
|
||||
etl::chrono::January
|
||||
etl::chrono::February
|
||||
etl::chrono::March
|
||||
etl::chrono::April
|
||||
etl::chrono::May
|
||||
etl::chrono::June
|
||||
etl::chrono::July
|
||||
etl::chrono::August
|
||||
etl::chrono::September
|
||||
etl::chrono::October
|
||||
etl::chrono::November
|
||||
etl::chrono::December
|
||||
____________________________________________________________________________________________________
|
||||
Hash
|
||||
|
||||
template <>
|
||||
struct hash<etl::chrono::month>
|
||||
Hash function for etl::chrono::month
|
||||
|
||||
104
docs/raw/chrono/month_day.txt
Normal file
104
docs/raw/chrono/month_day.txt
Normal file
@ -0,0 +1,104 @@
|
||||
month_day
|
||||
A template representing a month and day.
|
||||
Back to chrono
|
||||
____________________________________________________________________________________________________
|
||||
month_day
|
||||
|
||||
STL equivalent: std::chrono::month_day
|
||||
|
||||
class month_day
|
||||
____________________________________________________________________________________________________
|
||||
Construction
|
||||
|
||||
ETL_CONSTEXPR
|
||||
month_day()
|
||||
Default constructor.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
month_day(const etl::chrono::month& m,
|
||||
const etl::chrono::day& d)
|
||||
ETL_NOEXCEPT
|
||||
Construct from month and day.
|
||||
____________________________________________________________________________________________________
|
||||
Access
|
||||
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::month month() const
|
||||
ETL_NOEXCEPT
|
||||
Returns the month.
|
||||
______________________________________________
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::day day() const
|
||||
ETL_NOEXCEPT
|
||||
Returns the day.
|
||||
____________________________________________________________________________________________________
|
||||
Tests
|
||||
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
bool ok() const
|
||||
ETL_NOEXCEPT
|
||||
Returns true if the month and day is within the valid limits.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
int compare(const month_day& other) const
|
||||
ETL_NOEXCEPT
|
||||
Compare month_day with another.
|
||||
if month < other.month, returns -1
|
||||
else if month > other.month, returns 1
|
||||
else if day < other.day, returns -1
|
||||
else if day > other.day, returns 1
|
||||
else returns 0
|
||||
____________________________________________________________________________________________________
|
||||
Non-member comparison operators
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
bool operator ==(const etl::chrono::month_day& lhs,
|
||||
const etl::chrono::month_day& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Equality operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
bool operator !=(const etl::chrono::month_day& lhs,
|
||||
const etl::chrono::month_day& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Inequality operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
bool operator <(const etl::chrono::month_day& lhs,
|
||||
const etl::chrono::month_day& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Less-than operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
bool operator <=(const etl::chrono::month_day& lhs,
|
||||
const etl::chrono::month_day& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Less-than-equal operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
bool operator <(const etl::chrono::month_day& lhs,
|
||||
const etl::chrono::month_day& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Greater-than operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
bool operator <=(const etl::chrono::month_day& lhs,
|
||||
const etl::chrono::month_day& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Greater-than-equal operator.
|
||||
______________________________________________
|
||||
[[nodiscard]] constexpr
|
||||
auto operator <=>(const etl::chrono::month_day& lhs,
|
||||
const etl::chrono::month_day& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Spaceship operator
|
||||
____________________________________________________________________________________________________
|
||||
Hash
|
||||
|
||||
template <typename TRep, typename TPeriod>
|
||||
struct hash<etl::chrono::month_day>
|
||||
Hash function for etl::chrono::month_day
|
||||
|
||||
91
docs/raw/chrono/month_day_last.txt
Normal file
91
docs/raw/chrono/month_day_last.txt
Normal file
@ -0,0 +1,91 @@
|
||||
month_day_last
|
||||
A template representing a month and day.
|
||||
Back to chrono
|
||||
____________________________________________________________________________________________________
|
||||
month_day_last
|
||||
|
||||
STL equivalent: std::chrono::month_day_last
|
||||
|
||||
class month_day_last
|
||||
____________________________________________________________________________________________________
|
||||
Construction
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
explicit month_day_last(const etl::chrono::month& m)
|
||||
ETL_NOEXCEPT
|
||||
Construct from month.
|
||||
____________________________________________________________________________________________________
|
||||
Access
|
||||
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::month month() const
|
||||
ETL_NOEXCEPT
|
||||
Returns the month.
|
||||
____________________________________________________________________________________________________
|
||||
Tests
|
||||
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
bool ok() const
|
||||
ETL_NOEXCEPT
|
||||
Returns true if the month is within the valid limits.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
int compare(const month_day_last& other) const
|
||||
ETL_NOEXCEPT
|
||||
Compare month_day_last with another.
|
||||
if month < other.month, returns -1
|
||||
else if month > other.month, returns 1
|
||||
else returns 0
|
||||
____________________________________________________________________________________________________
|
||||
Non-member comparison operators
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
bool operator ==(const etl::chrono::month_day_last& lhs,
|
||||
const etl::chrono::month_day_last& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Equality operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
bool operator !=(const etl::chrono::month_day_last& lhs,
|
||||
const etl::chrono::month_day_last& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Inequality operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
bool operator <(const etl::chrono::month_day_last& lhs,
|
||||
const etl::chrono::month_day_last& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Less-than operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
bool operator <=(const etl::chrono::month_day_last& lhs,
|
||||
const etl::chrono::month_day_last& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Less-than-equal operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
bool operator <(const etl::chrono::month_day_last& lhs,
|
||||
const etl::chrono::month_day_last& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Greater-than operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
bool operator <=(const etl::chrono::month_day_last& lhs,
|
||||
const etl::chrono::month_day_last& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Greater-than-equal operator.
|
||||
______________________________________________
|
||||
[[nodiscard]] constexpr
|
||||
auto operator <=>(const etl::chrono::month_day_last& lhs,
|
||||
const etl::chrono::month_day_last& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Spaceship operator
|
||||
____________________________________________________________________________________________________
|
||||
Hash
|
||||
|
||||
template <typename TRep, typename TPeriod>
|
||||
struct hash<etl::chrono::month_day_last>
|
||||
Hash function for etl::chrono::month_day_last
|
||||
|
||||
94
docs/raw/chrono/month_weekday.txt
Normal file
94
docs/raw/chrono/month_weekday.txt
Normal file
@ -0,0 +1,94 @@
|
||||
month_weekday
|
||||
A template representing a month and weekday.
|
||||
Back to chrono
|
||||
____________________________________________________________________________________________________
|
||||
month_weekday
|
||||
|
||||
STL equivalent: std::chrono::month_weekday
|
||||
|
||||
class month_weekday
|
||||
____________________________________________________________________________________________________
|
||||
Construction
|
||||
|
||||
ETL_CONSTEXPR
|
||||
month_weekday()
|
||||
Default constructor.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
month_weekday(const etl::chrono::month& m,
|
||||
const etl::chrono::weekday_indexed& wd)
|
||||
ETL_NOEXCEPT
|
||||
Construct from month and weekday_indexed.
|
||||
____________________________________________________________________________________________________
|
||||
Access
|
||||
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::month month() const
|
||||
ETL_NOEXCEPT
|
||||
Returns the month.
|
||||
______________________________________________
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::weekday_indexed weekday_indexed() const
|
||||
ETL_NOEXCEPT
|
||||
Returns the weekday.
|
||||
____________________________________________________________________________________________________
|
||||
Tests
|
||||
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
bool ok() const
|
||||
ETL_NOEXCEPT
|
||||
Returns true if the month and day is within the valid limits.
|
||||
____________________________________________________________________________________________________
|
||||
Non-member comparison operators
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
bool operator ==(const etl::chrono::month_weekday& lhs,
|
||||
const etl::chrono::month_weekday& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Equality operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
bool operator !=(const etl::chrono::month_weekday& lhs,
|
||||
const etl::chrono::month_weekday& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Inequality operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
bool operator <(const etl::chrono::month_weekday& lhs,
|
||||
const etl::chrono::month_weekday& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Less-than operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
bool operator <=(const etl::chrono::month_weekday& lhs,
|
||||
const etl::chrono::month_weekday& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Less-than-equal operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
bool operator <(const etl::chrono::month_weekday& lhs,
|
||||
const etl::chrono::month_weekday& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Greater-than operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
bool operator <=(const etl::chrono::month_weekday& lhs,
|
||||
const etl::chrono::month_weekday& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Greater-than-equal operator.
|
||||
______________________________________________
|
||||
[[nodiscard]] constexpr
|
||||
auto operator <=>(const etl::chrono::month_weekday& lhs,
|
||||
const etl::chrono::month_weekday& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Spaceship operator
|
||||
____________________________________________________________________________________________________
|
||||
Hash
|
||||
|
||||
template <typename TRep, typename TPeriod>
|
||||
struct hash<etl::chrono::month_weekday>
|
||||
Hash function for etl::chrono::month_weekday
|
||||
|
||||
88
docs/raw/chrono/month_weekday_last.txt
Normal file
88
docs/raw/chrono/month_weekday_last.txt
Normal file
@ -0,0 +1,88 @@
|
||||
month_weekday_last
|
||||
A template representing a month and weekday_last.
|
||||
Back to chrono
|
||||
____________________________________________________________________________________________________
|
||||
month_weekday_last
|
||||
|
||||
STL equivalent: std::chrono::month_weekday_last
|
||||
|
||||
class month_weekday_last
|
||||
____________________________________________________________________________________________________
|
||||
Construction
|
||||
|
||||
ETL_CONSTEXPR
|
||||
month_weekday_last()
|
||||
Default constructor.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
month_weekday_last(const etl::chrono::month& m,
|
||||
const etl::chrono::weekday_last& wd)
|
||||
ETL_NOEXCEPT
|
||||
Construct from month and weekday_last.
|
||||
____________________________________________________________________________________________________
|
||||
Access
|
||||
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::month month() const
|
||||
ETL_NOEXCEPT
|
||||
Returns the month.
|
||||
______________________________________________
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::weekday_last weekday_last() const
|
||||
ETL_NOEXCEPT
|
||||
Returns the weekday.
|
||||
____________________________________________________________________________________________________
|
||||
Tests
|
||||
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
bool ok() const
|
||||
ETL_NOEXCEPT
|
||||
Returns true if the month and day is within the valid limits.
|
||||
____________________________________________________________________________________________________
|
||||
Non-member comparison operators
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
bool operator ==(const etl::chrono::month_weekday_last& lhs,
|
||||
const etl::chrono::month_weekday_last& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Equality operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
bool operator !=(const etl::chrono::month_weekday_last& lhs,
|
||||
const etl::chrono::month_weekday_last& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Inequality operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
bool operator <(const etl::chrono::month_weekday_last& lhs,
|
||||
const etl::chrono::month_weekday_last& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Less-than operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
bool operator <=(const etl::chrono::month_weekday_last& lhs,
|
||||
const etl::chrono::month_weekday_last& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Less-than-equal operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
bool operator <(const etl::chrono::month_weekday_last& lhs,
|
||||
const etl::chrono::month_weekday_last& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Greater-than operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
bool operator <=(const etl::chrono::month_weekday_last& lhs,
|
||||
const etl::chrono::month_weekday_last& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Greater-than-equal operator.
|
||||
____________________________________________________________________________________________________
|
||||
Hash
|
||||
|
||||
template <typename TRep, typename TPeriod>
|
||||
struct hash<etl::chrono::month_weekday_last>
|
||||
Hash function for etl::chrono::month_weekday_last
|
||||
|
||||
182
docs/raw/chrono/time_point.txt
Normal file
182
docs/raw/chrono/time_point.txt
Normal file
@ -0,0 +1,182 @@
|
||||
time_point
|
||||
etl::chrono::time_point represents a point in time.
|
||||
Back to chrono
|
||||
____________________________________________________________________________________________________
|
||||
tme_point
|
||||
|
||||
Represents a point in time storing a TDuration indicating the time
|
||||
interval from the start of the TClock's epoch.
|
||||
|
||||
template <typename TClock, typename TDuration = typename TClock::duration>
|
||||
class time_point
|
||||
____________________________________________________________________________________________________
|
||||
Member types
|
||||
|
||||
using clock = TClock
|
||||
using duration = TDuration
|
||||
using rep = typename TDuration::rep
|
||||
using period = typename TDuration::period
|
||||
____________________________________________________________________________________________________
|
||||
Constructors
|
||||
|
||||
ETL_CONSTEXPR
|
||||
time_point()
|
||||
ETL_NOEXCEPT
|
||||
Default constructor.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
explicit time_point(const duration& dur_)
|
||||
ETL_NOEXCEPT
|
||||
Construct from a duration.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
time_point(const time_point& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Copy constructor.
|
||||
______________________________________________
|
||||
template <typename TDuration2>
|
||||
ETL_CONSTEXPR14
|
||||
explicit time_point(const time_point<clock, TDuration2>& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Copy construct from another time_point with a different duration type.
|
||||
____________________________________________________________________________________________________
|
||||
Assignment
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
time_point& operator =(const time_point& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Assignment operator.
|
||||
____________________________________________________________________________________________________
|
||||
Access
|
||||
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14 duration time_since_epoch() const
|
||||
ETL_NOEXCEPT
|
||||
Returns a duration representing the amount of time between this and the clock's epoch.
|
||||
____________________________________________________________________________________________________
|
||||
Member arithmetic operators
|
||||
|
||||
ETL_CONSTEXPR14 time_point& operator +=(const duration& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Adds a duration.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14 time_point& operator -=(const duration& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Subtracts a duration.
|
||||
____________________________________________________________________________________________________
|
||||
Constants
|
||||
|
||||
ETL_NODISCARD
|
||||
static ETL_CONSTEXPR14 time_point min()
|
||||
ETL_NOEXCEPT
|
||||
Returns a time_point with the smallest possible duration.
|
||||
______________________________________________
|
||||
ETL_NODISCARD
|
||||
static ETL_CONSTEXPR14 time_point max()
|
||||
ETL_NOEXCEPT
|
||||
Returns a time_point with the largest possible duration.
|
||||
____________________________________________________________________________________________________
|
||||
Rounding
|
||||
|
||||
template <typename TToDuration, typename TClock, typename TDuration>
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::time_point<TClock, TToDuration>
|
||||
floor(const etl::chrono::time_point<TClock, TDuration>& tp)
|
||||
ETL_NOEXCEPT
|
||||
Rounds down a duration to the nearest lower precision.
|
||||
______________________________________________
|
||||
template <typename TToDuration, typename TClock, typename TDuration>
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::time_point<TClock, TToDuration>
|
||||
ceil(const etl::chrono::time_point<TClock, TDuration>& tp)
|
||||
ETL_NOEXCEPT
|
||||
Rounds up a duration to the nearest higher precision.
|
||||
______________________________________________
|
||||
template <typename TToDuration, typename TClock, typename TDuration>
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::time_point<TClock, TToDuration>
|
||||
round(const etl::chrono::time_point<TClock, TDuration>& tp)
|
||||
ETL_NOEXCEPT
|
||||
Rounds a duration to the nearest precision.
|
||||
If the duration is exactly halfway, it rounds away from zero.
|
||||
____________________________________________________________________________________________________
|
||||
Casting
|
||||
|
||||
template <typename TToDuration, typename TClock, typename TDuration>
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::time_point<TClock, TToDuration>
|
||||
time_point_cast(const etl::chrono::time_point<TClock, TDuration>& tp)
|
||||
ETL_NOEXCEPT
|
||||
____________________________________________________________________________________________________
|
||||
Comparison
|
||||
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14 int compare(const time_point& other) const
|
||||
ETL_NOEXCEPT
|
||||
Compare day with another.
|
||||
If time_point < other, returns -1
|
||||
else if time_point > other, returns 1
|
||||
else returns 0
|
||||
____________________________________________________________________________________________________
|
||||
Non-member comparison operators
|
||||
|
||||
template <typename TClock, typename TDuration1, typename TDuration2>
|
||||
ETL_CONSTEXPR14
|
||||
bool operator ==(const time_point<TClock, TDuration1>& lhs,
|
||||
const time_point<TClock, TDuration2>& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Equality operator
|
||||
______________________________________________
|
||||
template <typename TClock, typename TDuration1, typename TDuration2>
|
||||
ETL_CONSTEXPR14
|
||||
bool operator !=(const time_point<TClock, TDuration1>& lhs,
|
||||
const time_point<TClock, TDuration2>& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Inequality operator
|
||||
______________________________________________
|
||||
template <typename TClock, typename TDuration1, typename TDuration2>
|
||||
ETL_CONSTEXPR14
|
||||
bool operator <(const time_point<TClock, TDuration1>& lhs,
|
||||
const time_point<TClock, TDuration2>& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Less-than operator
|
||||
______________________________________________
|
||||
template <typename TClock, typename TDuration1, typename TDuration2>
|
||||
ETL_CONSTEXPR14
|
||||
bool operator <=(const time_point<TClock, TDuration1>& lhs,
|
||||
const time_point<TClock, TDuration2>& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Less-than-equal operator
|
||||
______________________________________________
|
||||
template <typename TClock, typename TDuration1, typename TDuration2>
|
||||
ETL_CONSTEXPR14
|
||||
bool operator >(const time_point<TClock, TDuration1>& lhs,
|
||||
const time_point<TClock, TDuration2>& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Greater-than operator
|
||||
______________________________________________
|
||||
template <typename TClock, typename TDuration1, typename TDuration2>
|
||||
ETL_CONSTEXPR14
|
||||
bool operator >=(const time_point<TClock, TDuration1>& lhs,
|
||||
const time_point<TClock, TDuration2>& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Greater-than-equal operator
|
||||
______________________________________________
|
||||
template <typename TClock, typename TDuration1, typename TDuration2>
|
||||
[[nodiscard]] constexpr auto operator <=>(const etl::chrono::time_point<TClock, TDuration1>& lhs,
|
||||
const etl::chrono::time_point<TClock, TDuration2>& rhs)
|
||||
noexcept
|
||||
Spaceship operator
|
||||
C++20
|
||||
____________________________________________________________________________________________________
|
||||
etl::common_type specialisation
|
||||
|
||||
template <typename TClock, typename TDuration1, typename TDuration2>
|
||||
struct common_type<etl::chrono::time_point<TClock, TDuration1>,
|
||||
etl::chrono::time_point<TClock, TDuration2>>
|
||||
Defines type, which is the common type of two etl::chrono::time_point
|
||||
|
||||
229
docs/raw/chrono/weekday.txt
Normal file
229
docs/raw/chrono/weekday.txt
Normal file
@ -0,0 +1,229 @@
|
||||
weekday
|
||||
A template representing a weekday.
|
||||
Back to chrono
|
||||
____________________________________________________________________________________________________
|
||||
weekday
|
||||
|
||||
STL equivalent: std::chrono::weekday
|
||||
|
||||
class weekday
|
||||
____________________________________________________________________________________________________
|
||||
Construction
|
||||
|
||||
ETL_CONSTEXPR
|
||||
weekday()
|
||||
ETL_NOEXCEPT
|
||||
Default constructor.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR
|
||||
explicit weekday(unsigned value)
|
||||
ETL_NOEXCEPT
|
||||
Construct from unsigned.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
weekday(const etl::chrono::sys_days& sd)
|
||||
ETL_NOEXCEPT
|
||||
Construct from sys_days.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
weekday(const etl::chrono::local_days& sd)
|
||||
ETL_NOEXCEPT
|
||||
Construct from local_days.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
weekday(const etl::chrono::weekday& other)
|
||||
ETL_NOEXCEPT
|
||||
Copy constructor.
|
||||
____________________________________________________________________________________________________
|
||||
Tests
|
||||
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
bool ok() const
|
||||
ETL_NOEXCEPT
|
||||
Returns true if the weekday is valid
|
||||
______________________________________________
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
bool is_weekend() const
|
||||
ETL_NOEXCEPT
|
||||
Returns true if the weekday is a Saturday or Sunday.
|
||||
____________________________________________________________________________________________________
|
||||
Assignment
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::weekday& operator =(const etl::chrono::weekday& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Assignment operator
|
||||
____________________________________________________________________________________________________
|
||||
Access
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
int c_encoding() const
|
||||
ETL_NOEXCEPT
|
||||
Gets the value of the weekday using C encoding.
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
int iso_encoding() const
|
||||
ETL_NOEXCEPT
|
||||
Gets the value of the weekday using ISO encoding.
|
||||
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::weekday_indexed operator[](unsigned index) const
|
||||
ETL_NOEXCEPT
|
||||
Index operator, from index.
|
||||
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::weekday_last operator[](etl::chrono::last_spec last) const
|
||||
ETL_NOEXCEPT
|
||||
Index operator, from etl::chrono::last_spec.
|
||||
____________________________________________________________________________________________________
|
||||
Increment/decrement
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::weekday& operator ++()
|
||||
ETL_NOEXCEPT
|
||||
Pre-increment operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::weekday operator ++(int)
|
||||
ETL_NOEXCEPT
|
||||
Post-increment operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::weekday& operator --()
|
||||
ETL_NOEXCEPT
|
||||
Pre-decrement operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::weekday operator --(int)
|
||||
ETL_NOEXCEPT
|
||||
Post-decrement operator.
|
||||
____________________________________________________________________________________________________
|
||||
Mathematical operators
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::weekday& operator +=(const etl::chrono::weekdays& ms)
|
||||
ETL_NOEXCEPT
|
||||
Plus-equals operator adding etl::chrono::weekdays.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::weekday& operator -=(const etl::chrono::weekdays& ms)
|
||||
ETL_NOEXCEPT
|
||||
Minus-equals operator subtracting etl::chrono::weekdays.
|
||||
____________________________________________________________________________________________________
|
||||
Constants
|
||||
|
||||
ETL_NODISCARD
|
||||
static
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::weekday min()
|
||||
ETL_NOEXCEPT
|
||||
The minimum weekday value for which ok() will return true.
|
||||
______________________________________________
|
||||
ETL_NODISCARD
|
||||
static
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::weekday max()
|
||||
ETL_NOEXCEPT
|
||||
The maximum weekday value for which ok() will return true.
|
||||
____________________________________________________________________________________________________
|
||||
Non-member mathematical operators
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::weekday operator +(const etl::chrono::weekday& m,
|
||||
const etl::chrono::weekdays& ms)
|
||||
ETL_NOEXCEPT
|
||||
Add etl::chrono::weekdays to etl::chrono::weekday.
|
||||
Returns etl::chrono::weekday.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::weekday operator +(const etl::chrono::weekdays& ms,
|
||||
const etl::chrono::weekday& m)
|
||||
ETL_NOEXCEPT
|
||||
Add etl::chrono::weekday to etl::chrono::weekdays.
|
||||
Returns etl::chrono::weekday.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::weekday operator -(const etl::chrono::weekday& m,
|
||||
const etl::chrono::weekdays& ms)
|
||||
ETL_NOEXCEPT
|
||||
Subtract etl::chrono::weekdays from etl::chrono::weekday.
|
||||
Returns etl::chrono::weekday.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::weekday operator -(const etl::chrono::weekdays& ms,
|
||||
const etl::chrono::weekday& m)
|
||||
ETL_NOEXCEPT
|
||||
Subtract etl::chrono::weekday from etl::chrono::weekdays.
|
||||
Returns etl::chrono::weekdays.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::weekdays operator -(const etl::chrono::weekday& m1,
|
||||
const etl::chrono::weekday& m2) ETL_NOEXCEPT
|
||||
Subtract etl::chrono::weekday from etl::chrono::weekday.
|
||||
Returns etl::chrono::weekdays.
|
||||
____________________________________________________________________________________________________
|
||||
Non-member comparison operators
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
bool operator ==(const etl::chrono::weekday& m1,
|
||||
const etl::chrono::weekday& m2)
|
||||
ETL_NOEXCEPT
|
||||
Equality operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
bool operator !=(const etl::chrono::weekday& m1,
|
||||
const etl::chrono::weekday& m2)
|
||||
ETL_NOEXCEPT
|
||||
Inequality operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
bool operator <(const etl::chrono::weekday& m1,
|
||||
const etl::chrono::weekday& m2)
|
||||
ETL_NOEXCEPT
|
||||
Less-than operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
bool operator <=(const etl::chrono::weekday& m1,
|
||||
const etl::chrono::weekday& m2)
|
||||
ETL_NOEXCEPT
|
||||
Less-than-or-equal operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
bool operator >(const etl::chrono::weekday& m1,
|
||||
const etl::chrono::weekday& m2)
|
||||
ETL_NOEXCEPT
|
||||
Greater-than operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
bool operator >=(const etl::chrono::weekday& m1,
|
||||
const etl::chrono::weekday& m2)
|
||||
ETL_NOEXCEPT
|
||||
Greater-than-or-equal operator.
|
||||
______________________________________________
|
||||
[[nodiscard]] inline constexpr
|
||||
auto operator <=>(const etl::chrono::weekday& m1,
|
||||
const etl::chrono::weekday& m2)
|
||||
noexcept
|
||||
Spaceship operator.
|
||||
C++20
|
||||
____________________________________________________________________________________________________
|
||||
Defined weekdays
|
||||
|
||||
etl::chrono::Monday
|
||||
etl::chrono::Tuesday
|
||||
etl::chrono::Wednesday
|
||||
etl::chrono::Thursday
|
||||
etl::chrono::Friday
|
||||
etl::chrono::Saturday
|
||||
etl::chrono::Sunday
|
||||
____________________________________________________________________________________________________
|
||||
Hash
|
||||
|
||||
template <>
|
||||
struct hash<etl::chrono::weekday>
|
||||
Hash function for etl::chrono::weekday
|
||||
|
||||
80
docs/raw/chrono/weekday_indexed.txt
Normal file
80
docs/raw/chrono/weekday_indexed.txt
Normal file
@ -0,0 +1,80 @@
|
||||
weekday_indexed
|
||||
A template representing a weekday_indexed.
|
||||
Back to chrono
|
||||
____________________________________________________________________________________________________
|
||||
weekday_indexed
|
||||
|
||||
STL equivalent: std::chrono::weekday_indexed
|
||||
|
||||
class weekday_indexed
|
||||
____________________________________________________________________________________________________
|
||||
Construction
|
||||
|
||||
ETL_CONSTEXPR
|
||||
weekday_indexed()
|
||||
ETL_NOEXCEPT
|
||||
Default constructor.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
weekday_indexed(const etl::chrono::weekday& wd, unsigned index)
|
||||
ETL_NOEXCEPT
|
||||
Construct from weekday and index.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
weekday_indexed(const etl::chrono::weekday_indexed& other)
|
||||
ETL_NOEXCEPT
|
||||
Copy constructor.
|
||||
____________________________________________________________________________________________________
|
||||
Tests
|
||||
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
bool ok() const
|
||||
ETL_NOEXCEPT
|
||||
Returns true if the weekday_indexed is valid
|
||||
______________________________________________
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
bool is_weekend() const
|
||||
ETL_NOEXCEPT
|
||||
Returns true if the weekday_indexed is a Saturday or Sunday.
|
||||
____________________________________________________________________________________________________
|
||||
Assignment
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::weekday_indexed& operator =(const etl::chrono::weekday_indexed& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Assignment operator
|
||||
____________________________________________________________________________________________________
|
||||
Access
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::weekday weekday() const
|
||||
ETL_NOEXCEPT
|
||||
Gets the weekday.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
unsigned index() const
|
||||
ETL_NOEXCEPT
|
||||
Gets the index.
|
||||
____________________________________________________________________________________________________
|
||||
Non-member comparison operators
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
bool operator ==(const etl::chrono::weekday_indexed& m1,
|
||||
const etl::chrono::weekday_indexed& m2)
|
||||
ETL_NOEXCEPT
|
||||
Equality operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
bool operator !=(const etl::chrono::weekday_indexed& m1,
|
||||
const etl::chrono::weekday_indexed& m2)
|
||||
ETL_NOEXCEPT
|
||||
Inequality operator.
|
||||
____________________________________________________________________________________________________
|
||||
Hash
|
||||
|
||||
template <>
|
||||
struct hash<etl::chrono::weekday_indexed>
|
||||
Hash function for etl::chrono::weekday_indexed
|
||||
|
||||
70
docs/raw/chrono/weekday_last.txt
Normal file
70
docs/raw/chrono/weekday_last.txt
Normal file
@ -0,0 +1,70 @@
|
||||
weekday_last
|
||||
A template representing a weekday_last.
|
||||
Back to chrono
|
||||
____________________________________________________________________________________________________
|
||||
weekday_last
|
||||
|
||||
STL equivalent: std::chrono::weekday_last
|
||||
|
||||
class weekday_last
|
||||
____________________________________________________________________________________________________
|
||||
Construction
|
||||
|
||||
ETL_CONSTEXPR
|
||||
weekday_last()
|
||||
ETL_NOEXCEPT
|
||||
Default constructor.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
weekday_last(const etl::chrono::weekday& wd)
|
||||
ETL_NOEXCEPT
|
||||
Construct from weekday and index.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
weekday_last(const etl::chrono::weekday_last& other)
|
||||
ETL_NOEXCEPT
|
||||
Copy constructor.
|
||||
____________________________________________________________________________________________________
|
||||
Tests
|
||||
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
bool ok() const
|
||||
ETL_NOEXCEPT
|
||||
Returns true if the weekday_last valid.
|
||||
____________________________________________________________________________________________________
|
||||
Assignment
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::weekday_last& operator =(const etl::chrono::weekday_last& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Assignment operator
|
||||
____________________________________________________________________________________________________
|
||||
Access
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::weekday weekday() const
|
||||
ETL_NOEXCEPT
|
||||
Gets the weekday.
|
||||
____________________________________________________________________________________________________
|
||||
Non-member comparison operators
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
bool operator ==(const etl::chrono::weekday_last& m1,
|
||||
const etl::chrono::weekday_last& m2)
|
||||
ETL_NOEXCEPT
|
||||
Equality operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
bool operator !=(const etl::chrono::weekday_last& m1,
|
||||
const etl::chrono::weekday_last& m2)
|
||||
ETL_NOEXCEPT
|
||||
Inequality operator.
|
||||
____________________________________________________________________________________________________
|
||||
Hash
|
||||
|
||||
template <>
|
||||
struct hash<etl::chrono::weekday_last>
|
||||
Hash function for etl::chrono::weekday_last
|
||||
|
||||
|
||||
206
docs/raw/chrono/year.txt
Normal file
206
docs/raw/chrono/year.txt
Normal file
@ -0,0 +1,206 @@
|
||||
year
|
||||
A template representing a year.
|
||||
Back to chrono
|
||||
____________________________________________________________________________________________________
|
||||
year
|
||||
|
||||
STL equivalent: std::chrono::year
|
||||
|
||||
class year
|
||||
____________________________________________________________________________________________________
|
||||
Typesdefs
|
||||
rep The internal representation.
|
||||
____________________________________________________________________________________________________
|
||||
Construction
|
||||
|
||||
ETL_CONSTEXPR
|
||||
year()
|
||||
ETL_NOEXCEPT
|
||||
Default constructor.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR
|
||||
explicit year(unsigned value)
|
||||
ETL_NOEXCEPT
|
||||
Construct from unsigned.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
year(const etl::chrono::year& other)
|
||||
ETL_NOEXCEPT
|
||||
Copy constructor.
|
||||
____________________________________________________________________________________________________
|
||||
Tests
|
||||
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
int compare(const etl::chrono::year& other) const
|
||||
ETL_NOEXCEPT
|
||||
Compare day with another.
|
||||
if year < other, returns -1
|
||||
else if year > other, returns 1
|
||||
else returns 0
|
||||
____________________________________________________________________________________________________
|
||||
Assignment
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year& operator =(const etl::chrono::year& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Assignment operator
|
||||
____________________________________________________________________________________________________
|
||||
Increment/decrement
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year& operator ++()
|
||||
ETL_NOEXCEPT
|
||||
Pre-increment operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year operator ++(int)
|
||||
ETL_NOEXCEPT
|
||||
Post-increment operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year& operator --()
|
||||
ETL_NOEXCEPT
|
||||
Pre-decrement operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year operator --(int)
|
||||
ETL_NOEXCEPT
|
||||
Post-decrement operator.
|
||||
____________________________________________________________________________________________________
|
||||
Mathematical operators
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year& operator +=(const etl::chrono::years& ys)
|
||||
ETL_NOEXCEPT
|
||||
Plus-equals operator adding etl::chrono::years.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year& operator -=(const etl::chrono::years& ys)
|
||||
ETL_NOEXCEPT
|
||||
Minus-equals operator subtracting etl::chrono::years.
|
||||
____________________________________________________________________________________________________
|
||||
Tests
|
||||
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
bool ok() const
|
||||
ETL_NOEXCEPT
|
||||
Returns true if the year is within the valid -32767 to 32767 range.
|
||||
______________________________________________
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
bool is_leap() const
|
||||
ETL_NOEXCEPT
|
||||
Returns true if the year is a leap year.
|
||||
____________________________________________________________________________________________________
|
||||
Constants
|
||||
|
||||
ETL_NODISCARD
|
||||
static
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year min()
|
||||
ETL_NOEXCEPT
|
||||
The minimum year value for which ok() will return true.
|
||||
______________________________________________
|
||||
ETL_NODISCARD
|
||||
static
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year max()
|
||||
ETL_NOEXCEPT
|
||||
The maximum year value for which ok() will return true.
|
||||
____________________________________________________________________________________________________
|
||||
Conversion
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
operator int() const
|
||||
ETL_NOEXCEPT
|
||||
Conversion operator to unsigned int.
|
||||
____________________________________________________________________________________________________
|
||||
Non-member mathematical operators
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year operator +(const etl::chrono::year& y,
|
||||
const etl::chrono::years& ys)
|
||||
ETL_NOEXCEPT
|
||||
Add etl::chrono::years to etl::chrono::year.
|
||||
Returns etl::chrono::year.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year operator +(const etl::chrono::years& ys,
|
||||
const etl::chrono::year& y)
|
||||
ETL_NOEXCEPT
|
||||
Add etl::chrono::year to etl::chrono::years.
|
||||
Returns etl::chrono::year.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year operator -(const etl::chrono::year& y,
|
||||
const etl::chrono::years& ys)
|
||||
ETL_NOEXCEPT
|
||||
Subtract etl::chrono::years from etl::chrono::year.
|
||||
Returns etl::chrono::year.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year operator -(const etl::chrono::years& ys,
|
||||
const etl::chrono::year& y)
|
||||
ETL_NOEXCEPT
|
||||
Subtract etl::chrono::year from etl::chrono::years.
|
||||
Returns etl::chrono::years.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::years operator -(const etl::chrono::year& y1,
|
||||
const etl::chrono::year& y2) ETL_NOEXCEPT
|
||||
Subtract etl::chrono::year from etl::chrono::year.
|
||||
Returns etl::chrono::years.
|
||||
____________________________________________________________________________________________________
|
||||
Non-member comparison operators
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
bool operator ==(const etl::chrono::year& y1,
|
||||
const etl::chrono::year& y2)
|
||||
ETL_NOEXCEPT
|
||||
Equality operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
bool operator !=(const etl::chrono::year& y1,
|
||||
const etl::chrono::year& y2)
|
||||
ETL_NOEXCEPT
|
||||
Inequality operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
bool operator <(const etl::chrono::year& y1,
|
||||
const etl::chrono::year& y2)
|
||||
ETL_NOEXCEPT
|
||||
Less-than operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
bool operator <=(const etl::chrono::year& y1,
|
||||
const etl::chrono::year& y2)
|
||||
ETL_NOEXCEPT
|
||||
Less-than-or-equal operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
bool operator >(const etl::chrono::year& y1,
|
||||
const etl::chrono::year& y2)
|
||||
ETL_NOEXCEPT
|
||||
Greater-than operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
bool operator >=(const etl::chrono::year& y1,
|
||||
const etl::chrono::year& y2)
|
||||
ETL_NOEXCEPT
|
||||
Greater-than-or-equal operator.
|
||||
______________________________________________
|
||||
[[nodiscard]] inline constexpr
|
||||
auto operator <=>(const etl::chrono::year& y1,
|
||||
const etl::chrono::year& y2)
|
||||
noexcept
|
||||
Spaceship operator.
|
||||
C++20
|
||||
____________________________________________________________________________________________________
|
||||
Hash
|
||||
|
||||
template <typename TRep, typename TPeriod>
|
||||
struct hash<etl::chrono::year>
|
||||
Hash function for etl::chrono::year
|
||||
|
||||
133
docs/raw/chrono/year_month.txt
Normal file
133
docs/raw/chrono/year_month.txt
Normal file
@ -0,0 +1,133 @@
|
||||
year_month
|
||||
A template representing a year and month.
|
||||
Back to chrono
|
||||
____________________________________________________________________________________________________
|
||||
year_month
|
||||
|
||||
STL equivalent: std::chrono::year_month
|
||||
|
||||
class year_month
|
||||
____________________________________________________________________________________________________
|
||||
Construction
|
||||
|
||||
ETL_CONSTEXPR
|
||||
year_month()
|
||||
Default constructor.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
year_month(const etl::chrono::year& y,
|
||||
const etl::chrono::month& m)
|
||||
ETL_NOEXCEPT
|
||||
Construct from month and day.
|
||||
____________________________________________________________________________________________________
|
||||
Access
|
||||
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year year() const
|
||||
ETL_NOEXCEPT
|
||||
Returns the year.
|
||||
______________________________________________
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::month month() const
|
||||
ETL_NOEXCEPT
|
||||
Returns the month.
|
||||
____________________________________________________________________________________________________
|
||||
Tests
|
||||
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
bool ok() const
|
||||
ETL_NOEXCEPT
|
||||
Returns true if the year and month is within the valid limits.
|
||||
______________________________________________
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
int compare(const etl::chrono::year_month& other) const
|
||||
ETL_NOEXCEPT
|
||||
if (y < other.y) return -1
|
||||
if (y > other.y) return 1
|
||||
if (m < other.m) return -1
|
||||
if (m > other.m) return 1
|
||||
else return 0
|
||||
____________________________________________________________________________________________________
|
||||
Non-member mathematical operators
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month operator +(const etl::chrono::year_month& ym,
|
||||
const etl::chrono::years& dy)
|
||||
Adds etl::chrono::years.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month operator +(const etl::chrono::years& dy,
|
||||
const etl::chrono::year_month& ym)
|
||||
ETL_NOEXCEPT
|
||||
Adds etl::chrono::years.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month operator +(const etl::chrono::year_month& ym,
|
||||
const etl::chrono::months& dm)
|
||||
ETL_NOEXCEPT
|
||||
Adds etl::chrono::months.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month operator +(const etl::chrono::months& dm,
|
||||
const etl::chrono::year_month& ym)
|
||||
ETL_NOEXCEPT
|
||||
Adds etl::chrono::months.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month operator -(const etl::chrono::year_month& ym,
|
||||
const etl::chrono::years& dy)
|
||||
ETL_NOEXCEPT
|
||||
Subtracts etl::chrono::years.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month operator -(const etl::chrono::year_month& ym,
|
||||
const etl::chrono::months& dm)
|
||||
ETL_NOEXCEPT
|
||||
Subtracts etl::chrono::months.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::months operator -(const etl::chrono::year_month& ym1,
|
||||
const etl::chrono::year_month& ym2)
|
||||
ETL_NOEXCEPT
|
||||
Subtracts etl::chrono::year_month.
|
||||
____________________________________________________________________________________________________
|
||||
Non-member comparison operators
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
bool operator ==(const etl::chrono::year_month& lhs,
|
||||
const etl::chrono::year_month& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Equality operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
bool operator !=(const etl::chrono::year_month& lhs,
|
||||
const etl::chrono::year_month& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Inequality operator.
|
||||
______________________________________________
|
||||
[[nodiscard]] friend constexpr
|
||||
auto operator <=>(const etl::chrono::year_month& lhs,
|
||||
const etl::chrono::year_month& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Spaceship operator
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
int compare(const year_month& other) const
|
||||
ETL_NOEXCEPT
|
||||
Compare year_month with another.
|
||||
if month < other.month, returns -1
|
||||
else if month > other.month, returns 1
|
||||
else if day < other.day, returns -1
|
||||
else if day > other.day, returns 1
|
||||
else returns 0;
|
||||
____________________________________________________________________________________________________
|
||||
Hash
|
||||
|
||||
template <typename TRep, typename TPeriod>
|
||||
struct hash<etl::chrono::year_month>
|
||||
Hash function for etl::chrono::year_month
|
||||
|
||||
175
docs/raw/chrono/year_month_day.txt
Normal file
175
docs/raw/chrono/year_month_day.txt
Normal file
@ -0,0 +1,175 @@
|
||||
year_month_day
|
||||
A template representing a year and month.
|
||||
Back to chrono
|
||||
____________________________________________________________________________________________________
|
||||
year_month_day
|
||||
|
||||
STL equivalent: std::chrono::year_month_day
|
||||
|
||||
class year_month_day
|
||||
____________________________________________________________________________________________________
|
||||
Construction
|
||||
|
||||
ETL_CONSTEXPR year_month_day()
|
||||
Default constructor.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
year_month_day(const etl::chrono::year& y,
|
||||
const etl::chrono::month& m,
|
||||
const etl::chrono::day& d)
|
||||
ETL_NOEXCEPT
|
||||
Construct from month and day.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
year_month_day(const etl::chrono::year_month_day_last& ymdl)
|
||||
ETL_NOEXCEPT
|
||||
Construct from year_month_day_last.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
year_month_day(const etl::chrono::sys_days& sd)
|
||||
ETL_NOEXCEPT
|
||||
Construct from sys_days.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
year_month_day(const etl::chrono::local_days& ld)
|
||||
ETL_NOEXCEPT
|
||||
Construct from local_days.
|
||||
____________________________________________________________________________________________________
|
||||
Access
|
||||
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year year() const
|
||||
ETL_NOEXCEPT
|
||||
Returns the year.
|
||||
______________________________________________
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::month month() const
|
||||
ETL_NOEXCEPT
|
||||
Returns the month.
|
||||
______________________________________________
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14 etl::chrono::day day() const ETL_NOEXCEPT
|
||||
Returns the day.
|
||||
____________________________________________________________________________________________________
|
||||
Tests
|
||||
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
bool ok() const
|
||||
ETL_NOEXCEPT
|
||||
Returns true if the year and month is within the valid limits.
|
||||
______________________________________________
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
int compare(const etl::chrono::year_month_day& other) const
|
||||
ETL_NOEXCEPT
|
||||
Compare year_month_day with another.
|
||||
if year < other.year, returns -1
|
||||
else if year > other.year, returns 1
|
||||
if month < other.month, returns -1
|
||||
else if month > other.month, returns 1
|
||||
else if day < other.day, returns -1
|
||||
else if day > other.day, returns 1
|
||||
else returns 0
|
||||
____________________________________________________________________________________________________
|
||||
operators
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month_day& operator +=(const etl::chrono::years& dy)
|
||||
ETL_NOEXCEPT
|
||||
Adds etl::chrono::years.
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month_day& operator +=(const etl::chrono::months& dm)
|
||||
ETL_NOEXCEPT
|
||||
Adds etl::chrono::months.
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month_day& operator -=(const etl::chrono::years& dy)
|
||||
ETL_NOEXCEPT
|
||||
Subtracts etl::chrono::years.
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month_day& operator -=(const etl::chrono::months& dm)
|
||||
ETL_NOEXCEPT
|
||||
Subtracts etl::chrono::months.
|
||||
____________________________________________________________________________________________________
|
||||
Non-member operators
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month_day operator +(const etl::chrono::year_month_day& ym,
|
||||
const etl::chrono::years& dy)
|
||||
Adds etl::chrono::years.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month_day operator +(const etl::chrono::years& dy,
|
||||
const etl::chrono::year_month_day& ym)
|
||||
ETL_NOEXCEPT
|
||||
Adds etl::chrono::years.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month_day operator +(const etl::chrono::year_month_day& ym,
|
||||
const etl::chrono::months& dm)
|
||||
ETL_NOEXCEPT
|
||||
Adds etl::chrono::months.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month operator +(const etl::chrono::months& dm,
|
||||
const etl::chrono::year_month_day& ym)
|
||||
ETL_NOEXCEPT
|
||||
Adds etl::chrono::months.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month operator -(const etl::chrono::year_month_day& ym,
|
||||
const etl::chrono::years& dy)
|
||||
ETL_NOEXCEPT
|
||||
Subtracts etl::chrono::years.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month operator -(const etl::chrono::year_month_day& ym,
|
||||
const etl::chrono::months& dm)
|
||||
ETL_NOEXCEPT
|
||||
Subtracts etl::chrono::months.
|
||||
___________________________________________________________________________________________________
|
||||
Non-member comparison operators
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
bool operator ==(const etl::chrono::year_month_day& lhs,
|
||||
const etl::chrono::year_month_day& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Equality operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
bool operator !=(const etl::chrono::year_month_day& lhs,
|
||||
const etl::chrono::year_month_day& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Inequality operator.
|
||||
______________________________________________
|
||||
[[nodiscard]] friend constexpr
|
||||
auto operator <=>(const etl::chrono::year_month_day& lhs,
|
||||
const etl::chrono::year_month_day& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Spaceship operator
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
int compare(const year_month& other) const
|
||||
ETL_NOEXCEPT
|
||||
Compare year_month_day with another.
|
||||
if year < other.year, returns -1
|
||||
else if year > other.year, returns 1
|
||||
if month < other.month, returns -1
|
||||
else if month > other.month, returns 1
|
||||
else if day < other.day, returns -1
|
||||
else if day > other.day, returns 1
|
||||
else returns 0
|
||||
____________________________________________________________________________________________________
|
||||
Hash
|
||||
|
||||
template <>
|
||||
struct hash<etl::chrono::year_month_day>
|
||||
Hash function for etl::chrono::year_month_day
|
||||
|
||||
|
||||
|
||||
164
docs/raw/chrono/year_month_day_last.txt
Normal file
164
docs/raw/chrono/year_month_day_last.txt
Normal file
@ -0,0 +1,164 @@
|
||||
year_month_day_last
|
||||
A template representing a year and month.
|
||||
Back to chrono
|
||||
____________________________________________________________________________________________________
|
||||
year_month_day_last
|
||||
|
||||
STL equivalent: std::chrono::year_month_day_last
|
||||
|
||||
class year_month_day_last
|
||||
____________________________________________________________________________________________________
|
||||
Construction
|
||||
|
||||
ETL_CONSTEXPR year_month_day_last()
|
||||
Default constructor.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
year_month_day(const etl::chrono::year& y,
|
||||
const etl::chrono::month_day_last& mdl)
|
||||
ETL_NOEXCEPT
|
||||
Construct from month and day.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
year_month_day(const etl::chrono::year_month_day_last& ymdl)
|
||||
ETL_NOEXCEPT
|
||||
Construct from year_month_day_last.
|
||||
____________________________________________________________________________________________________
|
||||
Access
|
||||
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year year() const
|
||||
ETL_NOEXCEPT
|
||||
Returns the year.
|
||||
______________________________________________
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::month month() const
|
||||
ETL_NOEXCEPT
|
||||
Returns the month.
|
||||
______________________________________________
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::month_day_last month_day_last() const
|
||||
ETL_NOEXCEPT
|
||||
Returns the month.
|
||||
____________________________________________________________________________________________________
|
||||
Tests
|
||||
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
bool ok() const
|
||||
ETL_NOEXCEPT
|
||||
Returns true if the year and month is within the valid limits.
|
||||
______________________________________________
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
int compare(const etl::chrono::year_month_day_last& other) const
|
||||
ETL_NOEXCEPT
|
||||
Compare year_month_day with another.
|
||||
if year < other.year, returns -1
|
||||
else if year > other.year, returns 1
|
||||
if month < other.month, returns -1
|
||||
else if month > other.month, returns 1
|
||||
else returns 0
|
||||
____________________________________________________________________________________________________
|
||||
operators
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month_day_last& operator +=(const etl::chrono::years& dy)
|
||||
ETL_NOEXCEPT
|
||||
Adds etl::chrono::years.
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month_day_last& operator +=(const etl::chrono::months& dm)
|
||||
ETL_NOEXCEPT
|
||||
Adds etl::chrono::months.
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month_day_last& operator -=(const etl::chrono::years& dy)
|
||||
ETL_NOEXCEPT
|
||||
Subtracts etl::chrono::years.
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month_day_last& operator -=(const etl::chrono::months& dm)
|
||||
ETL_NOEXCEPT
|
||||
Subtracts etl::chrono::months.
|
||||
____________________________________________________________________________________________________
|
||||
Non-member operators
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month_day_last operator +(const etl::chrono::year_month_day_last& ym,
|
||||
const etl::chrono::years& dy)
|
||||
Adds etl::chrono::years.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month_day_last operator +(const etl::chrono::years& dy,
|
||||
const etl::chrono::year_month_day_last& ym)
|
||||
ETL_NOEXCEPT
|
||||
Adds etl::chrono::years.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month_day_last operator +(const etl::chrono::year_month_day_last& ym,
|
||||
const etl::chrono::months& dm)
|
||||
ETL_NOEXCEPT
|
||||
Adds etl::chrono::months.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month_day_last operator +(const etl::chrono::months& dm,
|
||||
const etl::chrono::year_month_day_last& ym)
|
||||
ETL_NOEXCEPT
|
||||
Adds etl::chrono::months.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month_last operator -(const etl::chrono::year_month_day_last& ym,
|
||||
const etl::chrono::years& dy)
|
||||
ETL_NOEXCEPT
|
||||
Subtracts etl::chrono::years.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::year_month_day_last operator -(const etl::chrono::year_month_day& ym,
|
||||
const etl::chrono::months& dm)
|
||||
ETL_NOEXCEPT
|
||||
Subtracts etl::chrono::months.
|
||||
___________________________________________________________________________________________________
|
||||
Non-member comparison operators
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
bool operator ==(const etl::chrono::year_month_day_last& lhs,
|
||||
const etl::chrono::year_month_day_last& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Equality operator.
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
bool operator !=(const etl::chrono::year_month_day_last& lhs,
|
||||
const etl::chrono::year_month_day_last& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Inequality operator.
|
||||
______________________________________________
|
||||
[[nodiscard]] friend constexpr
|
||||
auto operator <=>(const etl::chrono::year_month_day& lhs,
|
||||
const etl::chrono::year_month_day& rhs)
|
||||
ETL_NOEXCEPT
|
||||
Spaceship operator
|
||||
______________________________________________
|
||||
ETL_CONSTEXPR14
|
||||
int compare(const year_month& other) const
|
||||
ETL_NOEXCEPT
|
||||
Compare year_month_day with another.
|
||||
if year < other.year, returns -1
|
||||
else if year > other.year, returns 1
|
||||
if month < other.month, returns -1
|
||||
else if month > other.month, returns 1
|
||||
else if day < other.day, returns -1
|
||||
else if day > other.day, returns 1
|
||||
else returns 0
|
||||
____________________________________________________________________________________________________
|
||||
Hash
|
||||
|
||||
template <>
|
||||
struct hash<etl::chrono::year_month_day_last>
|
||||
Hash function for etl::chrono::year_month_day_last
|
||||
|
||||
|
||||
|
||||
57
docs/raw/frameworks/Callback Service.txt
Normal file
57
docs/raw/frameworks/Callback Service.txt
Normal file
@ -0,0 +1,57 @@
|
||||
Callback Service
|
||||
This template class allows easier integration of 'C' style events (such as interrupt vectors) and C++ handlers.
|
||||
It can allow abstraction between low level events such as interrupts and their application dependent handlers.
|
||||
The handlers may be any combination of global, static or member functions.
|
||||
It utilises the templated function wrapper. See here.
|
||||
|
||||
The callbacks are identified by an id. The values of the ids must range from zero or a specified offset, up to the maximum number of specified callbacks. Calling an unused callback id will either do nothing or, if the user has specified a handler, call this with the id of the callback.
|
||||
|
||||
There are functions that use both runtime and compile time checks of the callback id.
|
||||
Compile time is preferable.
|
||||
____________________________________________________________________________________________________
|
||||
Member functions
|
||||
|
||||
template <const size_t RANGE, const size_t OFFSET = 0U>
|
||||
etl::callback_service
|
||||
|
||||
RANGE The id range of the callbacks.
|
||||
OFFSET The starting id for the range.
|
||||
____________________________________________________________________________________________________
|
||||
callback_service()
|
||||
|
||||
Sets all of the callbacks to route to the unhandled callback.
|
||||
Sets the unhandled callback to default (do nothing).
|
||||
____________________________________________________________________________________________________
|
||||
template <const size_t ID>
|
||||
void register_callback(etl::ifunction<size_t>& callback)
|
||||
|
||||
Registers callback with the id specified in the template parameter.
|
||||
A compile time error will occur if the id is out of range.
|
||||
____________________________________________________________________________________________________
|
||||
void register_callback(size_t id, etl::ifunction<size_t>& callback)
|
||||
|
||||
Registers callback with the id specified in the template parameter.
|
||||
The registration will be ignored if the id is out of range.
|
||||
____________________________________________________________________________________________________
|
||||
void register_unhandled_callback(etl::ifunction<size_t>& callback)
|
||||
|
||||
Registers the callback to be used for unhandled ids.
|
||||
____________________________________________________________________________________________________
|
||||
template <const size_t ID>
|
||||
void callback()
|
||||
|
||||
Calls the callback associated with the id.
|
||||
Calls the unhandled callback if the id has not been registered.
|
||||
A compile time error will occur if the id is out of range.
|
||||
____________________________________________________________________________________________________
|
||||
void callback(const size_t id)
|
||||
|
||||
Calls the callback associated with the id.
|
||||
Calls the unhandled callback if the id has not been registered or if is out of range.
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
Tutorial
|
||||
|
||||
See the example project in etl\examples\FunctionInterruptSimulation
|
||||
|
||||
200
docs/raw/frameworks/Callback Timer Atomic.txt
Normal file
200
docs/raw/frameworks/Callback Timer Atomic.txt
Normal file
@ -0,0 +1,200 @@
|
||||
Callback Timer Atomic
|
||||
20.22.0
|
||||
|
||||
A software timer class that can manage up to 254 timers. Each one may be repeating or single shot.
|
||||
When a timer triggers it will call the selected function. The function may be a class member or free function.
|
||||
The timers are driven from a call to tick(uint32_t count). This call would normally be made from a high priority interrupt routine. The destination function will receive the callback in the same context as the tick call.
|
||||
The call to tick has a low overhead when a timer is not 'due'. Internally the timers are stored in 'first timeout' order so only the head of the list needs to be checked.
|
||||
|
||||
Each timer may have a period of up to 232-2 ticks (4,294,967,294).
|
||||
At 1ms per tick this would equate to just over 49 days.
|
||||
|
||||
The framework relies on an atomic counter type. With this mechanism, calls to tick are never disabled. If the foreground thread is within a disable/enable section when the timer interrupt/thread is activated then the tick update will be deferred until the next tick period. The timer interrupt/thread may interrogate the return value of tick() to check whether the update was deferred.
|
||||
|
||||
Defines the following classes:-
|
||||
etl::icallback_timer_atomic<uint_least8_t MAX_TIMERS, typename TSemaphore>
|
||||
etl::callback_timer_atomic<typename TSemaphore>
|
||||
|
||||
20.25.0
|
||||
From this version, an atomic 'semaphore' counter type must be supplied.
|
||||
|
||||
Uses definitions from timer.h
|
||||
|
||||
Important:
|
||||
For correct operation of the timer framework, the routine that calls tick must not be pre-emptible by another routine that calls a timer function. Also, calls to the timer framework may only be made from the caller of tick and one other, lower priority, thread of execution
|
||||
____________________________________________________________________________________________________
|
||||
icallback_timer_atomic
|
||||
The base class for all timer controllers.
|
||||
|
||||
Type definitions
|
||||
callback_type etl::delegate<void(void)>
|
||||
The function type used for callbacks.
|
||||
_____________________________________________________________________________________________________
|
||||
Member functions
|
||||
etl::timer::id::type register_timer(callback_type callback,
|
||||
uint32_t period,
|
||||
bool repeating)
|
||||
Registers a timer calling a free or static function.
|
||||
callback A delegate to the callback funtion that will be callled when the timer expires.
|
||||
period The timer period in ticks.
|
||||
repeating false if single shot, true if repeating.
|
||||
|
||||
Returns the allocated timer id or etl::timer::mode::NO_TIMER if one was not available.
|
||||
____________________________________________________________________________________________________
|
||||
bool unregister_timer(etl::timer::id::type id)
|
||||
Unregisters a timer.
|
||||
If the timer is active then it will be stopped.
|
||||
Returns true if a timer with the id was successfully unregistered.
|
||||
___________________________________________________________________________________________________
|
||||
void enable(bool state)
|
||||
Enables or disables the timer manager according to the state.
|
||||
____________________________________________________________________________________________________
|
||||
bool is_running() const
|
||||
Returns true if the timer manager is enabled.
|
||||
____________________________________________________________________________________________________
|
||||
void clear()
|
||||
Clears the callback timer back to the initial state. All timers will be stopped and unregistered.
|
||||
____________________________________________________________________________________________________
|
||||
bool tick(uint32_t count)
|
||||
This function updates the internal tick counter (if enabled) and must pass the number of ticks that have occurred since the last call. If the count encompasses more than one period of a repeating timer then the timer will be triggered multiple times in one call to tick.
|
||||
Returns true if the tick counter was updated, otherwise false. This may be used by the calling routine to accumulate unprocessed tick counts.
|
||||
____________________________________________________________________________________________________
|
||||
bool start(etl::timer::id::type id, bool immediate = false)
|
||||
Starts the timer with the specified id.
|
||||
If the timer is already running then the timer Is restarted from the current tick count.
|
||||
If immediate is true then the timer is triggered on the next call to tick(). Note: Single shot timers will only trigger once.
|
||||
If the id does not correspond to a registered timer then returns false.
|
||||
____________________________________________________________________________________________________
|
||||
bool stop(etl::timer::id::type id)
|
||||
Stops the timer with the specified id.
|
||||
Does nothing if the timer is already stopped.
|
||||
if the id does not correspond to a registered timer then returns false.
|
||||
____________________________________________________________________________________________________
|
||||
bool set_period(etl::timer::id::type id, uint32_t period)
|
||||
Stops the timer with the specified id.
|
||||
Sets a new timer period.
|
||||
Returns true if successful.
|
||||
____________________________________________________________________________________________________
|
||||
bool set_mode(etl::timer::id::type id, bool repeating)
|
||||
Stops the timer with the specified id.
|
||||
Sets a new timer mode.
|
||||
Returns true if successful.
|
||||
____________________________________________________________________________________________________
|
||||
etl::timer::id::type time_to_next()
|
||||
Returns the time to the next timeout.
|
||||
20.38.0
|
||||
____________________________________________________________________________________________________
|
||||
Constants
|
||||
MAX_TIMERS
|
||||
The maximum number of timer that can be handled.
|
||||
____________________________________________________________________________________________________
|
||||
callback_timer_atomic
|
||||
|
||||
Template parameters
|
||||
MAX_TIMERS The number of timers to be supported. The maximum number is 254.
|
||||
A value of 255 will result in a compile error.
|
||||
____________________________________________________________________________________________________
|
||||
message_timer_atomic()
|
||||
Default construct.
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
//***************************************************************************
|
||||
// Class callback via etl::function
|
||||
//***************************************************************************
|
||||
class Test
|
||||
{
|
||||
public:
|
||||
|
||||
Test()
|
||||
: ticks(0)
|
||||
{
|
||||
}
|
||||
|
||||
void callback()
|
||||
{
|
||||
++ticks;
|
||||
}
|
||||
|
||||
int ticks;
|
||||
};
|
||||
|
||||
Test test;
|
||||
|
||||
using callback_type = etl::icallback_timer_atomic<std::atomic_int32_t>::callback_type;
|
||||
|
||||
callback_type member_callback = callback_type::create<Test, test, &Test::callback> member_callback;
|
||||
|
||||
//***************************************************************************
|
||||
// Free function callback via etl::function
|
||||
//***************************************************************************
|
||||
int free_ticks1 = 0;
|
||||
|
||||
void free_callback1()
|
||||
{
|
||||
++free_ticks;
|
||||
}
|
||||
|
||||
callback_type free_callback1 = callback_type::create<free_function_callback>();
|
||||
|
||||
//***************************************************************************
|
||||
// Free function callback via function pointer
|
||||
//***************************************************************************
|
||||
int free_ticks2 = 0;
|
||||
|
||||
void free_callback2()
|
||||
{
|
||||
++free_ticks2;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
// Timer controller.
|
||||
//***************************************************************************
|
||||
etl::callback_timer_atomic<2, std::atomic_int32_t> timer_controller;
|
||||
|
||||
//***************************************************************************
|
||||
// The main loop.
|
||||
//***************************************************************************
|
||||
int main()
|
||||
{
|
||||
etl::timer::id::type id1 = timer_controller.register_timer(member_callback,
|
||||
1000,
|
||||
etl::timer::mode::SINGLE_SHOT);
|
||||
|
||||
etl::timer::id::type id2 = timer_controller.register_timer(free_function_callback,
|
||||
100,
|
||||
etl::timer::mode::REPEATING);
|
||||
|
||||
timer_controller.start(id1);
|
||||
timer_controller.start(id2);
|
||||
|
||||
timer_controller.enable(true);
|
||||
|
||||
// Start timer interrupts here.
|
||||
|
||||
while (true)
|
||||
{
|
||||
// Loop forever.
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
// The interrupt timer callback.
|
||||
//***************************************************************************
|
||||
void timer_interrupt()
|
||||
{
|
||||
const uint32_t TICK = 1;
|
||||
static uint32_t nticks = TICK;
|
||||
|
||||
if (timer_controller.tick(nticks))
|
||||
{
|
||||
nticks = TICK;
|
||||
}
|
||||
else
|
||||
{
|
||||
nticks += TICK;
|
||||
}
|
||||
}
|
||||
|
||||
214
docs/raw/frameworks/Callback Timer Deferred Locked.txt
Normal file
214
docs/raw/frameworks/Callback Timer Deferred Locked.txt
Normal file
@ -0,0 +1,214 @@
|
||||
Callback Timer Deferred Locked
|
||||
20.43.0
|
||||
|
||||
A software timer class that can manage up to 254 timers. Each one may be repeating or single shot.
|
||||
When a timer triggers it will call the selected function. The function may be a class member or free function.
|
||||
The timers are driven from a call to tick(uint32_t count). This call would normally be made from a high priority interrupt routine. The destination function will receive the callback in the same context as the tick call.
|
||||
The call to tick has a low overhead when a timer is not 'due'. Internally the timers are stored in 'first timeout' order so only the head of the list needs to be checked.
|
||||
This class is different from the similar etl::callback_timer_locked in that it will record any timer events during the call to tick() so that they may be handled by handle_deferred().
|
||||
|
||||
Each timer may have a period of up to 232-2 ticks (4,294,967,294).
|
||||
At 1ms per tick this would equate to just over 49 days.
|
||||
|
||||
Defines the following classes:-
|
||||
etl::icallback_timer_locked
|
||||
etl::callback_timer_deferred_locked
|
||||
|
||||
The access to the timers is controlled by three external functions, supplied to the timer by the
|
||||
member function set_locks.
|
||||
|
||||
The three delegate parameters are:-
|
||||
Try Lock Attempts to set the lock. Returns true if successful, otherwise false.
|
||||
Lock Sets the lock.
|
||||
Unlock Resets the lock.
|
||||
|
||||
Uses definitions from timer.h
|
||||
|
||||
Important:
|
||||
For correct operation of the timer framework, the routine that calls tick must not be pre-emptible by another routine that calls a timer function. Also, calls to the timer framework may only be made from the caller of tick and one other, lower priority, thread of execution
|
||||
____________________________________________________________________________________________________
|
||||
icallback_timer_locked
|
||||
The base class for all timer controllers.
|
||||
|
||||
Type definitions
|
||||
callback_type etl::delegate<void(void)>
|
||||
The function type used for callbacks.
|
||||
|
||||
try_lock_type etl::delegate<bool(void)>
|
||||
The function type used for 'try lock'.
|
||||
|
||||
lock_type etl::delegate<void(void)>
|
||||
The function type used for 'lock'.
|
||||
|
||||
unlock_type etl::delegate<void(void)>
|
||||
The function type used for 'unlock'.
|
||||
____________________________________________________________________________________________________
|
||||
Member functions
|
||||
etl::timer::id::type register_timer(callback_type callback),
|
||||
uint32_t period,
|
||||
bool repeating)
|
||||
Registers a timer calling a free or static function.
|
||||
callback A delegate to the callback free funtion that will be callled when the timer expires.
|
||||
period The timer period in ticks.
|
||||
repeating false if single shot, true if repeating.
|
||||
|
||||
Returns the allocated timer id or etl::timer::mode::NO_TIMER if one was not available.
|
||||
____________________________________________________________________________________________________
|
||||
bool unregister_timer(etl::timer::id::type id)
|
||||
Unregisters a timer.
|
||||
If the timer is active then it will be stopped.
|
||||
Returns true if a timer with the id was successfully unregistered.
|
||||
___________________________________________________________________________________________________
|
||||
void enable(bool state)
|
||||
Enables or disables the timer manager according to the state.
|
||||
____________________________________________________________________________________________________
|
||||
bool is_running() const
|
||||
Returns true if the timer manager is enabled.
|
||||
____________________________________________________________________________________________________
|
||||
void clear()
|
||||
Clears the callback timer back to the initial state. All timers will be stopped and unregistered.
|
||||
____________________________________________________________________________________________________
|
||||
bool tick(uint32_t count)
|
||||
This function updates the internal tick counter (if enabled) and must pass the number of ticks that have occurred since the last call. If the count encompasses more than one period of a repeating timer then the timer will be triggered multiple times in one call to tick.
|
||||
Returns true if the tick counter was updated, otherwise false. This may be used by the calling routine to accumulate unprocessed tick counts.
|
||||
Any triggered events will be recorded so that they
|
||||
____________________________________________________________________________________________________
|
||||
void handle_deferred()
|
||||
Handles the work collected during the tick() call.
|
||||
You can call this function after tick() or you can call this on another task to handle the timer events.
|
||||
____________________________________________________________________________________________________
|
||||
bool start(etl::timer::id::type id, bool immediate = false)
|
||||
Starts the timer with the specified id.
|
||||
If the timer is already running then the timer Is restarted from the current tick count.
|
||||
If immediate is true then the timer is triggered on the next call to tick(). Note: Single shot timers will only trigger once.
|
||||
If the id does not correspond to a registered timer then returns false.
|
||||
____________________________________________________________________________________________________
|
||||
bool stop(etl::timer::id::type id)
|
||||
Stops the timer with the specified id.
|
||||
Does nothing if the timer is already stopped.
|
||||
if the id does not correspond to a registered timer then returns false.
|
||||
____________________________________________________________________________________________________
|
||||
bool set_period(etl::timer::id::type id, uint32_t period)
|
||||
Stops the timer with the specified id.
|
||||
Sets a new timer period.
|
||||
Returns true if successful.
|
||||
____________________________________________________________________________________________________
|
||||
bool set_mode(etl::timer::id::type id, bool repeating)
|
||||
Stops the timer with the specified id.
|
||||
Sets a new timer mode.
|
||||
Returns true if successful.
|
||||
____________________________________________________________________________________________________
|
||||
void set_locks(try_lock_type try_lock_, lock_type lock_, lock_type unlock_)
|
||||
Sets the try-lock, lock and unlock delegates.
|
||||
____________________________________________________________________________________________________
|
||||
etl::timer::id::type time_to_next()
|
||||
Returns the time to the next timeout.
|
||||
20.38.0
|
||||
____________________________________________________________________________________________________
|
||||
Constants
|
||||
MAX_TIMERS
|
||||
The maximum number of timers that can be handled.
|
||||
____________________________________________________________________________________________________
|
||||
callback_timer_locked
|
||||
|
||||
Template parameters
|
||||
MAX_TIMERS The number of timers to be supported. The maximum number is 254.
|
||||
A value of 255 will result in a compile error.
|
||||
|
||||
callback_timer_locked()
|
||||
Default construct.
|
||||
The lock callback delegates are not set.
|
||||
____________________________________________________________________________________________________
|
||||
callback_timer_locked(try_lock_type try_lock, lock_type lock, unlock_type unlock)
|
||||
Construct from lock callback delegates.
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
//***************************************************************************
|
||||
// Class callback via etl::function
|
||||
//***************************************************************************
|
||||
class Test
|
||||
{
|
||||
public:
|
||||
|
||||
Test()
|
||||
: ticks(0)
|
||||
{
|
||||
}
|
||||
|
||||
void callback()
|
||||
{
|
||||
++ticks;
|
||||
}
|
||||
|
||||
int ticks;
|
||||
};
|
||||
|
||||
using callback_type = etl::icallback_timer_atomic::callback_type;
|
||||
|
||||
callback_type member_callback = callback_type::create<Test, test, &Test::callback> member_callback;
|
||||
|
||||
//***************************************************************************
|
||||
// Free function callback via etl::function
|
||||
//***************************************************************************
|
||||
int free_ticks1 = 0;
|
||||
|
||||
void free_callback1()
|
||||
{
|
||||
++free_ticks;
|
||||
}
|
||||
|
||||
callback_type free_callback1 = callback_type::create<free_function_callback>();
|
||||
|
||||
//***************************************************************************
|
||||
// Timer controller.
|
||||
//***************************************************************************
|
||||
etl::callback_timer<2> timer_controller;
|
||||
|
||||
//***************************************************************************
|
||||
// The main loop.
|
||||
//***************************************************************************
|
||||
int main()
|
||||
{
|
||||
etl::timer::id::type id1 = timer_controller.register_timer(member_callback,
|
||||
1000,
|
||||
etl::timer::mode::SINGLE_SHOT);
|
||||
|
||||
etl::timer::id::type id2 = timer_controller.register_timer(free_function_callback,
|
||||
100,
|
||||
etl::timer::mode::REPEATING);
|
||||
|
||||
timer_controller.start(id1);
|
||||
timer_controller.start(id2);
|
||||
timer_controller.start(id3);
|
||||
|
||||
timer_controller.enable(true);
|
||||
|
||||
// Start timer interrupts here.
|
||||
|
||||
while (true)
|
||||
{
|
||||
// Loop forever.
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
// The interrupt timer callback.
|
||||
//***************************************************************************
|
||||
void timer_interrupt()
|
||||
{
|
||||
const uint32_t TICK = 1;
|
||||
static uint32_t nticks = TICK;
|
||||
|
||||
if (timer_controller.tick(nticks))
|
||||
{
|
||||
nticks = TICK;
|
||||
}
|
||||
else
|
||||
{
|
||||
nticks += TICK;
|
||||
}
|
||||
}
|
||||
|
||||
226
docs/raw/frameworks/Callback Timer Interrupt.txt
Normal file
226
docs/raw/frameworks/Callback Timer Interrupt.txt
Normal file
@ -0,0 +1,226 @@
|
||||
Callback Timer Interrupt
|
||||
20.25.0
|
||||
|
||||
A software timer class that can manage up to 254 timers. Each one may be repeating or single shot.
|
||||
When a timer triggers it will call the selected function. The function may be a class member or free function.
|
||||
The timers are driven from a call to tick(uint32_t count). This call would normally be made from a high priority interrupt routine. The destination function will receive the callback in the same context as the tick call.
|
||||
The call to tick has a low overhead when a timer is not 'due'. Internally the timers are stored in 'first timeout' order so only the head of the list needs to be checked.
|
||||
|
||||
Each timer may have a period of up to 232-2 ticks (4,294,967,294).
|
||||
At 1ms per tick this would equate to just over 49 days.
|
||||
|
||||
The framework relies on a supplied interrupt enable/disable guard type. With this mechanism, calls to tick are disabled if certain member functions are called. If the program flow is within a disable/enable section when the timer interrupt is activated then the tick update will be deferred until the next tick period. The timer interrupt may interrogate the return value of tick() to check whether the update was deferred. The guard allows timer functions to be to be called from the callback called by tick().
|
||||
|
||||
Defines the following classes:-
|
||||
etl::icallback_timer_atomic<uint_least8_t MAX_TIMERS, typename TInterruptGuard>
|
||||
etl::callback_timer_atomic<typename TInterruptGuard>
|
||||
|
||||
Uses definitions from timer.h
|
||||
|
||||
Important:
|
||||
For correct operation of the timer framework, the routine that calls tick must not be pre-emptible by another routine that calls a timer function. Also, calls to the timer framework may only be made from the caller of tick and one other, lower priority, thread of execution
|
||||
____________________________________________________________________________________________________
|
||||
icallback_timer_atomic
|
||||
The base class for all timer controllers.
|
||||
|
||||
Template parameters
|
||||
MAX_TIMERS The number of timers to be supported. The maximum number is 254.
|
||||
A value of 255 will result in a compile error.
|
||||
_____________________________________________________________________________________________________
|
||||
TInterruptGuard The type that enables/disables interrupts.
|
||||
|
||||
Type definitions
|
||||
callback_type etl::delegate<void(void)>
|
||||
The function type used for callbacks.
|
||||
_____________________________________________________________________________________________________
|
||||
Member functions
|
||||
etl::timer::id::type register_timer(callback_type callback,
|
||||
uint32_t period,
|
||||
bool repeating)
|
||||
Registers a timer calling a free or static function.
|
||||
callback A delegate to the callback funtion that will be callled when the timer expires.
|
||||
period The timer period in ticks.
|
||||
repeating false if single shot, true if repeating.
|
||||
|
||||
Returns the allocated timer id or etl::timer::mode::NO_TIMER if one was not available.
|
||||
____________________________________________________________________________________________________
|
||||
bool unregister_timer(etl::timer::id::type id)
|
||||
Unregisters a timer.
|
||||
If the timer is active then it will be stopped.
|
||||
Returns true if a timer with the id was successfully unregistered.
|
||||
___________________________________________________________________________________________________
|
||||
void enable(bool state)
|
||||
Enables or disables the timer manager according to the state.
|
||||
____________________________________________________________________________________________________
|
||||
bool is_running() const
|
||||
Returns true if the timer manager is enabled.
|
||||
____________________________________________________________________________________________________
|
||||
void clear()
|
||||
Clears the callback timer back to the initial state. All timers will be stopped and unregistered.
|
||||
____________________________________________________________________________________________________
|
||||
bool tick(uint32_t count)
|
||||
This function updates the internal tick counter (if enabled) and must pass the number of ticks that have occurred since the last call. If the count encompasses more than one period of a repeating timer then the timer will be triggered multiple times in one call to tick.
|
||||
Returns true if the tick counter was updated, otherwise false. This may be used by the calling routine to accumulate unprocessed tick counts.
|
||||
____________________________________________________________________________________________________
|
||||
bool start(etl::timer::id::type id, bool immediate = false)
|
||||
Starts the timer with the specified id.
|
||||
If the timer is already running then the timer Is restarted from the current tick count.
|
||||
If immediate is true then the timer is triggered on the next call to tick(). Note: Single shot timers will only trigger once.
|
||||
If the id does not correspond to a registered timer then returns false.
|
||||
____________________________________________________________________________________________________
|
||||
bool stop(etl::timer::id::type id)
|
||||
Stops the timer with the specified id.
|
||||
Does nothing if the timer is already stopped.
|
||||
if the id does not correspond to a registered timer then returns false.
|
||||
____________________________________________________________________________________________________
|
||||
bool set_period(etl::timer::id::type id, uint32_t period)
|
||||
Stops the timer with the specified id.
|
||||
Sets a new timer period.
|
||||
Returns true if successful.
|
||||
____________________________________________________________________________________________________
|
||||
bool set_mode(etl::timer::id::type id, bool repeating)
|
||||
Stops the timer with the specified id.
|
||||
Sets a new timer mode.
|
||||
Returns true if successful.
|
||||
____________________________________________________________________________________________________
|
||||
etl::timer::id::type time_to_next()
|
||||
Returns the time to the next timeout.
|
||||
20.38.0
|
||||
____________________________________________________________________________________________________
|
||||
Constants
|
||||
MAX_TIMERS
|
||||
The maximum number of timer that can be handled.
|
||||
____________________________________________________________________________________________________
|
||||
callback_timer_atomic
|
||||
|
||||
Template parameters
|
||||
MAX_TIMERS The number of timers to be supported. The maximum number is 254.
|
||||
A value of 255 will result in a compile error.
|
||||
|
||||
TInterruptGuard The type that enables/disables interrupts.
|
||||
____________________________________________________________________________________________________
|
||||
message_timer_atomic()
|
||||
Default construct.
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
//***************************************************************************
|
||||
// Class callback via etl::function
|
||||
//***************************************************************************
|
||||
class Test
|
||||
{
|
||||
public:
|
||||
|
||||
Test()
|
||||
: ticks(0)
|
||||
{
|
||||
}
|
||||
|
||||
void callback()
|
||||
{
|
||||
++ticks;
|
||||
}
|
||||
|
||||
int ticks;
|
||||
};
|
||||
|
||||
Test test;
|
||||
|
||||
//***************************************************************************
|
||||
// The interrupt guard type.
|
||||
// Saves and disables on contruction.
|
||||
// Restores on destruction.
|
||||
//***************************************************************************
|
||||
struct InterruptGuard
|
||||
{
|
||||
InterruptGuard()
|
||||
{
|
||||
state = __save_interrupts();
|
||||
__disable_interrupts();
|
||||
}
|
||||
|
||||
~InterruptGuard()
|
||||
{
|
||||
__restore_interrupts(state);
|
||||
}
|
||||
|
||||
int state;
|
||||
};
|
||||
|
||||
using callback_type = etl::icallback_timer_atomic<InterruptGuard>::callback_type;
|
||||
|
||||
callback_type member_callback = callback_type::create<Test, test, &Test::callback> member_callback;
|
||||
|
||||
//***************************************************************************
|
||||
// Free function callback via etl::function
|
||||
//***************************************************************************
|
||||
int free_ticks1 = 0;
|
||||
|
||||
void free_callback1()
|
||||
{
|
||||
++free_ticks;
|
||||
}
|
||||
|
||||
callback_type free_callback1 = callback_type::create<free_function_callback>();
|
||||
|
||||
//***************************************************************************
|
||||
// Free function callback via function pointer
|
||||
//***************************************************************************
|
||||
int free_ticks2 = 0;
|
||||
|
||||
void free_callback2()
|
||||
{
|
||||
++free_ticks2;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
// Timer controller.
|
||||
//***************************************************************************
|
||||
etl::callback_timer_atomic<2, InterruptGuard> timer_controller;
|
||||
|
||||
//***************************************************************************
|
||||
// The main loop.
|
||||
//***************************************************************************
|
||||
int main()
|
||||
{
|
||||
etl::timer::id::type id1 = timer_controller.register_timer(member_callback,
|
||||
1000,
|
||||
etl::timer::mode::SINGLE_SHOT);
|
||||
|
||||
etl::timer::id::type id2 = timer_controller.register_timer(free_function_callback,
|
||||
100,
|
||||
etl::timer::mode::REPEATING);
|
||||
|
||||
timer_controller.start(id1);
|
||||
timer_controller.start(id2);
|
||||
|
||||
timer_controller.enable(true);
|
||||
|
||||
// Start timer interrupts here.
|
||||
|
||||
while (true)
|
||||
{
|
||||
// Loop forever.
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
// The interrupt timer callback.
|
||||
//***************************************************************************
|
||||
void timer_interrupt()
|
||||
{
|
||||
const uint32_t TICK = 1;
|
||||
static uint32_t nticks = TICK;
|
||||
|
||||
if (timer_controller.tick(nticks))
|
||||
{
|
||||
nticks = TICK;
|
||||
}
|
||||
else
|
||||
{
|
||||
nticks += TICK;
|
||||
}
|
||||
}
|
||||
|
||||
207
docs/raw/frameworks/Callback Timer Locked.txt
Normal file
207
docs/raw/frameworks/Callback Timer Locked.txt
Normal file
@ -0,0 +1,207 @@
|
||||
Callback Timer Locked
|
||||
|
||||
A software timer class that can manage up to 254 timers. Each one may be repeating or single shot.
|
||||
When a timer triggers it will call the selected function. The function may be a class member or free function.
|
||||
The timers are driven from a call to tick(uint32_t count). This call would normally be made from a high priority interrupt routine. The destination function will receive the callback in the same context as the tick call.
|
||||
The call to tick has a low overhead when a timer is not 'due'. Internally the timers are stored in 'first timeout' order so only the head of the list needs to be checked.
|
||||
|
||||
Each timer may have a period of up to 232-2 ticks (4,294,967,294).
|
||||
At 1ms per tick this would equate to just over 49 days.
|
||||
|
||||
Defines the following classes:-
|
||||
etl::icallback_timer_locked
|
||||
etl::callback_timer_locked
|
||||
|
||||
The access to the timers is controlled by three external functions, supplied to the timer by the
|
||||
member function set_locks.
|
||||
|
||||
The three delegate parameters are:-
|
||||
Try Lock Attempts to set the lock. Returns true if successful, otherwise false.
|
||||
Lock Sets the lock.
|
||||
Unlock Resets the lock.
|
||||
|
||||
Uses definitions from timer.h
|
||||
|
||||
Important:
|
||||
For correct operation of the timer framework, the routine that calls tick must not be pre-emptible by another routine that calls a timer function. Also, calls to the timer framework may only be made from the caller of tick and one other, lower priority, thread of execution
|
||||
____________________________________________________________________________________________________
|
||||
icallback_timer_locked
|
||||
The base class for all timer controllers.
|
||||
|
||||
Type definitions
|
||||
callback_type etl::delegate<void(void)>
|
||||
The function type used for callbacks.
|
||||
|
||||
try_lock_type etl::delegate<bool(void)>
|
||||
The function type used for 'try lock'.
|
||||
|
||||
lock_type etl::delegate<void(void)>
|
||||
The function type used for 'lock'.
|
||||
|
||||
unlock_type etl::delegate<void(void)>
|
||||
The function type used for 'unlock'.
|
||||
____________________________________________________________________________________________________
|
||||
Member functions
|
||||
etl::timer::id::type register_timer(callback_type callback),
|
||||
uint32_t period,
|
||||
bool repeating)
|
||||
Registers a timer calling a free or static function.
|
||||
callback A delegate to the callback free funtion that will be callled when the timer expires.
|
||||
period The timer period in ticks.
|
||||
repeating false if single shot, true if repeating.
|
||||
|
||||
Returns the allocated timer id or etl::timer::mode::NO_TIMER if one was not available.
|
||||
____________________________________________________________________________________________________
|
||||
bool unregister_timer(etl::timer::id::type id)
|
||||
Unregisters a timer.
|
||||
If the timer is active then it will be stopped.
|
||||
Returns true if a timer with the id was successfully unregistered.
|
||||
___________________________________________________________________________________________________
|
||||
void enable(bool state)
|
||||
Enables or disables the timer manager according to the state.
|
||||
____________________________________________________________________________________________________
|
||||
bool is_running() const
|
||||
Returns true if the timer manager is enabled.
|
||||
____________________________________________________________________________________________________
|
||||
void clear()
|
||||
Clears the callback timer back to the initial state. All timers will be stopped and unregistered.
|
||||
____________________________________________________________________________________________________
|
||||
bool tick(uint32_t count)
|
||||
This function updates the internal tick counter (if enabled) and must pass the number of ticks that have occurred since the last call. If the count encompasses more than one period of a repeating timer then the timer will be triggered multiple times in one call to tick.
|
||||
Returns true if the tick counter was updated, otherwise false. This may be used by the calling routine to accumulate unprocessed tick counts.
|
||||
____________________________________________________________________________________________________
|
||||
bool start(etl::timer::id::type id, bool immediate = false)
|
||||
Starts the timer with the specified id.
|
||||
If the timer is already running then the timer Is restarted from the current tick count.
|
||||
If immediate is true then the timer is triggered on the next call to tick(). Note: Single shot timers will only trigger once.
|
||||
If the id does not correspond to a registered timer then returns false.
|
||||
____________________________________________________________________________________________________
|
||||
bool stop(etl::timer::id::type id)
|
||||
Stops the timer with the specified id.
|
||||
Does nothing if the timer is already stopped.
|
||||
if the id does not correspond to a registered timer then returns false.
|
||||
____________________________________________________________________________________________________
|
||||
bool set_period(etl::timer::id::type id, uint32_t period)
|
||||
Stops the timer with the specified id.
|
||||
Sets a new timer period.
|
||||
Returns true if successful.
|
||||
____________________________________________________________________________________________________
|
||||
bool set_mode(etl::timer::id::type id, bool repeating)
|
||||
Stops the timer with the specified id.
|
||||
Sets a new timer mode.
|
||||
Returns true if successful.
|
||||
____________________________________________________________________________________________________
|
||||
void set_locks(try_lock_type try_lock_, lock_type lock_, lock_type unlock_)
|
||||
Sets the try-lock, lock and unlock delegates.
|
||||
____________________________________________________________________________________________________
|
||||
etl::timer::id::type time_to_next()
|
||||
Returns the time to the next timeout.
|
||||
20.38.0
|
||||
____________________________________________________________________________________________________
|
||||
Constants
|
||||
MAX_TIMERS
|
||||
The maximum number of timers that can be handled.
|
||||
____________________________________________________________________________________________________
|
||||
callback_timer_locked
|
||||
|
||||
Template parameters
|
||||
MAX_TIMERS The number of timers to be supported. The maximum number is 254.
|
||||
A value of 255 will result in a compile error.
|
||||
|
||||
callback_timer_locked()
|
||||
Default construct.
|
||||
The lock callback delegates are not set.
|
||||
____________________________________________________________________________________________________
|
||||
callback_timer_locked(try_lock_type try_lock, lock_type lock, unlock_type unlock)
|
||||
Construct from lock callback delegates.
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
//***************************************************************************
|
||||
// Class callback via etl::function
|
||||
//***************************************************************************
|
||||
class Test
|
||||
{
|
||||
public:
|
||||
|
||||
Test()
|
||||
: ticks(0)
|
||||
{
|
||||
}
|
||||
|
||||
void callback()
|
||||
{
|
||||
++ticks;
|
||||
}
|
||||
|
||||
int ticks;
|
||||
};
|
||||
|
||||
using callback_type = etl::icallback_timer_atomic::callback_type;
|
||||
|
||||
callback_type member_callback = callback_type::create<Test, test, &Test::callback> member_callback;
|
||||
|
||||
//***************************************************************************
|
||||
// Free function callback via etl::function
|
||||
//***************************************************************************
|
||||
int free_ticks1 = 0;
|
||||
|
||||
void free_callback1()
|
||||
{
|
||||
++free_ticks;
|
||||
}
|
||||
|
||||
callback_type free_callback1 = callback_type::create<free_function_callback>();
|
||||
|
||||
//***************************************************************************
|
||||
// Timer controller.
|
||||
//***************************************************************************
|
||||
etl::callback_timer<2> timer_controller;
|
||||
|
||||
//***************************************************************************
|
||||
// The main loop.
|
||||
//***************************************************************************
|
||||
int main()
|
||||
{
|
||||
etl::timer::id::type id1 = timer_controller.register_timer(member_callback,
|
||||
1000,
|
||||
etl::timer::mode::SINGLE_SHOT);
|
||||
|
||||
etl::timer::id::type id2 = timer_controller.register_timer(free_function_callback,
|
||||
100,
|
||||
etl::timer::mode::REPEATING);
|
||||
|
||||
timer_controller.start(id1);
|
||||
timer_controller.start(id2);
|
||||
timer_controller.start(id3);
|
||||
|
||||
timer_controller.enable(true);
|
||||
|
||||
// Start timer interrupts here.
|
||||
|
||||
while (true)
|
||||
{
|
||||
// Loop forever.
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
// The interrupt timer callback.
|
||||
//***************************************************************************
|
||||
void timer_interrupt()
|
||||
{
|
||||
const uint32_t TICK = 1;
|
||||
static uint32_t nticks = TICK;
|
||||
|
||||
if (timer_controller.tick(nticks))
|
||||
{
|
||||
nticks = TICK;
|
||||
}
|
||||
else
|
||||
{
|
||||
nticks += TICK;
|
||||
}
|
||||
}
|
||||
|
||||
244
docs/raw/frameworks/Callback Timer.txt
Normal file
244
docs/raw/frameworks/Callback Timer.txt
Normal file
@ -0,0 +1,244 @@
|
||||
Callback Timer
|
||||
This class has been superseded.
|
||||
Consider using callback_timer_atomic or callback_timer_locked.
|
||||
|
||||
A software timer class that can manage up to 254 timers. Each one may be repeating or single shot.
|
||||
When a timer triggers it will call the selected function. The function may be a class member or free function.
|
||||
The timers are driven from a call to tick(uint32_t count). This call would normally be made from a high priority interrupt routine. The destination function will receive the callback in the same context as the tick call.
|
||||
The call to tick has a low overhead when a timer is not 'due'. Internally the timers are stored in 'first timeout' order so only the head of the list needs to be checked.
|
||||
|
||||
Each timer may have a period of up to 232-2 ticks (4,294,967,294).
|
||||
At 1ms per tick this would equate to just over 49 days.
|
||||
|
||||
Defines the following classes:-
|
||||
etl::icallback_timer
|
||||
etl::callback_timer
|
||||
etl::callback_timer_data
|
||||
|
||||
Uses definitions from timer.h
|
||||
|
||||
An example Keil project for the Nucleo 401RE may be found in examples/ArmTimerCallbacks - C++
|
||||
|
||||
Usage notes
|
||||
The message timer is designed to be used in a timer interrupt/thread - single foreground task environment. The timer tick call may pre-empt the foreground task, except when a timer function is within a ETL_DISABLE_TIMER_UPDATES / ETL_ENABLE_TIMER_UPDATES section. These macros will either use an atomic semaphore or contain code to disable or enable the relevant timer interrupts.
|
||||
|
||||
There are two macros that control which mechanism is used.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_CALLBACK_TIMER_USE_ATOMIC_LOCK
|
||||
|
||||
The framework relies on an atomic counter type. By default this is defined as etl::timer_semaphore_t.
|
||||
This in turn is either defined as std::atomic<uint32_t>, if the compiler supports std::atomic, or
|
||||
etl::atomic<uint32_t> if there is an atomic_xxx.h defined for the platform. A user defined type may be used for the semaphore by defining ETL_TIMER_SEMAPHORE_TYPE. Only the timer interrupt/thread and one foreground task may call register_timer, unregister_timer, clear, start or stop.
|
||||
With this mechanism, calls to tick are never disabled. If the foreground thread is within a disable/enable section when the timer interrupt/thread is activated then the tick update will be deferred until the next tick period. The timer interrupt/thread may interrogate the return value of tick() to check whether the update was deferred.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_CALLBACK_TIMER_USE_INTERRUPT_LOCK
|
||||
|
||||
The user must supply two macro definitions (ETL_CALLBACK_TIMER_DISABLE_INTERRUPTS and ETL_MESSAGE_TIMER_ENABLE_INTERRUPTS) to control interrupt enables. These macros must enable/disable all interrupts that may call tick, register_timer, unregister_timer, clear, start or stop.
|
||||
The user should ensure that mechanisms, such as memory barriers are used to disable re-ordering of the instructions.
|
||||
If the foreground task is within a disable/enable section when the timer interrupt is triggered then the tick update will be deferred until the interrupts are re-enabled. Depending on the resolution of the timers, the interrupt routine may be able to compensate for the delay by passing a modified tick count to tick().
|
||||
|
||||
Important:
|
||||
For correct operation of the timer framework, the routine that calls tick must not be pre-emptible by another routine that calls a timer function. Also, calls to the timer framework may only be made from the caller of tick and one other, lower priority, thread of execution
|
||||
____________________________________________________________________________________________________
|
||||
icallback_timer
|
||||
The base class for all timer controllers.
|
||||
|
||||
Member functions
|
||||
etl::timer::id::type register_timer(void (*p_callback)(),
|
||||
uint32_t period,
|
||||
bool repeating)
|
||||
|
||||
Registers a timer calling a free or static function.
|
||||
p_callback A pointer to the callback free funtion that will be callled when the timer expires.
|
||||
period The timer period in ticks.
|
||||
repeating false if single shot, true if repeating.
|
||||
|
||||
Returns the allocated timer id or etl::timer::mode::NO_TIMER if one was not available.
|
||||
_____________________________________________________________________________________________________
|
||||
etl::timer::id::type register_timer(etl::ifunction<void>& callback,
|
||||
uint32_t period,
|
||||
bool repeating)
|
||||
|
||||
Registers a timer calling a free, static or member function through the etl::ifunction interface.
|
||||
p_callback A reference to the etl::function callback function that will be called when the timer expires.
|
||||
period The timer period in ticks.
|
||||
repeating false if single shot, true if repeating.
|
||||
|
||||
Returns the allocated timer id or etl::timer::id::NO_TIMER if one was not available.
|
||||
_____________________________________________________________________________________________________
|
||||
etl::timer::id::type register_timer(etl::delegate<void()>& callback,
|
||||
uint32_t period,
|
||||
bool repeating)
|
||||
|
||||
Registers a timer calling a free, static or member function through the etl::delegate interface.
|
||||
p_callback A reference to the etl::delegate callback function that will be called when the timer expires.
|
||||
period The timer period in ticks.
|
||||
repeating false if single shot, true if repeating.
|
||||
|
||||
Returns the allocated timer id or etl::timer::id::NO_TIMER if one was not available.
|
||||
____________________________________________________________________________________________________
|
||||
bool unregister_timer(etl::timer::id::type id)
|
||||
|
||||
Unregisters a timer.
|
||||
If the timer is active then it will be stopped.
|
||||
Returns true if a timer with the id was successfully unregistered.
|
||||
___________________________________________________________________________________________________
|
||||
void enable(bool state)
|
||||
|
||||
Enables or disables the timer manager according to the state.
|
||||
____________________________________________________________________________________________________
|
||||
bool is_running() const
|
||||
|
||||
Returns true if the timer manager is enabled.
|
||||
____________________________________________________________________________________________________
|
||||
void clear()
|
||||
|
||||
Clears the callback timer back to the initial state. All timers will be stopped and unregistered.
|
||||
____________________________________________________________________________________________________
|
||||
bool tick(uint32_t count)
|
||||
|
||||
This function updates the internal tick counter (if enabled) and must pass the number of ticks that have occurred since the last call. If the count encompasses more than one period of a repeating timer then the timer will be triggered multiple times in one call to tick.
|
||||
Returns true if the tick counter was updated, otherwise false. This may be used by the calling routine to accumulate unprocessed tick counts.
|
||||
____________________________________________________________________________________________________
|
||||
bool start(etl::timer::id::type id, bool immediate = false)
|
||||
|
||||
Starts the timer with the specified id.
|
||||
If the timer is already running then the timer Is restarted from the current tick count.
|
||||
If immediate is true then the timer is triggered on the next call to tick(). Note: Single shot timers will only trigger once.
|
||||
If the id does not correspond to a registered timer then returns false.
|
||||
____________________________________________________________________________________________________
|
||||
bool stop(etl::timer::id::type id)
|
||||
|
||||
Stops the timer with the specified id.
|
||||
Does nothing if the timer is already stopped.
|
||||
if the id does not correspond to a registered timer then returns false.
|
||||
____________________________________________________________________________________________________
|
||||
bool set_period(etl::timer::id::type id, uint32_t period)
|
||||
|
||||
Stops the timer with the specified id.
|
||||
Sets a new timer period.
|
||||
Returns true if successful.
|
||||
____________________________________________________________________________________________________
|
||||
bool set_mode(etl::timer::id::type id, bool repeating)
|
||||
|
||||
Stops the timer with the specified id.
|
||||
Sets a new timer mode.
|
||||
Returns true if successful.
|
||||
____________________________________________________________________________________________________
|
||||
etl::timer::id::type time_to_next()
|
||||
Returns the time to the next timeout.
|
||||
20.38.0
|
||||
____________________________________________________________________________________________________
|
||||
Constants
|
||||
|
||||
MAX_TIMERS
|
||||
____________________________________________________________________________________________________
|
||||
callback_timer
|
||||
|
||||
Template parameters
|
||||
MAX_TIMERS The number of timers to be supported. The maximum number is 254.
|
||||
A value of 255 will result in a compile error.
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
//***************************************************************************
|
||||
// Class callback via etl::function
|
||||
//***************************************************************************
|
||||
class Test
|
||||
{
|
||||
public:
|
||||
|
||||
Test()
|
||||
: ticks(0)
|
||||
{
|
||||
}
|
||||
|
||||
void callback()
|
||||
{
|
||||
++ticks;
|
||||
}
|
||||
|
||||
int ticks;
|
||||
};
|
||||
|
||||
Test test;
|
||||
etl::function_mv<Test, &Test::callback> member_callback(test);
|
||||
|
||||
//***************************************************************************
|
||||
// Free function callback via etl::function
|
||||
//***************************************************************************
|
||||
int free_ticks1 = 0;
|
||||
|
||||
void free_callback1()
|
||||
{
|
||||
++free_ticks;
|
||||
}
|
||||
|
||||
etl::function_fv<free_callback1> free_function_callback;
|
||||
|
||||
//***************************************************************************
|
||||
// Free function callback via function pointer
|
||||
//***************************************************************************
|
||||
int free_ticks2 = 0;
|
||||
|
||||
void free_callback2()
|
||||
{
|
||||
++free_ticks2;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
// Timer controller.
|
||||
//***************************************************************************
|
||||
etl::callback_timer<3> timer_controller;
|
||||
|
||||
//***************************************************************************
|
||||
// The main loop.
|
||||
//***************************************************************************
|
||||
int main()
|
||||
{
|
||||
etl::timer::id::type id1 = timer_controller.register_timer(member_callback,
|
||||
1000,
|
||||
etl::timer::mode::SINGLE_SHOT);
|
||||
|
||||
etl::timer::id::type id2 = timer_controller.register_timer(free_function_callback,
|
||||
100,
|
||||
etl::timer::mode::REPEATING);
|
||||
|
||||
etl::timer::id::type id3 = timer_controller.register_timer(free_callback2,
|
||||
10,
|
||||
etl::timer::mode::REPEATING);
|
||||
|
||||
timer_controller.start(id1);
|
||||
timer_controller.start(id2);
|
||||
timer_controller.start(id3);
|
||||
|
||||
timer_controller.enable(true);
|
||||
|
||||
// Start timer interrupts here.
|
||||
|
||||
while (true)
|
||||
{
|
||||
// Loop forever.
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
// The interrupt timer callback.
|
||||
//***************************************************************************
|
||||
void timer_interrupt()
|
||||
{
|
||||
const uint32_t TICK = 1;
|
||||
static uint32_t nticks = TICK;
|
||||
|
||||
if (timer_controller.tick(nticks))
|
||||
{
|
||||
nticks = TICK;
|
||||
}
|
||||
else
|
||||
{
|
||||
nticks += TICK;
|
||||
}
|
||||
}
|
||||
|
||||
183
docs/raw/frameworks/Cooperative Scheduler.txt
Normal file
183
docs/raw/frameworks/Cooperative Scheduler.txt
Normal file
@ -0,0 +1,183 @@
|
||||
Cooperative Scheduler
|
||||
|
||||
A lightweight cooperative multi-tasking scheduler.
|
||||
Can be used stand-alone or in conjunction with a messaging system such as the ETL's message router or FSM as the back-end handler. For use when a complex OS or RTOS is overkill.
|
||||
|
||||
Calls an 'idle' callback whenever the scheduler returns true.
|
||||
Calls a 'watchdog' callback whenever the scheduler returns.
|
||||
|
||||
The scheduler makes use of etl::task.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
Scheduling Policies
|
||||
A number of built-in scheduling policies are available.
|
||||
Note: The tasks are stored in decreasing priority id order. i.e. Higher id = higher priority.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
Sequential Single
|
||||
etl::scheduler_policy_sequential_single
|
||||
|
||||
A sequential algorithm that calls a task if it has work to do , starting from the highest priority task.
|
||||
On return, it moves to the next task in the list. At the end of the list it returns the idle status.
|
||||
If no tasks with work were found then the idle status is set to true.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
Sequential Multiple
|
||||
etl::scheduler_policy_sequential_multiple
|
||||
|
||||
A sequential algorithm that calls a task if it has work to do , starting from the highest priority task.
|
||||
On return, it calls the task again if it still has work, otherwise it moves to the next task in the list.
|
||||
At the end of the list it returns the idle status.
|
||||
If no tasks with work were found then the idle status is set to true.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
Highest Priority
|
||||
etl::scheduler_policy_highest_priority
|
||||
|
||||
An algorithm that calls the highest priority task that has work to do.
|
||||
Returns the idle status.
|
||||
If no tasks with work were found then the idle status is set to true.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
Most Work
|
||||
etl::scheduler_policy_most_work
|
||||
|
||||
An algorithm that calls the task that has the most work to do, starting from the highest priority task.
|
||||
Returns the idle status.
|
||||
If no tasks with work were found then the idle status is set to true.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
Custom Scheduler
|
||||
Creating a custom scheduler policy is simple.
|
||||
Just create a structure with the following signature and add your own scheduling algorithm.
|
||||
To get 'idle' callbacks then the policy must regularly return true.
|
||||
To get 'watchdog' callbacks then the policy must regularly return.
|
||||
|
||||
struct scheduler_policy_custom
|
||||
{
|
||||
bool schedule_tasks(etl::ivector<etl::task*>& task_list)
|
||||
{
|
||||
bool idle = true;
|
||||
|
||||
//**************************************
|
||||
// Add your scheduling policy here.
|
||||
// Set 'idle' to false if any tasks were run.
|
||||
//**************************************
|
||||
|
||||
return idle;
|
||||
}
|
||||
};
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
ischeduler
|
||||
Can be used as a reference to all scheduler instances.
|
||||
|
||||
ischeduler()
|
||||
|
||||
Constructor
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
void set_idle_callback(etl::ifunction<void>& callback);
|
||||
|
||||
Sets the function to be called when idle.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
void set_watchdog_callback(etl::ifunction<void>& callback);
|
||||
|
||||
Sets the function to be called to reset the watchdog.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
void set_scheduler_running(bool scheduler_running);
|
||||
|
||||
Sets the running state of the scheduler.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
bool scheduler_is_running() const;
|
||||
|
||||
Gets the running state of the scheduler.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
void exit_scheduler()
|
||||
|
||||
Instructs the scheduler to exit after the next idle call.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
void add_task(etl::task& task);
|
||||
|
||||
Adds a task to the task list.
|
||||
The task list is in priority order where higher id = higher priority. Tasks with duplicate ids are in insert order.
|
||||
Emits an etl::scheduler_too_many_tasks_exception if the task list is full.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TSize>
|
||||
void add_task_list(etl::task** p_tasks, TSize size);
|
||||
|
||||
Emits an etl::scheduler_too_many_tasks_exception if the task list is full.
|
||||
Emits an etl::scheduler_null_task_exception if any of the task pointers is null.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
virtual void start()
|
||||
|
||||
Starts the scheduler.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
scheduler
|
||||
Inherits from etl::ischeduler.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
Template Parameters
|
||||
|
||||
TSchedulerPolicy The policy to use schedule tasks.
|
||||
MAX_TASKS The maximum number of tasks to schedule.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
Member Functions
|
||||
|
||||
scheduler()
|
||||
|
||||
Constructor.
|
||||
|
||||
void start()
|
||||
|
||||
Starts the scheduler.
|
||||
Emits an etl::scheduler_no_tasks_exception if there are no tasks in the list.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
Errors
|
||||
|
||||
scheduler_exception
|
||||
Inherits from etl::exception
|
||||
|
||||
scheduler_no_tasks_exception
|
||||
Inherits from etl::scheduler_exception
|
||||
|
||||
scheduler_null_task_exception
|
||||
Inherits from etl::scheduler_exception
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
Overview of use
|
||||
As a basic example, you will have to define the following...
|
||||
|
||||
Tasks
|
||||
For each of your tasks, derive a class from etl::task and overide the two virtual functions uint32_t task_request_work() const and void task_process_work(). task_request_work returns a value that informs the scheduler that this task has work to process. The return value should be non-zero if the task has work. This meaning of this is user defined, it could be the number of messages in the task's queue, or just a 0 = no work, 1 = have work. task_process_work allows the task to process any work that it has. How much work it processes on each call is user defined; often it will be one 'unit' of work and letting the policy determine which task gets the next opportunity to process more.
|
||||
|
||||
Task list
|
||||
An array of pointers to the tasks. Passed to the scheduler with add_task_list.
|
||||
Use add_task to add additional tasks.
|
||||
|
||||
The scheduler
|
||||
An instance of etl::scheduler with the required scheduling policy.
|
||||
Initialise the task list by calling add_task_list.
|
||||
|
||||
Callbacks
|
||||
If you wish to get callbacks for 'idle' or 'watchdog' then define callback functions and call set_idle_callback and set_watchdog_callback to tell the scheduler.
|
||||
The callbacks may be global, static or member function, wrapped in an etl::function.
|
||||
|
||||
Starting the scheduler
|
||||
The scheduler is started by calling start().
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
An example of the scheduler can be found in the repository in examples/Scheduler
|
||||
|
||||
58
docs/raw/frameworks/Delegate Service.txt
Normal file
58
docs/raw/frameworks/Delegate Service.txt
Normal file
@ -0,0 +1,58 @@
|
||||
Delegate Service
|
||||
This template class allows easier integration of 'C' style events (such as interrupt vectors) and C++ handlers.
|
||||
It can allow abstraction between low level events such as interrupts and their application dependent handlers.
|
||||
The handlers may be any combination of global, static, member functions, lambdas and functors.
|
||||
It utilises the templated function wrapper. See here.
|
||||
|
||||
The delegate callbacks are identified by an id. The values of the ids must range from zero or a specified offset, up to the maximum range of specified delegates. Calling an unused delegate id will either do nothing or, if the user has specified a handler, call this with the id of the delegate.
|
||||
|
||||
There are functions that use both runtime and compile time checks of the delegate id.
|
||||
Compile time is preferable.
|
||||
|
||||
template <size_t Range, size_t Offset = 0U, const etl::delegate<void(size_t)>* Delegates = nullptr>
|
||||
etl::delegate_service
|
||||
|
||||
Range The id range of the delegates (last - first + 1).
|
||||
Offset The starting id for the range. Default 0.
|
||||
Delegates An optional pointer to an array of delegate pointers.
|
||||
|
||||
If the pointer to a delegate array is supplied as a template parameter then the delegate service may be declared constexpr, otherwise the service is runtime only.
|
||||
____________________________________________________________________________________________________
|
||||
Member functions
|
||||
____________________________________________________________________________________________________
|
||||
delegate_service()
|
||||
Runtime only
|
||||
Sets all of the delegates to route to the unhandled delegate.
|
||||
Sets the unhandled delegate to default (do nothing).
|
||||
____________________________________________________________________________________________________
|
||||
template <const size_t ID>
|
||||
void register_delegate(etl::delegate<void(size_t)>& callback)
|
||||
Runtime only
|
||||
Registers delegate with the id specified in the template parameter.
|
||||
A compile time error will occur if the id is out of range.
|
||||
____________________________________________________________________________________________________
|
||||
void register_delegate(size_t id, etl::delegate<void(size_t)>& callback)
|
||||
Runtime only
|
||||
Registers delegate with the id specified in the template parameter.
|
||||
The registration will be ignored if the id is out of range.
|
||||
____________________________________________________________________________________________________
|
||||
void register_unhandled_delegate(etl::delegate<void(size_t)>& callback)
|
||||
Runtime only
|
||||
Registers the delegate to be used for unhandled ids.
|
||||
____________________________________________________________________________________________________
|
||||
template <const size_t ID>
|
||||
void call()
|
||||
Calls the delegate associated with the id.
|
||||
Calls the unhandled delegate if the id has not been registered.
|
||||
A compile time error will occur if the id is out of range.
|
||||
____________________________________________________________________________________________________
|
||||
void call(const size_t id)
|
||||
Calls the delegate associated with the id.
|
||||
Calls the unhandled delegate if the id has not been registered or if is out of range.
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
Tutorial
|
||||
|
||||
See the example project in etl\examples\FunctionInterruptSimulation-Delegates
|
||||
|
||||
434
docs/raw/frameworks/Finite State Machine.txt
Normal file
434
docs/raw/frameworks/Finite State Machine.txt
Normal file
@ -0,0 +1,434 @@
|
||||
Finite State Machine
|
||||
|
||||
This page documents version 20.0.0 and above.
|
||||
For version 19.x.x or earlier see this page.
|
||||
|
||||
A finite state machine driven by the reception of events (messages) . The incoming messages will be automatically routed to specific handlers based on the message list defined in the template parameters. Optional on_entry and on_exit handlers are available.
|
||||
|
||||
This FSM is slightly more involved to set up than the traditional simple table driven method, but provides great flexibility in implementation. It may also be faster due to the fact that all messages are routed through a direct switch/case/call method rather than scanning a lookup table and calling indirectly through function pointers.
|
||||
|
||||
The on_event functions are not virtual. The template class uses CRTP to directly call the derived class's functions.
|
||||
|
||||
Defines the following classes:-
|
||||
etl::ifsm_state
|
||||
etl::fsm_state <<template>>
|
||||
etl::fsm
|
||||
etl::fsm_exception
|
||||
etl::fsm_null_state_exception
|
||||
etl::fsm_state_id_exception
|
||||
etl::fsm_state_list_exception
|
||||
|
||||
template <typename... TStates>
|
||||
class fsm_state_pack
|
||||
A class to store FSM states.
|
||||
Static asserts if state IDs are not 0..N-1 and in order
|
||||
Static asserts if there are no states
|
||||
Static asserts if any state IDs are greater or equal to etl::No_State_Change
|
||||
20.43.0
|
||||
|
||||
Note: This header is a generated from fsm_generator.h. To handle more than the standard 16 message types then a new one must be generated.
|
||||
See Generators
|
||||
____________________________________________________________________________________________________
|
||||
Types
|
||||
|
||||
etl::fsm_state_id_t
|
||||
By default is defined as uint_least8_t.
|
||||
If the user defines ETL_FSM_STATE_ID_TYPE then the type will be set to this.
|
||||
____________________________________________________________________________________________________
|
||||
ifsm_state
|
||||
|
||||
The base for all FSM states.
|
||||
____________________________________________________________________________________________________
|
||||
etl::fsm_state_id_t get_state_id() const
|
||||
Returns the id of the state.
|
||||
____________________________________________________________________________________________________
|
||||
virtual fsm_state_id_t process_event(const etl::imessage& message) = 0
|
||||
|
||||
The etl::fsm_state will override this.
|
||||
Processes the event message from the specified source.
|
||||
____________________________________________________________________________________________________
|
||||
virtual fsm_state_id_t on_enter_state()
|
||||
By default returns No_State_Change.
|
||||
The derived state should override this to provide alternative behaviour.
|
||||
____________________________________________________________________________________________________
|
||||
virtual void on_exit_state()
|
||||
By default does nothing.
|
||||
The derived state should override this to provide alternative behaviour.
|
||||
____________________________________________________________________________________________________
|
||||
void add_child_state(etl::ifsm_state& state)
|
||||
Adds the specified state as a child state.
|
||||
The first state added will be the default state.
|
||||
This is only of use when used with an etl::hsfm instance.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TSize>
|
||||
void set_child_states(etl::ifsm_state** state_list, TSize size)
|
||||
Sets the list of child states.
|
||||
Sets the default state to the first in the list.
|
||||
Each state is modified to set it's parent state pointer.
|
||||
This is only of use when used with an etl::hsfm instance.
|
||||
____________________________________________________________________________________________________
|
||||
Constants
|
||||
|
||||
static ETL_CONSTANT fsm_state_id_t No_State_Change
|
||||
The return value to indicate that the state will not change.
|
||||
____________________________________________________________________________________________________
|
||||
fsm_state
|
||||
A templated state base. Inherits from etl::ifsm_state.
|
||||
____________________________________________________________________________________________________
|
||||
Template parameters
|
||||
|
||||
For C++03 to C++14
|
||||
TContext The FSM context class. i.e. The class derived from etl::fsm.
|
||||
TDerived The derived state.
|
||||
T1 The first message type.
|
||||
T2... The additional message types.
|
||||
The maximum number of types can be set by running the generator for this file. The default is 16
|
||||
____________________________________________________________________________________________________
|
||||
For C++17 and above
|
||||
TContext The FSM context class. i.e. The class derived from etl::fsm.
|
||||
TDerived The derived state.
|
||||
TMessage_Types... The message types.
|
||||
|
||||
This definition will automatically be selected if the compiler supports C++17. It uses fold expressions to resolve on_event() calls.
|
||||
To use the older C++03 compatible definition, define ETL_FSM_FORCE_CPP03 as a project setting or in the optional etl_profile.h.
|
||||
____________________________________________________________________________________________________
|
||||
The derived class must define the following member functions.
|
||||
|
||||
etl::fsm_state_id_t on_event(const Type& msg);
|
||||
sender The originator of the message.
|
||||
msg The event message. A const reference to the concrete message type.
|
||||
Replace Type with the concrete message type.
|
||||
And so on for all of the template parameter types.
|
||||
Returns the id of the next state.
|
||||
____________________________________________________________________________________________________
|
||||
etl::fsm_state_id_t on_event_unknown(const etl::imessage& msg);
|
||||
sender The originator of the message.
|
||||
msg The event message. A const reference to the base message type.
|
||||
Called when a message type is received that is not in the template list.
|
||||
Returns the id of the next state.
|
||||
____________________________________________________________________________________________________
|
||||
Member Functions
|
||||
|
||||
TContext& get_fsm_context() const
|
||||
Gets a reference to the FSM context.
|
||||
This is the class that was derived from etl::fsm.
|
||||
____________________________________________________________________________________________________
|
||||
Enumerations
|
||||
|
||||
STATE_ID The id of this state.
|
||||
____________________________________________________________________________________________________
|
||||
fsm
|
||||
The state machine.
|
||||
Inherits from etl::imessage_router.
|
||||
____________________________________________________________________________________________________
|
||||
fsm(etl::message_router_id_t id)
|
||||
Constructor.
|
||||
Sets the router id for the FSM.
|
||||
The FSM is not started.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TSize>
|
||||
void set_states(etl::ifsm_state** p_states, TSize size)
|
||||
Set the states for the FSM
|
||||
Emits an etl::fsm_state_list_exception if size is zero.
|
||||
Emits an etl::fsm_state_list_exception if states are in the incorrect id order.
|
||||
Emits an etl::fsm_null_state_exception if any of the state pointers is null.
|
||||
|
||||
Note: The pointers to the states in the state list must be at the index specified by the state id.
|
||||
i.e. In the example below stateList[StateId::IDLE] == &idle
|
||||
____________________________________________________________________________________________________
|
||||
template <typename... TStates>
|
||||
void set_states(etl::fsm_state_pack<TStates...>& state_pack)
|
||||
Set the states for the FSM
|
||||
____________________________________________________________________________________________________
|
||||
void start(bool call_on_enter_state = true);
|
||||
Starts the FSM.
|
||||
If call_on_enter_state is true then on_enter_state is called for the initial state. Default is true.
|
||||
Can only be called once.
|
||||
Subsequent calls will do nothing.
|
||||
____________________________________________________________________________________________________
|
||||
void receive(const etl::imessage& message)
|
||||
Top level message handler for the FSM.
|
||||
___________________________________________________________________________________________________
|
||||
void receive(etl::message_router_id_t destination_router_id,
|
||||
const etl::imessage& message)
|
||||
Top level message handler for the FSM.
|
||||
If the destination id is not the FSM's id, then the message is ignored.
|
||||
____________________________________________________________________________________________________
|
||||
bool accepts(etl::message_id_t id) const
|
||||
|
||||
Returns true.
|
||||
____________________________________________________________________________________________________
|
||||
etl::fsm_state_id_t get_state_id() const
|
||||
Gets the current state id.
|
||||
____________________________________________________________________________________________________
|
||||
ifsm_state& get_state()
|
||||
Gets a reference to the current state interface.
|
||||
Emits an etl::etl::fsm_null_state_exception if the current state is null.
|
||||
____________________________________________________________________________________________________
|
||||
const ifsm_state& get_state() const
|
||||
Gets a const reference to the current state interface.
|
||||
Emits an etl::etl::fsm_null_state_exception if the current state is null.
|
||||
____________________________________________________________________________________________________
|
||||
bool is_started() const
|
||||
Checks if the FSM has been started.
|
||||
____________________________________________________________________________________________________
|
||||
void reset(bool call_on_exit_state = false)
|
||||
Resets the FSM to its pre-started state.
|
||||
If call_on_exit_state is true then on_exit_state is called for the current state. Default is false.
|
||||
____________________________________________________________________________________________________
|
||||
etl::fsm_state_id_t transition_to(etl::fsm_state_id_t new_state_id)
|
||||
Invokes a state transition.
|
||||
Returns the new state id.
|
||||
____________________________________________________________________________________________________
|
||||
Errors
|
||||
|
||||
fsm_exception
|
||||
Inherits from etl::exception
|
||||
|
||||
fsm_null_state_exception
|
||||
Inherits from etl::fsm_exception
|
||||
|
||||
fsm_state_id_exception
|
||||
Inherits from etl::fsm_exception
|
||||
|
||||
fsm_state_list_exception
|
||||
Inherits from etl::fsm_exception
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
An example of a queued FSM can be found in the repository in examples\QueuedFSM
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
const etl::message_router_id_t MOTOR_CONTROL = 0;
|
||||
|
||||
//***************************************************************************
|
||||
// Events
|
||||
struct EventId
|
||||
{
|
||||
enum
|
||||
{
|
||||
START,
|
||||
STOP,
|
||||
STOPPED,
|
||||
SET_SPEED
|
||||
};
|
||||
};
|
||||
|
||||
//***********************************
|
||||
class Start : public etl::message<EventId::START>
|
||||
{
|
||||
};
|
||||
|
||||
//***********************************
|
||||
class Stop : public etl::message<EventId::STOP>
|
||||
{
|
||||
public:
|
||||
|
||||
Stop() : isEmergencyStop(false) {}
|
||||
Stop(bool emergency) : isEmergencyStop(emergency) {}
|
||||
|
||||
const bool isEmergencyStop;
|
||||
};
|
||||
|
||||
//***********************************
|
||||
class SetSpeed : public etl::message<EventId::SET_SPEED>
|
||||
{
|
||||
public:
|
||||
|
||||
SetSpeed(int speed) : speed(speed) {}
|
||||
|
||||
const int speed;
|
||||
};
|
||||
|
||||
//***********************************
|
||||
class Stopped : public etl::message<EventId::STOPPED>
|
||||
{
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
// States
|
||||
struct StateId
|
||||
{
|
||||
enum
|
||||
{
|
||||
IDLE,
|
||||
RUNNING,
|
||||
WINDING_DOWN,
|
||||
NUMBER_OF_STATES
|
||||
};
|
||||
};
|
||||
|
||||
//***********************************
|
||||
// The motor control FSM.
|
||||
//***********************************
|
||||
class MotorControl : public etl::fsm
|
||||
{
|
||||
public:
|
||||
|
||||
MotorControl()
|
||||
: fsm(MOTOR_CONTROL)
|
||||
{
|
||||
}
|
||||
|
||||
void SetRunningLampOn()
|
||||
{
|
||||
}
|
||||
|
||||
void SetRunningLampOff()
|
||||
{
|
||||
}
|
||||
|
||||
void SetEmergencyLampOn()
|
||||
{
|
||||
}
|
||||
|
||||
void SpeedChangeWarning()
|
||||
{
|
||||
}
|
||||
|
||||
void LogUnknownEvent(etl::imessage& msg)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//***********************************
|
||||
// The idle state.
|
||||
// Accepts Start events.
|
||||
//***********************************
|
||||
class Idle : public etl::fsm_state<MotorControl, Idle, StateId::IDLE, Start>
|
||||
{
|
||||
public:
|
||||
|
||||
//***********************************
|
||||
etl::fsm_state_id_t on_event(const Start& event)
|
||||
{
|
||||
return StateId::RUNNING;
|
||||
}
|
||||
|
||||
//***********************************
|
||||
etl::fsm_state_id_t on_event_unknown(const etl::imessage& event)
|
||||
{
|
||||
get_fsm_context().LogUnknownEvent(event);
|
||||
|
||||
return No_State_Change;
|
||||
}
|
||||
};
|
||||
|
||||
//***********************************
|
||||
// The running state.
|
||||
// Accepts Stop and SetSpeed events.
|
||||
//***********************************
|
||||
class Running : public etl::fsm_state<MotorControl, Running, StateId::RUNNING, Stop, SetSpeed>
|
||||
{
|
||||
public:
|
||||
|
||||
//***********************************
|
||||
etl::fsm_state_id_t on_event(const Stop& event)
|
||||
{
|
||||
if (event.isEmergencyStop)
|
||||
{
|
||||
get_fsm_context().SetEmergencyLampOn();
|
||||
|
||||
return StateId::IDLE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return StateId::WINDING_DOWN;
|
||||
}
|
||||
}
|
||||
|
||||
//***********************************
|
||||
etl::fsm_state_id_t on_event(const SetSpeed& event)
|
||||
{
|
||||
get_fsm_context().SpeedChangeWarning();
|
||||
|
||||
return No_State_Change;
|
||||
}
|
||||
|
||||
//***********************************
|
||||
etl::fsm_state_id_t on_event_unknown(const etl::imessage& event)
|
||||
{
|
||||
get_fsm_context().LogUnknownEvent(event);
|
||||
|
||||
return STATE_ID;
|
||||
}
|
||||
|
||||
//***********************************
|
||||
etl::fsm_state_id_t on_enter_state()
|
||||
{
|
||||
get_fsm_context().SetRunningLampOn();
|
||||
|
||||
return No_State_Change;
|
||||
}
|
||||
|
||||
//***********************************
|
||||
void on_exit_state()
|
||||
{
|
||||
get_fsm_context().SetRunningLampOff();
|
||||
|
||||
return No_State_Change;
|
||||
}
|
||||
};
|
||||
|
||||
//***********************************
|
||||
// The winding down state.
|
||||
// Accepts Stopped events.
|
||||
//***********************************
|
||||
class WindingDown : public etl::fsm_state<MotorControl, WindingDown, StateId::WINDING_DOWN, Stopped>
|
||||
{
|
||||
public:
|
||||
|
||||
//***********************************
|
||||
etl::fsm_state_id_t on_event(etl::imessage_router& sender, const Stopped& event)
|
||||
{
|
||||
return StateId::IDLE;
|
||||
}
|
||||
|
||||
//***********************************
|
||||
etl::fsm_state_id_t on_event_unknown(etl::imessage_router& sender, const etl::imessage& event)
|
||||
{
|
||||
get_fsm_context().LogUnknownEvent(event);
|
||||
|
||||
return No_State_Change;
|
||||
}
|
||||
};
|
||||
|
||||
// The states.
|
||||
Idle idle;
|
||||
Running running;
|
||||
WindingDown windingDown;
|
||||
|
||||
// The states must be in state id order.
|
||||
etl::ifsm_state* stateList[StateId::NUMBER_OF_STATES] =
|
||||
{
|
||||
&idle, &running, &windingDown
|
||||
};
|
||||
|
||||
The FSM.
|
||||
MotorControl motorControl;
|
||||
|
||||
// Set the FSM's state list
|
||||
motorControl.set_states(stateList, etl::size(stateList));
|
||||
|
||||
// Start the motor. The first state is 'IDLE'.
|
||||
motorControl.start();
|
||||
|
||||
// Receive a Start event. The next state is 'RUNNING'.
|
||||
motorControl.receive(Start());
|
||||
|
||||
// Receive a SetSpeed event. The state is still 'RUNNING'.
|
||||
motorControl.receive(SetSpeed(100));
|
||||
|
||||
// Receive a Stop event. The next state is 'WINDING_DOWN'.
|
||||
motorControl.receive(Stop);
|
||||
|
||||
// Receive a Stopped event. The next state is 'IDLE'.
|
||||
motorControl.receive(Stopped);
|
||||
|
||||
// Receive a Start event. The next state is 'RUNNING'.
|
||||
motorControl.receive(Start());
|
||||
|
||||
// Receive a Stop(emergency) event. The next state is 'IDLE'.
|
||||
motorControl.receive(Stop(true));
|
||||
|
||||
|
||||
98
docs/raw/frameworks/Hierarchical Finite State Machine.txt
Normal file
98
docs/raw/frameworks/Hierarchical Finite State Machine.txt
Normal file
@ -0,0 +1,98 @@
|
||||
Hierarchical Finite State Machine
|
||||
20.10.0
|
||||
|
||||
The ETL's etl::hfsm is derived from etl::fsm and utilises the same state template classes.
|
||||
See etl::fsm
|
||||
|
||||
Note:
|
||||
For an etl::hfsm, on_enter_state() cannot force a state change. It must return etl::ifsm_state::No_State_Change.
|
||||
If it does not, then an ETL_ASSERT will be raised.
|
||||
|
||||
Defines etl::hfsm plus all defined in fsm.h.
|
||||
____________________________________________________________________________________________________
|
||||
hfsm
|
||||
|
||||
The state machine.
|
||||
Inherits from etl::fsm.
|
||||
____________________________________________________________________________________________________
|
||||
hfsm(etl::message_router_id_t id)
|
||||
Constructor.
|
||||
Sets the router id for the HFSM.
|
||||
The HFSM is not started.
|
||||
____________________________________________________________________________________________________
|
||||
void receive(const etl::imessage& message)
|
||||
Top level message handler for the HFSM.
|
||||
____________________________________________________________________________________________________
|
||||
Errors
|
||||
|
||||
Additional errors to etl::fsm.
|
||||
|
||||
fsm_state_composite_state_change_forbidden
|
||||
Inherits from etl::fsm_exception
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// The states.
|
||||
Idle idle;
|
||||
Running running;
|
||||
WindingUp windingUp;
|
||||
WindingDown windingDown;
|
||||
AtSpeed atSpeed;
|
||||
|
||||
struct StateId
|
||||
{
|
||||
enum
|
||||
{
|
||||
Idle,
|
||||
Running,
|
||||
Winding_Up,
|
||||
Winding_Down,
|
||||
At_Speed,
|
||||
Number_Of_States
|
||||
};
|
||||
}
|
||||
|
||||
struct EventId
|
||||
{
|
||||
enum
|
||||
{
|
||||
Start,
|
||||
Stop,
|
||||
EStop,
|
||||
Stopped,
|
||||
Set_Speed,
|
||||
Timeout
|
||||
};
|
||||
};
|
||||
|
||||
// These are all of the states for this HSFM.
|
||||
etl::ifsm_state* stateList[StateId::Number_Of_States] =
|
||||
{
|
||||
&idle, &running, &windingUp, &windingDown, &atSpeed
|
||||
};
|
||||
|
||||
// These states are child states of 'Running'.
|
||||
etl::ifsm_state* childStates[] =
|
||||
{
|
||||
&windingUp, &atSpeed, &windingDown
|
||||
};
|
||||
|
||||
MotorControl motorControl;
|
||||
|
||||
running.set_child_states(childStates, etl::size(childStates));
|
||||
|
||||
motorControl.Initialise(stateList, etl::size(stateList));
|
||||
|
||||
148
docs/raw/frameworks/Message Broker.txt
Normal file
148
docs/raw/frameworks/Message Broker.txt
Normal file
@ -0,0 +1,148 @@
|
||||
Message Broker
|
||||
|
||||
A variant of the observer pattern in that message routers and derived types are be able to subscribe to selected sets of messages. The message_broker is similar to the message_bus, but it provides more control over the routing of messages. While the message_bus simply broadcasts every message to all subscribers, the message_broker allows you to specify which subscribers should receive each message.
|
||||
|
||||
Derived from imessage_router
|
||||
____________________________________________________________________________________________________
|
||||
Types
|
||||
|
||||
message_id_span_t etl::span<const etl::message_id_t>
|
||||
____________________________________________________________________________________________________
|
||||
subscription
|
||||
A nested class of etl::message_broker
|
||||
The base for broker subscription information.
|
||||
Derive from this to define your subscription class.
|
||||
See Example.
|
||||
____________________________________________________________________________________________________
|
||||
subscription(etl::imessage_router& router)
|
||||
Constructor.
|
||||
____________________________________________________________________________________________________
|
||||
virtual message_id_span_t message_id_list() const = 0;
|
||||
Override this to return a span of message ids.
|
||||
____________________________________________________________________________________________________
|
||||
message_broker
|
||||
|
||||
message_broker()
|
||||
The broker is constructed with an id of etl::imessage_router::MESSAGE_BROKER.
|
||||
____________________________________________________________________________________________________
|
||||
message_broker(etl::imessage_router& successor)
|
||||
The broker is constructed with an id of etl::imessage_router::MESSAGE_BROKER.
|
||||
Sets the successor.
|
||||
____________________________________________________________________________________________________
|
||||
message_broker(etl::message_router_id_t id)
|
||||
The broker is constructed with the specified id.
|
||||
____________________________________________________________________________________________________
|
||||
message_broker(etl::message_router_id_t id, etl::imessage_router& successor)
|
||||
The broker is constructed with the specified id.
|
||||
Sets the successor.
|
||||
____________________________________________________________________________________________________
|
||||
void subscribe(etl::imessage_router& router)
|
||||
Subscribes an etl::imessage_router derived class to the broker.
|
||||
A subscription object must have a lifetime of at least the same as the broker.
|
||||
A subscription cannot be shared with another broker.
|
||||
____________________________________________________________________________________________________
|
||||
void unsubscribe(etl::imessage_router& router)
|
||||
Unsubscribes the specified etl::imessage_router derived class from the bus.
|
||||
Does not unsubscribe from nested buses.
|
||||
____________________________________________________________________________________________________
|
||||
void receive(const etl::imessage& message)
|
||||
void receive(etl::shared_message message)
|
||||
Receives a message and distributes it to all subscribers that have registered to receive the message type.
|
||||
Forwards the message to any successor.
|
||||
|
||||
Override this in a derived class if you wish to capture messages sent to the broker.
|
||||
Call the base receive function from here to allow normal operation to continue.
|
||||
____________________________________________________________________________________________________
|
||||
bool accepts(etl::message_id_t id) const
|
||||
Always returns true.
|
||||
____________________________________________________________________________________________________
|
||||
void clear()
|
||||
Clears the broker of all subscribers.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE
|
||||
Always returns false.
|
||||
____________________________________________________________________________________________________
|
||||
bool is_producer() const ETL_OVERRIDE
|
||||
Always returns true.
|
||||
____________________________________________________________________________________________________
|
||||
bool is_consumer() const ETL_OVERRIDE
|
||||
Always returns true.
|
||||
____________________________________________________________________________________________________
|
||||
bool empty() const
|
||||
Returns true is the are are no subscribers.
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
// Some router ids.
|
||||
enum
|
||||
{
|
||||
ROUTER_ID_1,
|
||||
ROUTER_ID_2,
|
||||
};
|
||||
|
||||
// Custom subscription type.
|
||||
class Subscription : public etl::message_broker::subscription
|
||||
{
|
||||
public:
|
||||
|
||||
Subscription(etl::imessage_router& router, std::initializer_list<etl::message_id_t> id_list_)
|
||||
: etl::message_broker::subscription(router)
|
||||
, id_list(id_list_)
|
||||
{
|
||||
}
|
||||
|
||||
etl::message_broker::message_id_span_t message_id_list() const override
|
||||
{
|
||||
return etl::message_broker::message_id_span_t(id_list.begin(), id_list.end());
|
||||
}
|
||||
|
||||
std::vector<etl::message_id_t> id_list;
|
||||
};
|
||||
|
||||
// Instances of messages.
|
||||
Message1 message1;
|
||||
Message2 message2;
|
||||
Message3 message3;
|
||||
Message4 message4;
|
||||
|
||||
// Custom broker.
|
||||
class Broker : public etl::message_broker
|
||||
{
|
||||
public:
|
||||
|
||||
using etl::message_broker::receive;
|
||||
|
||||
// Hook incoming messages and translate Message4 to Message3.
|
||||
void receive(const etl::imessage& msg) override
|
||||
{
|
||||
if (msg.get_message_id() == Message4::ID)
|
||||
{
|
||||
etl::message_broker::receive(Message3());
|
||||
}
|
||||
else
|
||||
{
|
||||
etl::message_broker::receive(msg);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Instances of message routers.
|
||||
Router1 router1;
|
||||
Router2 router2;
|
||||
|
||||
// The subscriptions.
|
||||
Subscription subscription1{ router1, { Message1::ID, Message2::ID } };
|
||||
Subscription subscription2{ router2, { Message2::ID, Message3::ID } };
|
||||
|
||||
// Instance of message broker.
|
||||
etl::message_broker broker;
|
||||
|
||||
// Subscribe router1 and router1 to the broker.
|
||||
broker.subscribe(subscription1);
|
||||
broker.subscribe(subscription2);
|
||||
|
||||
broker.receive(message1); // Received by router1
|
||||
broker.receive(message2); // Received by router1 and router2
|
||||
broker.receive(message3); // Received by router2
|
||||
broker.receive(message4); // Received by router2 as a Message3
|
||||
|
||||
157
docs/raw/frameworks/Message Bus.txt
Normal file
157
docs/raw/frameworks/Message Bus.txt
Normal file
@ -0,0 +1,157 @@
|
||||
Message Bus
|
||||
20.33.0
|
||||
This page documents version 20.0.0 and above.
|
||||
For version 19.x.x or earlier see this page.
|
||||
|
||||
A variant of the observer pattern in that message routers and derived types are be able to subscribe to messages on a bus. The messages can be either broadcast, to be automatically picked up by any router that has a handler, or addressed to a particular router or router id. Message buses may be nested by setting a successor.
|
||||
____________________________________________________________________________________________________
|
||||
imessage_bus
|
||||
Derived from imessage_router
|
||||
|
||||
The base for all message buses.
|
||||
Inherits publicly from etl::imessage_router.
|
||||
Message buses are therefore also a type of router.
|
||||
Objects of type etl::imessage_bus cannot be directly constructed.
|
||||
|
||||
Member functions
|
||||
|
||||
bool subscribe(etl::imessage_router& router);
|
||||
Subscribes an etl::imessage_router derived class to the bus.
|
||||
Returns true on success.
|
||||
____________________________________________________________________________________________________
|
||||
void unsubscribe(etl::imessage_router& router);
|
||||
Unsubscribes the specified etl::imessage_router derived class from the bus.
|
||||
Does not unsubscribe from nested buses.
|
||||
____________________________________________________________________________________________________
|
||||
void unsubscribe(etl::message_router_id_t id)
|
||||
Unsubscribes routers with the specified id from the bus.
|
||||
Does not unsubscribe from nested buses.
|
||||
|
||||
etl::imessage::MESSAGE_BUS will unsubscribe all message buses.
|
||||
etl::imessage::ALL_MESSAGE_ROUTERS will unsubscribe all routers and buses. Equivalent to calling clear().
|
||||
____________________________________________________________________________________________________
|
||||
void receive(const etl::imessage& message);
|
||||
void receive(etl::shared_message message);
|
||||
Receives a message and distributes it to all subscribers.
|
||||
Forwards the message to any successor.
|
||||
|
||||
The routers are called first, in order of ascending router id.
|
||||
Routers with the duplicate ids will be called in subscribe order.
|
||||
Any nested message buses are called in subscribe order.
|
||||
____________________________________________________________________________________________________
|
||||
void receive(etl::message_router_id_t destination_router_id,
|
||||
const etl::imessage& message);
|
||||
void receive(etl::message_router_id_t destination_router_id,
|
||||
etl::shared_message message);
|
||||
Receives a message and distributes it to all subscribers that have the specified router id.
|
||||
Forwards the message to any successor.
|
||||
|
||||
Routers with the duplicate ids will be called in subscribe order.
|
||||
Any nested message buses are called in subscribe order.
|
||||
|
||||
Override this in a derived class if you wish to capture messages sent to the bus.
|
||||
Call the base receive function from here to allow normal operation to continue.
|
||||
____________________________________________________________________________________________________
|
||||
bool accepts(etl::message_id_t id) const;
|
||||
Always returns true.
|
||||
____________________________________________________________________________________________________
|
||||
size_t size() const;
|
||||
Returns the number of subscribers.
|
||||
____________________________________________________________________________________________________
|
||||
void clear();
|
||||
Clears the bus of all subscribers.
|
||||
|
||||
Message buses inherit all of the public functions of etl::imessage_router.
|
||||
|
||||
Errors
|
||||
message_bus_exception
|
||||
Base error class for etl::message_bus. Inherits from etl::exception
|
||||
____________________________________________________________________________________________________
|
||||
message_bus_too_many_subscribers
|
||||
Emitted when the number of subscribers exceeds the capacity. Inherits from etl::message_bus_exception.
|
||||
____________________________________________________________________________________________________
|
||||
message_bus
|
||||
Derived from imessage_bus.
|
||||
|
||||
template <const uint_least8_t MAX_ROUTERS>
|
||||
class message_bus
|
||||
|
||||
MAX_ROUTERS The maximum number of routers that can be subscribed.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
Member functions
|
||||
|
||||
message_bus()
|
||||
Constructs a message bus.
|
||||
Message buses always have a router id of etl::imessage::MESSAGE_BUS.
|
||||
|
||||
message_bus(etl::imessage_router& successor)
|
||||
Constructs a message bus and sets the successor.
|
||||
Message buses always have a router id of etl::imessage::MESSAGE_BUS.
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
// Some router ids.
|
||||
enum
|
||||
{
|
||||
ROUTER_ID_1,
|
||||
ROUTER_ID_2,
|
||||
ROUTER_ID_3
|
||||
};
|
||||
|
||||
// Instances of messages.
|
||||
MessageA messageA;
|
||||
|
||||
// Instances of message routers.
|
||||
RouterA routerA(ROUTER_ID_1);
|
||||
RouterB routerB(ROUTER_ID_1);
|
||||
RouterC routerC(ROUTER_ID_2);
|
||||
RouterD routerD(ROUTER_ID_3);
|
||||
RouterE routerE(ROUTER_ID_1);
|
||||
|
||||
// Instances of message buses.
|
||||
etl::message_bus<4> bus1;
|
||||
etl::message_bus<2> bus2;
|
||||
etl::message_bus<1> bus3;
|
||||
|
||||
// Subscribe bus2 & bus3 to bus1.
|
||||
bus1.subscribe(bus3);
|
||||
bus1.subscribe(bus2);
|
||||
|
||||
// Subscribe routerB & routerA to bus1.
|
||||
bus1.subscribe(routerB);
|
||||
bus1.subscribe(routerA);
|
||||
|
||||
// Subscribe routerD & routerC to bus2.
|
||||
bus2.subscribe(routerD);
|
||||
bus2.subscribe(routerC);
|
||||
|
||||
// Subscribe routerE to bus3.
|
||||
bus3.subscibe(routerE);
|
||||
|
||||
// Assume all routers accept the same messages.
|
||||
|
||||
// Broadcast messageA to everyone.
|
||||
bus1.receive(messageA);
|
||||
|
||||
The call order will be...
|
||||
routerB
|
||||
routerA
|
||||
routerE
|
||||
routerC
|
||||
routerD
|
||||
|
||||
// Address messageA to routers with id ROUTER_ID_1.
|
||||
bus1.receive(ROUTER_ID_1, messageA);
|
||||
|
||||
The call order will be...
|
||||
routerB
|
||||
routerA
|
||||
routerE
|
||||
|
||||
// Address messageA to routers with id ROUTER_ID_3.
|
||||
bus1.receive(ROUTER_ID_3, messageA);
|
||||
|
||||
The call order will be...
|
||||
routerD
|
||||
|
||||
96
docs/raw/frameworks/Message Router Registry.txt
Normal file
96
docs/raw/frameworks/Message Router Registry.txt
Normal file
@ -0,0 +1,96 @@
|
||||
Message Router Registry
|
||||
|
||||
20.6.0
|
||||
A class that will act as a registry for all message router types.
|
||||
When iterating through the registry, routers with identical IDs are ordered by insertion.
|
||||
|
||||
Defines the following classes:-
|
||||
etl::imessage_router_registry
|
||||
etl::message_router_registry
|
||||
____________________________________________________________________________________________________
|
||||
imessage_router_registry
|
||||
|
||||
The base class for all router registries.
|
||||
|
||||
Iterators
|
||||
iterator
|
||||
const_iterator
|
||||
____________________________________________________________________________________________________
|
||||
Member functions
|
||||
|
||||
iterator begin()
|
||||
const_iterator begin() const
|
||||
const_iterator cbegin() const
|
||||
Get the beginning of the registry.
|
||||
____________________________________________________________________________________________________
|
||||
iterator end()
|
||||
const_iterator end() const
|
||||
const_iterator cend() const
|
||||
Get the end of the registry.
|
||||
____________________________________________________________________________________________________
|
||||
iterator lower_bound(etl::message_router_id_t id)
|
||||
const_iterator lower_bound(etl::message_router_id_t id) const
|
||||
Get the lower bound in the registry of the router with the specified ID.
|
||||
____________________________________________________________________________________________________
|
||||
iterator upper_bound(etl::message_router_id_t id)
|
||||
const_iterator upper_bound(etl::message_router_id_t id) const
|
||||
Get the upper bound in the registry of the router with the specified ID.
|
||||
____________________________________________________________________________________________________
|
||||
etl::imessage_router* find(etl::message_router_id_t id)
|
||||
const etl::imessage_router* find(etl::message_router_id_t id) const
|
||||
Returns a pointer to the first router with the specified ID, or ETL_NULLPTR if it cannot be found.
|
||||
____________________________________________________________________________________________________
|
||||
void add(etl::imessage_router& router)
|
||||
void add(etl::imessage_router* p_router)
|
||||
Registers a router.
|
||||
If the registry is full then an ETL assert is emitted (etl::message_router_registry_full).
|
||||
Duplicate routers will be ignored.
|
||||
|
||||
template <typename TIterator>
|
||||
void add(TIterator first, const TIterator& last)
|
||||
Registers a collection of routers.
|
||||
If the registry becomes full then an ETL assert is emitted (etl::message_router_registry_full).
|
||||
Duplicate routers will be ignored.
|
||||
____________________________________________________________________________________________________
|
||||
void remove(etl::message_router_id_t id)
|
||||
Unregisters a router.
|
||||
____________________________________________________________________________________________________
|
||||
bool contains(const etl::message_router_id_t id) const
|
||||
bool contains(const etl::imessage_router* const p_router) const
|
||||
bool contains(const etl::imessage_router& router) const
|
||||
Returns true if the registry contains a router that has the specified ID or object.
|
||||
____________________________________________________________________________________________________
|
||||
bool empty() const
|
||||
Returns true if the registry is empty, otherwise false.
|
||||
____________________________________________________________________________________________________
|
||||
bool full() const
|
||||
Returns true if the registry is full, otherwise false.
|
||||
____________________________________________________________________________________________________
|
||||
size_t size() const
|
||||
Returns the size of the registry.
|
||||
____________________________________________________________________________________________________
|
||||
size_t available() const
|
||||
Returns the available size of the registry.
|
||||
____________________________________________________________________________________________________
|
||||
size_t max_size() const
|
||||
Returns the maximum size of the registry.
|
||||
____________________________________________________________________________________________________
|
||||
message_router_registry
|
||||
|
||||
message_router_registry()
|
||||
Default constructor.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TIterator>
|
||||
message_router_registry(TIterator first, const TIterator& last)
|
||||
Constructs from an iterator range.
|
||||
____________________________________________________________________________________________________
|
||||
message_router_registry(std::initializer_list<etl::imessage_router*> init)
|
||||
Initializer_list constructor.
|
||||
Enabled for C++11 or above and when using the STL.
|
||||
____________________________________________________________________________________________________
|
||||
message_router_registry(const message_router_registry& rhs)
|
||||
Copy constructor.
|
||||
____________________________________________________________________________________________________
|
||||
message_router_registry& operator =(const message_router_registry& rhs)
|
||||
Assignment operator.
|
||||
|
||||
345
docs/raw/frameworks/Message Router.txt
Normal file
345
docs/raw/frameworks/Message Router.txt
Normal file
@ -0,0 +1,345 @@
|
||||
Message Router
|
||||
|
||||
This page documents version 20.0.0 and above.
|
||||
For version 19.x.x or earlier see this page.
|
||||
|
||||
A class that will automatically route incoming messages to specific handlers based on the message types declared in the template parameter list. Messages are passed to the receive member function which will static cast it to its real type and call the matching on_receive function in the derived class. A compilation error will occur if the matching on_receive does not exist.
|
||||
|
||||
The on_receive functions are not virtual. The template base class uses CRTP to directly call the derived class's functions.
|
||||
|
||||
Defines the following classes:-
|
||||
etl::imessage_router
|
||||
etl::message_router
|
||||
etl::null_message_router
|
||||
|
||||
Note: This header is a generated from message_router_generator.h. To handle more than the standard 16 message types then a new one must be generated.
|
||||
See Generators
|
||||
____________________________________________________________________________________________________
|
||||
Message router ID
|
||||
Allowable router IDs run from 0 to MAX_MESSAGE_ROUTER (249) inclusive.
|
||||
|
||||
Each message router is given an ID. Whether this ID is unique or not depends on how you are using and identifying message routers.
|
||||
|
||||
Note: A message router 'group' is deemed to be a set of routers with identical IDs.
|
||||
The default router id is etl::imassage_router::MESSAGE_ROUTER.
|
||||
|
||||
Scenario 1
|
||||
You never send a message to a router using it's ID.
|
||||
You never use the ID to uniquely identify a router.
|
||||
You do not require the router ID to act as a priority level when subscribing to a message bus.
|
||||
You do not require that messages can be sent to a group.
|
||||
|
||||
All message router IDs can be identical.
|
||||
____________________________________________________________________________________________________
|
||||
Scenario 2
|
||||
You never use the ID to uniquely identify a router.
|
||||
You may use the router ID to send to a particular router group.
|
||||
You require the router ID to act as a priority level when subscribing to a message bus.
|
||||
|
||||
Router IDs will be assigned in groups. i.e. Some routers may share IDs.
|
||||
____________________________________________________________________________________________________
|
||||
Scenario 3
|
||||
You use the ID to uniquely identify a router.
|
||||
You use the router ID to send to a particular router.
|
||||
You require the router ID to act as a priority level when subscribing to a message bus.
|
||||
You require all priority levels to be unique.
|
||||
|
||||
All router IDs are unique
|
||||
____________________________________________________________________________________________________
|
||||
imessage_router
|
||||
The base class for all routers.
|
||||
|
||||
Member functions
|
||||
|
||||
virtual ~imessage_router() {}
|
||||
____________________________________________________________________________________________________
|
||||
virtual void receive(const etl::imessage& message) = 0;
|
||||
Overridden by the derived class.
|
||||
____________________________________________________________________________________________________
|
||||
virtual void receive(etl::message_router_id_t destination_router_id,
|
||||
const etl::imessage& message)
|
||||
Receive a message for a specific destination id.
|
||||
If the destination id is the router's id, then the message is forwarded to receive(message);
|
||||
Can be overridden by the derived class.
|
||||
____________________________________________________________________________________________________
|
||||
virtual void receive(etl::shared_message shared_msg)
|
||||
Receive a shared message.
|
||||
By default, forwards to receive(shared_msg.get_message());
|
||||
____________________________________________________________________________________________________
|
||||
virtual void receive(etl::message_router_id_t destination_router_id,
|
||||
etl::shared_message shared_msg)
|
||||
Receive a message for a specific destination id.
|
||||
By default, forwards to receive(destination_router_id, shared_msg.get_message());
|
||||
____________________________________________________________________________________________________
|
||||
virtual bool accepts(etl::message_id_t id) const = 0;
|
||||
Returns true if the router accepts the message id.
|
||||
Overridden by the derived class.
|
||||
____________________________________________________________________________________________________
|
||||
bool accepts(const etl::imessage& msg) const;
|
||||
Returns true if the router accepts the message.
|
||||
____________________________________________________________________________________________________
|
||||
etl::message_router_id_t get_message_router_id() const;
|
||||
Returns the router id.
|
||||
____________________________________________________________________________________________________
|
||||
virtual bool is_null_router() const = 0; DEPRECATED
|
||||
Returns true if the router is a null message router, otherwise false.
|
||||
____________________________________________________________________________________________________
|
||||
virtual bool is_producer() const = 0;
|
||||
Returns true if the router is a producer of messages, otherwise false.
|
||||
____________________________________________________________________________________________________
|
||||
virtual bool is_consumer() const = 0;
|
||||
Returns true if the router is a consumer of messages, otherwise false.
|
||||
____________________________________________________________________________________________________
|
||||
void set_successor(etl::imessage_router& successor);
|
||||
Sets the successor router. Any unhandled message will be sent here.
|
||||
Allows the router to implement the Chain Of Responsibility design pattern.
|
||||
|
||||
Enumerations
|
||||
NULL_MESSAGE_ROUTER
|
||||
MESSAGE_BUS
|
||||
ALL_MESSAGE_ROUTERS
|
||||
MAX_MESSAGE_ROUTER
|
||||
____________________________________________________________________________________________________
|
||||
message_router
|
||||
User defined message routers are derived from this class.
|
||||
Derived from imessage_router
|
||||
____________________________________________________________________________________________________
|
||||
For C++03 to C++14
|
||||
template <typename TDerived,
|
||||
typename T1, typename T2 = void, typename T3 = void, typename T4 = void,
|
||||
typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void,
|
||||
typename T9 = void, typename T10 = void, typename T11 = void, typename T12 = void,
|
||||
typename T13 = void, typename T14 = void, typename T15 = void, typename T16 = void>
|
||||
class message_router
|
||||
|
||||
Template parameters
|
||||
TDerived The derived class.
|
||||
T1 The first message type.
|
||||
T2... The additional message types.
|
||||
The maximum number of types can be set by running the generator for this file.
|
||||
The default is 16.This may be changed by running a modified version of generate_message_router.bat.
|
||||
See Generators
|
||||
____________________________________________________________________________________________________
|
||||
For C++17 and above
|
||||
template <typename TDerived, typename... TMessageTypes>
|
||||
class message_router
|
||||
|
||||
Template parameters
|
||||
TDerived The derived class.
|
||||
TMessageTypes The list of message types.
|
||||
|
||||
This definition will automatically be selected if the compiler supports C++17. It uses fold expressions to resolve on_receive() calls.
|
||||
To use the older C++03 compatible definition, define ETL_MESSAGE_ROUTER_FORCE_CPP03 as a project setting or in the optional etl_profile.h.
|
||||
____________________________________________________________________________________________________
|
||||
The derived class must define the following member functions.
|
||||
|
||||
void on_receive(const Type& msg);
|
||||
Replace Type with each concrete message type.
|
||||
Define for all of the template parameter types.
|
||||
____________________________________________________________________________________________________
|
||||
void on_receive_unknown(const etl::imessage& msg)
|
||||
Called when a message type is received that is not in the template list.
|
||||
___________________________________________________________________________________________________
|
||||
Member classes
|
||||
message_packet
|
||||
See etl::message_packet
|
||||
____________________________________________________________________________________________________
|
||||
Member functions
|
||||
message_router()
|
||||
Constructs the router.
|
||||
The router id is set to etl::imassage_router::MESSAGE_ROUTER.
|
||||
____________________________________________________________________________________________________
|
||||
message_router(etl::imessage_router& successor)
|
||||
Constructs the router.
|
||||
The router id must be between 0 and MAX_MESSAGE_ROUTER (249) . Other IDs are reserved for ETL use.
|
||||
Emits an error if the id is outside the legal range.
|
||||
Routers may have duplicate ids.
|
||||
Sets the successor router to this one. Any unhandled message will be sent here.
|
||||
____________________________________________________________________________________________________
|
||||
message_router(etl::message_router_id_t id)
|
||||
Constructs the router.
|
||||
The router id must be between 0 and 249. Ids 250 to 255 are reserved for ETL use.
|
||||
Asserts an error if the id is outside the legal range.
|
||||
Routers may have duplicate ids.
|
||||
____________________________________________________________________________________________________
|
||||
message_router(etl::message_router_id_t id, etl::imessage_router& successor)
|
||||
Constructs the router.
|
||||
The router id must be between 0 and MAX_MESSAGE_ROUTER (249) . Other IDs are reserved for ETL use.
|
||||
Sets the successor router to this one. Any unhandled message will be sent here.
|
||||
____________________________________________________________________________________________________
|
||||
void receive(const etl::imessage& msg)
|
||||
Receives a message and routes to the on_receive() handler.
|
||||
If not handled, passes the message on to a successor, if it exists.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TMessage>
|
||||
void receive(const TMessage& msg)
|
||||
Receives a message and routes directly to the on_receive() handler.
|
||||
This template function will be chosen for concrete message types.
|
||||
If not handled, passes the message on to a successor, if it exists.
|
||||
____________________________________________________________________________________________________
|
||||
bool accepts(etl::message_id_t id) const
|
||||
Returns true if the router accepts the message id.
|
||||
____________________________________________________________________________________________________
|
||||
Errors
|
||||
message_router_exception
|
||||
Base exception for router errors.
|
||||
Derived from etl::exception.
|
||||
____________________________________________________________________________________________________
|
||||
message_router_illegal_id
|
||||
The router id is out of the legal range.
|
||||
Derived from etl::message_router_exception
|
||||
____________________________________________________________________________________________________
|
||||
null_message_router
|
||||
This router can be used as a sink for messages or a 'null source' router.
|
||||
Derived from imessage_router
|
||||
____________________________________________________________________________________________________
|
||||
null_message_router()
|
||||
Constructs a null message router.
|
||||
The router id will be etl::imessage_router::NULL_MESSAGE_ROUTER.
|
||||
____________________________________________________________________________________________________
|
||||
void receive(const etl::imessage& message)
|
||||
Receives a message.
|
||||
Does nothing, except pass on to a successor, if it exists.
|
||||
____________________________________________________________________________________________________
|
||||
bool accepts(etl::message_id_t id) const
|
||||
Returns false if no successor is set.
|
||||
Returns true if a successor accepts the message id.
|
||||
____________________________________________________________________________________________________
|
||||
static null_message_router& instance()
|
||||
Returns an instance of etl::null_message_router.
|
||||
____________________________________________________________________________________________________
|
||||
message_producer
|
||||
This router can be used as a producer-only of messages, such an interrupt routine.
|
||||
Derived from imessage_router
|
||||
____________________________________________________________________________________________________
|
||||
message_producer(etl::message_router_id_t id);
|
||||
Constructs the router.
|
||||
The router id must be between 0 and 249. Ids 250 to 255 are reserved for ETL use.
|
||||
Emits an error if the id is outside the legal range.
|
||||
Routers may have duplicate ids.
|
||||
____________________________________________________________________________________________________
|
||||
void receive(const etl::imessage& message)
|
||||
Receives a message.
|
||||
Does nothing, except pass on to a successor, if it exists.
|
||||
____________________________________________________________________________________________________
|
||||
bool accepts(etl::message_id_t id) const
|
||||
Returns false if no successor is set.
|
||||
Returns true if a successor accepts the message id.
|
||||
____________________________________________________________________________________________________
|
||||
static null_message_router& instance()
|
||||
Returns an instance of etl::null_message_router.
|
||||
____________________________________________________________________________________________________
|
||||
Global functions
|
||||
|
||||
void send_message(etl::imessage_router& router,
|
||||
const etl::imessage& message);
|
||||
Send the message to the router.
|
||||
____________________________________________________________________________________________________
|
||||
void send_message(etl::imessage_router& router,
|
||||
etl::message_router_id_t id,
|
||||
const etl::imessage& message);
|
||||
Send the message to the router if it has the specified id.
|
||||
____________________________________________________________________________________________________
|
||||
void send_message(etl::imessage_router& router,
|
||||
etl::shared_message& message);
|
||||
Send the shared message to the router.
|
||||
____________________________________________________________________________________________________
|
||||
void send_message(etl::imessage_router& router,
|
||||
etl::message_router_id_t id,
|
||||
etl::shared_message& message);
|
||||
Send the shared message to the router if it has the specified id.
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
// Message ids.
|
||||
enum
|
||||
{
|
||||
START,
|
||||
STOP,
|
||||
SET_SPEED
|
||||
};
|
||||
|
||||
// The start message.
|
||||
struct Start : public etl::message<START>
|
||||
{
|
||||
};
|
||||
|
||||
// The stop message.
|
||||
struct Stop : public etl::message<STOP>
|
||||
{
|
||||
};
|
||||
|
||||
// The set speed message.
|
||||
struct SetSpeed : public etl::message<SET_SPEED>
|
||||
{
|
||||
SetSpeed(uint32_t speed_)
|
||||
: speed(speed_)
|
||||
{
|
||||
}
|
||||
|
||||
uint32_t speed;
|
||||
};
|
||||
|
||||
// The router.
|
||||
class Router : public etl::message_router<Router, Start, Stop, SetSpeed>
|
||||
{
|
||||
public:
|
||||
|
||||
// Construct the router with an id of 0.
|
||||
Router()
|
||||
: message_router(0)
|
||||
{
|
||||
}
|
||||
|
||||
// Received a start message.
|
||||
void on_receive(etl::imessage_router& sender, const Start& msg)
|
||||
{
|
||||
std::cout << "Start message received\n";
|
||||
}
|
||||
|
||||
// Received a stop message.
|
||||
void on_receive(const Stop& msg)
|
||||
{
|
||||
std::cout << "Start message received\n";
|
||||
}
|
||||
|
||||
// Received a set speed message.
|
||||
void on_receive(const SetSpeed& msg)
|
||||
{
|
||||
std::cout << "SetSpeed(" << msg.speed << ") message received\n";
|
||||
}
|
||||
|
||||
// Received an unknown message.
|
||||
void on_receive_unknown(const etl::imessage& msg)
|
||||
{
|
||||
std::cout << "Unknown message " << msg.message_id << " received\n";
|
||||
}
|
||||
}
|
||||
|
||||
// Router and message instances.
|
||||
Router router;
|
||||
Start start;
|
||||
Stop stop;
|
||||
SetSpeed halfSpeed(50);
|
||||
SetSpeed maxSpeed(100);
|
||||
|
||||
// A queue for Router messages.
|
||||
etl::queue<Router::message_packet, 10> queue;
|
||||
|
||||
// Add to the queue.
|
||||
queue.emplace(start);
|
||||
queue.emplace(stop);
|
||||
queue.emplace(maxSpeed);
|
||||
queue.emplace(halfSpeed);
|
||||
|
||||
// Send the queued messages to 'router'.
|
||||
while (!queue.empty())
|
||||
{
|
||||
etl::send_message(router, queue.front().get());
|
||||
queue.pop();
|
||||
}
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
An example of a queued message router can be found in the repository in examples/QueuedMessageRouter
|
||||
|
||||
232
docs/raw/frameworks/Message Timer Atomic.txt
Normal file
232
docs/raw/frameworks/Message Timer Atomic.txt
Normal file
@ -0,0 +1,232 @@
|
||||
Message Timer Atomic
|
||||
|
||||
A software timer class that can manage up to 254 timers. Each one may be repeating or single shot.
|
||||
When a timer triggers it will send the defined message to the selected message router or bus.
|
||||
The timers are driven from a call to tick(uint32_t count). This call would normally be made from a high priority interrupt routine. The destination router will receive the message in the same context as the tick call.
|
||||
The call to tick has a low overhead when a timer is not 'due'. Internally the timers are stored in 'first timeout' order so only the head of the list needs to be checked.
|
||||
|
||||
Each timer may have a period of up to 232-2 ticks (4,294,967,294).
|
||||
At 1ms per tick this would equate to just over 49 days.
|
||||
|
||||
The framework relies on an atomic counter type. With this mechanism, calls to tick are never disabled. If the foreground thread is within a disable/enable section when the timer interrupt/thread is activated then the tick update will be deferred until the next tick period. The timer interrupt/thread may interrogate the return value of tick() to check whether the update was deferred.
|
||||
|
||||
Defines the following classes:-
|
||||
etl::imessage_timer_atomic<uint_least8_t MAX_TIMERS, typename TSemaphore>
|
||||
etl::message_timer_atomic<typename TSemaphore>
|
||||
|
||||
20.25.0
|
||||
From this version, an atomic 'semaphore' counter type must be supplied.
|
||||
|
||||
Uses definitions from timer.h
|
||||
____________________________________________________________________________________________________
|
||||
imessage_timer_atomic
|
||||
|
||||
The base class for all timer controllers.
|
||||
|
||||
Member functions
|
||||
etl::timer::id::type register_timer(const etl::imessage& message,
|
||||
etl::imessage_router& router,
|
||||
uint32_t period,
|
||||
bool repeating,
|
||||
etl::message_router_id_t destination_router_id =
|
||||
etl::imessage_router::ALL_MESSAGE_ROUTERS)
|
||||
Registers a timer.
|
||||
message A reference to the message that will be sent when the timer expires.
|
||||
router A reference to a router or bus that will receive to message.
|
||||
period The timer period in ticks.
|
||||
repeating false if single shot, true if repeating.
|
||||
destination_router_id The id of the destination router. Only valid if the router is a bus. Default to all routers.
|
||||
|
||||
Returns the allocated timer id or etl::timer::id::NO_TIMER if one was not available.
|
||||
____________________________________________________________________________________________________
|
||||
bool unregister_timer(etl::timer::id::type id)
|
||||
Unregisters a timer.
|
||||
If the timer is active then it will be stopped.
|
||||
Returns true if a timer with the id was successfully unregistered.
|
||||
____________________________________________________________________________________________________
|
||||
void enable(bool state)
|
||||
Enables or disables the timer manager according to the state.
|
||||
____________________________________________________________________________________________________
|
||||
bool is_running() const
|
||||
Returns true if the timer manager is enabled.
|
||||
____________________________________________________________________________________________________
|
||||
void clear()
|
||||
Clears the message timer back to the initial state. All timers will be stopped and unregistered.
|
||||
____________________________________________________________________________________________________
|
||||
bool tick(uint32_t count)
|
||||
This function updates the internal tick counter (if enabled) and must be passed the number of ticks that have occurred since the last call. If the count encompasses more than one period of a repeating timer then the timer will be triggered multiple times in one call to tick.
|
||||
Returns true if the tick counter was updated, otherwise false. This may be used by the calling routine to accumulate unprocessed tick counts.
|
||||
___________________________________________________________________________________________________
|
||||
bool start(etl::timer::id::type id, bool immediate = false)
|
||||
Starts the timer with the specified id.
|
||||
If the timer is already running then the timer Is restarted from the current tick count.
|
||||
If immediate is true then the timer is triggered on the next call to tick(). Note: Single shot timers will only trigger once.
|
||||
If the id does not correspond to a registered timer then returns false.
|
||||
____________________________________________________________________________________________________
|
||||
bool stop(etl::timer::id::type id)
|
||||
Stops the timer with the specified id.
|
||||
Does nothing if the timer is already stopped.
|
||||
if the id does not correspond to a registered timer then returns false.
|
||||
____________________________________________________________________________________________________
|
||||
bool set_period(etl::timer::id::type id_, uint32_t period)
|
||||
Stops the timer with the specified id.
|
||||
Sets a new timer period.
|
||||
Returns true if successful.
|
||||
____________________________________________________________________________________________________
|
||||
bool set_mode(etl::timer::id::type id_, bool repeating)
|
||||
Stops the timer with the specified id.
|
||||
Sets a new timer mode.
|
||||
Returns true if successful.
|
||||
____________________________________________________________________________________________________
|
||||
etl::timer::id::type time_to_next()
|
||||
Returns the time to the next timeout.
|
||||
20.38.0
|
||||
____________________________________________________________________________________________________
|
||||
Constants
|
||||
MAX_TIMERS
|
||||
____________________________________________________________________________________________________
|
||||
message_timer_atomic
|
||||
|
||||
Template parameters
|
||||
MAX_TIMERS The number of timers to be supported. The maximum number is 254.
|
||||
A value of 255 will result in a compile error.
|
||||
____________________________________________________________________________________________________
|
||||
message_timer_atomic()
|
||||
Default construct.
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
//***************************************************************************
|
||||
// The set of messages.
|
||||
//***************************************************************************
|
||||
enum
|
||||
{
|
||||
MESSAGE1,
|
||||
MESSAGE2,
|
||||
MESSAGE3,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
ROUTER1 = 1,
|
||||
};
|
||||
|
||||
struct Message1 : public etl::message<MESSAGE1>
|
||||
{
|
||||
};
|
||||
|
||||
struct Message2 : public etl::message<MESSAGE2>
|
||||
{
|
||||
};
|
||||
|
||||
struct Message3 : public etl::message<MESSAGE3>
|
||||
{
|
||||
};
|
||||
|
||||
Message1 message1;
|
||||
Message2 message2;
|
||||
Message3 message3;
|
||||
|
||||
//***************************************************************************
|
||||
// Router that handles messages 1, 2, 3
|
||||
//***************************************************************************
|
||||
class Router1 : public etl::message_router<Router1, Message1, Message2, Message3>
|
||||
{
|
||||
public:
|
||||
|
||||
Router1()
|
||||
: message_router(ROUTER1)
|
||||
{
|
||||
}
|
||||
|
||||
void on_receive(const Message1& msg)
|
||||
{
|
||||
printf("Message 1 received\n");
|
||||
}
|
||||
|
||||
void on_receive(const Message2& msg)
|
||||
{
|
||||
printf("Message 2 received\n");
|
||||
}
|
||||
|
||||
void on_receive(const Message3& msg)
|
||||
{
|
||||
printf("Message 3 received\n");
|
||||
}
|
||||
|
||||
void on_receive_unknown(const etl::imessage& msg)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
// Bus that handles messages.
|
||||
//***************************************************************************
|
||||
class Bus1 : public etl::message_bus<1>
|
||||
{
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
// Router, bus and timer controller.
|
||||
//***************************************************************************
|
||||
Router1 router1;
|
||||
Bus1 bus1;
|
||||
|
||||
etl::message_timer_atomic<3, std::atomic_int32_t> timer_controller;
|
||||
|
||||
//***************************************************************************
|
||||
// The main loop.
|
||||
//***************************************************************************
|
||||
int main()
|
||||
{
|
||||
bus1.subscribe(router1);
|
||||
|
||||
etl::timer::id::type id1 = timer_controller.register_timer(message1,
|
||||
router1,
|
||||
1000,
|
||||
etl::timer::mode::SINGLE_SHOT);
|
||||
|
||||
etl::timer::id::type id2 = timer_controller.register_timer(message2,
|
||||
bus1,
|
||||
100,
|
||||
etl::timer::mode::REPEATING);
|
||||
|
||||
etl::timer::id::type id3 = timer_controller.register_timer(message3,
|
||||
router1,
|
||||
10,
|
||||
etl::timer::mode::REPEATING);
|
||||
|
||||
timer_controller.start(id1);
|
||||
timer_controller.start(id2);
|
||||
timer_controller.start(id3);
|
||||
|
||||
timer_controller.enable(true);
|
||||
|
||||
// Start timer interrupts here.
|
||||
|
||||
while (true)
|
||||
{
|
||||
// Loop forever.
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
// The interrupt timer callback.
|
||||
//***************************************************************************
|
||||
void timer_interrupt()
|
||||
{
|
||||
const uint32_t TICK = 1;
|
||||
static uint32_t nticks = TICK;
|
||||
|
||||
if (timer_controller.tick(nticks))
|
||||
{
|
||||
nticks = TICK;
|
||||
}
|
||||
else
|
||||
{
|
||||
nticks += TICK;
|
||||
}
|
||||
}
|
||||
|
||||
252
docs/raw/frameworks/Message Timer Interrupt.txt
Normal file
252
docs/raw/frameworks/Message Timer Interrupt.txt
Normal file
@ -0,0 +1,252 @@
|
||||
Message Timer Interrupt
|
||||
20.25.0
|
||||
|
||||
A software timer class that can manage up to 254 timers. Each one may be repeating or single shot.
|
||||
When a timer triggers it will send the defined message to the selected message router or bus.
|
||||
The timers are driven from a call to tick(uint32_t count). This call would normally be made from a high priority interrupt routine. The destination router will receive the message in the same context as the tick call.
|
||||
The call to tick has a low overhead when a timer is not 'due'. Internally the timers are stored in 'first timeout' order so only the head of the list needs to be checked.
|
||||
|
||||
Each timer may have a period of up to 232-2 ticks (4,294,967,294).
|
||||
At 1ms per tick this would equate to just over 49 days.
|
||||
|
||||
The framework relies on a supplied interrupt enable/disable guard type. With this mechanism, calls to tick are disabled if certain member functions are called. If the program flow is within a disable/enable section when the timer interrupt is activated then the tick update will be deferred until the next tick period. The timer interrupt may interrogate the return value of tick() to check whether the update was deferred. The guard allows timer functions to be to be called from the message handler called by tick().
|
||||
|
||||
Defines the following classes:-
|
||||
etl::imessage_timer_atomic<uint_least8_t MAX_TIMERS, typename TInterruptGuard>
|
||||
etl::message_timer_atomic<typename TInterruptGuard>
|
||||
|
||||
The TInterruptGuard type must disable and save the interrupt state on construction, and restore on destruction.
|
||||
|
||||
Uses definitions from timer.h
|
||||
____________________________________________________________________________________________________
|
||||
imessage_timer_atomic
|
||||
The base class for all timer controllers.
|
||||
|
||||
Template parameters
|
||||
TInterruptGuard The type that enables/disables interrupts.
|
||||
____________________________________________________________________________________________________
|
||||
Member functions
|
||||
etl::timer::id::type register_timer(const etl::imessage& message,
|
||||
etl::imessage_router& router,
|
||||
uint32_t period,
|
||||
bool repeating,
|
||||
etl::message_router_id_t destination_router_id =
|
||||
etl::imessage_router::ALL_MESSAGE_ROUTERS)
|
||||
Registers a timer.
|
||||
message A reference to the message that will be sent when the timer expires.
|
||||
router A reference to a router or bus that will receive to message.
|
||||
period The timer period in ticks.
|
||||
repeating false if single shot, true if repeating.
|
||||
destination_router_id The id of the destination router. Only valid if the router is a bus. Default to all routers.
|
||||
|
||||
Returns the allocated timer id or etl::timer::id::NO_TIMER if one was not available.
|
||||
____________________________________________________________________________________________________
|
||||
bool unregister_timer(etl::timer::id::type id)
|
||||
Unregisters a timer.
|
||||
If the timer is active then it will be stopped.
|
||||
Returns true if a timer with the id was successfully unregistered.
|
||||
____________________________________________________________________________________________________
|
||||
void enable(bool state)
|
||||
Enables or disables the timer manager according to the state.
|
||||
____________________________________________________________________________________________________
|
||||
bool is_running() const
|
||||
Returns true if the timer manager is enabled.
|
||||
____________________________________________________________________________________________________
|
||||
void clear()
|
||||
Clears the message timer back to the initial state. All timers will be stopped and unregistered.
|
||||
____________________________________________________________________________________________________
|
||||
bool tick(uint32_t count)
|
||||
This function updates the internal tick counter (if enabled) and must be passed the number of ticks that have occurred since the last call. If the count encompasses more than one period of a repeating timer then the timer will be triggered multiple times in one call to tick.
|
||||
Returns true if the tick counter was updated, otherwise false. This may be used by the calling routine to accumulate unprocessed tick counts.
|
||||
___________________________________________________________________________________________________
|
||||
bool start(etl::timer::id::type id, bool immediate = false)
|
||||
Starts the timer with the specified id.
|
||||
If the timer is already running then the timer Is restarted from the current tick count.
|
||||
If immediate is true then the timer is triggered on the next call to tick(). Note: Single shot timers will only trigger once.
|
||||
If the id does not correspond to a registered timer then returns false.
|
||||
____________________________________________________________________________________________________
|
||||
bool stop(etl::timer::id::type id)
|
||||
Stops the timer with the specified id.
|
||||
Does nothing if the timer is already stopped.
|
||||
if the id does not correspond to a registered timer then returns false.
|
||||
____________________________________________________________________________________________________
|
||||
bool set_period(etl::timer::id::type id_, uint32_t period)
|
||||
Stops the timer with the specified id.
|
||||
Sets a new timer period.
|
||||
Returns true if successful.
|
||||
____________________________________________________________________________________________________
|
||||
bool set_mode(etl::timer::id::type id_, bool repeating)
|
||||
Stops the timer with the specified id.
|
||||
Sets a new timer mode.
|
||||
Returns true if successful.
|
||||
____________________________________________________________________________________________________
|
||||
etl::timer::id::type time_to_next()
|
||||
Returns the time to the next timeout.
|
||||
20.38.0
|
||||
____________________________________________________________________________________________________
|
||||
Constants
|
||||
MAX_TIMERS
|
||||
____________________________________________________________________________________________________
|
||||
message_timer_atomic
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
message_timer_atomic()
|
||||
Default construct.
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
//***************************************************************************
|
||||
// The set of messages.
|
||||
//***************************************************************************
|
||||
enum
|
||||
{
|
||||
MESSAGE1,
|
||||
MESSAGE2,
|
||||
MESSAGE3,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
ROUTER1 = 1,
|
||||
};
|
||||
|
||||
struct Message1 : public etl::message<MESSAGE1>
|
||||
{
|
||||
};
|
||||
|
||||
struct Message2 : public etl::message<MESSAGE2>
|
||||
{
|
||||
};
|
||||
|
||||
struct Message3 : public etl::message<MESSAGE3>
|
||||
{
|
||||
};
|
||||
|
||||
Message1 message1;
|
||||
Message2 message2;
|
||||
Message3 message3;
|
||||
|
||||
//***************************************************************************
|
||||
// The interrupt guard type.
|
||||
// Saves and disables on contruction.
|
||||
// Restores on destruction.
|
||||
//***************************************************************************
|
||||
struct InterruptGuard
|
||||
{
|
||||
InterruptGuard()
|
||||
{
|
||||
state = __save_interrupts();
|
||||
__disable_interrupts();
|
||||
}
|
||||
|
||||
~InterruptGuard()
|
||||
{
|
||||
__restore_interrupts(state);
|
||||
}
|
||||
|
||||
int state;
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
// Router that handles messages 1, 2, 3
|
||||
//***************************************************************************
|
||||
class Router1 : public etl::message_router<Router1, Message1, Message2, Message3>
|
||||
{
|
||||
public:
|
||||
|
||||
Router1()
|
||||
: message_router(ROUTER1)
|
||||
{
|
||||
}
|
||||
|
||||
void on_receive(const Message1& msg)
|
||||
{
|
||||
printf("Message 1 received\n");
|
||||
}
|
||||
|
||||
void on_receive(const Message2& msg)
|
||||
{
|
||||
printf("Message 2 received\n");
|
||||
}
|
||||
|
||||
void on_receive(const Message3& msg)
|
||||
{
|
||||
printf("Message 3 received\n");
|
||||
}
|
||||
|
||||
void on_receive_unknown(const etl::imessage& msg)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
// Bus that handles messages.
|
||||
//***************************************************************************
|
||||
class Bus1 : public etl::message_bus<1>
|
||||
{
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
// Router, bus and timer controller.
|
||||
//***************************************************************************
|
||||
Router1 router1;
|
||||
Bus1 bus1;
|
||||
|
||||
etl::message_timer_atomic<3, InterruptGuard> timer_controller;
|
||||
|
||||
//***************************************************************************
|
||||
// The main loop.
|
||||
//***************************************************************************
|
||||
int main()
|
||||
{
|
||||
bus1.subscribe(router1);
|
||||
|
||||
etl::timer::id::type id1 = timer_controller.register_timer(message1,
|
||||
router1,
|
||||
1000,
|
||||
etl::timer::mode::SINGLE_SHOT);
|
||||
|
||||
etl::timer::id::type id2 = timer_controller.register_timer(message2,
|
||||
bus1,
|
||||
100,
|
||||
etl::timer::mode::REPEATING);
|
||||
|
||||
etl::timer::id::type id3 = timer_controller.register_timer(message3,
|
||||
router1,
|
||||
10,
|
||||
etl::timer::mode::REPEATING);
|
||||
|
||||
timer_controller.start(id1);
|
||||
timer_controller.start(id2);
|
||||
timer_controller.start(id3);
|
||||
|
||||
timer_controller.enable(true);
|
||||
|
||||
// Start timer interrupts here.
|
||||
|
||||
while (true)
|
||||
{
|
||||
// Loop forever.
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
// The interrupt timer callback.
|
||||
//***************************************************************************
|
||||
void timer_interrupt()
|
||||
{
|
||||
const uint32_t TICK = 1;
|
||||
static uint32_t nticks = TICK;
|
||||
|
||||
if (timer_controller.tick(nticks))
|
||||
{
|
||||
nticks = TICK;
|
||||
}
|
||||
else
|
||||
{
|
||||
nticks += TICK;
|
||||
}
|
||||
}
|
||||
|
||||
242
docs/raw/frameworks/Message Timer Locked.txt
Normal file
242
docs/raw/frameworks/Message Timer Locked.txt
Normal file
@ -0,0 +1,242 @@
|
||||
Message Timer Locked
|
||||
|
||||
A software timer class that can manage up to 254 timers. Each one may be repeating or single shot.
|
||||
When a timer triggers it will send the defined message to the selected message router or bus.
|
||||
The timers are driven from a call to tick(uint32_t count). This call would normally be made from a high priority interrupt routine. The destination router will receive the message in the same context as the tick call.
|
||||
The call to tick has a low overhead when a timer is not 'due'. Internally the timers are stored in 'first timeout' order so only the head of the list needs to be checked.
|
||||
|
||||
Each timer may have a period of up to 232-2 ticks (4,294,967,294).
|
||||
At 1ms per tick this would equate to just over 49 days.
|
||||
|
||||
Defines the following classes:-
|
||||
etl::imessage_timer_locked
|
||||
etl::message_timer_locked
|
||||
|
||||
The access to the timers is controlled by three external functions, supplied to the timer by the
|
||||
member function set_locks.
|
||||
|
||||
The three delegate parameters are:-
|
||||
Try Lock Attempts to set the lock. Returns true if successful, otherwise false.
|
||||
Lock Sets the lock.
|
||||
Unlock Resets the lock.
|
||||
|
||||
Uses definitions from timer.h
|
||||
____________________________________________________________________________________________________
|
||||
imessage_timer_atomic
|
||||
|
||||
The base class for all timer controllers.
|
||||
|
||||
Member functions
|
||||
etl::timer::id::type register_timer(const etl::imessage& message,
|
||||
etl::imessage_router& router,
|
||||
uint32_t period,
|
||||
bool repeating,
|
||||
etl::message_router_id_t destination_router_id =
|
||||
etl::imessage_router::ALL_MESSAGE_ROUTERS)
|
||||
Registers a timer.
|
||||
message A reference to the message that will be sent when the timer expires.
|
||||
router A reference to a router or bus that will receive to message.
|
||||
period The timer period in ticks.
|
||||
repeating false if single shot, true if repeating.
|
||||
destination_router_id The id of the destination router. Only valid if the router is a bus. Default to all routers.
|
||||
|
||||
Returns the allocated timer id or etl::timer::id::NO_TIMER if one was not available.
|
||||
____________________________________________________________________________________________________
|
||||
bool unregister_timer(etl::timer::id::type id)
|
||||
Unregisters a timer.
|
||||
If the timer is active then it will be stopped.
|
||||
Returns true if a timer with the id was successfully unregistered.
|
||||
____________________________________________________________________________________________________
|
||||
void enable(bool state)
|
||||
Enables or disables the timer manager according to the state.
|
||||
____________________________________________________________________________________________________
|
||||
bool is_running() const
|
||||
Returns true if the timer manager is enabled.
|
||||
____________________________________________________________________________________________________
|
||||
void clear()
|
||||
Clears the message timer back to the initial state. All timers will be stopped and unregistered.
|
||||
____________________________________________________________________________________________________
|
||||
bool tick(uint32_t count)
|
||||
This function updates the internal tick counter (if enabled) and must be passed the number of ticks that have occurred since the last call. If the count encompasses more than one period of a repeating timer then the timer will be triggered multiple times in one call to tick.
|
||||
Returns true if the tick counter was updated, otherwise false. This may be used by the calling routine to accumulate unprocessed tick counts.
|
||||
___________________________________________________________________________________________________
|
||||
bool start(etl::timer::id::type id, bool immediate = false)
|
||||
Starts the timer with the specified id.
|
||||
If the timer is already running then the timer Is restarted from the current tick count.
|
||||
If immediate is true then the timer is triggered on the next call to tick(). Note: Single shot timers will only trigger once.
|
||||
If the id does not correspond to a registered timer then returns false.
|
||||
____________________________________________________________________________________________________
|
||||
bool stop(etl::timer::id::type id)
|
||||
Stops the timer with the specified id.
|
||||
Does nothing if the timer is already stopped.
|
||||
if the id does not correspond to a registered timer then returns false.
|
||||
____________________________________________________________________________________________________
|
||||
bool set_period(etl::timer::id::type id_, uint32_t period)
|
||||
Stops the timer with the specified id.
|
||||
Sets a new timer period.
|
||||
Returns true if successful.
|
||||
____________________________________________________________________________________________________
|
||||
bool set_mode(etl::timer::id::type id_, bool repeating)
|
||||
Stops the timer with the specified id.
|
||||
Sets a new timer mode.
|
||||
Returns true if successful.
|
||||
____________________________________________________________________________________________________
|
||||
void set_locks(try_lock_type try_lock_, lock_type lock_, lock_type unlock_)
|
||||
Sets the try-lock, lock and unlock delegates.
|
||||
____________________________________________________________________________________________________
|
||||
etl::timer::id::type time_to_next()
|
||||
Returns the time to the next timeout.
|
||||
20.38.0
|
||||
____________________________________________________________________________________________________
|
||||
Constants
|
||||
MAX_TIMERS
|
||||
____________________________________________________________________________________________________
|
||||
message_timer_atomic
|
||||
|
||||
Template parameters
|
||||
MAX_TIMERS The number of timers to be supported. The maximum number is 254.
|
||||
A value of 255 will result in a compile error.
|
||||
____________________________________________________________________________________________________
|
||||
message_timer_locked()
|
||||
Default construct.
|
||||
The lock callback delegates are not set.
|
||||
____________________________________________________________________________________________________
|
||||
message_timer_locked(try_lock_type try_lock, lock_type lock, unlock_type unlock)
|
||||
Construct from lock callback delegates are not set.
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
//***************************************************************************
|
||||
// The set of messages.
|
||||
//***************************************************************************
|
||||
enum
|
||||
{
|
||||
MESSAGE1,
|
||||
MESSAGE2,
|
||||
MESSAGE3,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
ROUTER1 = 1,
|
||||
};
|
||||
|
||||
struct Message1 : public etl::message<MESSAGE1>
|
||||
{
|
||||
};
|
||||
|
||||
struct Message2 : public etl::message<MESSAGE2>
|
||||
{
|
||||
};
|
||||
|
||||
struct Message3 : public etl::message<MESSAGE3>
|
||||
{
|
||||
};
|
||||
|
||||
Message1 message1;
|
||||
Message2 message2;
|
||||
Message3 message3;
|
||||
|
||||
//***************************************************************************
|
||||
// Router that handles messages 1, 2, 3
|
||||
//***************************************************************************
|
||||
class Router1 : public etl::message_router<Router1, Message1, Message2, Message3>
|
||||
{
|
||||
public:
|
||||
|
||||
Router1()
|
||||
: message_router(ROUTER1)
|
||||
{
|
||||
}
|
||||
|
||||
void on_receive(const Message1& msg)
|
||||
{
|
||||
printf("Message 1 received\n");
|
||||
}
|
||||
|
||||
void on_receive(const Message2& msg)
|
||||
{
|
||||
printf("Message 2 received\n");
|
||||
}
|
||||
|
||||
void on_receive(const Message3& msg)
|
||||
{
|
||||
printf("Message 3 received\n");
|
||||
}
|
||||
|
||||
void on_receive_unknown(const etl::imessage& msg)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
// Bus that handles messages.
|
||||
//***************************************************************************
|
||||
class Bus1 : public etl::message_bus<1>
|
||||
{
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
// Router, bus and timer controller.
|
||||
//***************************************************************************
|
||||
Router1 router1;
|
||||
Bus1 bus1;
|
||||
|
||||
etl::message_timer_atomic<3> timer_controller;
|
||||
|
||||
//***************************************************************************
|
||||
// The main loop.
|
||||
//***************************************************************************
|
||||
int main()
|
||||
{
|
||||
bus1.subscribe(router1);
|
||||
|
||||
etl::timer::id::type id1 = timer_controller.register_timer(message1,
|
||||
router1,
|
||||
1000,
|
||||
etl::timer::mode::SINGLE_SHOT);
|
||||
|
||||
etl::timer::id::type id2 = timer_controller.register_timer(message2,
|
||||
bus1,
|
||||
100,
|
||||
etl::timer::mode::REPEATING);
|
||||
|
||||
etl::timer::id::type id3 = timer_controller.register_timer(message3,
|
||||
router1,
|
||||
10,
|
||||
etl::timer::mode::REPEATING);
|
||||
|
||||
timer_controller.start(id1);
|
||||
timer_controller.start(id2);
|
||||
timer_controller.start(id3);
|
||||
|
||||
timer_controller.enable(true);
|
||||
|
||||
// Start timer interrupts here.
|
||||
|
||||
while (true)
|
||||
{
|
||||
// Loop forever.
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
// The interrupt timer callback.
|
||||
//***************************************************************************
|
||||
void timer_interrupt()
|
||||
{
|
||||
const uint32_t TICK = 1;
|
||||
static uint32_t nticks = TICK;
|
||||
|
||||
if (timer_controller.tick(nticks))
|
||||
{
|
||||
nticks = TICK;
|
||||
}
|
||||
else
|
||||
{
|
||||
nticks += TICK;
|
||||
}
|
||||
}
|
||||
|
||||
246
docs/raw/frameworks/Message Timer.txt
Normal file
246
docs/raw/frameworks/Message Timer.txt
Normal file
@ -0,0 +1,246 @@
|
||||
Message Timer
|
||||
This class has been superseded.
|
||||
Consider using message_timer_atomic or message_timer_locked.
|
||||
|
||||
A software timer class that can manage up to 254 timers. Each one may be repeating or single shot.
|
||||
When a timer triggers it will send the defined message to the selected message router or bus.
|
||||
The timers are driven from a call to tick(uint32_t count). This call would normally be made from a high priority interrupt routine. The destination router will receive the message in the same context as the tick call.
|
||||
The call to tick has a low overhead when a timer is not 'due'. Internally the timers are stored in 'first timeout' order so only the head of the list needs to be checked.
|
||||
|
||||
Each timer may have a period of up to 232-2 ticks (4,294,967,294).
|
||||
At 1ms per tick this would equate to just over 49 days.
|
||||
|
||||
Defines the following classes:-
|
||||
etl::imessage_timer
|
||||
etl::message_timer
|
||||
etl::message_timer_data
|
||||
|
||||
Uses definitions from timer.h
|
||||
____________________________________________________________________________________________________
|
||||
Usage notes
|
||||
The message timer is designed to be used in a timer interrupt/thread - single foreground task environment. The timer tick call may pre-empt the foreground task, except when a timer function is within a ETL_DISABLE_TIMER_UPDATES / ETL_ENABLE_TIMER_UPDATES section. These macros will either use an atomic semaphore or contain code to disable or enable the relevant timer interrupts.
|
||||
|
||||
There are two macros that control which mechanism is used.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_MESSAGE_TIMER_USE_ATOMIC_LOCK
|
||||
|
||||
The framework relies on an atomic counter type. By default this is defined as etl::timer_semaphore_t.
|
||||
This in turn is either defined as std::atomic<uint32_t>, if the compiler supports std::atomic, or
|
||||
etl::atomic<uint32_t> if there is an atomic_xxx.h defined for the platform. A user defined type may be used for the semaphore by defining ETL_TIMER_SEMAPHORE_TYPE. Only the timer interrupt/thread and one foreground task may call register_timer, unregister_timer, clear, start or stop.
|
||||
With this mechanism, calls to tick are never disabled. If the foreground thread is within a disable/enable section when the timer interrupt/thread is activated then the tick update will be deferred until the next tick period. The timer interrupt/thread may interrogate the return value of tick() to check whether the update was deferred.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_MESSAGE_TIMER_USE_INTERRUPT_LOCK
|
||||
|
||||
The user must supply two macro definitions (ETL_MESSAGE_TIMER_DISABLE_INTERRUPTS and ETL_MESSAGE_TIMER_ENABLE_INTERRUPTS) to control interrupt enables. These macros must enable/disable all interrupts that may call tick, register_timer, unregister_timer, clear, start or stop.
|
||||
The user should ensure that mechanisms, such as memory barriers are used to disable re-ordering of the instructions.
|
||||
If the foreground task is within a disable/enable section when the timer interrupt is triggered then the tick update will be deferred until the interrupts are re-enabled. Depending on the resolution of the timers, the interrupt routine may be able to compensate for the delay by passing a modified tick count to tick().
|
||||
____________________________________________________________________________________________________
|
||||
imessage_timer
|
||||
|
||||
The base class for all timer controllers.
|
||||
|
||||
Member functions
|
||||
etl::timer::id::type register_timer(const etl::imessage& message,
|
||||
etl::imessage_router& router,
|
||||
uint32_t period,
|
||||
bool repeating,
|
||||
etl::message_router_id_t destination_router_id =
|
||||
etl::imessage_router::ALL_MESSAGE_ROUTERS)
|
||||
Registers a timer.
|
||||
message A reference to the message that will be sent when the timer expires.
|
||||
router A reference to a router or bus that will receive to message.
|
||||
period The timer period in ticks.
|
||||
repeating false if single shot, true if repeating.
|
||||
destination_router_id The id of the destination router. Only valid if the router is a bus. Default to all routers.
|
||||
|
||||
Returns the allocated timer id or etl::timer::id::NO_TIMER if one was not available.
|
||||
____________________________________________________________________________________________________
|
||||
bool unregister_timer(etl::timer::id::type id)
|
||||
Unregisters a timer.
|
||||
If the timer is active then it will be stopped.
|
||||
Returns true if a timer with the id was successfully unregistered.
|
||||
____________________________________________________________________________________________________
|
||||
void enable(bool state)
|
||||
Enables or disables the timer manager according to the state.
|
||||
____________________________________________________________________________________________________
|
||||
bool is_running() const
|
||||
Returns true if the timer manager is enabled.
|
||||
____________________________________________________________________________________________________
|
||||
void clear()
|
||||
Clears the message timer back to the initial state. All timers will be stopped and unregistered.
|
||||
____________________________________________________________________________________________________
|
||||
bool tick(uint32_t count)
|
||||
This function updates the internal tick counter (if enabled) and must be passed the number of ticks that have occurred since the last call. If the count encompasses more than one period of a repeating timer then the timer will be triggered multiple times in one call to tick.
|
||||
Returns true if the tick counter was updated, otherwise false. This may be used by the calling routine to accumulate unprocessed tick counts.
|
||||
___________________________________________________________________________________________________
|
||||
bool start(etl::timer::id::type id, bool immediate = false)
|
||||
Starts the timer with the specified id.
|
||||
If the timer is already running then the timer Is restarted from the current tick count.
|
||||
If immediate is true then the timer is triggered on the next call to tick(). Note: Single shot timers will only trigger once.
|
||||
If the id does not correspond to a registered timer then returns false.
|
||||
____________________________________________________________________________________________________
|
||||
bool stop(etl::timer::id::type id)
|
||||
Stops the timer with the specified id.
|
||||
Does nothing if the timer is already stopped.
|
||||
if the id does not correspond to a registered timer then returns false.
|
||||
____________________________________________________________________________________________________
|
||||
bool set_period(etl::timer::id::type id_, uint32_t period)
|
||||
Stops the timer with the specified id.
|
||||
Sets a new timer period.
|
||||
Returns true if successful.
|
||||
____________________________________________________________________________________________________
|
||||
bool set_mode(etl::timer::id::type id_, bool repeating)
|
||||
Stops the timer with the specified id.
|
||||
Sets a new timer mode.
|
||||
Returns true if successful.
|
||||
____________________________________________________________________________________________________
|
||||
etl::timer::id::type time_to_next()
|
||||
Returns the time to the next timeout.
|
||||
20.38.0
|
||||
____________________________________________________________________________________________________
|
||||
Constants
|
||||
MAX_TIMERS
|
||||
____________________________________________________________________________________________________
|
||||
message_timer
|
||||
|
||||
Template parameters
|
||||
MAX_TIMERS The number of timers to be supported. The maximum number is 254.
|
||||
A value of 255 will result in a compile error.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
//***************************************************************************
|
||||
// The set of messages.
|
||||
//***************************************************************************
|
||||
enum
|
||||
{
|
||||
MESSAGE1,
|
||||
MESSAGE2,
|
||||
MESSAGE3,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
ROUTER1 = 1,
|
||||
};
|
||||
|
||||
struct Message1 : public etl::message<MESSAGE1>
|
||||
{
|
||||
};
|
||||
|
||||
struct Message2 : public etl::message<MESSAGE2>
|
||||
{
|
||||
};
|
||||
|
||||
struct Message3 : public etl::message<MESSAGE3>
|
||||
{
|
||||
};
|
||||
|
||||
Message1 message1;
|
||||
Message2 message2;
|
||||
Message3 message3;
|
||||
|
||||
//***************************************************************************
|
||||
// Router that handles messages 1, 2, 3
|
||||
//***************************************************************************
|
||||
class Router1 : public etl::message_router<Router1, Message1, Message2, Message3>
|
||||
{
|
||||
public:
|
||||
|
||||
Router1()
|
||||
: message_router(ROUTER1)
|
||||
{
|
||||
}
|
||||
|
||||
void on_receive(const Message1& msg)
|
||||
{
|
||||
printf("Message 1 received\n");
|
||||
}
|
||||
|
||||
void on_receive(const Message2& msg)
|
||||
{
|
||||
printf("Message 2 received\n");
|
||||
}
|
||||
|
||||
void on_receive(const Message3& msg)
|
||||
{
|
||||
printf("Message 3 received\n");
|
||||
}
|
||||
|
||||
void on_receive_unknown(const etl::imessage& msg)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
// Bus that handles messages.
|
||||
//***************************************************************************
|
||||
class Bus1 : public etl::message_bus<1>
|
||||
{
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
// Router, bus and timer controller.
|
||||
//***************************************************************************
|
||||
Router1 router1;
|
||||
Bus1 bus1;
|
||||
|
||||
etl::message_timer<3> timer_controller;
|
||||
|
||||
//***************************************************************************
|
||||
// The main loop.
|
||||
//***************************************************************************
|
||||
int main()
|
||||
{
|
||||
bus1.subscribe(router1);
|
||||
|
||||
etl::timer::id::type id1 = timer_controller.register_timer(message1,
|
||||
router1,
|
||||
1000,
|
||||
etl::timer::mode::SINGLE_SHOT);
|
||||
|
||||
etl::timer::id::type id2 = timer_controller.register_timer(message2,
|
||||
bus1,
|
||||
100,
|
||||
etl::timer::mode::REPEATING);
|
||||
|
||||
etl::timer::id::type id3 = timer_controller.register_timer(message3,
|
||||
router1,
|
||||
10,
|
||||
etl::timer::mode::REPEATING);
|
||||
|
||||
timer_controller.start(id1);
|
||||
timer_controller.start(id2);
|
||||
timer_controller.start(id3);
|
||||
|
||||
timer_controller.enable(true);
|
||||
|
||||
// Start timer interrupts here.
|
||||
|
||||
while (true)
|
||||
{
|
||||
// Loop forever.
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
// The interrupt timer callback.
|
||||
//***************************************************************************
|
||||
void timer_interrupt()
|
||||
{
|
||||
const uint32_t TICK = 1;
|
||||
static uint32_t nticks = TICK;
|
||||
|
||||
if (timer_controller.tick(nticks))
|
||||
{
|
||||
nticks = TICK;
|
||||
}
|
||||
else
|
||||
{
|
||||
nticks += TICK;
|
||||
}
|
||||
}
|
||||
|
||||
82
docs/raw/frameworks/Messages.txt
Normal file
82
docs/raw/frameworks/Messages.txt
Normal file
@ -0,0 +1,82 @@
|
||||
Messages
|
||||
|
||||
Message types used for many of the framework classes.
|
||||
____________________________________________________________________________________________________
|
||||
message_types.h
|
||||
|
||||
etl::message_id_t
|
||||
The type used for message ids.
|
||||
By default can hold a value between 0 and 255.
|
||||
If ETL_MESSAGE_ID_TYPE is defined then this type will be used instead.
|
||||
____________________________________________________________________________________________________
|
||||
etl::message_router_id_t
|
||||
|
||||
The type used for message router ids.
|
||||
Can hold a value between 0 and 255.
|
||||
____________________________________________________________________________________________________
|
||||
message.h
|
||||
|
||||
The message classes are the common communication method across all of the message capable frameworks.
|
||||
They are identified by a unique id number that specialises the base class.
|
||||
____________________________________________________________________________________________________
|
||||
imessage
|
||||
|
||||
The base class for messages.
|
||||
It is this class that is passed around, usually by const reference.
|
||||
The class is abstract.
|
||||
____________________________________________________________________________________________________
|
||||
etl::message_id_t get_message_id() const ETL_NOEXCEPT = 0;
|
||||
Returns the id of the message.
|
||||
____________________________________________________________________________________________________
|
||||
message
|
||||
|
||||
message<size_t ID, typename TParent = etl::imessage>
|
||||
|
||||
Requires an integral id as the template parameter.
|
||||
Inherits from TParent, which defaults to etl::imessage.
|
||||
TParent allows additional base interfaces or functionality to be included.
|
||||
static asserts if TParent is not a base of etl::imessage.
|
||||
____________________________________________________________________________________________________
|
||||
ID
|
||||
The id of the message as an enum.
|
||||
Can be accessed by etl::message instances.
|
||||
____________________________________________________________________________________________________
|
||||
TParent
|
||||
The class that it inherits from. It must ultimately derive from etl::imessage.
|
||||
The default is etl::imessage.
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
enum
|
||||
{
|
||||
START,
|
||||
STOP,
|
||||
SET_SPEED
|
||||
};
|
||||
|
||||
struct MyInterface : public etl::imessage
|
||||
{
|
||||
virtual void DoStuff() = 0;
|
||||
};
|
||||
|
||||
// Start implements MyIterface
|
||||
struct Start : public etl::message<START, MyInterface>
|
||||
{
|
||||
void DoStuff() override
|
||||
{
|
||||
// Do stuff here.
|
||||
}
|
||||
};
|
||||
|
||||
struct Stop : public etl::message<STOP>
|
||||
{
|
||||
bool isEmergencyStop;
|
||||
};
|
||||
|
||||
struct SetSpeed : public etl::message<SET_SPEED>
|
||||
{
|
||||
uint32_t speed;
|
||||
};
|
||||
|
||||
void Receive(const etl::imessage& msg);
|
||||
|
||||
88
docs/raw/frameworks/Reference Counted Message Pool.txt
Normal file
88
docs/raw/frameworks/Reference Counted Message Pool.txt
Normal file
@ -0,0 +1,88 @@
|
||||
Reference Counted Message Pool
|
||||
|
||||
Allocates etl::ireference_counted_message types that are used by etl::shared_message.
|
||||
Uses a supplied memory_block allocator derived from etl::imemory_block_allocator
|
||||
|
||||
ireference_counted_message_pool.h
|
||||
Defines the following class.
|
||||
etl::ireference_counted_message_pool
|
||||
|
||||
reference_counted_message_pool.h
|
||||
Defines the following classes.
|
||||
etl::reference_counted_message_pool_exception
|
||||
etl::reference_counted_message_pool_allocation_failure
|
||||
etl::reference_counted_message_pool_release_failure
|
||||
|
||||
etl::reference_counted_message_pool<typename TCounter>
|
||||
____________________________________________________________________________________________________
|
||||
ireference_counted_message_pool
|
||||
|
||||
etl::ireference_counted_message_pool
|
||||
|
||||
The interface for reference counted message pools.
|
||||
virtual ~ireference_counted_message_pool() {}
|
||||
virtual void release(const etl::ipool_message& msg) = 0;
|
||||
|
||||
Virtual lock() and unlock() functions are defined. The default action is to do nothing.
|
||||
A derived class may override these functions to provide a thread or interrupt safe pool.
|
||||
virtual void lock()
|
||||
virtual void unlock()
|
||||
____________________________________________________________________________________________________
|
||||
reference_counted_message_pool
|
||||
|
||||
etl::reference_counted_message_pool<TCounter>
|
||||
The concrete reference counted message pool.
|
||||
|
||||
reference_counted_message_pool(imemory_block_allocator& memory_block_allocator)
|
||||
Constructs the pool and assigns the memory block allocator to it.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TMessage>
|
||||
etl::reference_counted_message<TMessage, TCounter>* allocate()
|
||||
Returns a pointer to a pool message that holds a TMessage.
|
||||
The message is default constructed.
|
||||
ETL_ASSERT if one cannot be allocated and returns ETL_NULLPTR .
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TMessage>
|
||||
etl::reference_counted_message<TMessage, TCounter>* allocate(const TMessage& message)
|
||||
Returns a pointer to a pool message that holds a TMessage.
|
||||
ETL_ASSERT if one cannot be allocated and returns ETL_NULLPTR .
|
||||
____________________________________________________________________________________________________
|
||||
void release(const etl::ireference_counted_message& rcmessage)
|
||||
Returns the reference counted to a pool message that holds a TMessage.
|
||||
ETL_ASSERT if it cannot be released. Reasons can include the message not belonging to the pool.
|
||||
____________________________________________________________________________________________________
|
||||
pool_message_parameters
|
||||
|
||||
C++03
|
||||
The C++03 version defines the largest size and alignment of up to 8 types at a time.
|
||||
|
||||
template <typename TMessage1, typename TMessage2 = TMessage1,
|
||||
typename TMessage3 = TMessage1, typename TMessage4 = TMessage1,
|
||||
typename TMessage5 = TMessage1, typename TMessage6 = TMessage1,
|
||||
typename TMessage7 = TMessage1, typename TMessage8 = TMessage1>
|
||||
struct pool_message_parameters
|
||||
|
||||
static const size_t max_size;
|
||||
The maximum size.
|
||||
|
||||
static const size_t max_alignment;
|
||||
The maximum alignment.
|
||||
|
||||
C++11 or above
|
||||
The C++11 version defines the largest size and alignment of a set of message types.
|
||||
template <typename TMessage1, typename... TMessages>
|
||||
struct pool_message_parameters
|
||||
|
||||
static constexpr size_t max_size
|
||||
The maximum size.
|
||||
|
||||
static constexpr size_t max_alignment;
|
||||
The maximum alignment.
|
||||
____________________________________________________________________________________________________
|
||||
For C++11, with atomic support.
|
||||
|
||||
template <typename TObject>
|
||||
using atomic_counted_message_pool = etl::reference_counted_message_pool<etl::atomic_int32_t>;
|
||||
Defines an alias to a reference counted message pool that uses an atomic.
|
||||
|
||||
|
||||
102
docs/raw/frameworks/Reference Counted Messages.txt
Normal file
102
docs/raw/frameworks/Reference Counted Messages.txt
Normal file
@ -0,0 +1,102 @@
|
||||
Reference Counted Messages
|
||||
|
||||
Reference counted message types that are used by etl::shared_message.
|
||||
|
||||
Defines the following classes.
|
||||
|
||||
etl::ireference_counted_message
|
||||
The interface of all reference counted message types.
|
||||
|
||||
etl::reference_counted_message<typename TMessage, typename TCounter>
|
||||
Derived from etl::ireference_counted_message
|
||||
|
||||
etl::persistent_message<typename TMessage>
|
||||
Derived from etl::ireference_counted_message
|
||||
____________________________________________________________________________________________________
|
||||
ireference_counted_message
|
||||
|
||||
etl::ireference_counted_message
|
||||
The interface of all reference counted message types.
|
||||
____________________________________________________________________________________________________
|
||||
virtual ~ireference_counted_message()
|
||||
____________________________________________________________________________________________________
|
||||
ETL_NODISCARD virtual etl::imessage& get_message() = 0;
|
||||
Get a reference to the message.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_NODISCARD virtual const etl::imessage& get_message() const = 0;
|
||||
Get a const reference to the message.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_NODISCARD virtual etl::ireference_counter& get_reference_counter() = 0;
|
||||
Get a reference to the reference counter.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_NODISCARD virtual const etl::ireference_counter& get_reference_counter() const = 0;
|
||||
Get a const reference to the reference counter.
|
||||
____________________________________________________________________________________________________
|
||||
virtual void release() = 0;
|
||||
Release back to the owner.
|
||||
____________________________________________________________________________________________________
|
||||
reference_counted_message
|
||||
|
||||
etl::reference_counted_message<typename TMessage, typename TCounter>
|
||||
|
||||
The implementation of reference counted messages owned by a pool.
|
||||
|
||||
Will static assert if TMessage is no derived from etl::imessage.
|
||||
____________________________________________________________________________________________________
|
||||
reference_counted_message(const TMessage& message, etl::ireference_counted_message_pool& owner)
|
||||
Constructs from a message and the pool from which the reference counted message is allocated.
|
||||
The message is copied.
|
||||
____________________________________________________________________________________________________
|
||||
reference_counted_message(etl::ireference_counted_message_pool& owner)
|
||||
Constructs from a message and the pool from which the reference counted message is allocated.
|
||||
The message is default constructed.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_NODISCARD TMessage& get_message() ETL_OVERRIDE
|
||||
Get a reference to the message.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_NODISCARD const TMessage& get_message() const ETL_OVERRIDE
|
||||
Get a const reference to the message.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_NODISCARD etl::ireference_counter& get_reference_counter() ETL_OVERRIDE
|
||||
Get a reference to the reference counter.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_NODISCARD const etl::ireference_counter& get_reference_counter() const ETL_OVERRIDE
|
||||
Get a const reference to the reference counter.
|
||||
____________________________________________________________________________________________________
|
||||
void release() ETL_OVERRIDE
|
||||
Release back to the owner pool.
|
||||
____________________________________________________________________________________________________
|
||||
persistent_message
|
||||
|
||||
etl::persistent_message<typename TMessage>
|
||||
|
||||
The implementation of reference counted messages not owned by a pool.
|
||||
It's counter type is void.
|
||||
|
||||
Will static assert if TMessage is not derived from etl::imessage.
|
||||
____________________________________________________________________________________________________
|
||||
persistent_message(const TMessage& message)
|
||||
Constructs from a message.
|
||||
The message is copied.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_NODISCARD TMessage& get_message() ETL_OVERRIDE
|
||||
Get a reference to the message.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_NODISCARD const TMessage& get_message() const ETL_OVERRIDE
|
||||
Get a const reference to the message.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_NODISCARD etl::ireference_counter& get_reference_counter() ETL_OVERRIDE
|
||||
Get a reference to the reference counter.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_NODISCARD const etl::ireference_counter& get_reference_counter() const ETL_OVERRIDE
|
||||
Get a const reference to the reference counter.
|
||||
____________________________________________________________________________________________________
|
||||
void release() ETL_OVERRIDE
|
||||
Does nothing for a persistent message.
|
||||
____________________________________________________________________________________________________
|
||||
For C++11, with atomic support.
|
||||
|
||||
template <typename TMessage>
|
||||
using atomic_counted_message = etl::reference_counted_message<TMessage, etl::atomic_int32_t>;
|
||||
Defines an alias to a reference counted message that uses an atomic.
|
||||
|
||||
38
docs/raw/frameworks/Shared Messages.txt
Normal file
38
docs/raw/frameworks/Shared Messages.txt
Normal file
@ -0,0 +1,38 @@
|
||||
Shared Messages
|
||||
|
||||
The type used to encapsulate reference counted messages.
|
||||
Shared messages are usually passed by value.
|
||||
|
||||
See the Shared Message Tutorial
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TPool, typename TMessage>
|
||||
shared_message(TPool& owner, const TMessage& message)
|
||||
|
||||
Static asserts if TPool is not derived from etl::ireference_counted_message_pool
|
||||
Static asserts if TMessage not derived from etl::imessage
|
||||
|
||||
Requires that TPool implements the following member function to allocate from the pool.
|
||||
template <typename TMessage>
|
||||
etl::ireference_counted_message* allocate(const TMessage& message)
|
||||
____________________________________________________________________________________________________
|
||||
explicit shared_message(etl::ireference_coutnted_message& message)
|
||||
Construct from a reference counted message.
|
||||
____________________________________________________________________________________________________
|
||||
shared_message(const etl::shared_message& other)
|
||||
Copy constructor.
|
||||
____________________________________________________________________________________________________
|
||||
shared_message& operator =(const etl::shared_message& other)
|
||||
Assignment operator.
|
||||
____________________________________________________________________________________________________
|
||||
~shared_message()
|
||||
Destructor.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_NODISCARD etl::imessage& get_message()
|
||||
Gets a reference to the contained message.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_NODISCARD const etl::imessage& get_message() const
|
||||
Gets a const reference to the contained message.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_NODISCARD uint32_t get_reference_count() const
|
||||
Gets the current reference count for this shared message.
|
||||
|
||||
310
docs/raw/frameworks/State Chart.txt
Normal file
310
docs/raw/frameworks/State Chart.txt
Normal file
@ -0,0 +1,310 @@
|
||||
State Chart
|
||||
A finite state machine driven by the reception of events. The incoming event will call the optional action based on a transition table. Optional on_entry and on_exit handlers can be declared in a state table.
|
||||
An optional parameter may be sent to event handlers.
|
||||
|
||||
This FSM is simpler, both in implementation and use, than the message based FSM class defined elsewhere in the ETL. See etl::fsm.
|
||||
|
||||
Defines the following classes:-
|
||||
etl::istate_chart
|
||||
etl::state_chart<TObject>
|
||||
etl::state_chart<TObject, TParameter>
|
||||
|
||||
TParameter defines how a data parameter will be passed to event handlers.
|
||||
This may be by value, pointer, reference or const reference.
|
||||
For C++11 or above, you may pass an rvalue reference.
|
||||
____________________________________________________________________________________________________
|
||||
istate_chart<TParameter> 20.23.0
|
||||
The base for all state charts.
|
||||
|
||||
Types
|
||||
event_id_t
|
||||
The type for event ids.
|
||||
|
||||
state_id_t
|
||||
The type for state ids.
|
||||
|
||||
Member Functions
|
||||
event_it_t get_state_id() const
|
||||
Returns the id of the state.
|
||||
____________________________________________________________________________________________________
|
||||
virtual void process_event(event_id_t event_id, TParameter data) = 0
|
||||
etl::state_chart will override this.
|
||||
Processes the event message.
|
||||
If a data parameter has been configured for etl::state_chart, then one will be default constructed.
|
||||
____________________________________________________________________________________________________
|
||||
virtual void start(bool on_entry_initial = true)
|
||||
Starts the state chart.
|
||||
____________________________________________________________________________________________________
|
||||
istate_chart<void> 20.23.0
|
||||
The base for all state charts.
|
||||
|
||||
Types
|
||||
event_id_t
|
||||
The type for event ids.
|
||||
|
||||
state_id_t
|
||||
The type for state ids.
|
||||
|
||||
Member Functions
|
||||
event_it_t get_state_id() const
|
||||
Returns the id of the state.
|
||||
____________________________________________________________________________________________________
|
||||
virtual void process_event(event_id_t event_id) = 0
|
||||
etl::state_chart will override this.
|
||||
Processes the event message.
|
||||
If a data parameter has been configured for etl::state_chart, then one will be default constructed.
|
||||
____________________________________________________________________________________________________
|
||||
virtual void start(bool on_entry_initial = true)
|
||||
Starts the state chart.
|
||||
____________________________________________________________________________________________________
|
||||
state_chart
|
||||
For run-time defined transition and state tables.
|
||||
A templated class. Inherits from etl::istate_chart<TParameter> or etl::istate_chart<void>.
|
||||
|
||||
Template parameters
|
||||
TObject The object type that supplies actions, guards, on entry and on exit functionality.
|
||||
TParameter The type that will be passed as a parameter (optional).
|
||||
____________________________________________________________________________________________________
|
||||
Types
|
||||
|
||||
TParameter parameter_t
|
||||
____________________________________________________________________________________________________
|
||||
Constructor
|
||||
|
||||
state_chart(TObject& object,
|
||||
const transition* transition_table_begin,
|
||||
const transition* transition_table_end,
|
||||
const state* state_table_begin,
|
||||
const state* state_table_end,
|
||||
const state_id_t state_id)
|
||||
|
||||
object
|
||||
The instance of the that supplies actions, guards, on entry and on exit functionality.
|
||||
|
||||
transition_table_begin
|
||||
transition_table_end
|
||||
The table of transitions, defining the relationship between events and state changes; defines option actions and guards.
|
||||
Note: The transition table must have the same lifetime as the state chart. i.e. It must exist while the state chart exists.
|
||||
|
||||
state_table_begin
|
||||
state_table_end
|
||||
Sets the optional state table defining any 'on entry' and 'on exit' for states.
|
||||
Not all states have to have entries in the table. States with no 'on entry' and 'on_exit' functionality may be omitted.
|
||||
Note: The state table must have the same lifetime as the state chart. i.e. It must exist while the state chart exists.
|
||||
|
||||
state_id
|
||||
The initial state id.
|
||||
Note: The constructors do not call the 'on entry' function for the initial state
|
||||
____________________________________________________________________________________________________
|
||||
state_chart_ct void parameter
|
||||
state_chart_ctp non-void parameter
|
||||
For compile-time defined transition and state tables.
|
||||
A templated class. Inherits from etl::istate_chart<TParameter> or etl::istate_chart<void>.
|
||||
|
||||
Template parameters
|
||||
TObject The object type that supplies actions, guards, on entry and on exit functionality.
|
||||
TParameter The type that will be passed as a parameter (state_chart_ctp).
|
||||
TObject_Ref A reference to the TObject instance.
|
||||
Transition_Table_Begin A pointer to the start of the transition table.
|
||||
Transition_Table_Size The number of elements in the transition table.
|
||||
State_Table_Begin A pointer to the start of the state table.
|
||||
State_Table_Size The number of elements in the transition table.
|
||||
Initial_State The initial state.
|
||||
____________________________________________________________________________________________________
|
||||
Types
|
||||
TParameter parameter_t
|
||||
____________________________________________________________________________________________________
|
||||
Constructor
|
||||
|
||||
state_chart()
|
||||
____________________________________________________________________________________________________
|
||||
Member Functions
|
||||
|
||||
void start(bool on_entry_initial = true)
|
||||
Starts the state chart.
|
||||
if on_entry_initial is true and the initial state has an on_entry method, then this will be called.
|
||||
The function does nothing after the first call.
|
||||
____________________________________________________________________________________________________
|
||||
void process_event(event_id_t event_id) For void parameter.
|
||||
Triggers the state chart with the event.
|
||||
____________________________________________________________________________________________________
|
||||
void process_event(event_id_t event_id, parameter_t data) For non-void parameter.
|
||||
Triggers the state chart with the event.
|
||||
Passes the parameter to the event handler.
|
||||
____________________________________________________________________________________________________
|
||||
TObject& get_object()
|
||||
const TObject& get_object() const
|
||||
Gets the implementation object instance.
|
||||
____________________________________________________________________________________________________
|
||||
void set_transition_table(const transition* transition_table_begin,
|
||||
const transition* transition_table_end)
|
||||
Not defined for state_chart_ct or state_chart_ctp.
|
||||
The table of transitions, defining the relationship between events and state changes; defines option actions and guards.
|
||||
Note: The transition table must have the same scope as the state chart. i.e. It must exist while the state chart exists.
|
||||
____________________________________________________________________________________________________
|
||||
void set_state_table(const state* state_table_begin,
|
||||
const state* state_table_end)
|
||||
Not defined for state_chart_ct or state_chart_ctp.
|
||||
Sets the optional state table defining any on_entry and on_exit for states.
|
||||
Not all states have to have entries in the table. States with no on_entry and on_exit functionality may be omitted.
|
||||
Note: The state table must have the same scope as the state chart. i.e. It must exist while the state chart exists.
|
||||
____________________________________________________________________________________________________
|
||||
Member Types
|
||||
|
||||
transition
|
||||
____________________________________________________________________________________________________
|
||||
For etl::state_chart<TImplementation>
|
||||
transition(const state_id_t current_state_id,
|
||||
const event_id_t event_id,
|
||||
const state_id_t next_state_id,
|
||||
void (TObject::* const action)() = nullptr,
|
||||
bool (TObject::* const guard)() = nullptr)
|
||||
|
||||
transition(const event_id_t event_id,
|
||||
const state_id_t next_state_id,
|
||||
void (TObject::* const action)() = nullptr,
|
||||
bool (TObject::* const guard)() = nullptr)
|
||||
____________________________________________________________________________________________________
|
||||
For etl::state_chart<TImplementation, TParameter>
|
||||
transition(const state_id_t current_state_id,
|
||||
const event_id_t event_id,
|
||||
const state_id_t next_state_id,
|
||||
void (TObject::* const action)(data_parameter_type) = nullptr,
|
||||
bool (TObject::* const guard)() = nullptr)
|
||||
|
||||
transition(const event_id_t event_id,
|
||||
const state_id_t next_state_id,
|
||||
void (TObject::* const action)(data_parameter_type) = nullptr,
|
||||
bool (TObject::* const guard)() = nullptr)
|
||||
|
||||
current_state_id
|
||||
The state id that the state chart must be in for the event to be processed.
|
||||
If the second constructor form is used then the 'current state' is considered to be don't care.
|
||||
|
||||
event_id
|
||||
The event id for this transition.
|
||||
|
||||
next_state_id
|
||||
The state id that the state chart will be in after the event.
|
||||
|
||||
action
|
||||
An optional pointer to the action that will be called when the transition occurs.
|
||||
|
||||
guard
|
||||
An optional pointer to the guard for this transition. The transition will only occur if the guard returns true.
|
||||
If the guard returns false then the scan of the transition table continues from the next position.
|
||||
____________________________________________________________________________________________________
|
||||
state
|
||||
|
||||
ETL_CONSTEXPR state(const state_id_t state_id_,
|
||||
void (TObject::* const on_entry)() = ETL_NULLPTR,
|
||||
void (TObject::* const on_exit)() = ETL_NULLPTR)
|
||||
|
||||
state_id
|
||||
The ID of the state.
|
||||
|
||||
on_entry
|
||||
An optional pointer to the function that will be called when a state is entered.
|
||||
|
||||
on_exit
|
||||
An optional pointer to the function that will be called when a state is entered.
|
||||
___________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
class MotorControl : public etl::state_chart<MotorControl>
|
||||
{
|
||||
void OnStart();
|
||||
void OnStop();
|
||||
void OnSetSpeed();
|
||||
bool StartGuard();
|
||||
|
||||
static const etl::array<MotorControl::transition, 5> transitionTable;
|
||||
};
|
||||
|
||||
const etl::array<MotorControl::transition, 5> MotorControl::transitionTable =
|
||||
{
|
||||
MotorControl::transition(IDLE,
|
||||
START,
|
||||
RUNNING,
|
||||
&MotorControl::OnStart,
|
||||
&MotorControl::StartGuard),
|
||||
|
||||
MotorControl::transition(RUNNING,
|
||||
STOP,
|
||||
WINDING_DOWN,
|
||||
&MotorControl::OnStop),
|
||||
|
||||
MotorControl::transition(WINDING_DOWN,
|
||||
STOPPED,
|
||||
IDLE),
|
||||
|
||||
MotorControl::transition(RUNNING,
|
||||
EMERGENCY_STOP,
|
||||
IDLE,
|
||||
&MotorControl::OnStop),
|
||||
|
||||
MotorControl::transition(RUNNING,
|
||||
SET_SPEED,
|
||||
RUNNING,
|
||||
&MotorControl::OnSetSpeed)
|
||||
};
|
||||
____________________________________________________________________________________________________
|
||||
state
|
||||
|
||||
state(const state_id_t state_id,
|
||||
void (TObject::* const on_entry)() = nullptr,
|
||||
void (TObject::* const on_exit)() = nullptr)
|
||||
|
||||
state_id
|
||||
The id for this state.
|
||||
|
||||
on_entry
|
||||
An optional pointer to the function that will be called when the state chart enters the state.
|
||||
|
||||
on_exit
|
||||
An optional pointer to the function that will be called when the state chart exits the state.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
class MotorControl : public etl::state_chart<MotorControl>
|
||||
{
|
||||
void OnExitIdle();
|
||||
void OnEnterStopped();
|
||||
void OnEnterRunning);
|
||||
void OnExitRunning();
|
||||
|
||||
static const etl::array<MotorControl::state, 3> stateTable;
|
||||
};
|
||||
|
||||
const etl::array<MotorControl::state, 3> MotorControl::stateTable =
|
||||
{
|
||||
MotorControl::state(IDLE, nullptr, &MotorControl::OnExitIdle),
|
||||
MotorControl::state(STOPPED, &MotorControl::OnEnterStopped, nullptr),
|
||||
MotorControl::state(RUNNING, &MotorControl::OnEnterRunning, &MotorControl::OnExitRunning)
|
||||
};
|
||||
____________________________________________________________________________________________________
|
||||
Notes
|
||||
____________________________________________________________________________________________________
|
||||
Order of execution
|
||||
When an event is processed, the execution occurs in the following order.
|
||||
(Assuming all functions have been declared in the transition and state tables)
|
||||
|
||||
A call to the guard function.
|
||||
A call to the action function.
|
||||
A call to the current state's exit function (if the transition changes the state).
|
||||
A call to the next state's entry function (if the transition changes the state).
|
||||
____________________________________________________________________________________________________
|
||||
Usage
|
||||
The state chart may either used with inheritance or composition.
|
||||
|
||||
class Implementation : public etl::state_chart<Implementation>
|
||||
|
||||
class Implementation
|
||||
{
|
||||
etl::state_chart<Implementation> stateChart;
|
||||
};
|
||||
|
||||
Use inheritance when the implementation is a state machine.
|
||||
Use composition if the implementation contains a state machine.
|
||||
|
||||
41
docs/raw/frameworks/Task.txt
Normal file
41
docs/raw/frameworks/Task.txt
Normal file
@ -0,0 +1,41 @@
|
||||
Task
|
||||
The base for tasks controlled by etl::scheduler.
|
||||
____________________________________________________________________________________________________
|
||||
Types
|
||||
|
||||
etl::task_priority_t
|
||||
The type for task priorities.
|
||||
____________________________________________________________________________________________________
|
||||
task
|
||||
|
||||
task(task_priority_t priority)
|
||||
Constructor.
|
||||
Sets the task priority.
|
||||
____________________________________________________________________________________________________
|
||||
virtual ~task();
|
||||
Virtual destructor
|
||||
____________________________________________________________________________________________________
|
||||
virtual uint32_t task_request_work() const = 0;
|
||||
The derived task must override this.
|
||||
Should return a value that represents the amount of work to do. This may be the number of items in the task's message queue, for example.
|
||||
Return zero if the task requires no processing time.
|
||||
____________________________________________________________________________________________________
|
||||
virtual void task_process_work() = 0;
|
||||
The derived task must override this.
|
||||
The task should process one unit of work.
|
||||
____________________________________________________________________________________________________
|
||||
virtual void on_task_added(); 19.4.0
|
||||
The derived task may override this.
|
||||
By default, does nothing.
|
||||
____________________________________________________________________________________________________
|
||||
void set_task_running(bool task_running);
|
||||
Enables/disables the task from processing work.
|
||||
Enabled by default.
|
||||
____________________________________________________________________________________________________
|
||||
bool task_is_running() const;
|
||||
Returns true if the task is in the 'running' state.
|
||||
____________________________________________________________________________________________________
|
||||
etl::task_priority_t get_task_priority() const;
|
||||
Returns the priority of the task.
|
||||
|
||||
|
||||
90
docs/raw/frameworks/Timer.txt
Normal file
90
docs/raw/frameworks/Timer.txt
Normal file
@ -0,0 +1,90 @@
|
||||
Timer
|
||||
Contains definitions common to timers.
|
||||
|
||||
struct timer
|
||||
{
|
||||
// Timer modes.
|
||||
struct mode
|
||||
{
|
||||
enum
|
||||
{
|
||||
SINGLE_SHOT = false,
|
||||
REPEATING = true
|
||||
};
|
||||
|
||||
typedef bool type;
|
||||
};
|
||||
|
||||
// Timer start status.
|
||||
struct start
|
||||
{
|
||||
enum
|
||||
{
|
||||
DELAYED = false,
|
||||
IMMEDIATE = true
|
||||
};
|
||||
|
||||
typedef bool type;
|
||||
};
|
||||
|
||||
// Timer id.
|
||||
struct id
|
||||
{
|
||||
enum
|
||||
{
|
||||
NO_TIMER = 255
|
||||
};
|
||||
|
||||
typedef uint_least8_t type;
|
||||
};
|
||||
|
||||
// Timer state.
|
||||
struct state
|
||||
{
|
||||
enum
|
||||
{
|
||||
INACTIVE = 0xFFFFFFFF
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
timer
|
||||
mode
|
||||
Types
|
||||
type
|
||||
The type for timer mode.
|
||||
Defined as bool
|
||||
|
||||
Constants
|
||||
SINGLE_SHOT
|
||||
The timer expires once and then stops.
|
||||
|
||||
REPEATING
|
||||
The timer is restarted after every timeout.
|
||||
|
||||
start
|
||||
Types
|
||||
type
|
||||
The type for timer start mode.
|
||||
Defined as bool
|
||||
|
||||
Constants
|
||||
IMMEDIATE
|
||||
Single Shot
|
||||
The timer is triggered on the next tick. The normal timeout does not occur.
|
||||
Repeating
|
||||
The timer is triggered on the next tick and then on subsequent timeouts.
|
||||
DELAYED
|
||||
The timer is triggered on the timeout.
|
||||
|
||||
id
|
||||
Types
|
||||
type
|
||||
The type for timer identifiers.
|
||||
Defined as uint_least8_t
|
||||
|
||||
Constants
|
||||
NO_TIMER
|
||||
The id of an unregistered timer.
|
||||
|
||||
BIN
docs/raw/frameworks/hfsm.png
Normal file
BIN
docs/raw/frameworks/hfsm.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 44 KiB |
103
docs/raw/frameworks/message_packet.txt
Normal file
103
docs/raw/frameworks/message_packet.txt
Normal file
@ -0,0 +1,103 @@
|
||||
message_packet
|
||||
|
||||
A container for more than one type of message.
|
||||
The messages must have been derived from etl::imessage.
|
||||
|
||||
The messages types that the packet may contain are listed as template parameters.
|
||||
e.g. etl::message_packet<Message1, Message2, Message3>
|
||||
|
||||
From 20.40.0 message types are not rquired to have a virtual destructor.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
message_packet()
|
||||
Default constructs a message packet.
|
||||
is_valid() returns false.
|
||||
___________________________________________________________________________________________________
|
||||
explicit message_packet(const etl::imessage&)
|
||||
Constructs a message packet from an etl::imessage reference.
|
||||
Asserts an etl::unhandled_message_exception error if the parameter is not one listed in the template parameter list.
|
||||
___________________________________________________________________________________________________
|
||||
explicit message_packet(etl::imessage&&) C++11
|
||||
Move constructs a message packet from an etl::imessage rvalue reference.
|
||||
Emits an etl::unhandled_message_exception error if the parameter is not one listed in the template parameter list.
|
||||
___________________________________________________________________________________________________
|
||||
20.22.0
|
||||
template <typename TMessage>
|
||||
explicit message_packet(const TMessage&)
|
||||
Constructs a message packet from a TMessage reference.
|
||||
Emits a compile time static assert if the parameter is not one listed in the template parameter list.
|
||||
___________________________________________________________________________________________________
|
||||
20.22.0
|
||||
template <typename TMessage>
|
||||
explicit message_packet(TMessage&&) C++11
|
||||
Move constructs a message packet from a TMessage rvalue reference.
|
||||
Emits a compile time static assert if the parameter is not one listed in the template parameter list.
|
||||
___________________________________________________________________________________________________
|
||||
message_packet(const message_packet&)
|
||||
Constructs a message packet from an message_packet reference.
|
||||
Emits an etl::unhandled_message_exception error if the parameter is not one listed in the template parameter list.
|
||||
___________________________________________________________________________________________________
|
||||
message_packet(message_packet&&)
|
||||
Move constructs a message packet from an message_packet rvalue reference.
|
||||
Emits an etl::unhandled_message_exception if the parameter is not one listed in the template parameter list.
|
||||
___________________________________________________________________________________________________
|
||||
message_packet& operator =(const message_packet&)
|
||||
Assigns a message packet from an message_packet reference.
|
||||
Emits an etl::unhandled_message_exception error if the parameter is not one listed in the template parameter list.
|
||||
___________________________________________________________________________________________________
|
||||
message_packet& operator =(message_packet&&)
|
||||
Move assigns a message packet from an message_packet rvalue reference.
|
||||
Emits an etl::unhandled_message_exception error if the parameter is not one listed in the template parameter list.
|
||||
___________________________________________________________________________________________________
|
||||
etl::imessage& get()
|
||||
const etl::imessage& get() const
|
||||
Returns a reference to an etl::imessage
|
||||
___________________________________________________________________________________________________
|
||||
bool is_valid() const
|
||||
Returns true if the packet contains a valid message, otherwise false.
|
||||
____________________________________________________________________________________________________
|
||||
Constants
|
||||
|
||||
SIZE The size of the largest message.
|
||||
ALIGNMENT The largest message alignment.
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
enum
|
||||
{
|
||||
MESSAGE1,
|
||||
MESSAGE2,
|
||||
MESSAGE3
|
||||
};
|
||||
|
||||
struct Message1 : public etl::message<MESSAGE1>
|
||||
{
|
||||
};
|
||||
|
||||
struct Message2 : public etl::message<MESSAGE2>
|
||||
{
|
||||
};
|
||||
|
||||
struct Message3 : public etl::message<MESSAGE3>
|
||||
{
|
||||
};
|
||||
|
||||
using Packet = etl::message_packet<Message1, Message2>
|
||||
|
||||
Message1 message1;
|
||||
Message2 message2;
|
||||
Message3 message3;
|
||||
|
||||
Packet packet1(message1);
|
||||
Packet packet2(message2);
|
||||
Packet packet3(message3); // Runtime time error! Packet does not support Message3 type.
|
||||
|
||||
etl::imessage& m1 = message1;
|
||||
Packet packet4(m1); // Construct from an etl::imessage reference.
|
||||
|
||||
etl::imessage& m3 = message3;
|
||||
Packet packet4(m3); // Asserts etl::unhandled_message_exception! Packet does not support Message3 type.
|
||||
|
||||
etl::imessage& m = packet2.get(); // Get a reference to an etl::imessage from the packet.
|
||||
|
||||
|
||||
257
docs/raw/frameworks/signal.txt
Normal file
257
docs/raw/frameworks/signal.txt
Normal file
@ -0,0 +1,257 @@
|
||||
signal
|
||||
20.44.0
|
||||
|
||||
A class that implements simple signal/slot framework.
|
||||
Uses etl::delegate as the default slot type, though other types may be used.
|
||||
|
||||
template <typename TFunction, size_t Size, typename TSlot = etl::delegate<TFunction>>
|
||||
class signal
|
||||
TFunction The callback function signature.
|
||||
Size The maximum numbr of slots for the signal.
|
||||
TSlot The callback slot type. Default = etl::delegate<TFunction>
|
||||
____________________________________________________________________________________________________
|
||||
Types
|
||||
|
||||
slot_type Defined as the slot type.
|
||||
size_type The size type used internally.
|
||||
span_type The span type used in the connect API.
|
||||
____________________________________________________________________________________________________
|
||||
Constructors
|
||||
|
||||
template <typename... TSlots>
|
||||
ETL_CONSTEXPR14 explicit signal(TSlots&&... slots) ETL_NOEXCEPT
|
||||
Construct the signal from a variadic list of slots.
|
||||
Can be used as a constexpr constructor.
|
||||
Static asserts if any of the
|
||||
____________________________________________________________________________________________________
|
||||
Connect
|
||||
|
||||
bool connect(const slot_type& slot)
|
||||
Connects the slot, if not already connected and returns true.
|
||||
If the signal is full, ETL_ASSERTs etl::signal_full and returns false.
|
||||
____________________________________________________________________________________________________
|
||||
bool connect(std::initializer_list<const slot_type> slots)
|
||||
Connects all of the slots and returns true.
|
||||
If the number of slots exceeds the signal's max size, asserts an etl::signal_full and returns false.
|
||||
Enabled if ETL_HAS_INITIALIZER_LIST and ETL_USING_CPP17 are defined as 1.
|
||||
____________________________________________________________________________________________________
|
||||
bool connect(const span_type slots)
|
||||
Connects all of the slots and returns true.
|
||||
If the number of slots exceeds the signal's max size, asserts an etl::signal_full and returns false.
|
||||
____________________________________________________________________________________________________
|
||||
Disconnect
|
||||
|
||||
void disconnect(const slot_type& slot) ETL_NOEXCEPT
|
||||
Disconnects slot from the signal.
|
||||
If the signal does not contain the slot. there is no error.
|
||||
____________________________________________________________________________________________________
|
||||
void disconnect(std::initializer_list<const slot_type> slots) ETL_NOEXCEPT
|
||||
Disconnects all of the slots from the signal.
|
||||
If the signal does not contain a particular slot, there is no error.
|
||||
Enabled if ETL_HAS_INITIALIZER_LIST and ETL_USING_CPP17 are defined as 1.
|
||||
____________________________________________________________________________________________________
|
||||
void disconnect(const span_type slots) ETL_NOEXCEPT
|
||||
Disconnects all of the slots from the signal.
|
||||
If the signal does not contain a particular slot, there is no error.
|
||||
____________________________________________________________________________________________________
|
||||
void disconnect_all() ETL_NOEXCEPT
|
||||
Disconnects all slots from the signal.
|
||||
____________________________________________________________________________________________________
|
||||
Status
|
||||
|
||||
ETL_CONSTEXPR14 bool connected(const slot_type& slot) const ETL_NOEXCEPT
|
||||
Checks if a slot is connected to the signal.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_CONSTEXPR14 bool empty() const ETL_NOEXCEPT
|
||||
Return true if the signal has no slots connected.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_CONSTEXPR14 bool full() const ETL_NOEXCEPT
|
||||
Return true if the signal has the maximum number of slots connected.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_CONSTEXPR14 size_type max_size() const ETL_NOEXCEPT
|
||||
Returns the total number of slots that can be connected.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_CONSTEXPR14 size_type size() const ETL_NOEXCEPT
|
||||
Returns the total slots currently connected.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_CONSTEXPR14 size_type available() const ETL_NOEXCEPT
|
||||
Returns the total empty slots available.
|
||||
____________________________________________________________________________________________________
|
||||
Call
|
||||
|
||||
template <typename... TArgs>
|
||||
void operator()(TArgs&&... args) const ETL_NOEXCEPT
|
||||
Function operator that calls each slot with the supplied parameters.
|
||||
____________________________________________________________________________________________________
|
||||
Errors
|
||||
|
||||
etl::signal_full Indicates that an attempt to add a slot to a full signal occurred.
|
||||
|
||||
Inherits from etl::signal_exception
|
||||
____________________________________________________________________________________________________
|
||||
Examples
|
||||
|
||||
constexpr size_t MaxSlots = 3;
|
||||
|
||||
using callback_type = void(int a, int b);
|
||||
using signal_type = etl::signal<callback_type, MaxSlots>;
|
||||
using slot_type = signal_type::slot_type;
|
||||
using span_type = signal_type::span_type;
|
||||
|
||||
using not_slot_type = etl::delegate<void(int)>;
|
||||
____________________________________________________________________________________________________
|
||||
Defining the slot functions
|
||||
|
||||
void Function1(int a, int b)
|
||||
{
|
||||
std::cout << "Function1: " << a << "," << b << "\n";
|
||||
}
|
||||
|
||||
void Function2(int a, int b)
|
||||
{
|
||||
std::cout << "Function2: " << a << "," << b << "\n";
|
||||
}
|
||||
|
||||
void Function3(int a, int b)
|
||||
{
|
||||
std::cout << "Function3: " << a << "," << b << "\n";
|
||||
}
|
||||
|
||||
void Function4(int a, int b)
|
||||
{
|
||||
std::cout << "Function4: " << a << "," << b << "\n";
|
||||
}
|
||||
|
||||
void Function5(int a)
|
||||
{
|
||||
std::cout << "Function5: " << a << "\n";
|
||||
}
|
||||
____________________________________________________________________________________________________
|
||||
Creating the slots
|
||||
|
||||
constexpr slot_type MakeSlot1() noexcept
|
||||
{
|
||||
return slot_type::create<Function1>();
|
||||
}
|
||||
|
||||
constexpr slot_type MakeSlot2() noexcept
|
||||
{
|
||||
return slot_type::create<Function2>();
|
||||
}
|
||||
|
||||
constexpr slot_type MakeSlot3() noexcept
|
||||
{
|
||||
return slot_type::create<Function3>();
|
||||
}
|
||||
|
||||
constexpr slot_type MakeSlot4() noexcept
|
||||
{
|
||||
return slot_type::create<Function4>();
|
||||
}
|
||||
|
||||
constexpr not_slot_type MakeSlot5() noexcept
|
||||
{
|
||||
return not_slot_type::create<Function5>();
|
||||
}
|
||||
____________________________________________________________________________________________________
|
||||
Defining the signal as constexpr
|
||||
|
||||
// Define the signal and connect as constexpr
|
||||
constexpr signal_type({ MakeSlot1(), MakeSlot2(), MakeSlot3() });
|
||||
|
||||
// Define the signal and connect as constexpr.
|
||||
// Static assert "Number of slots exceeds capacity"
|
||||
constexpr signal_type({ MakeSlot1(), MakeSlot2(), MakeSlot3(), MakeSlot4() });
|
||||
|
||||
// Define the signal and connect as constexpr.
|
||||
// Static assert "All slots must be slot_type"
|
||||
constexpr signal_type({ MakeSlot1(), MakeSlot2(), MakeSlot5() });
|
||||
____________________________________________________________________________________________________
|
||||
Defining the signal at runtime
|
||||
|
||||
// Define the signal.
|
||||
signal_type signal;
|
||||
|
||||
// Connect one at a time.
|
||||
signal.connect(MakeSlot1());
|
||||
signal.connect(MakeSlot2());
|
||||
signal.connect(MakeSlot3());
|
||||
|
||||
// Connect using initializer_list.
|
||||
signal.connect({ MakeSlot1(), MakeSlot2(), MakeSlot3() });
|
||||
|
||||
// Connect using span.
|
||||
const slot_type slot_list[] = { MakeSlot1(), MakeSlot2(), MakeSlot3() };
|
||||
signal.connect(slot_list);
|
||||
____________________________________________________________________________________________________
|
||||
Checking the status
|
||||
|
||||
// Define the signal.
|
||||
signal_type signal;
|
||||
|
||||
signal.max_size() // Returns 3
|
||||
signal.size() // Returns 0
|
||||
signal.available() // Returns 3
|
||||
signal.empty(); // Returns true
|
||||
signal.full(); // Returns false
|
||||
signal.connected(MakeSlot1()) // Returns false
|
||||
signal.connected(MakeSlot2()) // Returns false
|
||||
signal.connected(MakeSlot3()) // Returns false
|
||||
|
||||
signal.connect(MakeSlot1()); // Returns true
|
||||
|
||||
signal.max_size() // Returns 3
|
||||
signal.size() // Returns 1
|
||||
signal.available() // Returns 2
|
||||
signal.empty(); // Returns false
|
||||
signal.full(); // Returns false
|
||||
signal.connected(MakeSlot1()) // Returns true
|
||||
signal.connected(MakeSlot2()) // Returns false
|
||||
signal.connected(MakeSlot3()) // Returns false
|
||||
|
||||
signal.connect(MakeSlot1()); // Already connected. Returns true
|
||||
|
||||
signal.max_size() // Returns 3
|
||||
signal.size() // Returns 1
|
||||
signal.available() // Returns 2
|
||||
signal.empty(); // Returns false
|
||||
signal.full(); // Returns false
|
||||
signal.connected(MakeSlot1()) // Returns true
|
||||
signal.connected(MakeSlot2()) // Returns false
|
||||
signal.connected(MakeSlot3()) // Returns false
|
||||
|
||||
signal.connect(MakeSlot2()); // Returns true
|
||||
|
||||
signal.max_size() // Returns 3
|
||||
signal.size() // Returns 2
|
||||
signal.available() // Returns 1
|
||||
signal.empty(); // Returns false
|
||||
signal.full(); // Returns false
|
||||
signal.connected(MakeSlot1()) // Returns true
|
||||
signal.connected(MakeSlot2()) // Returns true
|
||||
signal.connected(MakeSlot3()) // Returns false
|
||||
|
||||
signal.connect(MakeSlot3()); // Returns true
|
||||
|
||||
signal.max_size() // Returns 3
|
||||
signal.size() // Returns 3
|
||||
signal.available() // Returns 0
|
||||
signal.empty(); // Returns false
|
||||
signal.full(); // Returns true
|
||||
signal.connected(MakeSlot1()) // Returns true
|
||||
signal.connected(MakeSlot2()) // Returns true
|
||||
signal.connected(MakeSlot3()) // Returns true
|
||||
|
||||
signal.connect(MakeSlot4()); // ETL_ASSERT etl::signal_full. Returns false
|
||||
____________________________________________________________________________________________________
|
||||
Calling the signal
|
||||
|
||||
signal_type signal({ MakeSlot1(), MakeSlot2(), MakeSlot3() });
|
||||
|
||||
signal(1, 2); // Call all of the slots with the parameters 1 & 2
|
||||
|
||||
Output
|
||||
Function1: 1,2
|
||||
Function2: 1,2
|
||||
Function3: 1,2
|
||||
|
||||
419
docs/raw/maths/Checksums & hashes.txt
Normal file
419
docs/raw/maths/Checksums & hashes.txt
Normal file
@ -0,0 +1,419 @@
|
||||
Checksums & hashes
|
||||
A set of algorithms for producing checksums and hashes from data.
|
||||
____________________________________________________________________________________________________
|
||||
Generic hashes
|
||||
Type Class Header
|
||||
Checksum checksum checksum.h (8, 16, 32 or 64 bit)
|
||||
BSD Checksum bsd_checksum checksum.h (8, 16, 32 or 64 bit)
|
||||
XOR Checksum xor_checksum checksum.h (8, 16, 32 or 64 bit)
|
||||
XOR + Rotate Checksum xor_rotate_checksum checksum.h (8, 16, 32 or 64 bit)
|
||||
Parity parity_checksum checksum.h (8, 16, 32 or 64 bit)
|
||||
|
||||
FNV-1 32 bit fnv1_32 fnv1.h
|
||||
FNV-1 64 bit fnv1_64 fnv1.h
|
||||
FNV-1a 32 bit fnv1a_32 fnv1.h
|
||||
FNV-1a 64 bit fnv1a_64 fnv1.h
|
||||
|
||||
Jenkins jenkins jenkins.h
|
||||
|
||||
Pearson pearson pearson.h
|
||||
|
||||
Murmur3 murmur3 murmur3.h (32 or 64 bit)
|
||||
____________________________________________________________________________________________________
|
||||
CRC hashes
|
||||
Type Class Table size Header
|
||||
CRC1 crc1 0 crc1.h, crc.h
|
||||
|
||||
CRC8 CCITT crc8_ccitt 256 crc8_ccitt.h, crc.h
|
||||
crc8_ccitt_t4 4
|
||||
crc8_ccitt_t16 16
|
||||
crc8_ccitt_t256 256
|
||||
crc8_ccitt_t<N> N = 4, 16, 256
|
||||
|
||||
CRC8 CDMA2000 crc8_cdma2000 256 crc8_cdma2000.h, crc.h
|
||||
crc8_cdma2000_t4 4
|
||||
crc8_cdma2000_t16 16
|
||||
crc8_cdma2000_t256 256
|
||||
crc8_cdma2000_t<N> N = 4, 16, 256
|
||||
|
||||
CRC8 DARC crc8_darc 256 crc8_darc.h, crc.h
|
||||
crc8_darc_t4 4
|
||||
crc8_darc_t16 16
|
||||
crc8_darc_t256 256
|
||||
crc8_darc_t<N> N = 4, 16, 256
|
||||
|
||||
CRC8 EBU crc8_ebu 256 crc8_ebu.h, crc.h
|
||||
crc8_ebu_t4 4
|
||||
crc8_ebu_t16 16
|
||||
crc8_ebu_t256 256
|
||||
crc8_ebu_t<N> N = 4, 16, 256
|
||||
|
||||
CRC8 ICODE crc8_icode 256 crc8_icode.h, crc.h
|
||||
crc8_icode_t4 4
|
||||
crc8_icode_t16 16
|
||||
crc8_icode_t256 256
|
||||
crc8_icode_t<N> N = 4, 16, 256
|
||||
|
||||
CRC8 ITU crc8_itu 256 crc8_itu.h, crc.h
|
||||
crc8_itu_t4 4
|
||||
crc8_itu_t16 16
|
||||
crc8_itu_t256 256
|
||||
crc8_itu_t<N> N = 4, 16, 256
|
||||
|
||||
CRC8 J1850 crc8_j1850 256 crc8_j1850.h, crc.h
|
||||
crc8_j1850_t4 4
|
||||
crc8_j1850_t16 16
|
||||
crc8_j1850_t256 256
|
||||
crc8_j1850<N> N = 4, 16, 256
|
||||
|
||||
CRC8 J1850 Zero crc8_j1850_zero 256 crc8_j1850_zero.h, crc.h
|
||||
crc8_j1850_zero_t4 4
|
||||
crc8_j1850_zero_t16 16
|
||||
crc8_j1850_zero_t256 256
|
||||
crc8_j1850_zero<N> N = 4, 16, 256
|
||||
|
||||
CRC8 MAXIM crc8_maxim 256 crc8_maxim.h, crc.h
|
||||
crc8_maxim_t4 4
|
||||
crc8_maxim_t16 16
|
||||
crc8_maxim_t256 256
|
||||
crc8_maxim_t<N> N = 4, 16, 256
|
||||
|
||||
CRC8 Opensafety crc8_opensafety 256 crc8_opensafety.h, crc.h
|
||||
20.42.2 crc8_opensafety_t4 4
|
||||
crc8_opensafety_t16 16
|
||||
crc8_opensafety_t256 256
|
||||
crc8_opensafety_t<N> N = 4, 16, 256
|
||||
|
||||
CRC8 ROHC crc8_rohc 256 crc8_rohc.h, crc.h
|
||||
crc8_rohc_t4 4
|
||||
crc8_rohc_t16 16
|
||||
crc8_rohc_t256 256
|
||||
crc8_rohc_t<N> N = 4, 16, 256
|
||||
|
||||
CRC8 WCDMA crc8_wcdma 256 crc8_wcdma.h, crc.h
|
||||
crc8_wcdma_t4 4
|
||||
crc8_wcdma_t16 16
|
||||
crc8_wcdma_t256 256
|
||||
crc8_wcdma_t<N> N = 4, 16, 256
|
||||
____________________________________________________________________________________________________
|
||||
CRC16 crc16 256 crc16.h, crc.h
|
||||
crc16_t4 4
|
||||
crc16_t16 16
|
||||
crc16_t256 256
|
||||
crc16_t<N> N = 4, 16, 256
|
||||
|
||||
CRC16-A crc16_a 256 crc16_a.h, crc.h
|
||||
crc16_a_t4 4
|
||||
crc16_a_t16 16
|
||||
crc16_a_t256 256
|
||||
crc16_a_t<N> N = 4, 16, 256
|
||||
|
||||
CRC16 Aug CCITT crc16_aug_ccitt 256 crc16_aug_ccitt.h, crc.h
|
||||
crc16_aug_ccitt_t4 4
|
||||
crc16_aug_ccitt_t16 16
|
||||
crc16_aug_ccitt_t256 256
|
||||
crc16_aug_ccitt_t<N> N = 4, 16, 256
|
||||
|
||||
CRC16 BUYPASS crc16_buypass 256 crc16_buypass.h, crc.h
|
||||
crc16_buypass_t4 4
|
||||
crc16_buypass_t16 16
|
||||
crc16_buypass_t256 256
|
||||
crc16_buypass_t<N> N = 4, 16, 256
|
||||
|
||||
CRC16 CCITT crc16_ccitt 256 crc16_ccitt.h, crc.h
|
||||
crc16_ccitt_t4 4
|
||||
crc16_ccitt_t16 16
|
||||
crc16_ccitt_t256 256
|
||||
crc16_ccitt_t<N> N = 4, 16, 256
|
||||
|
||||
CRC16 CDMA2000 crc16_cdma2000 256 crc16_cdma2000.h, crc.h
|
||||
crc16_cdma2000_t4 4
|
||||
crc16_cdma2000_t16 16
|
||||
crc16_cdma2000_t256 256
|
||||
crc16_cdma2000_t<N> N = 4, 16, 256
|
||||
|
||||
CRC16 DDS110 crc16_dds110 256 crc16_dds110.h, crc.h
|
||||
crc16_dds110_t4 4
|
||||
crc16_dds110_t16 16
|
||||
crc16_dds110_t256 256
|
||||
crc16_dds110_t<N> N = 4, 16, 256
|
||||
|
||||
CRC16 DECTR crc16_dectr 256 crc16_dectr.h, crc.h
|
||||
crc16_dectr_t4 4
|
||||
crc16_dectr_t16 16
|
||||
crc16_dectr_t256 256
|
||||
crc16_dectr_t<N> N = 4, 16, 256
|
||||
|
||||
CRC16 DECTX crc16_dectx 256 crc16_dectx.h, crc.h
|
||||
crc16_dectx_t4 4
|
||||
crc16_dectx_t16 16
|
||||
crc16_dectx_t256 256
|
||||
crc16_dectx_t<N> N = 4, 16, 256
|
||||
|
||||
CRC16 DNP crc16_dnp 256 crc16_dnp.h, crc.h
|
||||
crc16_dnp_t4 4
|
||||
crc16_dnp_t16 16
|
||||
crc16_dnp_t256 256
|
||||
crc16_dnp_t<N> N = 4, 16, 256
|
||||
|
||||
CRC16 EN13757 crc16_en13757 256 crc16_en13757.h, crc.h
|
||||
crc16_en13757_t4 4
|
||||
crc16_en13757_t16 16
|
||||
crc16_en13757_t256 256
|
||||
crc16_en13757_t<N> N = 4, 16, 256
|
||||
|
||||
CRC16 GENIBUS crc16_genibus 256 crc16_genibus.h, crc.h
|
||||
crc16_genibus_t4 4
|
||||
crc16_genibus_t16 16
|
||||
crc16_genibus_t256 256
|
||||
crc16_genibus_t<N> N = 4, 16, 256
|
||||
|
||||
CRC16 KERMIT crc16_kermit 256 crc16_kermit.h, crc.h
|
||||
crc16_kermit_t4 4
|
||||
crc16_kermit_t16 16
|
||||
crc16_kermit_t256 256
|
||||
crc16_kermit_t<N> N = 4, 16, 256
|
||||
|
||||
CRC16 MAXIM crc16_maxim 256 crc16_maxim.h, crc.h
|
||||
crc16_maxim_t4 4
|
||||
crc16_maxim_t16 16
|
||||
crc16_maxim_t256 256
|
||||
crc16_maxim_t<N> N = 4, 16, 256
|
||||
|
||||
CRC16 MCRF4XX crc16_mcrf4xx 256 crc16_mcrf4xx.h, crc.h
|
||||
crc16_mcrf4xx_t4 4
|
||||
crc16_mcrf4xx_t16 16
|
||||
crc16_mcrf4xx_t256 256
|
||||
crc16_mcrf4xx_t<N> N = 4, 16, 256
|
||||
|
||||
CRC16 MODBUS crc16_modbus 256 crc16_modbus.h, crc.h
|
||||
crc16_modbus_t4 4
|
||||
crc16_modbus_t16 16
|
||||
crc16_modbus_t256 256
|
||||
crc16_modbus_t<N> N = 4, 16, 256
|
||||
|
||||
CRC16 Opensafety-A crc16_opensafety_a 256 crc16_opensafety_a.h, crc.h
|
||||
20.42.2 crc16_opensafety_a_t4 4
|
||||
crc16_opensafety_a_t16 16
|
||||
crc16_opensafety_a_t256 256
|
||||
crc16_opensafety_a_t<N> N = 4, 16, 256
|
||||
|
||||
CRC16 Opensafety-B crc16_opensafety_b 256 crc16_opensafety_b.h, crc.h
|
||||
20.42.2 crc16_opensafety_b_t4 4
|
||||
crc16_opensafety_b_t16 16
|
||||
crc16_opensafety_b_t256 256
|
||||
crc16_opensafety_b_t<N> N = 4, 16, 256
|
||||
|
||||
CRC16 PROFIBUS crc16_profibus 256 crc16_profibus.h, crc.h
|
||||
crc16_profibus_t4 4
|
||||
crc16_profibus_t16 16
|
||||
crc16_profibus_t256 256
|
||||
crc16_profibus_t<N> N = 4, 16, 256
|
||||
|
||||
CRC16 RIELLO crc16_riello 256 crc16_riello.h, crc.h
|
||||
crc16_riello_t4 4
|
||||
crc16_riello_t16 16
|
||||
crc16_riello_t256 256
|
||||
crc16_riello_t<N> N = 4, 16, 256
|
||||
|
||||
CRC16 T10DIF crc16_t10dif 256 crc16_t10dif.h, crc.h
|
||||
crc16_t10dif_t4 4
|
||||
crc16_t10dif_t16 16
|
||||
crc16_t10dif_t256 256
|
||||
crc16_t10dif_t<N> N = 4, 16, 256
|
||||
|
||||
CRC16 TELEDISK crc16_teledisk 256 crc16_teledisk.h, crc.h
|
||||
crc16_teledisk_t4 4
|
||||
crc16_teledisk_t16 16
|
||||
crc16_teledisk_t256 256
|
||||
crc16_teledisk_t<N> N = 4, 16, 256
|
||||
|
||||
CRC16 TMS37157 crc16_tms37157 256 crc16_tms37157.h, crc.h
|
||||
crc16_tms37157_t4 4
|
||||
crc16_tms37157_t16 16
|
||||
crc16_tms37157_t256 256
|
||||
crc16_tms37157_t<N> N = 4, 16, 256
|
||||
|
||||
CRC16 USB crc16_usb 256 crc16_usb.h, crc.h
|
||||
crc16_usb_t4 4
|
||||
crc16_usb_t16 16
|
||||
crc16_usb_t256 256
|
||||
crc16_usb_t<N> N = 4, 16, 256
|
||||
|
||||
CRC16 X25 crc16_x25 256 crc16_x25.h, crc.h
|
||||
crc16_x25_t4 4
|
||||
crc16_x25_t16 16
|
||||
crc16_x25_t256 256
|
||||
crc16_x25_t<N> N = 4, 16, 256
|
||||
|
||||
CRC16 XMODEM crc16_xmodem 256 crc16_xmodem.h, crc.h
|
||||
crc16_xmodem_t4 4
|
||||
crc16_xmodem_t16 16
|
||||
crc16_xmodem_t256 256
|
||||
crc16_xmodem_t<N> N = 4, 16, 256
|
||||
____________________________________________________________________________________________________
|
||||
CRC32 crc32 256 crc32.h, crc.h
|
||||
crc32_t4 4
|
||||
crc32_t16 16
|
||||
crc32_t256 256
|
||||
crc32_t<N> N = 4, 16, 256
|
||||
|
||||
CRC32 BZIP2 crc32_bzip2 256 crc32_bzip2.h, crc.h
|
||||
crc32_bzip2_t4 4
|
||||
crc32_bzip2_t16 16
|
||||
crc32_bzip2_t256 256
|
||||
crc32_bzip2_t<N> N = 4, 16, 256
|
||||
|
||||
CRC32-C crc32_c 256 crc32_c.h, crc.h
|
||||
crc32_c_t4 4
|
||||
crc32_c_t16 16
|
||||
crc32_c_t256 256
|
||||
crc32_c_t<N> N = 4, 16, 256
|
||||
|
||||
CRC32-D crc32_d 256 crc32_d.h, crc.h
|
||||
crc32_d_t4 4
|
||||
crc32_d_t16 16
|
||||
crc32_d_t256 256
|
||||
crc32_d_t<N> N = 4, 16, 256
|
||||
|
||||
CRC32 JAMCRC crc32_jamcrc 256 crc32_jamcrc.h, crc.h
|
||||
crc32_jamcrc_t4 4
|
||||
crc32_jamcrc_t16 16
|
||||
crc32_jamcrc_t256 256
|
||||
crc32_jamcrc_t<N> N = 4, 16, 256
|
||||
|
||||
CRC32 MPEG2 crc32_mpeg2 256 crc32_mpeg2.h, crc.h
|
||||
crc32_mpeg2_t4 4
|
||||
crc32_mpeg2_t16 16
|
||||
crc32_mpeg2_t256 256
|
||||
crc32_mpeg2_t<N> N = 4, 16, 256
|
||||
|
||||
CRC32 POSIX crc32_posix 256 crc32_posix.h, crc.h
|
||||
crc32_posix_t4 4
|
||||
crc32_posix_t16 16
|
||||
crc32_posix_t256 256
|
||||
crc32_posix_t<N> N = 4, 16, 256
|
||||
|
||||
CRC32-Q crc32_q 256 crc32_q.h, crc.h
|
||||
crc32_q_t4 4
|
||||
crc32_q_t16 16
|
||||
crc32_q_t256 256
|
||||
crc32_q_t<N> N = 4, 16, 256
|
||||
|
||||
CRC32 XFER crc32_xfer 256 crc32_xfer.h, crc.h
|
||||
crc32_xfer_t4 4
|
||||
crc32_xfer_t16 16
|
||||
crc32_xfer_t256 256
|
||||
crc32_xfer_t<N> N = 4, 16, 256
|
||||
____________________________________________________________________________________________________
|
||||
CRC64 ECMA crc64_ecma 256 crc64_ecma.h, crc.h
|
||||
crc32_ecma_t4 4
|
||||
crc32_ecma_t16 16
|
||||
crc32_ecma_t256 256
|
||||
crc32_ecma_t<N> N = 4, 16, 256
|
||||
|
||||
CRC64 ISO crc64_iso 256 crc64_iso.h, crc.h
|
||||
20.42.2 crc32_iso_t4 4
|
||||
crc32_iso_t16 16
|
||||
crc32_iso_t256 256
|
||||
crc32_iso_t<N> N = 4, 16, 256
|
||||
|
||||
The library also includes etl::hash which is a reverse engineered version of std::hash in hash.h
|
||||
|
||||
All hashing templates have the same API, apart from the members returning the hash value, which return the appropriate type.
|
||||
|
||||
A hash that requires finalising before the value is read should do it in the conversion operator and value() member functions. Trying to add values after finalisation should result in an etl::hash_finalised error being asserted. Construction or reset should clear any finalisation flag.
|
||||
____________________________________________________________________________________________________
|
||||
Hash API
|
||||
All hashing algorithms supply the following API.
|
||||
|
||||
Default constructor
|
||||
Initialises the hash value to its appropriate starting value.
|
||||
____________________________________________________________________________________________________
|
||||
Constructor from a range. (Any iterator type)
|
||||
Creates a hash from the supplied range.
|
||||
____________________________________________________________________________________________________
|
||||
void reset();
|
||||
Resets the hash to the initial condition.
|
||||
____________________________________________________________________________________________________
|
||||
void add(uint8_t value);
|
||||
Adds a uint8_t to the hash.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TIterator>
|
||||
void add(TIterator begin, Titerator end);
|
||||
|
||||
Adds a range of values to the hash.
|
||||
If the type pointed to must be default castable to uint8_t.
|
||||
____________________________________________________________________________________________________
|
||||
value_type value() const;
|
||||
Returns the hash value.
|
||||
The hash will be finalised if required.
|
||||
____________________________________________________________________________________________________
|
||||
operator value_type() const;
|
||||
Returns the hash value.
|
||||
The hash will be finalised if required.
|
||||
__________________________________________________________________________________________________
|
||||
iterator input()
|
||||
Returns an iterator that allows the input of new values.
|
||||
|
||||
Example
|
||||
std::array data{ 9, 1, 8, 2, 7, 3, 6, 4, 5 };
|
||||
etl::crc32 crc_calculator;
|
||||
std::copy(data.begin(), data.end(), crc_calculator.input());
|
||||
uint32_t crc = crc_calculator.value();
|
||||
____________________________________________________________________________________________________
|
||||
Creating a new frame check type.
|
||||
The frame_check_sequence class may be customised with new policies that contain the expected typedef and member functions:-
|
||||
|
||||
Example
|
||||
|
||||
struct special_16
|
||||
{
|
||||
typedef uint16_t value_type;
|
||||
|
||||
inline uint16_t initial() const
|
||||
{
|
||||
return 0xFFFF; // The initial value.
|
||||
}
|
||||
|
||||
inline uint16_t add(T sum, uint8_t value) const
|
||||
{
|
||||
return etl::rotate_left(sum, 3) ^ value; // How to add each value.
|
||||
}
|
||||
|
||||
inline uint16_t final(T sum) const
|
||||
{
|
||||
return ~sum; // How to read the final value.
|
||||
}
|
||||
};
|
||||
|
||||
The hash class would be declared as follows.
|
||||
|
||||
//*************************************************************************
|
||||
/// Special checksum
|
||||
//*************************************************************************
|
||||
class special_checksum : public etl::frame_check_sequence<special_16>
|
||||
{
|
||||
public:
|
||||
|
||||
//*************************************************************************
|
||||
/// Default constructor.
|
||||
//*************************************************************************
|
||||
special_checksum()
|
||||
{
|
||||
this->reset();
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Constructor from range.
|
||||
/// \param begin Start of the range.
|
||||
/// \param end End of the range.
|
||||
//*************************************************************************
|
||||
template <typename TIterator>
|
||||
special_checksum(TIterator begin, const TIterator end)
|
||||
{
|
||||
this->reset();
|
||||
this->add(begin, end);
|
||||
}
|
||||
};
|
||||
|
||||
143
docs/raw/maths/Constants.txt
Normal file
143
docs/raw/maths/Constants.txt
Normal file
@ -0,0 +1,143 @@
|
||||
Constants
|
||||
A set of compile time constants.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
log.h
|
||||
log
|
||||
template <size_t N, size_t BASE>
|
||||
struct log;
|
||||
|
||||
Defines the member value as the log of N to base BASE.
|
||||
Set to the integer below the ideal floating point value.
|
||||
|
||||
C++17 and above
|
||||
template <size_t N, size_t BASE>
|
||||
inline constexpr size_t log_v = log<N, BASE>::value;
|
||||
____________________________________________________________________________________________________
|
||||
log2
|
||||
template <size_t N>
|
||||
struct log2;
|
||||
|
||||
Defines the member value as the log of N to base 2
|
||||
Set to the integer below the ideal floating point value.
|
||||
|
||||
C++17 and above
|
||||
template <size_t N>
|
||||
inline constexpr size_t log2_v = log2<N>::value;
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
log10
|
||||
template <size_t N>
|
||||
struct log10;
|
||||
|
||||
Defines the member value as the log of N to base 10
|
||||
Set to the integer below the ideal floating point value.
|
||||
|
||||
C++17 and above
|
||||
template <size_t N>
|
||||
inline constexpr size_t log10_v = log10<N>::value;
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
power.h
|
||||
power
|
||||
template <size_t N, size_t POWER>
|
||||
struct power;
|
||||
|
||||
Defines the member value as N raised to the power POWER.
|
||||
|
||||
C++17 and above
|
||||
template <size_t N, size_t POWER>
|
||||
inline constexpr size_t power_v = power<N, POWER>::value;
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
power_of_2_round_up
|
||||
template <size_t N>
|
||||
struct power_of_2_round_up;
|
||||
|
||||
Defines the member value to the next equal or higher power of 2.
|
||||
|
||||
power_of_2_round_up<7> -> 8
|
||||
power_of_2_round_up<8> -> 8
|
||||
power_of_2_round_up<9> -> 16
|
||||
|
||||
C++17 and above
|
||||
template <size_t N, size_t POWER>
|
||||
inline constexpr size_t power_of_2_round_up_v = power_of_2_round_up<N, POWER>::value;
|
||||
____________________________________________________________________________________________________
|
||||
power_of_2_round_down
|
||||
template <size_t N>
|
||||
struct power_of_2_round_down;
|
||||
|
||||
Defines the member value to the next equal or lower power of 2.
|
||||
|
||||
power_of_2_round_down<7> -> 4
|
||||
power_of_2_round_down<8> -> 4
|
||||
power_of_2_round_down<9> -> 8
|
||||
|
||||
C++17 and above
|
||||
template <size_t N, size_t POWER>
|
||||
inline constexpr size_t power_of_2_round_down_v = power_of_2_round_down<N, POWER>::value;
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
is_power_of_2
|
||||
template <size_t N>
|
||||
struct is_power_of_2;
|
||||
|
||||
Defines the member value to true if N is a power of 2, otherwise false.
|
||||
|
||||
C++17 and above
|
||||
template <size_t N, size_t POWER>
|
||||
inline constexpr size_t is_power_of_2_v = is_power_of_2<N, POWER>::value;
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
sqrt.h
|
||||
sqrt
|
||||
template <size_t N, size_t I = 1>
|
||||
struct sqrt;
|
||||
|
||||
Defines the member value as the largest integer that, when squared, is at less than or equal to N.
|
||||
|
||||
C++17 and above
|
||||
template <size_t N, size_t I = 1>
|
||||
inline constexpr size_t sqrt_v = sqrt<N, POWER>::value;
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
factorial.h
|
||||
factorial
|
||||
template <const size_t N>
|
||||
struct factorial;
|
||||
|
||||
Defines the member value as the Nth factorial.
|
||||
|
||||
C++17 and above
|
||||
template <size_t N>
|
||||
inline constexpr size_t factorial_v = factorial<N>::value;
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
fibbonacci.h
|
||||
fibbonacci
|
||||
template <const size_t N>
|
||||
struct fibbonacci;
|
||||
|
||||
Defines the member value as the Nth in the Fibbonacci sequence
|
||||
|
||||
C++17 and above
|
||||
template <size_t N>
|
||||
inline constexpr size_t fibbonacci_v = fibbonacci<N>::value;
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
math_constants.h
|
||||
|
||||
Namespace : etl::math
|
||||
|
||||
ETL_CONSTANT double pi = 3.14159265358979;
|
||||
ETL_CONSTANT double pi_reciprocal = 0.31830988618379;
|
||||
ETL_CONSTANT double pi_squared = 9.86960440108936;
|
||||
ETL_CONSTANT double e = 2.71828182845905;
|
||||
ETL_CONSTANT double e_reciprocal = 0.36787944117144;
|
||||
ETL_CONSTANT double e_squared = 7.38905609893065;
|
||||
ETL_CONSTANT double root2 = 1.41421356237310;
|
||||
ETL_CONSTANT double root2_reciprocal = 0.70710678118655;
|
||||
ETL_CONSTANT double euler = 0.57721566490153;
|
||||
ETL_CONSTANT double golden_ratio = 1.61803398874989;
|
||||
|
||||
74
docs/raw/maths/Correlation.txt
Normal file
74
docs/raw/maths/Correlation.txt
Normal file
@ -0,0 +1,74 @@
|
||||
Correlation
|
||||
20.9.0
|
||||
Calculates the correlation of two sets of data.
|
||||
|
||||
template <bool Correlation_Type, typename TInput, typename TCalc = TInput>
|
||||
class correlation : public etl::binary_function<TInput, TInput, void>
|
||||
|
||||
Correlation_Type Population or Sample.
|
||||
TInput The input data type.
|
||||
TCalc The type to use for internal calculations. By default, equal to TInput.
|
||||
____________________________________________________________________________________________________
|
||||
correlation_type
|
||||
etl::correlation_type::Sample
|
||||
etl::correlation_type::Population
|
||||
____________________________________________________________________________________________________
|
||||
correlation
|
||||
correlation()
|
||||
Default constructor.
|
||||
|
||||
template <typename TIterator>
|
||||
correlation(TIterator first1, TIterator last1, TIterator first2)
|
||||
Construct from two iterator ranges.
|
||||
____________________________________________________________________________________________________
|
||||
void add(TInput value1, TInput value2)
|
||||
Add a pair of values.
|
||||
|
||||
template <typename TIterator>
|
||||
void add(TIterator first1, TIterator last1, TIterator first2)
|
||||
Add a range of values.
|
||||
____________________________________________________________________________________________________
|
||||
void operator()(TInput value1, TInput value2)
|
||||
Add a pair of values.
|
||||
|
||||
template <typename TIterator>
|
||||
void operator()(TIterator first1, TIterator last1, TIterator first2)
|
||||
Add a range of values.
|
||||
____________________________________________________________________________________________________
|
||||
double get_covariance() const
|
||||
Returns the calculated covariance for the data.
|
||||
____________________________________________________________________________________________________
|
||||
double get_correlation() const
|
||||
Returns the calculated correlation for the data.
|
||||
____________________________________________________________________________________________________
|
||||
operator double() const
|
||||
Returns the calculated correlation for the data.
|
||||
____________________________________________________________________________________________________
|
||||
size_t count() const
|
||||
Get the total number added entries.
|
||||
____________________________________________________________________________________________________
|
||||
void clear()
|
||||
Clear the correlation.
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
std::array<char, 10> input_c
|
||||
{
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
|
||||
};
|
||||
|
||||
std::array<char, 10> input_c_inv
|
||||
{
|
||||
0, -1, -2, -3, -4, -5, -6, -7, -8, -9
|
||||
};
|
||||
|
||||
etl::correlation<etl::correlation_type::Population, char, int32_t> correlation(input_c.begin(),
|
||||
input_c.end(),
|
||||
input_c_inv.begin());
|
||||
|
||||
double correlation_result;
|
||||
double covariance_result;
|
||||
|
||||
correlation_result = correlation; // correlation_result == -1.0
|
||||
covariance_result = correlation.get_covariance(); // covariance_result == -8.25
|
||||
|
||||
67
docs/raw/maths/Covariance.txt
Normal file
67
docs/raw/maths/Covariance.txt
Normal file
@ -0,0 +1,67 @@
|
||||
Covariance
|
||||
20.9.0
|
||||
template <bool Correlation_Type, typename TInput, typename TCalc = TInput>
|
||||
class correlation : public etl::binary_function<TInput, TInput, void>
|
||||
|
||||
Covariance_Type Population or Sample.
|
||||
TInput The input data type.
|
||||
TCalc The type to use for internal calculations. By default, equal to TInput.
|
||||
____________________________________________________________________________________________________
|
||||
covariance_type
|
||||
etl::covariance_type::Sample
|
||||
etl::covariance_type::Population
|
||||
____________________________________________________________________________________________________
|
||||
covariance
|
||||
covariance()
|
||||
Default constructor.
|
||||
|
||||
template <typename TIterator>
|
||||
covariance(TIterator first1, TIterator last1, TIterator first2)
|
||||
Construct from two iterator ranges.
|
||||
____________________________________________________________________________________________________
|
||||
void add(TInput value1, TInput value2)
|
||||
Add a pair of values.
|
||||
|
||||
template <typename TIterator>
|
||||
void add(TIterator first1, TIterator last1, TIterator first2)
|
||||
Add a range of values.
|
||||
____________________________________________________________________________________________________
|
||||
void operator()(TInput value1, TInput value2)
|
||||
Add a pair of values.
|
||||
|
||||
template <typename TIterator>
|
||||
void operator()(TIterator first1, TIterator last1, TIterator first2)
|
||||
Add a range of values.
|
||||
____________________________________________________________________________________________________
|
||||
double get_covariance() const
|
||||
Returns the calculated covariance for the data.
|
||||
____________________________________________________________________________________________________
|
||||
operator double() const
|
||||
Returns the calculated covariance for the data.
|
||||
____________________________________________________________________________________________________
|
||||
size_t count() const
|
||||
Get the total number added entries.
|
||||
____________________________________________________________________________________________________
|
||||
void clear()
|
||||
Clear the covariance.
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
std::array<char, 10> input_c
|
||||
{
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
|
||||
};
|
||||
|
||||
std::array<char, 10> input_c_inv
|
||||
{
|
||||
0, -1, -2, -3, -4, -5, -6, -7, -8, -9
|
||||
};
|
||||
|
||||
etl::covariance<etl::covariance_type::Population, char, int32_t> covariance(input_c.begin(),
|
||||
input_c.end(),
|
||||
input_c_inv.begin());
|
||||
|
||||
double covariance_result;
|
||||
|
||||
covariance_result = covariance; // covariance_result == -8.25
|
||||
|
||||
48
docs/raw/maths/Gamma.txt
Normal file
48
docs/raw/maths/Gamma.txt
Normal file
@ -0,0 +1,48 @@
|
||||
Gamma
|
||||
20.9.0
|
||||
|
||||
There are two gamma functors, gamma_encode and gamma_decode.
|
||||
|
||||
template <typename TInput>
|
||||
class gamma_encode : public etl::unary_function<TInput, TInput>
|
||||
|
||||
template <typename TInput>
|
||||
class gamma_decode : public etl::unary_function<TInput, TInput>
|
||||
|
||||
TInput The input data type.
|
||||
____________________________________________________________________________________________________
|
||||
gamma_encode(double gamma, TInput maximum)
|
||||
Constructor.
|
||||
____________________________________________________________________________________________________
|
||||
TInput operator()(TInput value) const
|
||||
Gamma a value.
|
||||
____________________________________________________________________________________________________
|
||||
gamma_decode(double gamma, TInput maximum)
|
||||
Constructor.
|
||||
____________________________________________________________________________________________________
|
||||
TInput operator()(TInput value) const
|
||||
Gamma a value.
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
std::array<double, 10> input
|
||||
{
|
||||
0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0
|
||||
};
|
||||
|
||||
std::array<double, 10> output_encode;
|
||||
|
||||
etl::gamma_encode<double> gamma_encode(0.5, 9.0);
|
||||
|
||||
std::transform(input.begin(), input.end(), output_encode.begin(), gamma_encode);
|
||||
|
||||
// output_encode == 0.0, 0.11, 0.44, 1.00, 1.78, 2.78, 4.00, 5.44, 7.11, 9.00
|
||||
|
||||
std::array<double, 10> output_decode;
|
||||
|
||||
etl::gamma_decode<double> gamma_decode(0.5, 9.0);
|
||||
|
||||
std::transform(output_encode.begin(), output_encode.end(), output_decode.begin(), gamma_decode);
|
||||
|
||||
// output_decode == 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0
|
||||
|
||||
157
docs/raw/maths/Histogram.txt
Normal file
157
docs/raw/maths/Histogram.txt
Normal file
@ -0,0 +1,157 @@
|
||||
Histogram
|
||||
20.9.0
|
||||
____________________________________________________________________________________________________
|
||||
histogram
|
||||
|
||||
Types
|
||||
const_iterator The iterator used to traverse the histogram data.
|
||||
key_type The index type for the histogram.
|
||||
count_type The type used for the histogram counter.
|
||||
value_type The type returned from the histogram.
|
||||
____________________________________________________________________________________________________
|
||||
Constants
|
||||
Max_Size The maximum number of elements in the histogram.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TKey, typename TCount, size_t Max_Keys>
|
||||
class histogram
|
||||
A histogram where the start index of the keys is defined in the constructor.
|
||||
|
||||
histogram()
|
||||
Default constructor.
|
||||
|
||||
template <typename TIterator>
|
||||
histogram(TIterator first, TIterator last)
|
||||
Construct from an iterator range.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TKey, typename TCount, size_t Max_Keys, size_t Start_Index>
|
||||
class histogram
|
||||
A histogram where the start index of the keys is defined as a template parameter.
|
||||
|
||||
histogram()
|
||||
Default constructor.
|
||||
|
||||
template <typename TIterator>
|
||||
histogram(TIterator first, TIterator last)
|
||||
Construct from an iterator range.
|
||||
____________________________________________________________________________________________________
|
||||
histogram(const histogram& other)
|
||||
Copy constructor.
|
||||
|
||||
histogram(histogram&& other)
|
||||
Move constructor.
|
||||
|
||||
histogram& operator =(const histogram& rhs)
|
||||
Assignment operator.
|
||||
|
||||
histogram& operator =(histogram&& rhs)
|
||||
Move assignment operator.
|
||||
____________________________________________________________________________________________________
|
||||
void add(key_type key)
|
||||
Increment the count for the key.
|
||||
|
||||
template <typename TIterator>
|
||||
void add(TIterator first, TIterator last)
|
||||
Increment the counts for the keys from an iterator range.
|
||||
____________________________________________________________________________________________________
|
||||
void operator ()(key_type key)
|
||||
Increment the count for the key.
|
||||
|
||||
template <typename TIterator>
|
||||
void operator ()(TIterator first, TIterator last)
|
||||
Increment the counts for the keys from an iterator range.
|
||||
____________________________________________________________________________________________________
|
||||
value_type operator [](key_type key) const
|
||||
Get the count for a key.
|
||||
____________________________________________________________________________________________________
|
||||
const_iterator begin() const
|
||||
const_iterator cbegin() const
|
||||
Get the iterator to the first histogram entry.
|
||||
____________________________________________________________________________________________________
|
||||
const_iterator end() const
|
||||
const_iterator cend() const
|
||||
Get the iterator to the last + 1 histogram entry.
|
||||
____________________________________________________________________________________________________
|
||||
void clear()
|
||||
Clear the counts to zero.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_CONSTEXPR size_t size() const
|
||||
Get the number of items in the histogram.
|
||||
Always equal to max_size().
|
||||
____________________________________________________________________________________________________
|
||||
ETL_CONSTEXPR size_t max_size() const
|
||||
Get the number of items in the histogram.
|
||||
____________________________________________________________________________________________________
|
||||
size_t count() const
|
||||
Get the total of all the counts.
|
||||
____________________________________________________________________________________________________
|
||||
sparse_histogram
|
||||
|
||||
Types
|
||||
const_iterator The iterator used to traverse the histogram data.
|
||||
key_type The index type for the histogram.
|
||||
count_type The type used for the histogram counter.
|
||||
value_type The type returned from the histogram. A pair containing the key and count.
|
||||
____________________________________________________________________________________________________
|
||||
Constants
|
||||
Max_Size The maximum number of elements in the histogram.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TKey, typename TCount, size_t Max_Keys>
|
||||
class sparse_histogram
|
||||
A histogram where the keys are sparse or non-integral types.
|
||||
|
||||
sparse_histogram()
|
||||
Default constructor.
|
||||
|
||||
template <typename TIterator>
|
||||
sparse_histogram(TIterator first, TIterator last)
|
||||
Construct from an iterator range.
|
||||
|
||||
sparse_histogram(const sparse_histogram& other)
|
||||
Copy constructor.
|
||||
|
||||
sparse_histogram(sparse_histogram&& other)
|
||||
Move constructor.
|
||||
|
||||
sparse_histogram& operator =(const sparse_histogram& rhs)
|
||||
Assignment operator.
|
||||
|
||||
sparse_histogram& operator =(sparse_histogram&& rhs)
|
||||
Move assignment operator.
|
||||
____________________________________________________________________________________________________
|
||||
void add(key_type key)
|
||||
Increment the count for the key.
|
||||
|
||||
template <typename TIterator>
|
||||
void add(TIterator first, TIterator last)
|
||||
Increment the counts for the keys from an iterator range.
|
||||
____________________________________________________________________________________________________
|
||||
void operator ()(key_type key)
|
||||
Increment the count for the key.
|
||||
|
||||
template <typename TIterator>
|
||||
void operator ()(TIterator first, TIterator last)
|
||||
Increment the counts for the keys from an iterator range.
|
||||
____________________________________________________________________________________________________
|
||||
const value_type& operator [](key_type key) const
|
||||
Get the count for a key.
|
||||
____________________________________________________________________________________________________
|
||||
const_iterator begin() const
|
||||
const_iterator cbegin() const
|
||||
Get the iterator to the first histogram entry.
|
||||
____________________________________________________________________________________________________
|
||||
const_iterator end() const
|
||||
const_iterator cend() const
|
||||
Get the iterator to the last + 1 histogram entry.
|
||||
____________________________________________________________________________________________________
|
||||
void clear()
|
||||
Clear the counts to zero.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_CONSTEXPR size_t size() const
|
||||
Get the number of items in the histogram.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_CONSTEXPR size_t max_size() const
|
||||
Get the number of items in the histogram.
|
||||
____________________________________________________________________________________________________
|
||||
size_t count() const
|
||||
Get the total of all the counts.
|
||||
|
||||
39
docs/raw/maths/Invert.txt
Normal file
39
docs/raw/maths/Invert.txt
Normal file
@ -0,0 +1,39 @@
|
||||
Invert
|
||||
20.9.0
|
||||
Invert an input range.
|
||||
|
||||
template <typename TInput>
|
||||
class invert : public etl::unary_function<TInput, TInput>
|
||||
|
||||
TInput The input data type.
|
||||
____________________________________________________________________________________________________
|
||||
invert()
|
||||
offset = 0
|
||||
minuend = etl::numeric_limits<TInput>::is_signed) ? TInput(0)
|
||||
: etl::numeric_limits<TInput>::max())
|
||||
If the type is signed then the input values have their sign changed.
|
||||
i.e. 10 => -10, -10 => 10.
|
||||
If the type is unsigned then the input values are subtracted from the type's maximum value.
|
||||
|
||||
invert(TInput offset, TInput minuend)
|
||||
Sets the offset and minuend.
|
||||
____________________________________________________________________________________________________
|
||||
TInput operator()(TInput value) const
|
||||
Invert a value.
|
||||
Calculates minuend - (value - offset)
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
std::array<int, 10> input =
|
||||
{
|
||||
10, 11, 12, 13, 14, 15, 16, 17, 18, 19
|
||||
};
|
||||
|
||||
std::array<int, 10> output;
|
||||
|
||||
etl::invert<int> invert(10, 100); // offset = 10, minuend = 100
|
||||
|
||||
std::transform(input.begin(), input.end(), output.begin(), invert);
|
||||
|
||||
// output = 100.0, 99.0, 98.0, 97.0, 96.0, 95.0, 94.0, 93.0, 92.0, 91.0
|
||||
|
||||
32
docs/raw/maths/Limiter.txt
Normal file
32
docs/raw/maths/Limiter.txt
Normal file
@ -0,0 +1,32 @@
|
||||
Limiter
|
||||
20.9.0
|
||||
Limits an input range.
|
||||
|
||||
template <typename TInput, typename TCompare = etl::less<TInput> >
|
||||
class limit : public etl::unary_function<TInput, TInput>
|
||||
|
||||
TInput The input data type.
|
||||
TCompare The functor type used to compare values to the threshold. The default is etl::less
|
||||
____________________________________________________________________________________________________
|
||||
limit(TInput lowest, TInput highest)
|
||||
lowest The lowest limit.
|
||||
highest The highest limit.
|
||||
____________________________________________________________________________________________________
|
||||
TInput operator()(TInput value) const
|
||||
Limit a value.
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
std::array<int, 10> input =
|
||||
{
|
||||
10, 11, 12, 13, 14, 15, 16, 17, 18, 19
|
||||
};
|
||||
|
||||
std::array<int, 10> output;
|
||||
|
||||
etl::limiter<int> limiter(13, 16);
|
||||
|
||||
std::transform(input.begin(), input.end(), output.begin(), limiter);
|
||||
|
||||
// output = 13, 13, 13, 13, 14, 15, 16, 16, 16, 16
|
||||
|
||||
55
docs/raw/maths/Mean.txt
Normal file
55
docs/raw/maths/Mean.txt
Normal file
@ -0,0 +1,55 @@
|
||||
Mean
|
||||
20.9.0
|
||||
|
||||
template <typename TInput, typename TCalc = TInput>
|
||||
class mean : public etl::unary_function<TInput, void>
|
||||
|
||||
TInput The input data type.
|
||||
TCalc The type to use for internal calculations. By default, equal to TInput.
|
||||
____________________________________________________________________________________________________
|
||||
mean()
|
||||
Default constructor.
|
||||
|
||||
template <typename TIterator>
|
||||
mean(TIterator first, TIterator last)
|
||||
Construct from an iterator range.
|
||||
____________________________________________________________________________________________________
|
||||
void add(TInput value1)
|
||||
Add a value.
|
||||
|
||||
template <typename TIterator>
|
||||
void add(TIterator first, TIterator last)
|
||||
Add a range of values.
|
||||
____________________________________________________________________________________________________
|
||||
void operator()(TInput value)
|
||||
Add a values.
|
||||
|
||||
template <typename TIterator>
|
||||
void operator()(TIterator first, TIterator last)
|
||||
Add a range of values.
|
||||
____________________________________________________________________________________________________
|
||||
double get_mean() const
|
||||
Returns the calculated mean for the data.
|
||||
____________________________________________________________________________________________________
|
||||
operator double() const
|
||||
Returns the calculated mean for the data.
|
||||
____________________________________________________________________________________________________
|
||||
size_t count() const
|
||||
Get the total number added entries.
|
||||
____________________________________________________________________________________________________
|
||||
void clear()
|
||||
Clear the mean.
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
std::array<char, 10> input
|
||||
{
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
|
||||
};
|
||||
|
||||
etl::mean<char, int32_t> mean(input.begin(), input.end());
|
||||
|
||||
double mean_result;
|
||||
|
||||
mean_result = mean; // mean_result == 4.5
|
||||
|
||||
49
docs/raw/maths/Quantize.txt
Normal file
49
docs/raw/maths/Quantize.txt
Normal file
@ -0,0 +1,49 @@
|
||||
Quantize
|
||||
20.9.0
|
||||
Quantizes an input range.
|
||||
|
||||
template <typename TInput, typename TCompare = etl::less<TInput> >
|
||||
class quantize : public etl::unary_function<TInput, TInput>
|
||||
|
||||
TInput The input data type.
|
||||
TCompare The functor type used to compare values to the threshold. The default is etl::less
|
||||
____________________________________________________________________________________________________
|
||||
quantize(const TInput* p_thresholds,
|
||||
const TInput* p_quantizations,
|
||||
size_t n_quantizations,
|
||||
TCompare compare = TCompare())
|
||||
p_thresholds A pointer to the list of threshold values.
|
||||
p_quantizations A pointer to the list of quantization values. One more than the number of thresholds.
|
||||
n_quantizations The number of quantization values.
|
||||
____________________________________________________________________________________________________
|
||||
TInput operator()(TInput value) const
|
||||
Quantatize a value.
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
constexpr size_t Size = 20U;
|
||||
constexpr size_t NThresholds = 4U;
|
||||
|
||||
std::array<int, NThresholds> thresholds =
|
||||
{
|
||||
14, 18, 22, 25
|
||||
};
|
||||
|
||||
std::array<int, NThresholds + 1> quantizations =
|
||||
{
|
||||
1, 2, 3, 4, 5
|
||||
};
|
||||
|
||||
std::array<int, Size> input =
|
||||
{
|
||||
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29
|
||||
};
|
||||
|
||||
std::array<int, Size> output;
|
||||
|
||||
etl::quantize<int> quantize(thresholds.data(), quantizations.data(), quantizations.size());
|
||||
|
||||
std::transform(input.begin(), input.end(), output.begin(), quantize);
|
||||
|
||||
// output = 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 5, 5, 5, 5, 5
|
||||
|
||||
56
docs/raw/maths/RMS.txt
Normal file
56
docs/raw/maths/RMS.txt
Normal file
@ -0,0 +1,56 @@
|
||||
RMS
|
||||
(Root Mean Square)
|
||||
20.9.0
|
||||
|
||||
template <typename TInput, typename TCalc = TInput>
|
||||
class rms : public etl::unary_function<TInput, void>
|
||||
|
||||
TInput The input data type.
|
||||
TCalc The type to use for internal calculations. By default, equal to TInput.
|
||||
____________________________________________________________________________________________________
|
||||
rms()
|
||||
Default constructor.
|
||||
|
||||
template <typename TIterator>
|
||||
rms(TIterator first, TIterator last)
|
||||
Construct from an iterator range.
|
||||
____________________________________________________________________________________________________
|
||||
void add(TInput value1)
|
||||
Add a value.
|
||||
|
||||
template <typename TIterator>
|
||||
void add(TIterator first, TIterator last)
|
||||
Add a range of values.
|
||||
____________________________________________________________________________________________________
|
||||
void operator()(TInput value)
|
||||
Add a values.
|
||||
|
||||
template <typename TIterator>
|
||||
void operator()(TIterator first, TIterator last)
|
||||
Add a range of values.
|
||||
____________________________________________________________________________________________________
|
||||
double get_rms()
|
||||
Returns the calculated RMS for the data.
|
||||
____________________________________________________________________________________________________
|
||||
operator double()
|
||||
Returns the calculated RMS value for the data.
|
||||
____________________________________________________________________________________________________
|
||||
size_t count() const
|
||||
Get the total number added entries.
|
||||
____________________________________________________________________________________________________
|
||||
void clear()
|
||||
Clear the mean.
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
std::array<char, 10> input
|
||||
{
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
|
||||
};
|
||||
|
||||
etl::rms<char, int32_t> rms(input.begin(), input.end());
|
||||
|
||||
double rms_result;
|
||||
|
||||
rms_result = rms; // rms_result == 5.21
|
||||
|
||||
33
docs/raw/maths/Rescale.txt
Normal file
33
docs/raw/maths/Rescale.txt
Normal file
@ -0,0 +1,33 @@
|
||||
Rescale
|
||||
20.9.0
|
||||
Rescales an input range.
|
||||
|
||||
template <typename TInput, typename TOutput>
|
||||
class rescale : public etl::unary_function<TOutput, TInput>
|
||||
|
||||
TInput The input data type.
|
||||
TCompare The functor type used to compare values to the threshold. The default is etl::less
|
||||
____________________________________________________________________________________________________
|
||||
rescale (TInput input_min_value,
|
||||
TInput input_max_value,
|
||||
TOutput output_min_value,
|
||||
TOutput output_max_value)
|
||||
____________________________________________________________________________________________________
|
||||
TOutput operator()(TInput value) const
|
||||
Rescale a value.
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
std::array<char, 10> input =
|
||||
{
|
||||
10, 11, 12, 13, 14, 15, 16, 17, 18, 19
|
||||
};
|
||||
|
||||
std::array<int, 10> output;
|
||||
|
||||
etl::rescale<char, int> rescale(10, 19, 40000, 41900);
|
||||
|
||||
std::transform(input.begin(), input.end(), output.begin(), rescale);
|
||||
|
||||
// output = 40000, 40211, 40422, 40633, 40844, 41055, 41266, 41477, 41688, 41900
|
||||
|
||||
175
docs/raw/maths/Rounded integral division.txt
Normal file
175
docs/raw/maths/Rounded integral division.txt
Normal file
@ -0,0 +1,175 @@
|
||||
Rounded integral division
|
||||
Rounded division algorithms for integral values.
|
||||
20.43.0
|
||||
|
||||
These algorithms perform integer division while rounding the result as though the fractional part were actually present. They do not check for a denominator of zero.
|
||||
____________________________________________________________________________________________________
|
||||
divide_round_to_ceiling
|
||||
Values are rounded to the next more positive integral value.
|
||||
|
||||
template <typename T1, typename T2>
|
||||
ETL_CONSTEXPR14
|
||||
etl::common_type_t<T1, T2>
|
||||
divide_round_to_ceiling(T1 numerator, T2 denominator) ETL_NOEXCEPT
|
||||
|
||||
.151 / 100 == 2
|
||||
.150 / 100 == 2
|
||||
.149 / 100 == 2
|
||||
.51 / 100 == 1
|
||||
..50 / 100 == 1
|
||||
..49 / 100 == 1
|
||||
.-49 / 100 == 0
|
||||
.-50 / 100 == 0
|
||||
.-51 / 100 == 0
|
||||
-149 / 100 == -1
|
||||
-150 / 100 == -1
|
||||
-151 / 100 == -1
|
||||
____________________________________________________________________________________________________
|
||||
divide_round_to_floor
|
||||
Values are rounded to the next more negative integral value.
|
||||
|
||||
template <typename T1, typename T2>
|
||||
ETL_CONSTEXPR14
|
||||
etl::common_type_t<T1, T2>
|
||||
divide_round_to_floor(T1 numerator, T2 denominator) ETL_NOEXCEPT
|
||||
|
||||
.151 / 100 == 1
|
||||
.150 / 100 == 1
|
||||
.149 / 100 == 1
|
||||
..51 / 100 == 0
|
||||
..50 / 100 == 0
|
||||
..49 / 100 == 0
|
||||
.-49 / 100 == -1
|
||||
.-50 / 100 == -1
|
||||
.-51 / 100 == -1
|
||||
-149 / 100 == -2
|
||||
-150 / 100 == -2
|
||||
-151 / 100 == -2
|
||||
____________________________________________________________________________________________________
|
||||
divide_round_to_zero
|
||||
Values are rounded towards zero.
|
||||
|
||||
template <typename T1, typename T2>
|
||||
ETL_CONSTEXPR14
|
||||
etl::common_type_t<T1, T2>
|
||||
divide_round_to_zero(T1 numerator, T2 denominator) ETL_NOEXCEPT
|
||||
|
||||
.151 / 100 == 1
|
||||
.150 / 100 == 1
|
||||
.149 / 100 == 1
|
||||
..51 / 100 == 0
|
||||
..50 / 100 == 0
|
||||
..49 / 100 == 0
|
||||
.-49 / 100 == 0
|
||||
.-50 / 100 == 0
|
||||
.-51 / 100 == 0
|
||||
-149 / 100 == -1
|
||||
-150 / 100 == -1
|
||||
-151 / 100 == -1
|
||||
____________________________________________________________________________________________________
|
||||
divide_round_to_infinity
|
||||
Values are rounded towards infinity.
|
||||
|
||||
template <typename T1, typename T2>
|
||||
ETL_CONSTEXPR14
|
||||
etl::common_type_t<T1, T2>
|
||||
divide_round_to_infinity(T1 numerator, T2 denominator) ETL_NOEXCEPT
|
||||
|
||||
.151 / 100 == 2
|
||||
.150 / 100 == 2
|
||||
.149 / 100 == 2
|
||||
..51 / 100 == 1
|
||||
..50 / 100 == 1
|
||||
..49 / 100 == 1
|
||||
.-49 / 100 == -1
|
||||
.-50 / 100 == -1
|
||||
.-51 / 100 == -1
|
||||
-149 / 100 == -2
|
||||
-150 / 100 == -2
|
||||
-151 / 100 == -2
|
||||
____________________________________________________________________________________________________
|
||||
divide_round_half_up
|
||||
Values are rounded to the nearest integral value. 'Half' values are rounded up (towards infinity).
|
||||
|
||||
template <typename T1, typename T2>
|
||||
ETL_CONSTEXPR14
|
||||
etl::common_type_t<T1, T2>
|
||||
divide_round_half_up(T1 numerator, T2 denominator) ETL_NOEXCEPT
|
||||
|
||||
.151 / 100 == 3
|
||||
.150 / 100 == 3
|
||||
.149 / 100 == 1
|
||||
..51 / 100 == 1
|
||||
..50 / 100 == 1
|
||||
..49 / 100 == 0
|
||||
.-49 / 100 == 0
|
||||
.-50 / 100 == -1
|
||||
.-51 / 100 == -1
|
||||
-149 / 100 == -1
|
||||
-150 / 100 == -3
|
||||
-151 / 100 == -3
|
||||
____________________________________________________________________________________________________
|
||||
divide_round_half_down
|
||||
Values are rounded to the nearest integral value. 'Half' values are rounded up (towards zero)
|
||||
|
||||
template <typename T1, typename T2>
|
||||
ETL_CONSTEXPR14
|
||||
etl::common_type_t<T1, T2>
|
||||
divide_round_half_down(T1 numerator, T2 denominator) ETL_NOEXCEPT
|
||||
|
||||
.151 / 100 == 3
|
||||
.150 / 100 == 2
|
||||
.149 / 100 == 1
|
||||
..51 / 100 == 1
|
||||
..50 / 100 == 0
|
||||
..49 / 100 == 0
|
||||
.-49 / 100 == 0
|
||||
.-50 / 100 == 0
|
||||
.-51 / 100 == -1
|
||||
-149 / 100 == -1
|
||||
-150 / 100 == -2
|
||||
-151 / 100 == -3
|
||||
____________________________________________________________________________________________________
|
||||
divide_round_half_even
|
||||
(Banker's rounding)
|
||||
Values are rounded to the nearest integral value. 'Half' values are rounded to the nearest even value.
|
||||
|
||||
template <typename T1, typename T2>
|
||||
ETL_CONSTEXPR14
|
||||
etl::common_type_t<T1, T2>
|
||||
divide_round_half_even(T1 numerator, T2 denominator) ETL_NOEXCEPT
|
||||
|
||||
.151 / 100 == 2
|
||||
.150 / 100 == 2
|
||||
.149 / 100 == 1
|
||||
..51 / 100 == 1
|
||||
..50 / 100 == 0
|
||||
..49 / 100 == 0
|
||||
.-49 / 100 == 0
|
||||
.-50 / 100 == 0
|
||||
.-51 / 100 == -1
|
||||
-149 / 100 == -1
|
||||
-150 / 100 == -2
|
||||
-151 / 100 == -2
|
||||
____________________________________________________________________________________________________
|
||||
divide_round_half_odd
|
||||
Values are rounded to the nearest integral value. 'Half' values are rounded to the nearest odd value.
|
||||
|
||||
template <typename T1, typename T2>
|
||||
ETL_CONSTEXPR14
|
||||
etl::common_type_t<T1, T2>
|
||||
divide_round_half_even(T1 numerator, T2 denominator) ETL_NOEXCEPT
|
||||
|
||||
.151 / 100 == 2
|
||||
.150 / 100 == 1
|
||||
.149 / 100 == 1
|
||||
..51 / 100 == 1
|
||||
..50 / 100 == 1
|
||||
..49 / 100 == 0
|
||||
.-49 / 100 == 0
|
||||
.-50 / 100 == -1
|
||||
.-51 / 100 == -1
|
||||
-149 / 100 == -1
|
||||
-150 / 100 == -1
|
||||
-151 / 100 == -2
|
||||
|
||||
257
docs/raw/maths/Scaled Rounding.txt
Normal file
257
docs/raw/maths/Scaled Rounding.txt
Normal file
@ -0,0 +1,257 @@
|
||||
Scaled Rounding
|
||||
Rounding algorithms for scaled integral values.
|
||||
|
||||
From 20.40.1 all scaling functions are ETL_NODISCARD and ETL_CONSTEXPR14.
|
||||
|
||||
It is often advantageous to use scaled integral values rather than floating point for performance reasons.
|
||||
These functions will round the supplied values according to various popular rounding algorithms.
|
||||
See http://www.clivemaxfield.com/diycalculator/sp-round.shtml
|
||||
|
||||
The results may be scaled or unscaled.
|
||||
Scaled : The result has the same scaling as the input value.
|
||||
Unscaled : The result has the scaling factor removed from the input value. 'Unscaled' is a little faster than 'scaled'.
|
||||
|
||||
Assume a scaling factor of 10 for all of the examples below (simulated one decimal place).
|
||||
i.e. 5.1 => 51
|
||||
____________________________________________________________________________________________________
|
||||
Round Ceiling
|
||||
|
||||
Values are rounded to the next more positive integral value.
|
||||
|
||||
Scaling = 10
|
||||
Therefore 54 represents 5.4
|
||||
|
||||
template <size_t Scaling, typename T>
|
||||
T round_ceiling_scaled(T value)
|
||||
|
||||
-54 => -50 -5.4 => -5.0
|
||||
-55 => -50 -5.5 => -5.0
|
||||
-56 => -50 -5.6 => -5.0
|
||||
|
||||
54 => 60 5.4 => 6.0
|
||||
55 => 60 5.5 => 6.0
|
||||
56 => 60 5.5 => 6.0
|
||||
|
||||
template <size_t Scaling, typename T>
|
||||
T round_ceiling_unscaled(T value)
|
||||
|
||||
-54 => -5 -5.4 => -5
|
||||
-55 => -5 -5.5 => -5
|
||||
-56 => -5 -5.6 => -5
|
||||
|
||||
54 => 6 5.4 => 6
|
||||
55 => 6 5.5 => 6
|
||||
56 => 6 5.6 => 6
|
||||
____________________________________________________________________________________________________
|
||||
Round Floor
|
||||
|
||||
Values are rounded to the next more negative integral value.
|
||||
|
||||
Scaling = 10
|
||||
Therefore 54 represents 5.4
|
||||
|
||||
template <size_t Scaling, typename T>
|
||||
T round_floor_scaled(T value)
|
||||
|
||||
-54 => -60 -5.4 => -6.0
|
||||
-55 => -60 -5.5 => -6.0
|
||||
-56 => -60 -5.6 => -6.0
|
||||
|
||||
54 => 50 5.4 => 5.0
|
||||
55 => 50 5.5 => 5.0
|
||||
56 => 50 5.6 => 5.0
|
||||
|
||||
template <size_t Scaling, typename T>
|
||||
T round_floor_unscaled(T value)
|
||||
|
||||
-54 => -6 -5.4 => -6
|
||||
-55 => -6 -5.5 => -6
|
||||
-56 => -6 -5.6 => -6
|
||||
|
||||
54 => 5 5.4 => 5
|
||||
55 => 5 5.5 => 5
|
||||
56 => 5 5.6 => 5
|
||||
____________________________________________________________________________________________________
|
||||
Round Half Up
|
||||
|
||||
Values are rounded to the nearest integral value. 'Half' values are rounded up (towards infinity).
|
||||
|
||||
template <size_t Scaling, typename T>
|
||||
T round_half_up_scaled(T value)
|
||||
|
||||
-54 => -50 -5.4 => -5.0
|
||||
-55 => -60 -5.5 => -5.0
|
||||
-56 => -60 -5.6 => -5.0
|
||||
|
||||
54 => 50
|
||||
55 => 60
|
||||
56 => 60
|
||||
|
||||
template <size_t Scaling, typename T>
|
||||
T round_half_up_unscaled(T value)
|
||||
|
||||
-54 => -5
|
||||
-55 => -6
|
||||
-56 => -6
|
||||
|
||||
54 => 5
|
||||
55 => 6
|
||||
56 => 6
|
||||
____________________________________________________________________________________________________
|
||||
Round Half Down
|
||||
|
||||
Values are rounded to the nearest integral value. 'Half' values are rounded down (towards zero).
|
||||
|
||||
template <size_t Scaling, typename T>
|
||||
T round_half_down_scaled(T value)
|
||||
|
||||
-54 => -50
|
||||
-55 => -50
|
||||
-56 => -60
|
||||
|
||||
54 => 50
|
||||
55 => 50
|
||||
56 => 60
|
||||
|
||||
template <size_t Scaling, typename T>
|
||||
T round_half_down_unscaled(T value)
|
||||
|
||||
-54 => -5
|
||||
-55 => -5
|
||||
-56 => -6
|
||||
|
||||
54 => 5
|
||||
55 => 5
|
||||
56 => 6
|
||||
____________________________________________________________________________________________________
|
||||
Round To Zero
|
||||
|
||||
Values are rounded towards zero.
|
||||
|
||||
template <size_t Scaling, typename T>
|
||||
T round_zero_scaled(T value)
|
||||
|
||||
-54 => -50
|
||||
-55 => -50
|
||||
-56 => -50
|
||||
|
||||
54 => 50
|
||||
55 => 50
|
||||
56 => 50
|
||||
|
||||
template <size_t Scaling, typename T>
|
||||
T round_zero_unscaled(T value)
|
||||
|
||||
-54 => -5
|
||||
-55 => -5
|
||||
-56 => -5
|
||||
|
||||
54 => 5
|
||||
55 => 5
|
||||
56 => 5
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
Round To Infinity
|
||||
|
||||
Values are rounded towards infinity.
|
||||
|
||||
template <size_t Scaling, typename T>
|
||||
T round_infinity_scaled(T value)
|
||||
|
||||
-54 => -60
|
||||
-55 => -60
|
||||
-56 => -60
|
||||
|
||||
54 => 60
|
||||
55 => 60
|
||||
56 => 60
|
||||
|
||||
template <size_t Scaling, typename T>
|
||||
T round_infinity_unscaled(T value)
|
||||
|
||||
-54 => -6
|
||||
-55 => -6
|
||||
-56 => -6
|
||||
|
||||
54 => 6
|
||||
55 => 6
|
||||
56 => 6
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
Round Half Even (Banker's Rounding)
|
||||
|
||||
Values are rounded to the nearest integral value. 'Half' values are rounded to the nearest even value.
|
||||
|
||||
template <size_t Scaling, typename T>
|
||||
T round_half_even_scaled(T value)
|
||||
|
||||
-54 => -50
|
||||
-55 => -60
|
||||
-56 => -60
|
||||
-64 => -60
|
||||
-65 => -60
|
||||
-66 => -70
|
||||
|
||||
54 => 50
|
||||
55 => 60
|
||||
56 => 60
|
||||
64 => 60
|
||||
65 => 60
|
||||
66 => 70
|
||||
|
||||
template <size_t Scaling, typename T>
|
||||
T round_half_even_unscaled(T value)
|
||||
|
||||
-54 => -5
|
||||
-55 => -6
|
||||
-56 => -6
|
||||
-64 => -6
|
||||
-65 => -6
|
||||
-66 => -7
|
||||
|
||||
54 => 5
|
||||
55 => 6
|
||||
56 => 6
|
||||
64 => 6
|
||||
65 => 6
|
||||
66 => 7
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
Round Half Odd
|
||||
|
||||
Values are rounded to the nearest integral value. 'Half' values are rounded to the nearest odd value.
|
||||
|
||||
template <size_t Scaling, typename T>
|
||||
T round_half_even_scaled(T value)
|
||||
|
||||
-54 => -50
|
||||
-55 => -50
|
||||
-56 => -60
|
||||
-64 => -60
|
||||
-65 => -70
|
||||
-66 => -70
|
||||
|
||||
54 => 50
|
||||
55 => 50
|
||||
56 => 60
|
||||
64 => 60
|
||||
65 => 70
|
||||
66 => 70
|
||||
|
||||
template <size_t Scaling, typename T>
|
||||
T round_half_even_unscaled(T value)
|
||||
|
||||
-54 => -5
|
||||
-55 => -5
|
||||
-56 => -6
|
||||
-64 => -6
|
||||
-65 => -7
|
||||
-66 => -7
|
||||
|
||||
54 => 5
|
||||
55 => 5
|
||||
56 => 6
|
||||
64 => 6
|
||||
65 => 7
|
||||
66 => 7
|
||||
|
||||
67
docs/raw/maths/Standard Deviation.txt
Normal file
67
docs/raw/maths/Standard Deviation.txt
Normal file
@ -0,0 +1,67 @@
|
||||
Standard Deviation
|
||||
20.9.0
|
||||
|
||||
template <bool Standard_Deviation_Type, typename TInput, typename TCalc = TInput>
|
||||
class standard_deviation : public etl::unary_function<TInput, void>
|
||||
|
||||
Standard_Deviation_Type Population or Sample.
|
||||
TInput The input data type.
|
||||
TCalc The type to use for internal calculations. By default, equal to TInput.
|
||||
____________________________________________________________________________________________________
|
||||
standard_deviation_type
|
||||
etl::standard_deviation_type::Sample
|
||||
etl::standard_deviation_type::Population
|
||||
____________________________________________________________________________________________________
|
||||
standard_deviation
|
||||
standard_deviation()
|
||||
Default constructor.
|
||||
|
||||
template <typename TIterator>
|
||||
standard_deviation(TIterator first, TIterator last)
|
||||
Construct from an iterator range.
|
||||
____________________________________________________________________________________________________
|
||||
void add(TInput value1)
|
||||
Add a value.
|
||||
|
||||
template <typename TIterator>
|
||||
void add(TIterator first, TIterator last)
|
||||
Add a range of values.
|
||||
____________________________________________________________________________________________________
|
||||
void operator()(TInput value)
|
||||
Add a values.
|
||||
|
||||
template <typename TIterator>
|
||||
void operator()(TIterator first, TIterator last)
|
||||
Add a range of values.
|
||||
____________________________________________________________________________________________________
|
||||
double get_standard_deviation() const
|
||||
Returns the calculated standard deviation for the data.
|
||||
____________________________________________________________________________________________________
|
||||
double get_variance() const
|
||||
Returns the calculated variance for the data.
|
||||
____________________________________________________________________________________________________
|
||||
operator double() const
|
||||
Returns the calculated standard deviation for the data.
|
||||
____________________________________________________________________________________________________
|
||||
size_t count() const
|
||||
Get the total number added entries.
|
||||
____________________________________________________________________________________________________
|
||||
void clear()
|
||||
Clear the standard deviation.
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
std::array<char, 10> input
|
||||
{
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
|
||||
};
|
||||
|
||||
etl::standard_deviation<etl::standard_deviation_type::Population, char, int32_t>
|
||||
standard_deviation(input.begin(), input.end());
|
||||
|
||||
double standard_deviation_result;
|
||||
double variance_result;
|
||||
|
||||
standard_deviation_result = standard_deviation; // standard_deviation_result == 2.87
|
||||
variance_result = standard_deviation.get_variance(); // variance_result == 8.25
|
||||
|
||||
33
docs/raw/maths/Threshold.txt
Normal file
33
docs/raw/maths/Threshold.txt
Normal file
@ -0,0 +1,33 @@
|
||||
Threshold
|
||||
20.9.0
|
||||
|
||||
template <typename TInput, typename TCompare = etl::less<TInput> >
|
||||
class threshold : public etl::unary_function<TInput, TInput>
|
||||
|
||||
TInput The input data type.
|
||||
TCompare The functor type used to compare values to the threshold. The default is etl::less
|
||||
____________________________________________________________________________________________________
|
||||
threshold(TInput threshold_value,
|
||||
TInput true_value,
|
||||
TInput false_value,
|
||||
TCompare compare = TCompare())
|
||||
Constructor.
|
||||
____________________________________________________________________________________________________
|
||||
TInput operator()(TInput value) const
|
||||
Threshold a value.
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
std::array<int, 10> input
|
||||
{
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
|
||||
};
|
||||
|
||||
std::array<int, 10> output;
|
||||
|
||||
etl::threshold<int> threshold(4, 0, 9); // Compares each value to 4 and output 0 or 9.
|
||||
|
||||
std::transform(input.begin(), input.end(), output.begin(), threshold);
|
||||
|
||||
// output == 0, 0, 0, 0, 9, 9, 9, 9, 9, 9
|
||||
|
||||
62
docs/raw/maths/Variance.txt
Normal file
62
docs/raw/maths/Variance.txt
Normal file
@ -0,0 +1,62 @@
|
||||
Variance
|
||||
20.9.0
|
||||
|
||||
template <bool Variance_Type, typename TInput, typename TCalc = TInput>
|
||||
class variance : public etl::unary_function<TInput, void>
|
||||
|
||||
Variance_Type Population or Sample.
|
||||
TInput The input data type.
|
||||
TCalc The type to use for internal calculations. By default, equal to TInput.
|
||||
____________________________________________________________________________________________________
|
||||
variance_type
|
||||
etl::variance_type::Sample
|
||||
etl::variance_type::Population
|
||||
____________________________________________________________________________________________________
|
||||
variance
|
||||
variance()
|
||||
Default constructor.
|
||||
|
||||
template <typename TIterator>
|
||||
variance(TIterator first, TIterator last)
|
||||
Construct from an iterator range.
|
||||
____________________________________________________________________________________________________
|
||||
void add(TInput value1)
|
||||
Add a value.
|
||||
|
||||
template <typename TIterator>
|
||||
void add(TIterator first, TIterator last)
|
||||
Add a range of values.
|
||||
____________________________________________________________________________________________________
|
||||
void operator()(TInput value)
|
||||
Add a values.
|
||||
|
||||
template <typename TIterator>
|
||||
void operator()(TIterator first, TIterator last)
|
||||
Add a range of values.
|
||||
____________________________________________________________________________________________________
|
||||
double get_variance() const
|
||||
Returns the calculated variance for the data.
|
||||
____________________________________________________________________________________________________
|
||||
operator double() const
|
||||
Returns the calculated variance for the data.
|
||||
____________________________________________________________________________________________________
|
||||
size_t count() const
|
||||
Get the total number added entries.
|
||||
____________________________________________________________________________________________________
|
||||
void clear()
|
||||
Clear the variance.
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
std::array<char, 10> input
|
||||
{
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
|
||||
};
|
||||
|
||||
etl::variance<etl::variance_type::Population, char, int32_t> variance(input.begin(),
|
||||
input.end());
|
||||
|
||||
double variance_result;
|
||||
|
||||
variance_result = variance; // variance_result == 8.25
|
||||
|
||||
24
docs/raw/maths/absolute.txt
Normal file
24
docs/raw/maths/absolute.txt
Normal file
@ -0,0 +1,24 @@
|
||||
absolute
|
||||
A template functions that return the absolute value.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR T absolute(T value)
|
||||
Returns the absolute of value.
|
||||
|
||||
If T is int8_t:-
|
||||
0 => 0
|
||||
127 => 127
|
||||
-127 => 127
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR etl::make_unsigned_t<T> absolute_unsigned(T value)
|
||||
Returns the absolute of value, cast to the unsigned version of type T.
|
||||
|
||||
If T is int8_t:-
|
||||
|
||||
Return type is etl::make_unsigned_t<T>
|
||||
0 => 0
|
||||
127 => 127
|
||||
-127 => 127
|
||||
-128 => 128
|
||||
|
||||
30
docs/raw/maths/comb-perm.txt
Normal file
30
docs/raw/maths/comb-perm.txt
Normal file
@ -0,0 +1,30 @@
|
||||
|
||||
Combinations / Permutations
|
||||
Templates to provide combinations and permutations constants.
|
||||
____________________________________________________________________________________________________
|
||||
Combinations
|
||||
|
||||
template <size_t N, size_t K>
|
||||
struct combinations
|
||||
|
||||
Member const
|
||||
static ETL_CONSTEXPR size_t value = Number of combinations of K items from a total of N
|
||||
|
||||
If C++17 is supported.
|
||||
template <size_t N, size_t K>
|
||||
inline constexpr size_t combinations_v = combinations<N, K>::value;
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
Permutations
|
||||
|
||||
template <size_t N, size_t K>
|
||||
struct permutations
|
||||
|
||||
Member const
|
||||
static ETL_CONSTEXPR size_t value = Number of permutations of K items from a total of N
|
||||
|
||||
If C++17 is supported.
|
||||
template <size_t N, size_t K>
|
||||
inline constexpr size_t permutations_v = permutations<N, K>::value;
|
||||
|
||||
|
||||
7
docs/raw/maths/is_negative.txt
Normal file
7
docs/raw/maths/is_negative.txt
Normal file
@ -0,0 +1,7 @@
|
||||
is_negative
|
||||
|
||||
Allows a parameter of type T to be checked for a positive or negative value, while eliminating compiler warnings for checking < 0 for unsigned types.
|
||||
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR bool is_negative(const T value)
|
||||
|
||||
88
docs/raw/maths/pseudo_moving_average.txt
Normal file
88
docs/raw/maths/pseudo_moving_average.txt
Normal file
@ -0,0 +1,88 @@
|
||||
pseudo_moving_average
|
||||
|
||||
A moving average algorithm that continuously calculates an average value from a stream of samples.
|
||||
The sample size does not affect the size of the instantiated object. There is no overhead based on the number of samples as it simulates a window of N values from the current average.
|
||||
|
||||
There are four variants of the algorithm; two for integral values and two for floating point. Each sub variant allows the selection of compile time or run time sample size.
|
||||
The integral variant allows a compile time scaling factor to emulate fixed point arithmetic.
|
||||
____________________________________________________________________________________________________
|
||||
Integral
|
||||
|
||||
template <typename T, const size_t SAMPLE_SIZE, const size_t SCALING>
|
||||
pseudo_moving_average;
|
||||
|
||||
static const size_t SAMPLE_SIZE
|
||||
The number of samples averaged over.
|
||||
If this value is zero, then the run time sample size specialisation is used.
|
||||
|
||||
static const size_t SCALING
|
||||
The sample scaling factor.
|
||||
__________________________________________________________________________________________________
|
||||
pseudo_moving_average(const T initial_value)
|
||||
Constructs the object with the initial value for the average.
|
||||
__________________________________________________________________________________________________
|
||||
pseudo_moving_average(const T initial_value, const size_t sample_size)
|
||||
For runtime sample size specialisation only.
|
||||
Constructs the object with the initial value for the average and the sample size.
|
||||
__________________________________________________________________________________________________
|
||||
void clear(const T initial_value)
|
||||
Clears the object to the initial value for the average.
|
||||
__________________________________________________________________________________________________
|
||||
void add(T new_value)
|
||||
Adds a new sample value.
|
||||
__________________________________________________________________________________________________
|
||||
T value() const
|
||||
Returns the scaled value of the average.
|
||||
To unscale the returned value, use one of the rounding found in scaled_rounding.
|
||||
__________________________________________________________________________________________________
|
||||
iterator input()
|
||||
|
||||
Returns an iterator that allows the input of new values.
|
||||
|
||||
Example
|
||||
std::array data{ 9, 1, 8, 2, 7, 3, 6, 4, 5 };
|
||||
etl::pseudo_moving_average<int, SAMPLE_SIZE, SCALING> cma(0);
|
||||
std::copy(data.begin(), data.end(), cma.input());
|
||||
int average = cma.value();
|
||||
__________________________________________________________________________________________________
|
||||
void set_sample_size(const size_t sample_size)
|
||||
|
||||
For runtime sample size specialisation only.
|
||||
Sets the sample size.
|
||||
____________________________________________________________________________________________________
|
||||
Floating point
|
||||
|
||||
template <typename T, const size_t SAMPLE_SIZE>
|
||||
pseudo_moving_average;
|
||||
|
||||
static const size_t SAMPLE_SIZE
|
||||
The number of samples averaged over.
|
||||
__________________________________________________________________________________________________
|
||||
pseudo_moving_average(const T initial_value)
|
||||
Constructs the object with the initial value for the average.
|
||||
__________________________________________________________________________________________________
|
||||
pseudo_moving_average(const T initial_value, const size_t sample_size)
|
||||
For runtime sample size specialisation only.
|
||||
Constructs the object with the initial value for the average and the sample size.
|
||||
__________________________________________________________________________________________________
|
||||
void clear(const T initial_value)
|
||||
Clears the object to the initial value for the average.
|
||||
__________________________________________________________________________________________________
|
||||
void add(T new_value)
|
||||
Adds a new sample value.
|
||||
__________________________________________________________________________________________________
|
||||
T value() const
|
||||
Returns the average value.
|
||||
__________________________________________________________________________________________________
|
||||
void set_sample_size(const size_t sample_size)
|
||||
For runtime sample size specialisation only.
|
||||
Sets the sample size.
|
||||
____________________________________________________________________________________________________
|
||||
How It Works
|
||||
|
||||
If the current moving average is 5, then an equivalent sequence of samples (for a sample size of 9), that gives the same average, would be 5, 5, 5, 5, 5, 5, 5, 5, 5
|
||||
|
||||
This means, to find the average when adding a new sample to a moving average that has a current value of 5, all we need to do is multiply the current average by the sample size (9), add the new sample, and divide by the sample size + 1 (10).
|
||||
|
||||
Wikipedia
|
||||
|
||||
13
docs/raw/maths/radix.txt
Normal file
13
docs/raw/maths/radix.txt
Normal file
@ -0,0 +1,13 @@
|
||||
radix
|
||||
A smart enumeration to encode radix constants.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
struct radix
|
||||
|
||||
Define the constants:
|
||||
undefined
|
||||
binary
|
||||
octal
|
||||
decimal
|
||||
hex
|
||||
|
||||
234
docs/raw/maths/random.txt
Normal file
234
docs/raw/maths/random.txt
Normal file
@ -0,0 +1,234 @@
|
||||
random
|
||||
Utilities for producing random numbers.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
random
|
||||
The base class for all 32 bit random number generators.
|
||||
|
||||
If ETL_POLYMORPHIC_RANDOM is defined, then the base class will have the following members, otherwise the base is empty.
|
||||
|
||||
virtual ~random();
|
||||
virtual void initialise(uint32_t seed) = 0;
|
||||
virtual uint32_t operator()() = 0;
|
||||
virtual uint32_t range(uint32_t low, uint32_t high) = 0;
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
random_xorshift
|
||||
Uses a 128bit XOR shift algorithm for producing a pseudo-random sequence of integers.
|
||||
The result is a 32 bit integer between 0 and 4,294,967,295 (2^32 - 1).
|
||||
|
||||
random_xor_shift()
|
||||
|
||||
Constructor.
|
||||
Uses the address of the object as the seed for the sequence.
|
||||
|
||||
random_xor_shift(uint32_t seed)
|
||||
|
||||
Constructor.
|
||||
Uses seed as the seed for the sequence.
|
||||
|
||||
void initialise(uint32_t seed)
|
||||
|
||||
Sets the seed as the new seed for the sequence.
|
||||
|
||||
uint32_t operator()()
|
||||
|
||||
Returns the next number in the pseudo-random sequence.
|
||||
|
||||
uint32_t range(uint32_t low, uint32_t high)
|
||||
|
||||
Returns a number between the specified ranges, inclusive.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
random_lcg
|
||||
Generates a 32 bit pseudo-random number using a linear congruent generator.
|
||||
The result is a 32 bit integer between 0 and 2,147,483,647 (2^31 - 1).
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
random_lcg()
|
||||
|
||||
Constructor.
|
||||
Uses the address of the object as the seed for the sequence
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
random_lcg(uint32_t seed)
|
||||
|
||||
Constructor.
|
||||
Uses seed as the seed for the sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
void initialise(uint32_t seed)
|
||||
|
||||
Sets the seed as the new seed for the sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
uint32_t operator()()
|
||||
|
||||
Returns the next number in the pseudo-random sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
uint32_t range(uint32_t low, uint32_t high)
|
||||
|
||||
Returns a number between the specified ranges, inclusive.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
random_clcg
|
||||
Generates a 32 bit pseudo-random number using a combined linear congruent generator.
|
||||
The result is a 32 bit integer between 0 and 2,147,483,647 (2^31 - 1).
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
random_clcg()
|
||||
|
||||
Constructor.
|
||||
Uses the address of the object as the seed for the sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
random_clcg(uint32_t seed)
|
||||
|
||||
Constructor.
|
||||
Uses seed as the seed for the sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
void initialise(uint32_t seed)
|
||||
|
||||
Sets the seed as the new seed for the sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
uint32_t operator()()
|
||||
|
||||
Returns the next number in the pseudo-random sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
uint32_t range(uint32_t low, uint32_t high)
|
||||
Returns a number between the specified ranges, inclusive.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
random_lsfr
|
||||
Generates a 32 bit pseudo-random number using a linear shift feedback register.
|
||||
The result is a 32 bit integer between 1 and 4,294,967,295 (2^32 - 1).
|
||||
The seed must not be zero. The output does not include zero.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
random_lsfr()
|
||||
|
||||
Constructor.
|
||||
Uses the address of the object as the seed for the sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
random_lsfr(uint32_t seed)
|
||||
|
||||
Constructor.
|
||||
Uses seed as the seed for the sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
void initialise(uint32_t seed)
|
||||
|
||||
Sets the seed as the new seed for the sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
uint32_t operator()()
|
||||
|
||||
Returns the next number in the pseudo-random sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
uint32_t range(uint32_t low, uint32_t high)
|
||||
|
||||
Returns a number between the specified ranges, inclusive.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
random_mwc
|
||||
Generates a 32 bit pseudo-random number using a multiply-with-carry algorithm.
|
||||
The result is a 32 bit integer between 1 and 4,294,967,295 (2^32 - 1).
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
random_mwc()
|
||||
|
||||
Constructor.
|
||||
Uses the address of the object as the seed for the sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
random_mwc(uint32_t seed)
|
||||
|
||||
Constructor.
|
||||
Uses seed as the seed for the sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
void initialise(uint32_t seed)
|
||||
|
||||
Sets the seed as the new seed for the sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
uint32_t operator()()
|
||||
|
||||
Returns the next number in the pseudo-random sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
uint32_t range(uint32_t low, uint32_t high)
|
||||
|
||||
Returns a number between the specified ranges, inclusive.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
random_pcg
|
||||
Generates a 32 bit pseudo-random number using a permuted congruential generator algorithm.
|
||||
The result is a 32 bit integer between 1 and 4,294,967,295 (2^32 - 1).
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
random_pcg()
|
||||
|
||||
Constructor.
|
||||
Uses the address of the object as the seed for the sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
random_pcg(uint32_t seed)
|
||||
|
||||
Constructor.
|
||||
Uses seed as the seed for the sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
void initialise(uint32_t seed)
|
||||
|
||||
Sets the seed as the new seed for the sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
uint32_t operator()()
|
||||
|
||||
Returns the next number in the pseudo-random sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
uint32_t range(uint32_t low, uint32_t high)
|
||||
|
||||
Returns a number between the specified ranges, inclusive.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
random_hash
|
||||
|
||||
template <typename THash>
|
||||
Generates a 32 bit pseudo-random number by applying a user supplied 32bit hash to a counter.
|
||||
The hash must implement void add(uint8_t) and uint8_t value() member functions.
|
||||
____________________________________________________________________________________________________
|
||||
random_hash()
|
||||
|
||||
Constructor.
|
||||
Uses the address of the object as the seed for the sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
random_hash(uint32_t seed)
|
||||
|
||||
Constructor.
|
||||
Uses seed as the seed for the sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
void initialise(uint32_t seed)
|
||||
|
||||
Sets the seed as the new seed for the sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
uint32_t operator()()
|
||||
|
||||
Returns the next number in the pseudo-random sequence.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
uint32_t range(uint32_t low, uint32_t high)
|
||||
|
||||
Returns a number between the specified ranges, inclusive.
|
||||
|
||||
56
docs/raw/maths/ratio.txt
Normal file
56
docs/raw/maths/ratio.txt
Normal file
@ -0,0 +1,56 @@
|
||||
ratio
|
||||
A template constant to encode ratios.
|
||||
C++11 equivalent std::ratio
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
template <const size_t NUM, const size_t DEN = 1>
|
||||
struct ratio
|
||||
{
|
||||
static ETL_CONSTANT intmax_t num = NUM;
|
||||
static ETL_CONSTANT intmax_t den = DEN;
|
||||
};
|
||||
|
||||
num : Numerator
|
||||
den : Denominator
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
Predefined ratios
|
||||
|
||||
If INT_MAX > INT32_MAX
|
||||
typedef ratio<1, 1000000000000000000000000> yocto;
|
||||
typedef ratio<1, 1000000000000000000000> zepto;
|
||||
typedef ratio<1, 1000000000000000000> atto;
|
||||
typedef ratio<1, 1000000000000000> femto;
|
||||
typedef ratio<1, 1000000000000> pico;
|
||||
|
||||
If INT_MAX >= INT32_MAX
|
||||
typedef ratio<1, 1000000000> nano;
|
||||
typedef ratio<1, 1000000> micro;
|
||||
|
||||
If INT_MAX >= INT16_MAX
|
||||
typedef ratio<1, 1000> milli;
|
||||
typedef ratio<1, 100> centi;
|
||||
typedef ratio<1, 10> deci;
|
||||
typedef ratio<10, 1> deca;
|
||||
typedef ratio<100, 1> hecto;
|
||||
typedef ratio<1000, 1> kilo;
|
||||
|
||||
If INT_MAX >= INT32_MAX
|
||||
typedef ratio<1000000, 1> mega;
|
||||
typedef ratio<1000000000, 1> giga;
|
||||
|
||||
If INT_MAX > INT32_MAX
|
||||
typedef ratio<1000000000000, 1> tera;
|
||||
typedef ratio<1000000000000000, 1> peta;
|
||||
typedef ratio<1000000000000000000, 1> exa;
|
||||
typedef ratio<1000000000000000000000, 1> zetta;
|
||||
typedef ratio<1000000000000000000000000, 1> yotta;
|
||||
|
||||
An approximation of PI to 6 digits.
|
||||
typedef ratio<355, 113> ratio_pi;
|
||||
|
||||
An approximation of root 2.
|
||||
typedef ratio<239, 169> ratio_root2;
|
||||
|
||||
An approximation of e.
|
||||
typedef ratio<326, 120> ratio_e;
|
||||
931
docs/raw/utilities/Algorithms.txt
Normal file
931
docs/raw/utilities/Algorithms.txt
Normal file
@ -0,0 +1,931 @@
|
||||
Algorithms
|
||||
A set of algorithms from the STL.
|
||||
|
||||
If ETL_NO_STL is defined then the ETL implements its own reverse engineered versions.
|
||||
Otherwise, the ETL will often be a wrapper around the STL's implementation.
|
||||
|
||||
Functions returning pair will either use std::pair or, if ETL_NO_STL is defined, etl::pair.
|
||||
|
||||
Constexpr
|
||||
Some algorithms will be constexpr, dependent on the compiler support and ETL setup.
|
||||
|
||||
ETL_FORCE_CONSTEXPR_ALGORITHMS
|
||||
If this macro is defined, then certain algorithms will be always be constexpr, regardless of STL setting or availability of compiler built-ins. The downside, if the STL is not use, is that some copy algorithms may be less efficient when used at run-time.
|
||||
See the descriptions below.
|
||||
____________________________________________________________________________________________________
|
||||
swap
|
||||
Only defined if ETL_NO_STL is defined.
|
||||
|
||||
template <typename T>
|
||||
void swap(T& a, T& b) ETL_NOEXCEPT
|
||||
Swaps two values
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T, size_t N>
|
||||
void swap(T(&a)[N], T(&b)[N]) ETL_NOEXCEPT
|
||||
Swaps two arrays
|
||||
https://en.cppreference.com/w/cpp/algorithm/swap
|
||||
____________________________________________________________________________________________________
|
||||
iter_swap
|
||||
template <typename TIterator1, typename TIterator2>
|
||||
void iter_swap(TIterator1 a, TIterator2 b)
|
||||
Swaps the elements pointed to by two iterators
|
||||
https://en.cppreference.com/w/cpp/algorithm/iter_swap
|
||||
____________________________________________________________________________________________________
|
||||
swap_ranges
|
||||
template <typename T1terator1, typename TIterator2>
|
||||
TIterator2 swap_ranges(T1terator1 first1,
|
||||
T1terator1 last1,
|
||||
TIterator2 first2)
|
||||
Swaps two ranges of elements
|
||||
https://en.cppreference.com/w/cpp/algorithm/swap_ranges
|
||||
____________________________________________________________________________________________________
|
||||
copy
|
||||
template <typename TInputIterator, typename TOutputIterator>
|
||||
TOutputIterator copy(TInputIterator sb, TInputIterator se, TOutputIterator db)
|
||||
Copies the elements in the range, defined by sb, se, to another range beginning at db
|
||||
https://en.cppreference.com/w/cpp/algorithm/copy
|
||||
|
||||
Constexpr
|
||||
This function is constexpr under the following conditions.
|
||||
⦁ The STL is in use and C++20 is supported.
|
||||
⦁ The iterator is non-pointer or the type is not trivially copyable and C++14 is supported.
|
||||
⦁ The iterator is a pointer, the type is trivially copyable, built-in memcpy is supports, and C++14 is supported.
|
||||
⦁ The iterator is a pointer, the type is trivially copyable, ETL_FORCE_CONSTEXPR_ALGORITHMS is defined as 1, and C++14 is supported.
|
||||
____________________________________________________________________________________________________
|
||||
copy_s
|
||||
ETL extension
|
||||
template <typename TInputIterator, typename TOutputIterator>
|
||||
TOutputIterator copy_s(TInputIterator i_begin, TInputIterator i_end,
|
||||
TOutputIterator o_begin, TOutputIterator o_end)
|
||||
A safer four parameter version that will stop copying when either iterator reaches the end of its range.
|
||||
|
||||
Constexpr
|
||||
This function is constexpr under the following conditions.
|
||||
⦁ The STL is in use and C++20 is supported.
|
||||
⦁ The iterator is non-pointer or the type is not trivially copyable and C++14 is supported.
|
||||
⦁ The iterator is a pointer, the type is trivially copyable, built-in memcpy is supports, and C++14 is supported.
|
||||
⦁ The iterator is a pointer, the type is trivially copyable, ETL_FORCE_CONSTEXPR_ALGORITHMS is defined as 1, and C++14 is supported.
|
||||
____________________________________________________________________________________________________
|
||||
copy_n
|
||||
template <typename TInputIterator, typename TSize, typename TOutputIterator>
|
||||
TOutputIterator copy_n(TInputIterator begin, TSize n, TOutputIterator result)
|
||||
Copies exactly n values from the range beginning at begin to the range beginning at result.
|
||||
https://en.cppreference.com/w/cpp/algorithm/copy_n
|
||||
|
||||
Constexpr
|
||||
This function is constexpr under the following conditions.
|
||||
⦁ The STL is in use and C++20 is supported.
|
||||
⦁ The iterator is non-pointer or the type is not trivially copyable and C++14 is supported.
|
||||
⦁ The iterator is a pointer, the type is trivially copyable, built-in memcpy is supports, and C++14 is supported.
|
||||
⦁ The iterator is a pointer, the type is trivially copyable, ETL_FORCE_CONSTEXPR_ALGORITHMS is defined as 1, and C++14 is supported.
|
||||
____________________________________________________________________________________________________
|
||||
copy_n_s
|
||||
ETL extension
|
||||
template <typename TInputIterator, typename TSize, typename TOutputIterator>
|
||||
TOutputIterator copy_n_s(TInputIterator i_begin,
|
||||
TSize n,
|
||||
TOutputIterator o_begin, TOutputIterator o_end)
|
||||
A safer version that will stop copying when either n items have been copied or the output iterator reaches the end of its range.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TInputIterator, typename TSize1, typename TOutputIterator, typename TSize2>
|
||||
TOutputIterator copy_n_s(TIterator i_begin,
|
||||
TSize1 n1,
|
||||
TOutputIterator o_begin,
|
||||
TSize1 n2,)
|
||||
A safer version that will stop copying when either n1 or n2 items have been copied.
|
||||
|
||||
Constexpr
|
||||
This function is constexpr under the following conditions.
|
||||
⦁ The STL is in use and C++20 is supported.
|
||||
⦁ The iterator is non-pointer or the type is not trivially copyable and C++14 is supported.
|
||||
⦁ The iterator is a pointer, the type is trivially copyable, built-in memcpy is supports, and C++14 is supported.
|
||||
⦁ The iterator is a pointer, the type is trivially copyable, ETL_FORCE_CONSTEXPR_ALGORITHMS is defined as 1, and C++14 is supported.
|
||||
____________________________________________________________________________________________________
|
||||
copy_if
|
||||
template <typename TIterator, typename TOutputIterator, typename TUnaryPredicate>
|
||||
ETL_CONSTEXPR14
|
||||
TOutputIterator copy_if(TIterator begin, TIterator end, TOutputIterator out, TUnaryPredicate predicate)
|
||||
Only copies the elements for which the predicate predicate returns true
|
||||
|
||||
https://en.cppreference.com/w/cpp/algorithm/copy
|
||||
____________________________________________________________________________________________________
|
||||
copy_if_s
|
||||
ETL extension
|
||||
template <typename TIterator, typename TOutputIterator, typename TUnaryPredicate>
|
||||
ETL_CONSTEXPR14
|
||||
TOutputIterator copy_if_s(TIterator i_begin, TIterator i_end,
|
||||
TOutputIterator o_begin, TOutputIterator o_end,
|
||||
TUnaryPredicate predicate)
|
||||
A safer version that will stop copying when either iterator reaches the end of its range
|
||||
____________________________________________________________________________________________________
|
||||
copy_n_if
|
||||
ETL extension
|
||||
template <typename TIterator, typename TSize, typename TOutputIterator, typename TUnaryPredicate>
|
||||
ETL_CONSTEXPR14
|
||||
TOutputIterator copy_n_if(TIterator begin, TSize n, TOutputIterator out, TUnaryPredicate predicate)
|
||||
A combination of copy_if and copy_n
|
||||
____________________________________________________________________________________________________
|
||||
reverse_copy
|
||||
template <typename TIterator1, typename TIterator2>
|
||||
TIterator2 reverse_copy(TIterator1 sb, TIterator1 se, TIterator2 db)
|
||||
Copies the elements from the range sb, se to another range beginning at db in such a way that the elements in the new range are in reverse order.
|
||||
https://en.cppreference.com/w/cpp/algorithm/reverse_copy
|
||||
|
||||
Constexpr
|
||||
This function is constexpr under the following conditions.
|
||||
⦁ The STL is in use and C++20 is supported.
|
||||
⦁ The STL is in use and ETL_FORCE_CONSTEXPR_ALGORITHMS is defined as 1.
|
||||
⦁ The STL is not in use.
|
||||
____________________________________________________________________________________________________
|
||||
copy_backward
|
||||
template <typename TIterator1, typename TIterator2>
|
||||
TIterator2 copy_backward(TIterator1 sb, TIterator1 se, TIterator2 de)
|
||||
Copies the elements from the range, defined by sb, se to another range ending at db
|
||||
The elements are copied in reverse order.
|
||||
https://en.cppreference.com/w/cpp/algorithm/copy_backward
|
||||
|
||||
Constexpr
|
||||
This function is constexpr under the following conditions.
|
||||
⦁ The STL is in use and C++20 is supported.
|
||||
⦁ The STL is in use and ETL_FORCE_CONSTEXPR_ALGORITHMS is defined as 1.
|
||||
⦁ The STL is not in use.
|
||||
____________________________________________________________________________________________________
|
||||
count
|
||||
template <typename TIterator, typename T>
|
||||
typename iterator_traits<TIterator>::difference_type count(TIterator first,
|
||||
TIterator last,
|
||||
const T& value)
|
||||
Counts the elements that are equal to value
|
||||
https://en.cppreference.com/w/cpp/algorithm/count
|
||||
____________________________________________________________________________________________________
|
||||
count_if
|
||||
template <typename TIterator, typename TUnaryPredicate>
|
||||
typename iterator_traits<TIterator>::difference_type count_if(TIterator first,
|
||||
TIterator last,
|
||||
TUnaryPredicate predicate)
|
||||
Counts the elements where predicate returns true
|
||||
https://en.cppreference.com/w/cpp/algorithm/count
|
||||
____________________________________________________________________________________________________
|
||||
equal
|
||||
template <typename TIterator1, typename TIterator2>
|
||||
bool equal(TIterator1 first1, TIterator1 last1, TIterator2 first2)
|
||||
Returns true if the range first1, last1 is equal to the range first2, first2 + distance(first1, last1)
|
||||
https://en.cppreference.com/w/cpp/algorithm/equal
|
||||
____________________________________________________________________________________________________
|
||||
lexicographical_compare
|
||||
template <typename TIterator1, typename TIterator2>
|
||||
bool lexicographical_compare(TIterator1 first1, TIterator1 last1,
|
||||
TIterator2 first2, TIterator2 last2)
|
||||
Checks if the range first1, last1 is lexicographically less than the range first2, last2, using the 'less-than' operator
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TIterator1, typename TIterator2, typename TCompare>
|
||||
bool lexicographical_compare(TIterator1 first1, TIterator1 last1,
|
||||
TIterator2 first2, TIterator2 last2,
|
||||
TCompare compare)
|
||||
Checks if the range first1, last1 is lexicographically less than the range first2, last2, using compare
|
||||
https://en.cppreference.com/w/cpp/algorithm/lexicographical_compare
|
||||
____________________________________________________________________________________________________
|
||||
heap
|
||||
Heap control functions
|
||||
|
||||
Make Heap
|
||||
template <typename TIterator>
|
||||
void make_heap(TIterator first, TIterator last)
|
||||
|
||||
template <typename TIterator, typename TCompare>
|
||||
void make_heap(TIterator first, TIterator last, TCompare compare)
|
||||
|
||||
https://en.cppreference.com/w/cpp/algorithm/make_heap
|
||||
____________________________________________________________________________________________________
|
||||
Is Heap
|
||||
template <typename TIterator>
|
||||
bool is_heap(TIterator first, TIterator last)
|
||||
|
||||
template <typename TIterator, typename TCompare>
|
||||
bool is_heap(TIterator first, TIterator last, TCompare compare)
|
||||
|
||||
https://en.cppreference.com/w/cpp/algorithm/is_heap
|
||||
____________________________________________________________________________________________________
|
||||
Pop Heap
|
||||
template <typename TIterator>
|
||||
void pop_heap(TIterator first, TIterator last)
|
||||
|
||||
template <typename TIterator, typename TCompare>
|
||||
void pop_heap(TIterator first, TIterator last, TCompare compare)
|
||||
|
||||
https://en.cppreference.com/w/cpp/algorithm/pop_heap
|
||||
____________________________________________________________________________________________________
|
||||
Push Heap
|
||||
template <typename TIterator>
|
||||
void push_heap(TIterator first, TIterator last)
|
||||
|
||||
template <typename TIterator, typename TCompare>
|
||||
void push_heap(TIterator first, TIterator last, TCompare compare)
|
||||
|
||||
https://en.cppreference.com/w/cpp/algorithm/push_heap
|
||||
____________________________________________________________________________________________________
|
||||
min
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR const T& min(const T& a, const T& b)
|
||||
Returns the minimum of the two values
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T, typename TCompare>
|
||||
ETL_CONSTEXPR const T& min(const T& a, const T& b, TCompare compare)
|
||||
Returns the value where compare returns true if a is less than b
|
||||
|
||||
https://en.cppreference.com/w/cpp/algorithm/min
|
||||
____________________________________________________________________________________________________
|
||||
max
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR const T& max(const T& a, const T& b)
|
||||
Returns the maximum of the two values
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T, typename TCompare>
|
||||
ETL_CONSTEXPR const T& max(const T& a, const T& b, TCompare compare)
|
||||
Returns the value where compare returns true if a is less than b
|
||||
|
||||
https://en.cppreference.com/w/cpp/algorithm/max
|
||||
____________________________________________________________________________________________________
|
||||
minmax
|
||||
template <typename T>
|
||||
pair<const T&, const T&> minmax(const T& a, const T& b)
|
||||
Returns the lesser and greater values
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T, typename TCompare>
|
||||
pair<const T&, const T&> minmax(const T& a, const T& b, TCompare compare)
|
||||
Returns the lesser and greater values using compare
|
||||
|
||||
https://en.cppreference.com/w/cpp/algorithm/minmax
|
||||
____________________________________________________________________________________________________
|
||||
min_element
|
||||
template <typename TIterator>
|
||||
TIterator min_element(TIterator begin, TIterator end)
|
||||
Finds the smallest element in the range begin, end
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TIterator, typename TCompare>
|
||||
TIterator min_element(TIterator begin, TIterator end, TCompare compare)
|
||||
Finds the smallest element in the range begin, end using compare
|
||||
|
||||
https://en.cppreference.com/w/cpp/algorithm/min_element
|
||||
____________________________________________________________________________________________________
|
||||
max_element
|
||||
template <typename TIterator>
|
||||
TIterator max_element(TIterator begin, TIterator end)
|
||||
Finds the greatest element in the range begin, end
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TIterator, typename TCompare>
|
||||
TIterator max_element(TIterator begin, TIterator end, TCompare compare)
|
||||
Finds the greatest element in the range begin, end using compare
|
||||
|
||||
https://en.cppreference.com/w/cpp/algorithm/max_element
|
||||
____________________________________________________________________________________________________
|
||||
minmax_element
|
||||
template <typename TIterator>
|
||||
pair<TIterator, TIterator> minmax_element(TIterator begin, TIterator end)
|
||||
Finds the smallest and greatest element in the range begin, end
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TIterator, typename TCompare>
|
||||
pair<TIterator, TIterator> minmax_element(TIterator begin, TIterator end, TCompare compare)
|
||||
Finds the smallest and greatest element in the range begin, end using compare
|
||||
|
||||
https://en.cppreference.com/w/cpp/algorithm/minmax_element
|
||||
____________________________________________________________________________________________________
|
||||
multimin
|
||||
multimin_compare
|
||||
multimin_iter
|
||||
multimin_iter_compare
|
||||
ETL extension
|
||||
C++11 only
|
||||
Variadic functions to return the minimum value, or iterator to value, from a variable length parameter list.
|
||||
|
||||
template <typename T, typename... Tx>
|
||||
constexpr const T& multimin(const T& t, const Tx&... tx)
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TCompare, typename T, typename... Tx>
|
||||
constexpr const T& multimin_compare(TCompare compare, const T& t, const Tx&... tx)
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TIterator, typename... TIteratorx>
|
||||
constexpr const TIterator& multimin_iter(const TIterator& t, const TIteratorx&... tx)
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TCompare, typename TIterator, typename... TIteratorx>
|
||||
constexpr const TIterator& multimin_iter_compare(TCompare compare,
|
||||
const TIterator& t, const TIteratorx&... tx)
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
int minimum;
|
||||
|
||||
minimum = etl::multimin(1, 2, 3, 4, 5, 6, 7, 8));
|
||||
minimum = etl::multimin_compare(std::less<int>(), 1, 2, 3, 4, 5, 6, 7, 8));
|
||||
minimum = etl::multimin_compare(std::greater<int>(), 1, 2, 3, 4, 5, 6, 7, 8));
|
||||
|
||||
int i[8] = { 1, 2, 3, 4, 5, 6, 7, 8 };
|
||||
|
||||
int* p_minimum;
|
||||
|
||||
p_minimum = etl::multimin_iter(&i[0], &i[1], &i[2], &i[3], &i[4], &i[5], &i[6], &i[7]));
|
||||
p_minimum = etl::multimin_iter_compare(std::less<int>(),
|
||||
&i[0], &i[1], &i[2], &i[3], &i[4], &i[5], &i[6], &i[7]));
|
||||
p_minimum = etl::multimin_iter_compare(std::greater<int>(),
|
||||
&i[0], &i[1], &i[2], &i[3], &i[4], &i[5], &i[6], &i[7]));
|
||||
____________________________________________________________________________________________________
|
||||
multimax
|
||||
multimax_compare
|
||||
multimax_iter
|
||||
multimax_iter_compare
|
||||
ETL extension
|
||||
|
||||
C++11 only variadic functions to return the maximum value, or iterator to value, from a variable length parameter list.
|
||||
|
||||
template <typename T, typename... Tx>
|
||||
constexpr const T& multimax(const T& t, const Tx&... tx)
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TCompare, typename T, typename... Tx>
|
||||
constexpr const T& multimax_compare(TCompare compare, const T& t, const Tx&... tx)
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TIterator, typename... TIteratorx>
|
||||
constexpr const TIterator& multimax_iter(const TIterator& t, const TIteratorx&... tx)
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TCompare, typename TIterator, typename... TIteratorx>
|
||||
constexpr const TIterator& multimax_iter_compare(TCompare compare,
|
||||
const TIterator& t,
|
||||
const TIteratorx&... tx)
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
int maximum;
|
||||
|
||||
maximum = etl::multimax(1, 2, 3, 4, 5, 6, 7, 8));
|
||||
maximum = etl::multimax_compare(std::less<int>(), 1, 2, 3, 4, 5, 6, 7, 8));
|
||||
maximum = etl::multimax_compare(std::greater<int>(), 1, 2, 3, 4, 5, 6, 7, 8));
|
||||
|
||||
int i[8] = { 1, 2, 3, 4, 5, 6, 7, 8 };
|
||||
|
||||
int* p_maximum;
|
||||
|
||||
p_maximum = etl::multimax_iter(&i[0], &i[1], &i[2], &i[3], &i[4], &i[5], &i[6], &i[7]));
|
||||
p_maximum = etl::multimax_iter_compare(std::less<int>(),
|
||||
&i[0], &i[1], &i[2], &i[3], &i[4], &i[5], &i[6], &i[7]));
|
||||
p_maximum = etl::multimax_iter_compare(std::greater<int>(),
|
||||
&i[0], &i[1], &i[2], &i[3], &i[4], &i[5], &i[6], &i[7]));
|
||||
____________________________________________________________________________________________________
|
||||
move
|
||||
template <typename TIterator1, typename TIterator2>
|
||||
TIterator2 move(TIterator1 sb, TIterator1 se, TIterator2 db)
|
||||
Moves the elements in the range sb, se to another range beginning at db
|
||||
|
||||
https://en.cppreference.com/w/cpp/algorithm/move
|
||||
|
||||
Constexpr
|
||||
This function is constexpr under the following conditions.
|
||||
⦁ The STL is in use and C++20 is supported.
|
||||
⦁ The iterator is non-pointer or the type is not trivially copyable and C++14 is supported.
|
||||
⦁ The iterator is a pointer, the type is trivially copyable, built-in memcpy is supports, and C++14 is supported.
|
||||
⦁ The iterator is a pointer, the type is trivially copyable, ETL_FORCE_CONSTEXPR_ALGORITHMS is defined as 1, and C++14 is supported.
|
||||
____________________________________________________________________________________________________
|
||||
move_s
|
||||
ETL extension
|
||||
template <typename TInputIterator, typename TOutputIterator>
|
||||
TOutputIterator move_s(TInputIterator i_begin, TInputIterator i_end,
|
||||
TOutputIterator o_begin, TOutputIterator o_end)
|
||||
A safer four parameter version that will stop moving when either iterator reaches the end of its range.
|
||||
|
||||
Constexpr
|
||||
This function is constexpr under the following conditions.
|
||||
⦁ The STL is in use and C++20 is supported.
|
||||
⦁ The iterator is non-pointer or the type is not trivially copyable and C++14 is supported.
|
||||
⦁ The iterator is a pointer, the type is trivially copyable, built-in memcpy is supports, and C++14 is supported.
|
||||
⦁ The iterator is a pointer, the type is trivially copyable, ETL_FORCE_CONSTEXPR_ALGORITHMS is defined as 1, and C++14 is supported.
|
||||
____________________________________________________________________________________________________
|
||||
move_backward
|
||||
template <typename TIterator1, typename TIterator2>
|
||||
TIterator2 move_backward(TIterator1 sb, TIterator1 se, TIterator2 de)
|
||||
Moves the elements in the range sb, se to another range ending at de
|
||||
The elements are moved in reverse order
|
||||
|
||||
https://en.cppreference.com/w/cpp/algorithm/move_backward
|
||||
|
||||
Constexpr
|
||||
This function is constexpr under the following conditions.
|
||||
⦁ The STL is in use and C++20 is supported.
|
||||
⦁ The iterator is non-pointer or the type is not trivially copyable and C++14 is supported.
|
||||
⦁ The iterator is a pointer, the type is trivially copyable, built-in memcpy is supports, and C++14 is supported.
|
||||
⦁ The iterator is a pointer, the type is trivially copyable, ETL_FORCE_CONSTEXPR_ALGORITHMS is defined as 1, and C++14 is supported.
|
||||
____________________________________________________________________________________________________
|
||||
reverse
|
||||
template <typename TIterator>
|
||||
void reverse(TIterator b, TIterator e)
|
||||
Reverses the order of the elements in the range b, e
|
||||
|
||||
https://en.cppreference.com/w/cpp/algorithm/reverse
|
||||
____________________________________________________________________________________________________
|
||||
for_each_if
|
||||
ETL extension
|
||||
template <typename TIterator, typename TUnaryFunction, typename TUnaryPredicate>
|
||||
TUnaryFunction for_each_if(TIterator begin,
|
||||
const TIterator end,
|
||||
TUnaryFunction function,
|
||||
TUnaryPredicate predicate)
|
||||
Applies function to each element if predicate returns true
|
||||
____________________________________________________________________________________________________
|
||||
for_each_n
|
||||
ETL extension
|
||||
template <typename TIterator, typename TSize, typename TUnaryFunction>
|
||||
TIterator for_each_n(TIterator begin,
|
||||
TSize n,
|
||||
TUnaryFunction function)
|
||||
Applies function to n elements, starting from begin
|
||||
____________________________________________________________________________________________________
|
||||
for_each_n_if
|
||||
ETL extension
|
||||
template <typename TIterator, typename TSize, typename TUnaryFunction, typename TUnaryPredicate>
|
||||
TIterator for_each_n_if(TIterator begin,
|
||||
TSize n,
|
||||
TUnaryFunction function,
|
||||
TUnaryPredicate predicate)
|
||||
Combination of for_each_if and for_each_n
|
||||
____________________________________________________________________________________________________
|
||||
fill
|
||||
template <typename TIterator, typename TValue>
|
||||
void fill(TIterator first, TIterator last, const TValue& value)
|
||||
Assigns the given value to the elements in the range first, last
|
||||
|
||||
https://en.cppreference.com/w/cpp/algorithm/fill
|
||||
____________________________________________________________________________________________________
|
||||
fill_n
|
||||
template <typename TIterator, typename TSize, typename TValue>
|
||||
TIterator fill_n(TIterator first, TSize count, const TValue& value)
|
||||
Assigns the given value to the first count elements in the range beginning at first
|
||||
|
||||
https://en.cppreference.com/w/cpp/algorithm/fill_n
|
||||
____________________________________________________________________________________________________
|
||||
find
|
||||
template <typename TIterator, typename T>
|
||||
TIterator find(TIterator first, TIterator last, const T& value)
|
||||
Searches for an element equal to value
|
||||
|
||||
https://en.cppreference.com/w/cpp/algorithm/find
|
||||
____________________________________________________________________________________________________
|
||||
find_end
|
||||
Searches for the last occurrence of the sequence b, e in the range sb, be
|
||||
|
||||
template <typename TIterator1, typename TIterator2>
|
||||
TIterator1 find_end(TIterator1 b, TIterator1 e,
|
||||
TIterator2 sb, TIterator2 se)
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TIterator1, typename TIterator2, typename TPredicate>
|
||||
TIterator1 find_end(TIterator1 b, TIterator1 e,
|
||||
TIterator2 sb, TIterator2 se,
|
||||
TPredicate predicate)
|
||||
|
||||
https://en.cppreference.com/w/cpp/algorithm/find_end
|
||||
____________________________________________________________________________________________________
|
||||
find_if
|
||||
template <typename TIterator, typename TUnaryPredicate>
|
||||
TIterator find_if(TIterator first, TIterator last, TUnaryPredicate predicate)
|
||||
Searches for the first element that satisfies the predicate
|
||||
|
||||
https://en.cppreference.com/w/cpp/algorithm/find
|
||||
____________________________________________________________________________________________________
|
||||
find_if_not
|
||||
template <typename TIterator, typename TUnaryPredicate>
|
||||
TIterator find_if_not(TIterator begin, TIterator end, TUnaryPredicate predicate)
|
||||
Searches for the first element that does not satisfy the predicate
|
||||
|
||||
https://en.cppreference.com/w/cpp/algorithm/find
|
||||
____________________________________________________________________________________________________
|
||||
lower_bound
|
||||
template <typename TIterator, typename TValue>
|
||||
TIterator lower_bound(TIterator first, TIterator last, const TValue& value)
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TIterator, typename TValue, typename TCompare>
|
||||
TIterator lower_bound(TIterator first, TIterator last, const TValue& value, TCompare compare)
|
||||
|
||||
https://en.cppreference.com/w/cpp/algorithm/lower_bound
|
||||
____________________________________________________________________________________________________
|
||||
upper_bound
|
||||
template <typename TIterator, typename TValue>
|
||||
TIterator upper_bound(TIterator first, TIterator last, const TValue& value)
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TIterator, typename TValue, typename TCompare>
|
||||
TIterator upper_bound(TIterator first, TIterator last, const TValue& value, TCompare compare)
|
||||
|
||||
https://en.cppreference.com/w/cpp/algorithm/upper_bound
|
||||
____________________________________________________________________________________________________
|
||||
equal_range
|
||||
template <typename TIterator, typename TValue>
|
||||
pair<TIterator, TIterator> equal_range(TIterator first, TIterator last, const TValue& value)
|
||||
Returns an iterator pointing to the first element in the range first, last that is not less than value, or last if no such element is found.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TIterator, typename TValue, typename TCompare>
|
||||
pair<TIterator, TIterator> equal_range(TIterator first, TIterator last,
|
||||
const TValue& value, TCompare compare)
|
||||
Returns an iterator pointing to the first element in the range first, last that is not less than value using compare, or last if no such element is found.
|
||||
|
||||
https://en.cppreference.com/w/cpp/algorithm/equal_range
|
||||
____________________________________________________________________________________________________
|
||||
binary_find
|
||||
ETL extension
|
||||
template <typename TIterator, typename TValue>
|
||||
TIterator binary_find(TIterator begin,
|
||||
TIterator end,
|
||||
const TValue& value)
|
||||
Finds the first item in a sorted container that matches the value.
|
||||
Returns an iterator to the value or end.
|
||||
____________________________________________________________________________________________________
|
||||
ETL extension
|
||||
template <typename TIterator, typename TValue, typename TBinaryPredicate, typename TBinaryEquality>
|
||||
TIterator binary_find(TIterator begin,
|
||||
TIterator end,
|
||||
const TValue& value,
|
||||
TBinaryPredicate predicate,
|
||||
TBinaryEquality equality)
|
||||
Finds the first item in a sorted container that matches the value.
|
||||
Returns an iterator to the value or end.
|
||||
Comparison and equality predicates are supplied.
|
||||
____________________________________________________________________________________________________
|
||||
search
|
||||
template <typename TIterator1, typename TIterator2>
|
||||
TIterator1 search(TIterator1 first, TIterator1 last,
|
||||
TIterator2 search_first, TIterator2 search_last)
|
||||
Searches for the first occurrence of the sequence of elements first, last in the range search_first, search_last
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TIterator1, typename TIterator2, typename TCompare>
|
||||
TIterator1 search(TIterator1 first, TIterator1 last,
|
||||
TIterator2 search_first, TIterator2 search_last,
|
||||
TCompare compare)
|
||||
Searches for the first occurrence of the sequence of elements first, last in the range search_first, search_last
|
||||
Uses compare to check equality of the values
|
||||
|
||||
https://en.cppreference.com/w/cpp/algorithm/search
|
||||
____________________________________________________________________________________________________
|
||||
binary_search
|
||||
template <typename TIterator, typename T, typename Compare>
|
||||
bool binary_search(TIterator first, TIterator last, const T& value, Compare compare)
|
||||
|
||||
template <typename TIterator, typename T>
|
||||
bool binary_search(TIterator first, TIterator last, const T& value)
|
||||
|
||||
https://en.cppreference.com/w/cpp/algorithm/binary_search
|
||||
____________________________________________________________________________________________________
|
||||
all_of
|
||||
template <typename TIterator, typename TUnaryPredicate>
|
||||
bool all_of(TIterator begin, TIterator end, TUnaryPredicate predicate)
|
||||
Checks if predicate returns true for all elements in the range begin, end
|
||||
|
||||
https://en.cppreference.com/w/cpp/algorithm/all_any_none_of
|
||||
____________________________________________________________________________________________________
|
||||
any_of
|
||||
template <typename TIterator, typename TUnaryPredicate>
|
||||
bool any_of(TIterator begin, TIterator end, TUnaryPredicate predicate)
|
||||
Checks if predicate returns true for at least one element in the range begin, end
|
||||
|
||||
https://en.cppreference.com/w/cpp/algorithm/all_any_none_of
|
||||
____________________________________________________________________________________________________
|
||||
none_of
|
||||
template <typename TIterator, typename TUnaryPredicate>
|
||||
bool none_of(TIterator begin, TIterator end, TUnaryPredicate predicate)
|
||||
Checks if predicate returns true for no elements in the range begin, end
|
||||
|
||||
https://en.cppreference.com/w/cpp/algorithm/all_any_none_of
|
||||
____________________________________________________________________________________________________
|
||||
is_permutation
|
||||
Returns true if there exists a permutation of the elements in the range begin1, end1 that makes that range equal to the second range
|
||||
|
||||
template <typename TIterator1, typename TIterator2>
|
||||
bool is_permutation(TIterator1 begin1,
|
||||
TIterator1 end1,
|
||||
TIterator2 begin2)
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TIterator1, typename TIterator2>
|
||||
bool is_permutation(TIterator1 begin1,
|
||||
TIterator1 end1,
|
||||
TIterator2 begin2,
|
||||
TIterator2 end2)
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TIterator1,
|
||||
typename TIterator2,
|
||||
typename TBinaryPredicate>
|
||||
bool is_permutation(TIterator1 begin1,
|
||||
TIterator1 end1,
|
||||
TIterator2 begin2,
|
||||
TBinaryPredicate predicate)
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TIterator1,
|
||||
typename TIterator2,
|
||||
typename TBinaryPredicate>
|
||||
bool is_permutation(TIterator1 begin1,
|
||||
TIterator1 end1,
|
||||
TIterator2 begin2,
|
||||
TIterator2 end2,
|
||||
TBinaryPredicate predicate)
|
||||
|
||||
https://en.cppreference.com/w/cpp/algorithm/is_permutation
|
||||
____________________________________________________________________________________________________
|
||||
is_partitioned
|
||||
template <typename TIterator, typename TUnaryPredicate>
|
||||
bool is_partitioned(TIterator begin,
|
||||
TIterator end,
|
||||
TUnaryPredicate predicate)
|
||||
Returns true if all elements in the range begin, end that satisfy the predicate appear before all elements that don't. Also returns true if begin, end is empty.
|
||||
|
||||
https://en.cppreference.com/w/cpp/algorithm/is_partitioned
|
||||
____________________________________________________________________________________________________
|
||||
partition_point
|
||||
template <typename TIterator, typename TUnaryPredicate>
|
||||
TIterator partition_point(TIterator begin,
|
||||
TIterator end,
|
||||
TUnaryPredicate predicate)
|
||||
Examines the partitioned range begin, end and locates the end of the first partition according to predicate
|
||||
|
||||
https://en.cppreference.com/w/cpp/algorithm/partition_point
|
||||
____________________________________________________________________________________________________
|
||||
partition_copy
|
||||
template <typename TSource,
|
||||
typename TDestinationTrue,
|
||||
typename TDestinationFalse,
|
||||
typename TUnaryPredicate>
|
||||
pair<TDestinationTrue, TDestinationFalse> partition_copy(TSource begin,
|
||||
TSource end,
|
||||
TDestinationTrue destination_true,
|
||||
TDestinationFalse destination_false,
|
||||
TUnaryPredicate predicate)
|
||||
|
||||
Copies the elements from the range begin, end to two different ranges depending on the value returned by the predicate.
|
||||
The elements that satisfy the predicate p are copied to the range beginning at destination_true. The rest of the elements are copied to the range beginning at destination_false.
|
||||
|
||||
https://en.cppreference.com/w/cpp/algorithm/partition_copy
|
||||
____________________________________________________________________________________________________
|
||||
partition_transform
|
||||
ETL extension
|
||||
Transforms data from the source to one of two destinations.
|
||||
If the predicate returns true then the source data if modified by function_true and stored in destination_true.
|
||||
If the predicate returns false then the source data if modified by function_false and stored in destination_false.
|
||||
|
||||
One input range.
|
||||
template <typename TSource,
|
||||
typename TDestinationTrue,
|
||||
typename TDestinationFalse,
|
||||
typename TUnaryFunctionTrue,
|
||||
typename TUnaryFunctionFalse,
|
||||
typename TUnaryPredicate>
|
||||
pair<TDestinationTrue, TDestinationFalse>
|
||||
partition_transform(TSource begin,
|
||||
TSource end,
|
||||
TDestinationTrue destination_true,
|
||||
TDestinationFalse destination_false,
|
||||
TUnaryFunctionTrue function_true,
|
||||
TUnaryFunctionFalse function_false,
|
||||
TUnaryPredicate predicate)
|
||||
____________________________________________________________________________________________________
|
||||
Two input ranges.
|
||||
template <typename TSource1,
|
||||
typename TSource2,
|
||||
typename TDestinationTrue,
|
||||
typename TDestinationFalse,
|
||||
typename TUnaryFunctionTrue,
|
||||
typename TUnaryFunctionFalse,
|
||||
typename TUnaryPredicate>
|
||||
pair<TDestinationTrue, TDestinationFalse>
|
||||
partition_transform(TSource1 begin1,
|
||||
TSource1 end1,
|
||||
TSource2 begin2,
|
||||
TDestinationTrue destination_true,
|
||||
TDestinationFalse destination_false,
|
||||
TBinaryFunctionTrue function_true,
|
||||
TBinaryFunctionFalse function_false,
|
||||
TBinaryPredicate predicate)
|
||||
____________________________________________________________________________________________________
|
||||
rotate
|
||||
template <typename TIterator>
|
||||
TIterator rotate(TIterator first, TIterator middle, TIterator last)
|
||||
Performs a left rotation on the range of elements
|
||||
|
||||
https://en.cppreference.com/w/cpp/algorithm/rotate
|
||||
____________________________________________________________________________________________________
|
||||
transform_s
|
||||
ETL extension
|
||||
A safer version that will stop transforming when either iterator reaches the end of its range.
|
||||
|
||||
template <typename TIterator,
|
||||
typename TOutputIterator,
|
||||
typename TUnaryPredicate>
|
||||
void transform_s(TIterator i_begin,
|
||||
TIterator i_end,
|
||||
TOutputIterator o_begin,
|
||||
TOutputIterator o_end,
|
||||
TUnaryFunction function)
|
||||
____________________________________________________________________________________________________
|
||||
transform_n
|
||||
ETL extension
|
||||
Transform over n elements
|
||||
|
||||
One input range.
|
||||
template <typename TInputIterator,
|
||||
typename TSize,
|
||||
typename TOutputIterator,
|
||||
typename TUnaryFunction>
|
||||
void transform_n(TInputIterator i_begin,
|
||||
TSize n,
|
||||
TOutputIterator o_begin,
|
||||
TUnaryFunction function)
|
||||
____________________________________________________________________________________________________
|
||||
Two input ranges.
|
||||
template <typename TInputIterator1,
|
||||
typename TInputIterator2,
|
||||
typename TSize,
|
||||
typename TOutputIterator,
|
||||
typename TBinaryFunction>
|
||||
void transform_n(TInputIterator1 i_begin1,
|
||||
TInputIterator2 i_begin2,
|
||||
TSize n,
|
||||
TOutputIterator o_begin,
|
||||
TBinaryFunction function)
|
||||
____________________________________________________________________________________________________
|
||||
transform_if
|
||||
ETL extension
|
||||
Transforms data from the source based on a predicate.
|
||||
If the predicate returns true then the source data if modified by function and stored in the output range.
|
||||
If the predicate returns false then the source data is ignored.
|
||||
|
||||
One input range.
|
||||
template <typename TInputIterator,
|
||||
typename TOutputIterator,
|
||||
typename TUnaryFunction,
|
||||
typename TUnaryPredicate>
|
||||
TOutputIterator transform_if(TInputIterator i_begin,
|
||||
TInputIterator i_end,
|
||||
TOutputIterator o_begin,
|
||||
TUnaryFunction function,
|
||||
TUnaryPredicate predicate)
|
||||
____________________________________________________________________________________________________
|
||||
Two input ranges.
|
||||
template <typename TInputIterator1,
|
||||
typename TInputIterator2,
|
||||
typename TOutputIterator,
|
||||
typename TBinaryFunction,
|
||||
typename TBinaryPredicate>
|
||||
TOutputIterator transform_if(TInputIterator1 i_begin1,
|
||||
TInputIterator1 i_end1,
|
||||
TInputIterator2 i_begin2,
|
||||
TOutputIterator o_begin,
|
||||
TBinaryFunction function,
|
||||
TBinaryPredicate predicate)
|
||||
____________________________________________________________________________________________________
|
||||
transform_n_if
|
||||
ETL extension
|
||||
Transforms data from the source based on a predicate for 'n' items.
|
||||
If the predicate returns true then the source data if modified by function and stored in the output range.
|
||||
If the predicate returns false then the source data is ignored.
|
||||
|
||||
One input range.
|
||||
template <typename TInputIterator,
|
||||
typename TSize,
|
||||
typename TOutputIterator,
|
||||
typename TUnaryFunction,
|
||||
typename TUnaryPredicate>
|
||||
TOutputIterator transform_if(TInputIterator i_begin,
|
||||
TSize n,
|
||||
TOutputIterator o_begin,
|
||||
TUnaryFunction function,
|
||||
TUnaryPredicate predicate)
|
||||
____________________________________________________________________________________________________
|
||||
Two input ranges.
|
||||
template <typename TInputIterator1,
|
||||
typename TInputIterator2,
|
||||
typename TSize,
|
||||
typename TOutputIterator,
|
||||
typename TBinaryFunction,
|
||||
typename TBinaryPredicate>
|
||||
TOutputIterator transform_if(TInputIterator1 i_begin1,
|
||||
TSize n,
|
||||
TInputIterator2 i_begin2,
|
||||
TOutputIterator o_begin,
|
||||
TBinaryFunction function,
|
||||
TBinaryPredicate predicate)
|
||||
____________________________________________________________________________________________________
|
||||
shell_sort
|
||||
ETL extension
|
||||
Sorts a range using the shell sort algorithm.
|
||||
|
||||
template <typename TIterator>
|
||||
void shell_sort(TIterator first, TIterator last)
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TIterator, typename TCompare>
|
||||
void shell_sort(TIterator first, TIterator last, TCompare compare)
|
||||
|
||||
https://en.wikipedia.org/wiki/Shellsort
|
||||
____________________________________________________________________________________________________
|
||||
insertion_sort
|
||||
ETL extension
|
||||
Sorts a range using the insertion sort algorithm.
|
||||
|
||||
template <typename TIterator>
|
||||
void insertion_sort(TIterator first, TIterator last)
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TIterator, typename TCompare>
|
||||
void insertion_sort(TIterator first, TIterator last, TCompare compare)
|
||||
|
||||
https://en.wikipedia.org/wiki/Insertion_sort
|
||||
____________________________________________________________________________________________________
|
||||
heap_sort
|
||||
ETL extension
|
||||
16.2.0
|
||||
Sorts a range using the heap sort algorithm.
|
||||
|
||||
template <typename TIterator>
|
||||
void heap_sort(TIterator first, TIterator last)
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TIterator, typename TCompare>
|
||||
void heap_sort(TIterator first, TIterator last, TCompare compare)
|
||||
|
||||
https://en.wikipedia.org/wiki/Heapsort
|
||||
____________________________________________________________________________________________________
|
||||
selection_sort
|
||||
ETL extension
|
||||
20.7.0
|
||||
Sorts a range using the selection sort algorithm.
|
||||
|
||||
template <typename TIterator>
|
||||
void selection_sort(TIterator first, TIterator last)
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TIterator, typename TCompare>
|
||||
void selection_sort(TIterator first, TIterator last, TCompare compare)
|
||||
|
||||
https://en.wikipedia.org/wiki/Selectionsort
|
||||
____________________________________________________________________________________________________
|
||||
sort
|
||||
Sorts a range.
|
||||
|
||||
template <typename TIterator>
|
||||
void sort(TIterator first, TIterator last)
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TIterator, typename TCompare>
|
||||
void sort(TIterator first, TIterator last, TCompare compare)
|
||||
|
||||
If ETL_NO_STL is defined then uses etl::shell_sort, otherwise calls std::sort.
|
||||
|
||||
https://en.cppreference.com/w/cpp/algorithm/sort
|
||||
____________________________________________________________________________________________________
|
||||
stable_sort
|
||||
Stable sorts a range.
|
||||
|
||||
template <typename TIterator>
|
||||
void stable_sort(TIterator first, TIterator last)
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TIterator, typename TCompare>
|
||||
void stable_sort(TIterator first, TIterator last, TCompare compare)
|
||||
|
||||
If ETL_NO_STL is defined then uses etl::insertion_sort, otherwise calls std::stable_sort.
|
||||
|
||||
https://en.cppreference.com/w/cpp/algorithm/stable_sort
|
||||
____________________________________________________________________________________________________
|
||||
is_sorted
|
||||
Returns true is the range is sorted
|
||||
|
||||
template <typename TIterator>
|
||||
bool is_sorted(TIterator begin, TIterator end)
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
template <typename TIterator, typename TCompare>
|
||||
bool is_sorted(TIterator begin, TIterator end, TCompare compare)
|
||||
|
||||
https://en.cppreference.com/w/cpp/algorithm/is_sorted
|
||||
____________________________________________________________________________________________________
|
||||
is_sorted_until
|
||||
Returns an iterator the first element that is not sorted
|
||||
|
||||
template <typename TIterator>
|
||||
TIterator is_sorted_until(TIterator begin, TIterator end)
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TIterator, typename TCompare>
|
||||
TIterator is_sorted_until(TIterator begin, TIterator end, TCompare compare)
|
||||
|
||||
https://en.cppreference.com/w/cpp/algorithm/is_sorted_until
|
||||
____________________________________________________________________________________________________
|
||||
clamp
|
||||
Clamps a value between two limits.
|
||||
|
||||
template <typename T, typename TCompare>
|
||||
ETL_CONSTEXPR const T& clamp(const T& value, const T& low, const T& high, TCompare compare)
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR const T& clamp(const T& value, const T& low, const T& high )
|
||||
____________________________________________________________________________________________________
|
||||
accumulate
|
||||
Reverse engineered std::accumulate
|
||||
|
||||
template <typename TIterator, typename T>
|
||||
ETL_CONSTEXPR14 T accumulate(TIterator first, TIterator last, T sum)
|
||||
|
||||
template <typename TIterator, typename T, typename TBinaryOperation>
|
||||
ETL_CONSTEXPR14 T accumulate(TIterator first, TIterator last, T sum, TBinaryOperation operation)
|
||||
____________________________________________________________________________________________________
|
||||
remove
|
||||
template <typename TIterator, typename T>
|
||||
TIterator remove(TIterator first, TIterator last, const T& value)
|
||||
Removes all elements that are equal to value.
|
||||
____________________________________________________________________________________________________
|
||||
remove_if
|
||||
template <typename TIterator, typename TUnaryPredicate>
|
||||
TIterator remove_if(TIterator first, TIterator last, TPredicate predicate)
|
||||
Removes all elements that satisfy the predicate.
|
||||
|
||||
103
docs/raw/utilities/Alignment.txt
Normal file
103
docs/raw/utilities/Alignment.txt
Normal file
@ -0,0 +1,103 @@
|
||||
Alignment
|
||||
A way of aligning memory storage through template parameters.
|
||||
____________________________________________________________________________________________________
|
||||
type_with_alignment
|
||||
Returns a fundamental type that has the same alignment as that specified in the template parameter.
|
||||
|
||||
template <const size_t ALIGNMENT>
|
||||
class type_with_alignment
|
||||
|
||||
Example
|
||||
typedef etl::type_with_alignment<4>::type type_t;
|
||||
____________________________________________________________________________________________________
|
||||
aligned_storage
|
||||
Creates a memory store of the specified length at the specified alignment.
|
||||
|
||||
template <const size_t LENGTH, const size_t ALIGNMENT>
|
||||
struct aligned_storage;
|
||||
|
||||
Example
|
||||
// Creates aligned storage of length 100 at an alignment of 8.
|
||||
etl::aligned_storage<100, 8>::type storage;
|
||||
|
||||
The class defines various conversion operators for ease of use.
|
||||
|
||||
Conversions are supplied to T&, const T&, T*, const T*, plus explicit get_address and get_reference member functions.
|
||||
____________________________________________________________________________________________________
|
||||
aligned_storage_as
|
||||
Creates a memory store of the specified length at the same alignment as the specified type.
|
||||
|
||||
template <const size_t LENGTH, typename T>
|
||||
struct aligned_storage_as;
|
||||
|
||||
Example
|
||||
// Creates aligned storage of length 100 at an alignment of a double.
|
||||
etl::aligned_storage_as<100, double>::type storage;
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
typed_storage
|
||||
20.40.1
|
||||
|
||||
template <typename T>
|
||||
class typed_storage;
|
||||
Wrapper class that provides a memory area and lets the user create an instance of T in this memory at runtime.
|
||||
This class also erases the destructor call of T, i.e. if typed_storage goes out of scope, the destructor if the wrapped type will not be called. This can be done explicitly by calling destroy().
|
||||
|
||||
T value_type
|
||||
T& reference
|
||||
const T& const_reference
|
||||
T* pointer
|
||||
const T* const_pointer
|
||||
|
||||
typed_storage()
|
||||
Constructor
|
||||
|
||||
~typed_storage() = default;
|
||||
Defaulted destructor which will NOT call the destructor of the object which was created by calling create().
|
||||
____________________________________________________________________________________________________
|
||||
void destroy()
|
||||
Calls the destructor of the wrapped object and asserts if has_value() is false.
|
||||
____________________________________________________________________________________________________
|
||||
bool has_value() const
|
||||
Returns true if object has been constructed using create().
|
||||
Returns false otherwise.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename... Args>
|
||||
reference create(Args&&... args)
|
||||
Constructs the instance of T forwarding the given args to its constructor and asserts etl::typed_storage_error if has_value() is false.
|
||||
Returns the instance of T which has been constructed in the internal byte array.
|
||||
____________________________________________________________________________________________________
|
||||
pointer operator->()
|
||||
Returns a pointer of type T and asserts etl::typed_storage_error if has_value() is false.
|
||||
|
||||
const_pointer operator->() const
|
||||
Returns a const pointer of type T and asserts etl::typed_storage_error if has_value() is false.
|
||||
____________________________________________________________________________________________________
|
||||
reference operator*()
|
||||
Returns reference of type T and asserts if etl::typed_storage_error if has_value() is false.
|
||||
|
||||
const_reference operator*() const
|
||||
Returns const reference of type T and asserts etl::typed_storage_error if has_value() is false.
|
||||
____________________________________________________________________________________________________
|
||||
is_aligned
|
||||
20.35.12
|
||||
|
||||
bool is_aligned(void* p, size_t alignment)
|
||||
Check that p has alignment
|
||||
____________________________________________________________________________________________________
|
||||
template <size_t Alignment>
|
||||
bool is_aligned(void* p)
|
||||
Check that p has Alignment
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T>
|
||||
bool is_aligned(void* p)
|
||||
Check that p has the alignment of T
|
||||
____________________________________________________________________________________________________
|
||||
alignment_exception
|
||||
20.35.12
|
||||
Exception base for alignment
|
||||
____________________________________________________________________________________________________
|
||||
alignment_error
|
||||
20.35.12
|
||||
Memory misalignment exception.
|
||||
|
||||
13
docs/raw/utilities/Atomic.txt
Normal file
13
docs/raw/utilities/Atomic.txt
Normal file
@ -0,0 +1,13 @@
|
||||
Atomic
|
||||
This header attempts to replicate some of the types from std::atomic.
|
||||
|
||||
If ETL_CPP11_SUPPORTED is defined as 1 in the profile then etl::atomic will be defined in terms of std::atomic.
|
||||
Otherwise it will be implemented in terms of the built-in support, if available, from the compiler. For example, early GCC and Arm compilers will use the __sync built-ins.
|
||||
|
||||
If a type cannot be handled by the built-ins then the types are wrapped by etl::mutex.
|
||||
|
||||
If there is an ETL atomic type available for your platform then ETL_HAS_ATOMIC will be set to 1, otherwise
|
||||
it will be set to 0.
|
||||
|
||||
From 20.40.0 etl::atomic supports the is_always_lock_free property.
|
||||
|
||||
380
docs/raw/utilities/Binary.txt
Normal file
380
docs/raw/utilities/Binary.txt
Normal file
@ -0,0 +1,380 @@
|
||||
Binary
|
||||
Utility functions for manipulating binary numbers.
|
||||
|
||||
ETL_CONSTEXPR = constexpr for C++11 or above
|
||||
ETL_CONSTEXPR14 = constexpr for C++14 or above
|
||||
____________________________________________________________________________________________________
|
||||
Rotate
|
||||
Rotate the bits in the value left or right.
|
||||
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR14 T rotate_left(T value)
|
||||
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR14 T rotate_left(T value, size_t distance)
|
||||
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR14 T rotate_right(T value)
|
||||
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR14 T rotate_right(T value, size_t distance)
|
||||
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR14 T rotate(T value, typename etl::make_signed<size_t>::type distance)
|
||||
____________________________________________________________________________________________________
|
||||
Reverse bits
|
||||
Reverse the order of the bits in a value.
|
||||
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR14 T reverse_bits(T value)
|
||||
|
||||
The structures below define a member constant value that is Value reversed in bits.
|
||||
template <int8_t Value>
|
||||
struct reverse_bits_const<int8_t, Value>
|
||||
|
||||
template <uint8_t Value>
|
||||
struct reverse_bits_const<uint8_t, Value>
|
||||
|
||||
template <int16_t Value>
|
||||
struct reverse_bits_const<int16_t, Value>
|
||||
|
||||
template <uint16_t Value>
|
||||
struct reverse_bits_const<uint16_t, Value>
|
||||
|
||||
template <int32_t Value>
|
||||
struct reverse_bits_const<int32_t, Value>
|
||||
|
||||
template <uint32_t Value>
|
||||
struct reverse_bits_const<uint32_t, Value>
|
||||
|
||||
template <int64_t Value>
|
||||
struct reverse_bits_const<int64_t, Value>
|
||||
|
||||
template <uint64_t Value>
|
||||
struct reverse_bits_const<uint64_t, Value>
|
||||
|
||||
Defines value The reversed bits.
|
||||
____________________________________________________________________________________________________
|
||||
Reverse bytes
|
||||
Reverse the order of the bytes in a value.
|
||||
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR T reverse_bytes(T value)
|
||||
____________________________________________________________________________________________________
|
||||
Gray to binary
|
||||
Converts a gray code value to binary.
|
||||
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR14 T gray_to_binary(T value)
|
||||
____________________________________________________________________________________________________
|
||||
Binary to gray
|
||||
Converts a binary value to the gray code equivalent.
|
||||
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR T binary_to_gray(T value)
|
||||
____________________________________________________________________________________________________
|
||||
Count bits
|
||||
Counts the number of set bits in a value.
|
||||
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR14 T count_bits(T value)
|
||||
____________________________________________________________________________________________________
|
||||
Parity
|
||||
Returns 1 if the parity of the value is odd, 0 if it is even.
|
||||
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR14 T parity(T value)
|
||||
____________________________________________________________________________________________________
|
||||
Max value for N bits
|
||||
Returns maximum unsigned value a particular number of bits can represent.
|
||||
|
||||
template <size_t NBits>
|
||||
struct max_value_for_nbits
|
||||
|
||||
value_type The type for the value.
|
||||
value The maximum value.
|
||||
____________________________________________________________________________________________________
|
||||
Fold bits
|
||||
Fold a binary number down to a set number of bits using XOR.
|
||||
|
||||
template <typename TReturn, size_t NBits, typename TValue>
|
||||
ETL_CONSTEXPR14 TReturn fold_bits(TValue value)
|
||||
|
||||
Example
|
||||
0xE8C9AACCBC3D9A8F folded down to 20 bits = 0x998E8
|
||||
|
||||
uint32_t result = etl::fold_bits<uint32_t, 20>(0xE8C9AACCBC3D9A8F);
|
||||
____________________________________________________________________________________________________
|
||||
Sign extend
|
||||
Sign extends a binary number.
|
||||
|
||||
template <typename TReturn, const size_t NBits, typename TValue>
|
||||
ETL_CONSTEXPR14 TReturn sign_extend(TValue value)
|
||||
|
||||
Converts an N bit binary number, where bit N-1 is the sign bit, to a signed integral type.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
template <typename TReturn, const size_t NBits, const size_t Shift, typename TValue>
|
||||
ETL_CONSTEXPR14 TReturn sign_extend(TValue value)
|
||||
|
||||
Converts an N bit binary number, where bit N-1 is the sign bit, and SHIFT is the right shift amount, to a signed integral type.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
template <typename TReturn, typename TValue>
|
||||
ETL_CONSTEXPR14 TReturn sign_extend(TValue value, size_t nbits)
|
||||
|
||||
Converts an N bit binary number, where bit N-1 is the sign bit, to a signed integral type.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
template <typename TReturn, typename TValue>
|
||||
ETL_CONSTEXPR14 TReturn sign_extend(TValue value, size_t nbits, size_t shift)
|
||||
|
||||
Converts an N bit binary number, where bit N-1 is the sign bit, and shift is the right shift amount, to a signed integral type.
|
||||
____________________________________________________________________________________________________
|
||||
Count leading zeros
|
||||
Counts the number of leading zeros in a binary number
|
||||
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR14 T count_leading_zeros(T value)
|
||||
____________________________________________________________________________________________________
|
||||
Count trailing zeros
|
||||
Counts the number of trailing zeros in a binary number
|
||||
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR14 T count_trailing_zeros(T value)
|
||||
____________________________________________________________________________________________________
|
||||
Count leading ones
|
||||
Counts the number of leading ones in a binary number
|
||||
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR14 T count_leading_ones(T value)
|
||||
____________________________________________________________________________________________________
|
||||
Count trailing ones
|
||||
Counts the number of trailing ones in a binary number
|
||||
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR14 T count_trailing_ones(T value)
|
||||
____________________________________________________________________________________________________
|
||||
First set position
|
||||
Finds the index of the first set bit from lsb.
|
||||
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR14 uint_least8_t first_set_bit_position(T value)
|
||||
____________________________________________________________________________________________________
|
||||
First clear position
|
||||
Finds the index of the first clear bit from lsb.
|
||||
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR14 uint_least8_t first_clear_bit_position(T value)
|
||||
____________________________________________________________________________________________________
|
||||
First position of bit in the specified state
|
||||
Finds the index of the first bit in the specified state, from lsb.
|
||||
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR14 uint_least8_t first_bit_position(bool state, T value)
|
||||
____________________________________________________________________________________________________
|
||||
Fill a binary value with a pattern
|
||||
Fills a value of the specified width with a repeating binary pattern.
|
||||
|
||||
Run time
|
||||
template <typename TResult, typename TValue>
|
||||
ETL_CONSTEXPR TResult binary_fill(TValue value)
|
||||
|
||||
Generate 0x12121212
|
||||
etl::binary_fill<uint32_t>(uint8_t(0x12));
|
||||
|
||||
Partial compile time
|
||||
template <typename TResult, typename TValue, TValue N>
|
||||
ETL_CONSTEXPR TResult binary_fill(TValue value)
|
||||
|
||||
Generate 0x12121212
|
||||
etl::binary_fill<uint32_t, uint8_t, 0x12>();
|
||||
____________________________________________________________________________________________________
|
||||
Check a binary value for a zero byte
|
||||
Checks to see if a value contains a byte of value zero.
|
||||
|
||||
Run time
|
||||
template <typename TValue>
|
||||
ETL_CONSTEXPR14 bool has_zero_byte(const TValue value)
|
||||
|
||||
etl::has_zero_byte(uint32_t(0x01234567)) == false
|
||||
etl::has_zero_byte(uint32_t(0x01230067)) == true
|
||||
____________________________________________________________________________________________________
|
||||
Check a binary value for a particular value byte
|
||||
Checks to see if a value contains a byte of a particular value.
|
||||
|
||||
Run time
|
||||
template <typename TValue>
|
||||
ETL_CONSTEXPR14 bool has_byte_n(TValue value, uint8_t n)
|
||||
|
||||
etl::has_byte_n(uint32_t(0x01234567), 0x12) == false
|
||||
etl::has_byte_n(uint32_t(0x01234567), 0x45) == true
|
||||
|
||||
Partial compile time
|
||||
template <typename TValue, TValue N>
|
||||
ETL_CONSTEXPR14 bool has_byte_n(TValue value)
|
||||
|
||||
etl::has_byte_n<0x12>(uint32_t(0x01234567)) == false
|
||||
etl::has_byte_n<0x45>(uint32_t(0x01234567)) == true
|
||||
____________________________________________________________________________________________________
|
||||
Merge two values
|
||||
Merges two binary values according to a mask.
|
||||
Bits set in the mask select bits in the first value, clear bits select those in the second.
|
||||
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR T binary_merge(T first, T second, T mask)
|
||||
|
||||
uint8_t first = 0x12;
|
||||
uint8_t second = 0x34;
|
||||
|
||||
const uint8_t mask = 0xF0;
|
||||
|
||||
etl::binary_merge(first, second, mask) Equals 0x14
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T, T Mask>
|
||||
ETL_CONSTEXPR T binary_merge(T first, T second)
|
||||
|
||||
uint8_t first = 0x12;
|
||||
uint8_t second = 0x34;
|
||||
|
||||
const uint8_t mask = 0xF0;
|
||||
|
||||
etl::binary_merge<uint8_t, mask>(first, second) Equals 0x14
|
||||
____________________________________________________________________________________________________
|
||||
Interleave two values
|
||||
Interleaves two values such that bits abcd and efgh will result in eafbgchd.
|
||||
|
||||
ETL_CONSTEXPR14 uint16_t binary_interleave(uint8_t first, uint8_t second);
|
||||
ETL_CONSTEXPR14 int16_t binary_interleave(int8_t first, int8_t second);
|
||||
ETL_CONSTEXPR14 uint32_t binary_interleave(uint16_t first, uint16_t second);
|
||||
ETL_CONSTEXPR14 int32_t binary_interleave(int16_t first, int16_t second);
|
||||
ETL_CONSTEXPR14 uint64_t binary_interleave(uint32_t first, uint32_t second);
|
||||
ETL_CONSTEXPR14 int64_t binary_interleave(int32_t first, int32_t second);
|
||||
____________________________________________________________________________________________________
|
||||
Odd / Even
|
||||
Determines the odd or evenness of a value.
|
||||
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR bool is_odd(T value)
|
||||
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR bool is_even(T value);
|
||||
____________________________________________________________________________________________________
|
||||
Constants
|
||||
enum binary_constant
|
||||
|
||||
An enumeration of 256 constants from b00000000 to b11111111 (0 to 255)
|
||||
|
||||
enum bit_constant
|
||||
|
||||
An enumeration of 32 constants from b0 to b31 (1 to 4294967296)
|
||||
|
||||
template <size_t Position>
|
||||
struct bit
|
||||
|
||||
value_type The type of the value.
|
||||
value The value of the bit at POSITION.
|
||||
____________________________________________________________________________________________________
|
||||
Creating bit masks
|
||||
These classes and constexpr functions help create lsb and msb masks.
|
||||
|
||||
template <typename T, size_t NBits>
|
||||
class lsb_mask;
|
||||
Defines the member constant value as a binary value of NBits '1' shift to the LSB.
|
||||
e.g. lsb_mask<int8_t, 3>::value == 0b00000111
|
||||
20.34.0
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR T make_lsb_mask(size_t nbits)
|
||||
Returns a binary value of nbits '1' shift to the LSB.
|
||||
e.g. make_lsb_mask<int8_t>(3) == 0b00000111
|
||||
20.34.0
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T, size_t NBits>
|
||||
ETL_CONSTEXPR T make_lsb_mask()
|
||||
Returns a binary value of nbits '1' shift to the LSB.
|
||||
e.g. make_lsb_mask<int8_t, 3>() == 0b00000111
|
||||
20.38.7
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T, size_t NBits>
|
||||
class msb_mask;
|
||||
Returns a binary value of nbits '1' shift to the MSB.
|
||||
msb_mask<int8_t, 3>::value == 0b11100000
|
||||
20.34.0
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR T make_msb_mask(size_t nbits)
|
||||
Defines the member constant value as a binary value of NBits '1' shift to the MSB.
|
||||
e.g. make_msb_mask<int8_t>(3) == 0b11100000
|
||||
20.34.0
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T, size_t NBits>
|
||||
ETL_CONSTEXPR T make_msb_mask()
|
||||
Defines the member constant value as a binary value of NBits '1' shift to the MSB.
|
||||
e.g. make_msb_mask<int8_t, 3>() == 0b11100000
|
||||
20.38.7
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
Bit manipulation functors
|
||||
These functors are most useful where lambdas are not available.
|
||||
____________________________________________________________________________________________________
|
||||
binary_not
|
||||
template <typename T>
|
||||
struct binary_not : public etl::unary_function<T, T>;
|
||||
20.38.11
|
||||
____________________________________________________________________________________________________
|
||||
ETL_CONTEXPR
|
||||
binary_not()
|
||||
Default constructor.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_CONTEXPR
|
||||
ETL_NODISCARD
|
||||
T operator(T value)
|
||||
Returns ~value.
|
||||
____________________________________________________________________________________________________
|
||||
binary_and
|
||||
template <typename T>
|
||||
struct binary_and : public etl::unary_function<T, T>;
|
||||
20.38.11
|
||||
____________________________________________________________________________________________________
|
||||
ETL_CONTEXPR
|
||||
binary_and(T and_value)
|
||||
Constructor.
|
||||
Uses and_value as the second parameter in operator().
|
||||
____________________________________________________________________________________________________
|
||||
ETL_CONTEXPR
|
||||
ETL_NODISCARD
|
||||
T operator(T value)
|
||||
Returns value & and_value.
|
||||
____________________________________________________________________________________________________
|
||||
binary_or
|
||||
template <typename T>
|
||||
struct binary_or : public etl::unary_function<T, T>;
|
||||
20.38.11
|
||||
____________________________________________________________________________________________________
|
||||
ETL_CONTEXPR
|
||||
binary_and(T or_value)
|
||||
Constructor.
|
||||
Uses or_value as the second parameter in operator().
|
||||
____________________________________________________________________________________________________
|
||||
ETL_CONTEXPR
|
||||
ETL_NODISCARD
|
||||
T operator(T value)
|
||||
Returns value | or_value.
|
||||
____________________________________________________________________________________________________
|
||||
binary_xor
|
||||
template <typename T>
|
||||
struct binary_xor : public etl::unary_function<T, T>;
|
||||
20.38.11
|
||||
____________________________________________________________________________________________________
|
||||
ETL_CONTEXPR
|
||||
binary_xor(T xor_value)
|
||||
Constructor.
|
||||
Uses xor_value as the second parameter in operator().
|
||||
____________________________________________________________________________________________________
|
||||
ETL_CONTEXPR
|
||||
ETL_NODISCARD
|
||||
T operator(T value)
|
||||
Returns value ^ xor_value.
|
||||
|
||||
|
||||
72
docs/raw/utilities/Bit.txt
Normal file
72
docs/raw/utilities/Bit.txt
Normal file
@ -0,0 +1,72 @@
|
||||
Bit
|
||||
Utility functions for manipulating binary numbers.
|
||||
A reverse engineered version of C++20's and C++23's <bit> header.
|
||||
|
||||
ETL_CONSTEXPR14 = constexpr for C++14 or above
|
||||
____________________________________________________________________________________________________
|
||||
bit_cast
|
||||
template <typename TDestination, typename TSource>>
|
||||
ETL_CONSTEXPR14 TDestination bit_cast(const TSource& source) ETL_NOEXCEPT
|
||||
Returns a value of type TDestination by reinterpreting the TSource object.
|
||||
____________________________________________________________________________________________________
|
||||
byteswap
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR14 T byteswap(T n) ETL_NOEXCEPT
|
||||
Reverses the bytes in n.
|
||||
____________________________________________________________________________________________________
|
||||
has_single_bit
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR14 bool has_single_bit(T n) ETL_NOEXCEPT
|
||||
Checks if n is a power of two, or has one bit set.
|
||||
____________________________________________________________________________________________________
|
||||
bit_ceil
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR14 T bit_ceil(T n);
|
||||
Calculates the smallest power of two, that is not smaller than n.
|
||||
____________________________________________________________________________________________________
|
||||
bit_floor
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR14 T bit_floor(T n) ETL_NOEXCEPT
|
||||
Calculates the smallest power of two, that is not greater than n.
|
||||
____________________________________________________________________________________________________
|
||||
bit_width
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR14 T bit_width(T n) ETL_NOEXCEPT
|
||||
If n is not 0, calculates the number of bits needed to store it.
|
||||
If n is 0, then the result is 0.
|
||||
____________________________________________________________________________________________________
|
||||
rotl
|
||||
template <typename T>
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 T rotl(T value, int n) ETL_NOEXCEPT
|
||||
Computes a left circular shift of value by n.
|
||||
____________________________________________________________________________________________________
|
||||
rotr
|
||||
template <typename T>
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 T rotr(T value, int n) ETL_NOEXCEPT
|
||||
Computes a right circular shift of value by n.
|
||||
____________________________________________________________________________________________________
|
||||
countl_zero
|
||||
template <typename T>
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 int countl_zero(T value) ETL_NOEXCEPT
|
||||
Returns the number of consecutive 0 bits in n, starting from the most significant bit (left).
|
||||
____________________________________________________________________________________________________
|
||||
countl_one
|
||||
template <typename T>
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 int countl_one(T value) ETL_NOEXCEPT
|
||||
Returns the number of consecutive 1 bits in n, starting from the most significant bit (left).
|
||||
____________________________________________________________________________________________________
|
||||
countr_zero
|
||||
template <typename T>
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 int countr_zero(T value) ETL_NOEXCEPT
|
||||
Returns the number of consecutive 0 bits in n, starting from the least significant bit (right).
|
||||
____________________________________________________________________________________________________
|
||||
countr_one
|
||||
template <typename T>
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 int countr_one(T value) ETL_NOEXCEPT
|
||||
Returns the number of consecutive 1 bits in n, starting from the least significant bit (right).
|
||||
____________________________________________________________________________________________________
|
||||
popcount
|
||||
template <typename T>
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 int popcount(T value) ETL_NOEXCEPT
|
||||
Counts the number of 1 bits in an unsigned integer.
|
||||
|
||||
90
docs/raw/utilities/ETL Traits.txt
Normal file
90
docs/raw/utilities/ETL Traits.txt
Normal file
@ -0,0 +1,90 @@
|
||||
ETL Traits
|
||||
|
||||
A set of traits that reflect the platform settings. It gives a C++ style interface to the library macros.
|
||||
The traits are accessed under the etl::traits namespace.
|
||||
All traits are constexpr for C++11 and above, const for C++03 and below.
|
||||
____________________________________________________________________________________________________
|
||||
Trait Type Defined Macro
|
||||
using_stl bool platform.h ETL_USING_STL
|
||||
using_stlport bool platform.h ETL_USING_STLPORT
|
||||
using_cpp11 bool platform.h ETL_USING_CPP11
|
||||
using_cpp14 bool platform.h ETL_USING_CPP14
|
||||
using_cpp17 bool platform.h ETL_USING_CPP17
|
||||
using_cpp20 bool platform.h ETL_USING_CPP20
|
||||
using_cpp23 bool platform.h ETL_USING_CPP23
|
||||
cplusplus long builtin __cplusplus
|
||||
language_standard int platform.h ETL_LANGUAGE_STANDARD
|
||||
using_exceptions bool platform.h ETL_USING_EXCEPTIONS
|
||||
using_gcc_compiler bool platform.h ETL_USING_GCC_COMPILER
|
||||
using_microsoft_compiler bool platform.h ETL_USING_MICROSOFT_COMPILER
|
||||
using_arm5_compiler bool platform.h ETL_USING_ARM5_COMPILER
|
||||
using_arm6_compiler bool platform.h ETL_USING_ARM6_COMPILER
|
||||
using_arm7_compiler bool platform.h ETL_USING_ARM7_COMPILER
|
||||
using_clang_compiler bool platform.h ETL_USING_CLANG_COMPILER
|
||||
using_green_hills_compiler bool platform.h ETL_USING_GREEN_HILLS_COMPILER
|
||||
using_iar_compiler bool platform.h ETL_USING_IAR_COMPILER
|
||||
using_intel_compiler bool platform.h ETL_USING_INTEL_COMPILER
|
||||
using_texas_instruments_compiler bool platform.h ETL_USING_TEXAS_INSTRUMENTS_COMPILER
|
||||
using_builtin_is_assignable bool platform.h ETL_USING_BUILTIN_IS_ASSIGNABLE
|
||||
using_builtin_is_constructible bool platform.h ETL_USING_BUILTIN_IS_CONSTRUCTIBLE
|
||||
using_builtin_is_trivially_constructible bool platform.h ETL_USING_BUILTIN_IS_TRIVIALLY_CONSTRUCTIBLE
|
||||
using_builtin_is_trivially_destructible bool platform.h ETL_USING_BUILTIN_IS_TRIVIALLY_DESTRUCTIBLE
|
||||
using_builtin_is_trivially_copyable bool platform.h ETL_USING_BUILTIN_IS_TRIVIALLY_COPYABLE
|
||||
using_builtin_underlying_type bool platform.h ETL_USING_BUILTIN_UNDERLYING_TYPE
|
||||
using_builtin_memcpy bool platform.h ETL_USING_BUILTIN_MEMCPY
|
||||
using_builtin_memmove bool platform.h ETL_USING_BUILTIN_MEMMOVE
|
||||
using_builtin_memset bool platform.h ETL_USING_BUILTIN_MEMSET
|
||||
using_builtin_memcmp bool platform.h ETL_USING_BUILTIN_MEMCMP
|
||||
using_builtin_memchr bool platform.h ETL_USING_BUILTIN_MEMCHR
|
||||
using_generic_compiler bool platform.h ETL_USING_GENERIC_COMPILER
|
||||
has_8bit_types bool platform.h ETL_USING_8BIT_TYPES
|
||||
has_64bit_types bool platform.h ETL_USING_64BIT_TYPES
|
||||
has_atomic bool platform.h ETL_HAS_ATOMIC
|
||||
has_mutex bool mutex.h ETL_HAS_MUTEX
|
||||
has_nullptr bool platform.h ETL_HAS_NULLPTR
|
||||
has_char8_t bool platform.h ETL_HAS_CHAR8_T
|
||||
has_native_char8_t bool platform.h ETL_HAS_NATIVE_CHAR8_T
|
||||
has_native_char16_t bool platform.h ETL_HAS_NATIVE_CHAR16_T
|
||||
has_native_char32_t bool platform.h ETL_HAS_NATIVE_CHAR32_T
|
||||
has_string_truncation_checks bool platform.h ETL_HAS_STRING_TRUNCATION_CHECKS
|
||||
has_error_on_string_truncation bool platform.h ETL_HAS_ERROR_ON_STRING_TRUNCATION
|
||||
has_string_clear_after_use bool platform.h ETL_HAS_STRING_CLEAR_AFTER_USE
|
||||
has_istring_repair bool platform.h ETL_HAS_ISTRING_REPAIR
|
||||
has_ivector_repair bool platform.h ETL_HAS_IVECTOR_REPAIR
|
||||
has_mutable_array_view bool platform.h ETL_HAS_MUTABLE_ARRAY_VIEW
|
||||
has_ideque_repair bool platform.h ETL_HAS_IDEQUE_REPAIR
|
||||
has_initializer_list bool platform.h ETL_HAS_INITIALIZER_LIST
|
||||
is_debug_build bool platform.h ETL_IS_DEBUG_BUILD
|
||||
version long version.h ETL_VERSION_VALUE
|
||||
version_major long version.h ETL_VERSION_MAJOR
|
||||
version_minor long version.h ETL_VERSION_MINOR
|
||||
version_patch long version.h ETL_VERSION_PATCH
|
||||
version_string const char* version.h ETL_VERSION
|
||||
version_wstring const wchar_t* version.h ETL_VERSION_W
|
||||
version_u8string const char8_t* version.h ETL_VERSION_U8 if has_native_char8_t
|
||||
version_u16string const char16_t* version.h ETL_VERSION_U16
|
||||
version_u32string const char32_t* version.h ETL_VERSION_U32
|
||||
____________________________________________________________________________________________________
|
||||
Examples
|
||||
|
||||
if constexpr(etl::traits::is_debug_build)
|
||||
{
|
||||
std::cerr << etl::traits::version_string;
|
||||
}
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
template <bool Has_Atomic = etl::traits::has_atomic>
|
||||
class Controller;
|
||||
|
||||
template<>
|
||||
class Controller<false>
|
||||
{
|
||||
etl::mutex lock;
|
||||
};
|
||||
|
||||
template<>
|
||||
class Controller<true>
|
||||
{
|
||||
etl::atomic_int lock;
|
||||
};
|
||||
|
||||
12
docs/raw/utilities/ETL_STATIC_ASSERT.txt
Normal file
12
docs/raw/utilities/ETL_STATIC_ASSERT.txt
Normal file
@ -0,0 +1,12 @@
|
||||
ETL_STATIC_ASSERT
|
||||
Either maps on to the built-in static_assert or supplies a suitable definition.
|
||||
|
||||
ETL_STATIC_ASSERT(condition, message);
|
||||
|
||||
Example
|
||||
template <typename T>
|
||||
void Do_This(T value)
|
||||
{
|
||||
ETL_STATIC_ASSERT(etl::is_integral<T>::value, "Not an integral type");
|
||||
}
|
||||
|
||||
61
docs/raw/utilities/Endian.txt
Normal file
61
docs/raw/utilities/Endian.txt
Normal file
@ -0,0 +1,61 @@
|
||||
Endian
|
||||
Constants & utilities for endianess
|
||||
|
||||
For endian specific integral types, see unaligned_type.
|
||||
|
||||
The values for endianness are dependant on the platform setup.
|
||||
|
||||
If ETL_ENDIAN_NATIVE is defined by the user, then
|
||||
etl::endian::little = 0
|
||||
etl::endian::big = 1
|
||||
|
||||
If ETL_ENDIAN_NATIVE is not defined by the user, then the ETL selects an appropriate definition.
|
||||
If ETL_CPP20_SUPPORTED == 1 and ETL_USING_STL == 1 then
|
||||
etl::endian::little = std::endian::little
|
||||
etl::endian::big = std::endian::big
|
||||
etl::endian::native = std::endian::native
|
||||
|
||||
else, if __BYTE_ORDER__ is defined then
|
||||
If __ORDER_LITTLE_ENDIAN__ is defined then
|
||||
etl::endian::little = __ORDER_LITTLE_ENDIAN__
|
||||
etl::endian::big = __ORDER_BIG_ENDIAN__
|
||||
etl::endian::native = __BYTE_ORDER__
|
||||
|
||||
else if __LITTLE_ENDIAN__ is defined
|
||||
etl::endian::little = __LITTLE_ENDIAN__
|
||||
etl::endian::big = __BIG_ENDIAN__
|
||||
etl::endian::native = __BYTE_ORDER__
|
||||
|
||||
else
|
||||
The user needs to define ETL_ENDIAN_NATIVE either as 0 for little endian or 1 for big endian.
|
||||
____________________________________________________________________________________________________
|
||||
endian
|
||||
|
||||
A smart enumeration defining little and big members.
|
||||
|
||||
etl::endian::little;
|
||||
etl::endian::big;
|
||||
____________________________________________________________________________________________________
|
||||
endianness
|
||||
|
||||
Interrogates the endianness of the platform.
|
||||
|
||||
etl::endian operator ()() const
|
||||
constexpr if ETL_CPP11_SUPPORTED == 1 and ETL_ENDIAN_NATIVE is defined.
|
||||
____________________________________________________________________________________________________
|
||||
operator etl::endian() const
|
||||
constexpr if ETL_CPP11_SUPPORTED == 1 and ETL_ENDIAN_NATIVE is defined.
|
||||
____________________________________________________________________________________________________
|
||||
static etl::endian value()
|
||||
constexpr if ETL_CPP11_SUPPORTED == 1 and ETL_ENDIAN_NATIVE is defined.
|
||||
____________________________________________________________________________________________________
|
||||
Host to network
|
||||
|
||||
template <typename T>
|
||||
T hton(T value)
|
||||
____________________________________________________________________________________________________
|
||||
Network to host
|
||||
|
||||
template <typename T>
|
||||
T ntoh(T value)
|
||||
|
||||
29
docs/raw/utilities/Exception.txt
Normal file
29
docs/raw/utilities/Exception.txt
Normal file
@ -0,0 +1,29 @@
|
||||
Exception
|
||||
The base class for all ETL exceptions.
|
||||
|
||||
Typedefs
|
||||
typedef string_type const char*;
|
||||
typedef numeric_type int;
|
||||
|
||||
Constructor
|
||||
exception(string_type reason, string_type file_name, numeric_type line_number);
|
||||
|
||||
Access
|
||||
string_type what() const;
|
||||
Gets the reason for the exception.
|
||||
|
||||
Example
|
||||
struct vector_full : public etl::exception
|
||||
{
|
||||
vector_full(string_type file_name, numeric_type line_number)
|
||||
: exception(ETL_ERROR_TEXT("Vector: full", "E123"), file_name, line_number)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
Usually error will be called via the ETL error macro.
|
||||
|
||||
ETL_ERROR(derived_exception_class)
|
||||
|
||||
See error_handler.h
|
||||
|
||||
303
docs/raw/utilities/Iterator.txt
Normal file
303
docs/raw/utilities/Iterator.txt
Normal file
@ -0,0 +1,303 @@
|
||||
Iterator
|
||||
A set of templates to more easily determine the properties of iterator types.
|
||||
____________________________________________________________________________________________________
|
||||
Iterator concepts
|
||||
|
||||
Input
|
||||
is_input_iterator<T>::value
|
||||
Is T an input iterator?
|
||||
|
||||
is_input_iterator_concept<T>::value
|
||||
Can T be used as an input iterator?
|
||||
____________________________________________________________________________________________________
|
||||
Output
|
||||
is_output_iterator<T>::value
|
||||
Is T an output iterator?
|
||||
|
||||
is_output_iterator_concept<T>::value
|
||||
Can T be used as an output iterator?
|
||||
____________________________________________________________________________________________________
|
||||
Forward
|
||||
is_forward_iterator<T>::value
|
||||
Is T a forward iterator?
|
||||
|
||||
is_forward_iterator_concept<T>::value
|
||||
Can T be used as an forward iterator?
|
||||
____________________________________________________________________________________________________
|
||||
Bidirectional
|
||||
is_bidirectional_iterator<T>::value
|
||||
Is T a bidirectional iterator?
|
||||
|
||||
is_bidirectional_iterator_concept<T>::value
|
||||
Can T be used as a bidirectional iterator?
|
||||
____________________________________________________________________________________________________
|
||||
Random
|
||||
is_random_iterator<T>::value
|
||||
Is T a random iterator?
|
||||
|
||||
is_random_iterator_concept<T>::value
|
||||
Can T be used as a random iterator?
|
||||
____________________________________________________________________________________________________
|
||||
Iterator tags
|
||||
|
||||
struct input_iterator_tag
|
||||
struct output_iterator_tag
|
||||
struct forward_iterator_tag
|
||||
struct bidirectional_iterator_tag
|
||||
struct random_access_iterator_tag
|
||||
____________________________________________________________________________________________________
|
||||
Iterator traits
|
||||
|
||||
template <typename TIterator>
|
||||
struct iterator_traits
|
||||
|
||||
Defined types
|
||||
iterator_category
|
||||
value_type
|
||||
difference_type
|
||||
pointer
|
||||
reference
|
||||
____________________________________________________________________________________________________
|
||||
advance
|
||||
|
||||
template <typename TIterator, typename TDistance>
|
||||
ETL_CONSTEXPR17 void advance(TIterator& itr, TDistance n)
|
||||
____________________________________________________________________________________________________
|
||||
prev
|
||||
|
||||
template<typename TIterator>
|
||||
ETL_CONSTEXPR17 TIterator prev(TIterator itr,
|
||||
typename etl::iterator_traits<TIterator>::difference_type n = 1)
|
||||
____________________________________________________________________________________________________
|
||||
next
|
||||
|
||||
template<typename TIterator>
|
||||
ETL_CONSTEXPR17 TIterator next(TIterator itr,
|
||||
typename etl::iterator_traits<TIterator>::difference_type n = 1)
|
||||
____________________________________________________________________________________________________
|
||||
distance
|
||||
|
||||
template<typename TIterator>
|
||||
ETL_CONSTEXPR17 typename std::iterator_traits<TIterator>::difference_type
|
||||
distance(TIterator first, TIterator last)
|
||||
____________________________________________________________________________________________________
|
||||
iterator
|
||||
A base class provided to simplify definitions of the required types for iterators.
|
||||
https://en.cppreference.com/w/cpp/iterator/iterator
|
||||
|
||||
template <typename TCategory,
|
||||
typename T,
|
||||
typename TDistance = ptrdiff_t,
|
||||
typename TPointer = T* ,
|
||||
typename TReference = T&>
|
||||
struct iterator
|
||||
|
||||
Defined types
|
||||
value_type
|
||||
difference_type
|
||||
pointer
|
||||
reference
|
||||
iterator_category
|
||||
____________________________________________________________________________________________________
|
||||
reverse_iterator
|
||||
An iterator adaptor that reverses the direction of a given iterator
|
||||
|
||||
template <typename TIterator>
|
||||
class reverse_iterator
|
||||
|
||||
Defined types
|
||||
iterator_category
|
||||
value_type
|
||||
iterator_type
|
||||
difference_type
|
||||
pointer
|
||||
reference
|
||||
____________________________________________________________________________________________________
|
||||
move_iterator
|
||||
An iterator adaptor that converts the value returned by the underlying iterator into an rvalue.
|
||||
C++11 or above.
|
||||
|
||||
template <typename TIterator>
|
||||
class move_iterator
|
||||
|
||||
Defined types
|
||||
iterator_category
|
||||
value_type
|
||||
iterator_type
|
||||
difference_type
|
||||
pointer
|
||||
reference
|
||||
____________________________________________________________________________________________________
|
||||
back_insert_iterator
|
||||
|
||||
Inserts using push_back.
|
||||
|
||||
template <typename TContainer>
|
||||
class back_insert_iterator
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TContainer>
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
etl::back_insert_iterator<TContainer> back_inserter(TContainer& container)
|
||||
____________________________________________________________________________________________________
|
||||
front_insert_iterator
|
||||
|
||||
Inserts using push_front.
|
||||
|
||||
template <typename TContainer>
|
||||
class front_insert_iterator
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TContainer>
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
etl::front_insert_iterator<TContainer> front_inserter(TContainer& container)
|
||||
____________________________________________________________________________________________________
|
||||
push_insert_iterator
|
||||
|
||||
Inserts using push.
|
||||
|
||||
template <typename TContainer>
|
||||
class push_insert_iterator
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TContainer>
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
etl::push_insert_iterator<TContainer> push_inserter(TContainer& container)
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
begin
|
||||
|
||||
template <typename TContainer>
|
||||
ETL_CONSTEXPR typename TContainer::iterator begin(TContainer& container)
|
||||
Get the 'begin' iterator of container.
|
||||
Enabled if ETL_NOT_USING_STL or ETL_CPP11_NOT_SUPPORTED.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TContainer>
|
||||
ETL_CONSTEXPR typename TContainer::const_iterator begin(const TContainer& container)
|
||||
Get the 'begin' const_iterator of container.
|
||||
Enabled if ETL_NOT_USING_STL or ETL_CPP11_NOT_SUPPORTED.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TContainer>
|
||||
ETL_CONSTEXPR typename TContainer::const_iterator cbegin(const TContainer& container)
|
||||
Get the 'begin' const_iterator of container.
|
||||
Enabled if ETL_NOT_USING_STL or ETL_CPP11_NOT_SUPPORTED.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TValue, size_t Array_Size>
|
||||
ETL_CONSTEXPR TValue* begin(TValue(&data)[Array_Size])
|
||||
Get the 'begin' pointer for an array.
|
||||
Enabled if ETL_NOT_USING_STL or ETL_CPP11_NOT_SUPPORTED.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TValue, size_t Array_Size>
|
||||
ETL_CONSTEXPR const TValue* begin(const TValue(&data)[Array_Size])
|
||||
Get the 'begin' const pointer for an array.
|
||||
Enabled if ETL_NOT_USING_STL or ETL_CPP11_NOT_SUPPORTED.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TValue, size_t Array_Size>
|
||||
ETL_CONSTEXPR const TValue* cbegin(const TValue(&data)[Array_Size])
|
||||
Get the 'begin' const pointer for an array.
|
||||
Enabled if ETL_NOT_USING_STL or ETL_CPP11_NOT_SUPPORTED.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TContainer>
|
||||
ETL_CONSTEXPR typename TContainer::reverse_iterator rbegin(TContainer& container)
|
||||
Get the 'begin' reverse_iterator of container.
|
||||
Enabled if ETL_NOT_USING_STL or ETL_CPP14_NOT_SUPPORTED.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TContainer>
|
||||
ETL_CONSTEXPR typename TContainer::const_reverse_iterator rbegin(const TContainer& container)
|
||||
Get the 'begin' const_reverse_iterator of container.
|
||||
Enabled if ETL_NOT_USING_STL or ETL_CPP14_NOT_SUPPORTED.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TContainer>
|
||||
ETL_CONSTEXPR typename TContainer::const_reverse_iterator crbegin(const TContainer& container)
|
||||
Get the 'begin' const_reverse_iterator of container.
|
||||
Enabled if ETL_NOT_USING_STL or ETL_CPP14_NOT_SUPPORTED.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TValue, size_t Array_Size>
|
||||
ETL_OR_STD::reverse_iterator<TValue*> rbegin(TValue(&data)[Array_Size])
|
||||
Get the 'begin' reverse_iterator for an array.
|
||||
Enabled if ETL_NOT_USING_STL or ETL_CPP14_NOT_SUPPORTED.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TValue, size_t Array_Size>
|
||||
ETL_CONSTEXPR ETL_OR_STD::reverse_iterator<const TValue*> crbegin(const TValue(&data)[Array_Size])
|
||||
Get the 'begin' const_reverse_iterator for an array.
|
||||
Enabled if ETL_NOT_USING_STL or ETL_CPP14_NOT_SUPPORTED.
|
||||
____________________________________________________________________________________________________
|
||||
end
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TContainer>
|
||||
ETL_CONSTEXPR typename TContainer::iterator end(TContainer& container)
|
||||
Get the 'end' iterator of container.
|
||||
Enabled if ETL_NOT_USING_STL or ETL_CPP11_NOT_SUPPORTED.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TContainer>
|
||||
ETL_CONSTEXPR typename TContainer::const_iterator end(const TContainer& container)
|
||||
Get the 'end' const_iterator of container.
|
||||
Enabled if ETL_NOT_USING_STL or ETL_CPP11_NOT_SUPPORTED.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TContainer>
|
||||
ETL_CONSTEXPR typename TContainer::const_iterator cend(const TContainer& container)
|
||||
Get the 'end' const_iterator of container.
|
||||
Enabled if ETL_NOT_USING_STL or ETL_CPP11_NOT_SUPPORTED.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TValue, size_t Array_Size>
|
||||
ETL_CONSTEXPR TValue* end(TValue(&data)[Array_Size])
|
||||
Get the 'end' pointer for an array.
|
||||
Enabled if ETL_NOT_USING_STL or ETL_CPP11_NOT_SUPPORTED.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TValue, size_t Array_Size>
|
||||
ETL_CONSTEXPR const TValue* end(const TValue(&data)[Array_Size])
|
||||
Get the 'end' const pointer of an array.
|
||||
Enabled if ETL_NOT_USING_STL or ETL_CPP11_NOT_SUPPORTED
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TValue, size_t Array_Size>
|
||||
ETL_CONSTEXPR const TValue* cend(const TValue(&data)[Array_Size])
|
||||
Get the 'end' const pointer of an array.
|
||||
Enabled if ETL_NOT_USING_STL or ETL_CPP11_NOT_SUPPORTED
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TContainer>
|
||||
ETL_CONSTEXPR typename TContainer::reverse_iterator rend(TContainer& container)
|
||||
Get the 'end' reverse_iterator of container.
|
||||
Enabled if ETL_NOT_USING_STL or ETL_CPP14_NOT_SUPPORTED.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TContainer>
|
||||
ETL_CONSTEXPR typename TContainer::const_reverse_iterator rend(TContainer& container)
|
||||
Get the 'end' const_reverse_iterator of container.
|
||||
Enabled if ETL_NOT_USING_STL or ETL_CPP14_NOT_SUPPORTED.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TContainer>
|
||||
ETL_CONSTEXPR typename TContainer::const_reverse_iterator crend(const TContainer& container)
|
||||
Get the 'end' const_reverse_iterator of container.
|
||||
Enabled if ETL_NOT_USING_STL or ETL_CPP14_NOT_SUPPORTED.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TValue, size_t Array_Size>
|
||||
ETL_CONSTEXPR ETL_OR_STD::reverse_iterator<TValue*> rend(TValue(&data)[Array_Size])
|
||||
Get the 'end' reverse_iterator for an array.
|
||||
Enabled if ETL_NOT_USING_STL or ETL_CPP14_NOT_SUPPORTED.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TValue, size_t Array_Size>
|
||||
ETL_CONSTEXPR ETL_OR_STD::reverse_iterator<const TValue*> crend(const TValue(&data)[Array_Size])
|
||||
Get the 'end' const_reverse_iterator for an array.
|
||||
Enabled if ETL_NOT_USING_STL or ETL_CPP14_NOT_SUPPORTED.
|
||||
____________________________________________________________________________________________________
|
||||
size
|
||||
|
||||
template <typename TContainer>
|
||||
ETL_CONSTEXPR typename TContainer::size_type size(const TContainer& container)
|
||||
Get the size of a container.
|
||||
Expects the container to have defined size_type.
|
||||
Enabled if ETL_NOT_USING_STL or ETL_CPP17_NOT_SUPPORTED.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TValue, size_t Array_Size>
|
||||
ETL_CONSTEXPR size_t size(TValue(&)[Array_Size])
|
||||
Get the size of an array in elements at run time, or compile time if C++11 or above.
|
||||
Enabled if ETL_NOT_USING_STL or ETL_CPP17_NOT_SUPPORTED.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T, size_t Array_Size>
|
||||
char(&array_size(T(&array)[Array_Size]))[Array_Size];
|
||||
Get the size of an array in elements at compile time for C++03
|
||||
Usage:- sizeof(array_size(array))
|
||||
Enabled if ETL_NOT_USING_STL or ETL_CPP17_NOT_SUPPORTED.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_ARRAY_SIZE(a) calls sizeof(etl::array_size(a))
|
||||
|
||||
|
||||
255
docs/raw/utilities/Memory Cast.txt
Normal file
255
docs/raw/utilities/Memory Cast.txt
Normal file
@ -0,0 +1,255 @@
|
||||
Memory Cast
|
||||
20.11.0
|
||||
|
||||
Helper classes that simplify the interpretation of memory blocks.
|
||||
The member functions contain both compile and run time error checks for correct sized buffers.
|
||||
|
||||
etl::mem_cast
|
||||
etl::mem_cast_ptr
|
||||
etl::mem_cast_types
|
||||
____________________________________________________________________________________________________
|
||||
Error types
|
||||
|
||||
class mem_cast_exception : public etl::exception
|
||||
The base exception type for mem_cast types.
|
||||
|
||||
class mem_cast_size_exception : public etl::mem_cast_exception
|
||||
The exception type when the type size is too large.
|
||||
|
||||
class mem_cast_nullptr_exception : public etl::mem_cast_exception
|
||||
The exception type when the buffer pointer is null.
|
||||
____________________________________________________________________________________________________
|
||||
mem_cast
|
||||
This class owns an internal memory block, as defined by the template parameters.
|
||||
|
||||
template <size_t Size, size_t Alignment>
|
||||
class mem_cast
|
||||
The class is parameterised by the required memory block size and alignment.
|
||||
____________________________________________________________________________________________________
|
||||
Member constants
|
||||
|
||||
static ETL_CONSTANT size_t Size;
|
||||
static ETL_CONSTANT size_t Alignment;
|
||||
____________________________________________________________________________________________________
|
||||
Member functions
|
||||
mem_cast()
|
||||
Default constructor.
|
||||
The internal memory block contents are undefined.
|
||||
____________________________________________________________________________________________________
|
||||
template <size_t Other_Size, size_t Other_Alignment>
|
||||
mem_cast(const mem_cast<Other_Size, Other_Alignment>& other)
|
||||
Copy constructor.
|
||||
Copies the contents of the source buffer.
|
||||
Static asserts if the other buffer is not large enough.
|
||||
___________________________________________________________________________________________________
|
||||
template <size_t Other_Size, size_t Other_Alignment>
|
||||
mem_cast& operator =(const mem_cast<Other_Size, Other_Alignment>& rhs)
|
||||
Assignment operator.
|
||||
Static asserts if the rhs buffer is not large enough.
|
||||
___________________________________________________________________________________________________
|
||||
template <typename T>
|
||||
void assign(const T& value)
|
||||
Assign from value.
|
||||
Static asserts if the buffer is not large enough.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T>
|
||||
void assign_at_offset(size_t offset, const T& value)
|
||||
Assign from value at an offset from the start of the memory block.
|
||||
Raises an etl::mem_cast_size_exception ETL_ASSERT if the buffer is not large enough.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T, size_t Offset>
|
||||
void assign_at_offset(const T& value)
|
||||
Assign from value at an offset from the start of the memory block.
|
||||
Static asserts if the buffer is not large enough.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T, typename... TArgs>
|
||||
void emplace(TArgs... args)
|
||||
Emplace from parameters.
|
||||
Static asserts if the buffer is not large enough.
|
||||
C++11 or above.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T, typename... TArgs>
|
||||
void emplace_at_offset(size_t offset, TArgs... args)
|
||||
Emplace from parameters at an offset from the start of the memory block.
|
||||
Raises an etl::mem_cast_size_exception ETL_ASSERT if the buffer is not large enough.
|
||||
C++11 or above.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T, size_t Offset, typename... TArgs>
|
||||
void emplace_at_offset(TArgs... args)
|
||||
Emplace from parameters at an offset from the start of the memory block.
|
||||
Static asserts if the buffer is not large enough.
|
||||
C++11 or above.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T>
|
||||
ETL_NODISCARD T& ref()
|
||||
Get a reference to T.
|
||||
Static asserts if the buffer is not large enough.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T>
|
||||
ETL_NODISCARD const T& ref() const
|
||||
Get a const reference to T.
|
||||
Static asserts if the buffer is not large enough.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T>
|
||||
ETL_NODISCARD T& ref_at_offset(size_t offset)
|
||||
Get a reference to T at an offset from the start of the memory block (dynamic).
|
||||
Raises an etl::mem_cast_size_exception ETL_ASSERT if the buffer is not large enough.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T>
|
||||
ETL_NODISCARD const T& ref_at_offset(size_t offset) const
|
||||
Get a const reference to T at an offset from the start of the memory block (dynamic).
|
||||
Raises an etl::mem_cast_size_exception ETL_ASSERT if the buffer is not large enough.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T, size_t Offset>
|
||||
ETL_NODISCARD T& ref_at_offset()
|
||||
Get a reference to T at an offset from the start of the memory block (static).
|
||||
Static asserts if the buffer is not large enough.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T, size_t Offset>
|
||||
ETL_NODISCARD const T& ref_at_offset() const
|
||||
Get a const reference to T at an offset from the start of the memory block (static).
|
||||
Static asserts if the buffer is not large enough.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_NODISCARD static ETL_CONSTEXPR size_t size()
|
||||
Get the size of the buffer.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_NODISCARD static ETL_CONSTEXPR size_t alignment()
|
||||
Get the alignment of the buffer.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_NODISCARD char* data()
|
||||
Get a pointer to the internal buffer.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_NODISCARD const char* data() const
|
||||
Get a const pointer to the internal buffer
|
||||
____________________________________________________________________________________________________
|
||||
mem_cast_ptr
|
||||
This class contains a pointer to an external memory block.
|
||||
class mem_cast_ptr
|
||||
____________________________________________________________________________________________________
|
||||
Member constants
|
||||
|
||||
static ETL_CONSTANT size_t Undefined_Size;
|
||||
____________________________________________________________________________________________________
|
||||
Member functions
|
||||
mem_cast_ptr()
|
||||
Default constructor.
|
||||
The internal pointer to the memory block is initialised as nullptr.
|
||||
The size is defined as Undefined_Size.
|
||||
____________________________________________________________________________________________________
|
||||
mem_cast_ptr(const mem_cast_ptr& other)
|
||||
Copy constructor.
|
||||
Copies the memory block pointer, not the contents of the memory block.
|
||||
____________________________________________________________________________________________________
|
||||
mem_cast_ptr& operator =(const mem_cast_ptr& rhs)
|
||||
Assignment operator.
|
||||
Copies the memory block pointer, not the contents of the memory block.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T>
|
||||
void assign(const T& value)
|
||||
Assign from value.
|
||||
Raises an etl::mem_cast_nullptr_exception ETL_ASSERT if the memory block pointer is null.
|
||||
Raises an etl::mem_cast_size_exception ETL_ASSERT if the buffer is not large enough.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T>
|
||||
void assign_at_offset(size_t offset, const T& value)
|
||||
Assign from value at an offset from the start of the memory block.
|
||||
Raises an etl::mem_cast_nullptr_exception ETL_ASSERT if the memory block pointer is null.
|
||||
Raises an etl::mem_cast_size_exception ETL_ASSERT if the buffer is not large enough.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T, size_t Offset>
|
||||
void assign_at_offset(const T& value)
|
||||
Assign from value at an offset from the start of the memory block.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T, typename... TArgs>
|
||||
void emplace(TArgs... args)
|
||||
Emplace from parameters.
|
||||
C++11 or above.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T, typename... TArgs>
|
||||
void emplace_at_offset(size_t offset, TArgs... args)
|
||||
Emplace from parameters at offset.
|
||||
Raises an etl::mem_cast_nullptr_exception ETL_ASSERT if the memory block pointer is null.
|
||||
Raises an etl::mem_cast_size_exception ETL_ASSERT if the buffer is not large enough.
|
||||
C++11 or above.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T, size_t Offset, typename... TArgs>
|
||||
void emplace_at_offset(TArgs... args)
|
||||
Emplace from parameters at offset.
|
||||
Raises an etl::mem_cast_nullptr_exception ETL_ASSERT if the memory block pointer is null.
|
||||
Raises an etl::mem_cast_size_exception ETL_ASSERT if the buffer is not large enough.
|
||||
C++11 or above.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T>
|
||||
ETL_NODISCARD T& ref()
|
||||
Get a reference to T.
|
||||
Raises an etl::mem_cast_nullptr_exception ETL_ASSERT if the memory block pointer is null.
|
||||
Raises an etl::mem_cast_size_exception ETL_ASSERT if the buffer is not large enough.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T>
|
||||
ETL_NODISCARD const T& ref() const
|
||||
Get a const reference to T.
|
||||
Raises an etl::mem_cast_nullptr_exception ETL_ASSERT if the memory block pointer is null.
|
||||
Raises an ETL_ASSERT if the buffer is not large enough.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T>
|
||||
ETL_NODISCARD T& ref_at_offset(size_t offset)
|
||||
Get a reference to T at an offset from the start of the memory block (dynamic).
|
||||
Raises an etl::mem_cast_nullptr_exception ETL_ASSERT if the memory block pointer is null.
|
||||
Raises an etl::mem_cast_size_exception ETL_ASSERT if the buffer is not large enough.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T>
|
||||
ETL_NODISCARD const T& ref_at_offset(size_t offset) const
|
||||
Get a const reference to T at offset (dynamic).
|
||||
Raises an etl::mem_cast_nullptr_exception ETL_ASSERT if the memory block pointer is null.
|
||||
Raises an etl::mem_cast_size_exception ETL_ASSERT if the buffer is not large enough.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T, size_t Offset>
|
||||
ETL_NODISCARD T& ref_at_offset()
|
||||
Get a reference to T at an offset from the start of the memory block (static).
|
||||
Raises an etl::mem_cast_nullptr_exception ETL_ASSERT if the memory block pointer is null.
|
||||
Raises an etl::mem_cast_size_exception ETL_ASSERT if the buffer is not large enough.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T, size_t Offset>
|
||||
ETL_NODISCARD const T& ref_at_offset() const
|
||||
Get a const reference to T at an offset from the start of the memory block (static).
|
||||
Raises an etl::mem_cast_nullptr_exception ETL_ASSERT if the memory block pointer is null.
|
||||
Raises an etl::mem_cast_size_exception ETL_ASSERT if the buffer is not large enough.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_NODISCARD size_t size() const
|
||||
Get the size of the buffer.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_NODISCARD size_t alignment() const
|
||||
Get the alignment of the buffer.
|
||||
____________________________________________________________________________________________________
|
||||
void data(char* pbuffer, size_t buffer_size = Undefined_Size)
|
||||
Set the pointer to the external buffer.
|
||||
The default size is Undefined_Size.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_NODISCARD char* data()
|
||||
Get a pointer to the internal buffer.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_NODISCARD const char* data() const
|
||||
Get a const pointer to the internal buffer
|
||||
____________________________________________________________________________________________________
|
||||
mem_cast_types
|
||||
A variant of etl::mem_cast that deduces the size and alignment from the supplied list of types.
|
||||
____________________________________________________________________________________________________
|
||||
C++03
|
||||
template <typename T1, typename T2 = char, typename T3 = char, typename T4 = char,
|
||||
typename T5 = char, typename T6 = char, typename T7 = char, typename T8 = char,
|
||||
typename T9 = char, typename T10 = char, typename T11 = char, typename T12 = char,
|
||||
typename T13 = char, typename T14 = char, typename T15 = char, typename T16 = char>
|
||||
struct mem_cast_types :
|
||||
public etl::mem_cast<etl::largest<T1, T2, T3, T4, T5, T6, T7, T8,
|
||||
T9, T10, T11, T12, T13, T14, T15, T16>::size,
|
||||
etl::largest<T1, T2, T3, T4, T5, T6, T7, T8,
|
||||
T9, T10, T11, T12, T13, T14, T15, T16>::alignment>
|
||||
{
|
||||
};
|
||||
____________________________________________________________________________________________________
|
||||
C++11 and above
|
||||
template <typename... TTypes>
|
||||
using mem_cast_types = etl::mem_cast<etl::largest<TTypes...>::size,
|
||||
etl::largest<TTypes...>::alignment>;
|
||||
|
||||
|
||||
26
docs/raw/utilities/Memory Model.txt
Normal file
26
docs/raw/utilities/Memory Model.txt
Normal file
@ -0,0 +1,26 @@
|
||||
Memory Model
|
||||
This header defines enumerations and type lookups for supporting various memory models for the ETL.
|
||||
These allow template classes to use optimally sized variables for the model.
|
||||
For example, if a container will never have more than 256 elements then indexes and counts may be contained in an 8 bit type.
|
||||
|
||||
memory_model
|
||||
A user type that defines values for four different memory models.
|
||||
MEMORY_MODEL_SMALL
|
||||
MEMORY_MODEL_MEDIUM
|
||||
MEMORY_MODEL_LARGE
|
||||
MEMORY_MODEL_HUGE
|
||||
|
||||
Example
|
||||
etl::memory_model::MEMORY_MODEL_LARGE
|
||||
____________________________________________________________________________________________________
|
||||
size_type_lookup
|
||||
A type lookup template that defines a type that equates to the size type for memory model.
|
||||
|
||||
using size_type = typename etl::size_type_lookup<etl::memory_model::MEMORY_MODEL_LARGE>::type;
|
||||
|
||||
The defined types are...
|
||||
MEMORY_MODEL_SMALL uint_least8_t
|
||||
MEMORY_MODEL_MEDIUM uint_least16_t
|
||||
MEMORY_MODEL_LARGE uint_least32_t
|
||||
MEMORY_MODEL_HUGE uint_least64_t
|
||||
|
||||
448
docs/raw/utilities/Memory.txt
Normal file
448
docs/raw/utilities/Memory.txt
Normal file
@ -0,0 +1,448 @@
|
||||
Memory
|
||||
|
||||
These functions will create objects in uninitialised memory.
|
||||
POD types will be default or value initialised, Non-trivial types by calling placement new.
|
||||
____________________________________________________________________________________________________
|
||||
address_of
|
||||
|
||||
template <typename T>
|
||||
T* addressof(T& t)
|
||||
Returns the address of an object.
|
||||
____________________________________________________________________________________________________
|
||||
default_delete
|
||||
|
||||
template <typename T>
|
||||
struct default_delete
|
||||
|
||||
template <typename T>
|
||||
struct default_delete<T[]>
|
||||
____________________________________________________________________________________________________
|
||||
Create / Destroy
|
||||
Functions that create or destroy items in uninitialised memory.
|
||||
|
||||
template <typename T>
|
||||
void create_default_at(T* p)
|
||||
|
||||
template <typename T, typename TCounter>
|
||||
void create_default_at(T* p, Tcounter count)
|
||||
|
||||
Creates a default value. For POD types this will be undefined.
|
||||
The second version is supplied a counter, which will be incremented.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T>
|
||||
void create_value_at(T* p)
|
||||
|
||||
template <typename T, typename TCounter>
|
||||
void create_value_at(T* p, Tcounter count)
|
||||
|
||||
Creates a default value by constructing the item with T().
|
||||
The second version is supplied a counter, which will be incremented.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T>
|
||||
void create_copy_at(T* p)
|
||||
|
||||
template <typename T, typename TCounter>
|
||||
void create_copy_at(T* p, const T& value, Tcounter count)
|
||||
|
||||
Creates a default value by constructing the item with T(value).
|
||||
The second version is supplied a counter, which will be incremented.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T, typename TCounter>
|
||||
T& make_default_at(T* p, Tcounter count)
|
||||
|
||||
Creates a default value. For POD types this will be undefined.
|
||||
Returns a reference to the new object.
|
||||
The second version is supplied a counter, which will be incremented.
|
||||
|
||||
template <typename T>
|
||||
T& make_value_at(T* p)
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T, typename TCounter>
|
||||
T& make_value_at(T* p, Tcounter count)
|
||||
|
||||
Creates a default value by constructing the item with T().
|
||||
Returns a reference to the new object.
|
||||
The second version is supplied a counter, which will be incremented.
|
||||
|
||||
template <typename T>
|
||||
T& make_copy_at(T* p)
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T, typename TCounter>
|
||||
T& make_copy_at(T* p, const T& value, Tcounter count)
|
||||
|
||||
Creates a default value by constructing the item with T(value).
|
||||
Returns a reference to the new object.
|
||||
The second version is supplied a counter, which will be incremented.
|
||||
|
||||
template <typename T>
|
||||
void destroy_at(T* p)
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T, typename TCounter>
|
||||
void destroy_at(T* p, TCounter& count)
|
||||
|
||||
Calls the destructor for non-pod types.
|
||||
The second version is supplied a counter, which will be decremented.
|
||||
|
||||
template <typename T, typename TSize >
|
||||
void destroy_n(T* p, TSize n)
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T, typename TSize, typename TCounter>
|
||||
void destroy_n(T* p, TSize n, TCounter& count)
|
||||
|
||||
Calls the destructor for a range of non-pod types, starting at address p.
|
||||
The second version is supplied a counter, which will be decremented by the number of items destructed.
|
||||
|
||||
template <typename T>
|
||||
void destroy(T* p, T* p_end)
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T, typename TCounter>
|
||||
void destroy(T* p, T* p_end, TCounter& count)
|
||||
|
||||
Calls the destructor for a range of non-pod types, starting at address p.
|
||||
The second version is supplied a counter, which will be decremented by the number of items destructed.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T>
|
||||
struct create_copy
|
||||
|
||||
Derive from this, passing the derived class as the template parameter.
|
||||
Provides the following member functions that constructs a copy at the specified address.
|
||||
____________________________________________________________________________________________________
|
||||
void create_copy_at(void* p);
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TCounter>
|
||||
void create_copy_at(void* p, Tcounter& count);
|
||||
____________________________________________________________________________________________________
|
||||
T& make_copy_at(void* p);
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TCounter>
|
||||
T& make_copy_at(void* p, Tcounter& count);
|
||||
____________________________________________________________________________________________________
|
||||
Example:
|
||||
class Test : public etl::create_copy<Test>
|
||||
{
|
||||
// Other members.
|
||||
};
|
||||
|
||||
// Allocate memory large enough to contain a 'Test' object.
|
||||
char buffer[sizeof(Test)];
|
||||
|
||||
Test test;
|
||||
|
||||
// Copy construct 'test' into the buffer memory.
|
||||
Test& t = test.make_copy_at(buffer);
|
||||
____________________________________________________________________________________________________
|
||||
Create / Destroy objects
|
||||
Functions that create or destroy objects in uninitialised memory.
|
||||
Variations of the functions above that don't require an explicit reinterpret_cast.
|
||||
|
||||
template <typename TObject>
|
||||
TObject& construct_object_at(void* p, TObject&& object)
|
||||
20.35.12
|
||||
Construct the object at p.
|
||||
In a debug build the pointer is checked for correct alignment. An etl::alignment_error is asserted if incorrect.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TObject, typename... TArgs>
|
||||
TObject& construct_object_at(void* p, TArgs&&... args)
|
||||
20.35.12
|
||||
Construct the object at p from arguments.
|
||||
In a debug build the pointer is checked for correct alignment. An etl::alignment_error is asserted if incorrect.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TObject>
|
||||
TObject& get_object_at(void* p)
|
||||
20.35.12
|
||||
Get the object at p.
|
||||
In a debug build the pointer is checked for correct alignment. An etl::alignment_error is asserted if incorrect.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TObject>
|
||||
void destroy_object_at(void* p)
|
||||
20.35.12
|
||||
Destroy the object at p.
|
||||
In a debug build the pointer is checked for correct alignment. An etl::alignment_error is asserted if incorrect.
|
||||
____________________________________________________________________________________________________
|
||||
uninitialzed_fill
|
||||
|
||||
template <typename TIterator, typename TSize, typename T>
|
||||
TIterator uninitialized_fill_n(TIterator o_begin, TSize count, const T& value)
|
||||
|
||||
template <typename TIterator, typename TSize, typename T, typename TCounter>
|
||||
TIterator uninitialized_fill_n(TIterator o_begin, TSize count, const T& value, typename TCounter)
|
||||
|
||||
Fills uninitialised memory with N values.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TIterator, typename T>
|
||||
TIterator uninitialized_fill(TIterator o_begin, TIterator o_end, const T& value)
|
||||
|
||||
template <typename TIterator, typename TSize, typename T, typename TCounter>
|
||||
TIterator uninitialized_fill_n(TIterator o_begin, TSize count, const T& value, typename TCounter)
|
||||
|
||||
Fills uninitialised memory range with a value.
|
||||
____________________________________________________________________________________________________
|
||||
uninitialised_copy
|
||||
|
||||
template <typename TInputIterator, typename TOutputIterator>
|
||||
TIterator uninitialized_copy(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin)
|
||||
|
||||
template <typename TInputIterator, typename TOutputIterator, typename TCounter>
|
||||
TIterator uninitialized_copy(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin, typename TCounter)
|
||||
|
||||
Copies a range of objects to uninitialised memory.
|
||||
____________________________________________________________________________________________________
|
||||
uninitialized_copy_n
|
||||
|
||||
template <typename TInputIterator, typename TSize, typename TOutputIterator>
|
||||
TIterator uninitialized_copy_n(TInputIterator i_begin, TSize count, TOutputIterator o_begin)
|
||||
|
||||
template <typename TInputIterator, typename TSize, typename TOutputIterator, typename TCounter>
|
||||
TIterator uninitialized_copy_n(TInputIterator i_begin, TSize count, TOutputIterator o_begin, typename TCounter)
|
||||
|
||||
Copies N objects to uninitialised memory.
|
||||
____________________________________________________________________________________________________
|
||||
uninitialized_move
|
||||
|
||||
template <typename TInputIterator, typename TOutputIterator>
|
||||
TIterator uninitialized_move(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin)
|
||||
|
||||
template <typename TInputIterator, typename TOutputIterator, typename TCounter>
|
||||
TIterator uninitialized_move(TInputIterator i_begin, TInputIterator i_end, TOutputIterator o_begin, typename TCounter)
|
||||
|
||||
Moves a range of objects to uninitialised memory.
|
||||
|
||||
Note: If using C++03 then this function will call etl::uninitialized_copy
|
||||
____________________________________________________________________________________________________
|
||||
uninitialized_copy_n
|
||||
|
||||
template <typename TInputIterator, typename TSize, typename TOutputIterator>
|
||||
TIterator uninitialized_move_n(TInputIterator i_begin, TSize count, TOutputIterator o_begin)
|
||||
|
||||
template <typename TInputIterator, typename TSize, typename TOutputIterator, typename TCounter>
|
||||
TIterator uninitialized_move_n(TInputIterator i_begin, TSize count, TOutputIterator o_begin, typename TCounter)
|
||||
|
||||
Moves N objects to uninitialised memory.
|
||||
|
||||
Note: If using C++03 then this function will call etl::uninitialized_copy_n
|
||||
____________________________________________________________________________________________________
|
||||
uninitialized_default_construct
|
||||
|
||||
template <typename TOutputIterator>
|
||||
void uninitialized_default_construct(TOutputIterator o_begin, TOutputIterator o_end)
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TOutputIterator, typename TCounter>
|
||||
void uninitialized_default_construct(TOutputIterator o_begin, TOutputIterator o_end, typename TCounter)
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TOutputIterator, typename TSize>
|
||||
TOutputIterator uninitialized_default_construct_n(TOutputIterator o_begin, TSize n)
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TOutputIterator, typename TSize, typename TCounter>
|
||||
TOutputIterator uninitialized_default_construct_n(TOutputIterator o_begin, TSize n, TCounter& count)
|
||||
|
||||
Creates default values. For POD types this will be undefined.
|
||||
____________________________________________________________________________________________________
|
||||
uninitialized_value_construct
|
||||
|
||||
template <typename TOutputIterator>
|
||||
void uninitialized_value_construct(TOutputIterator o_begin, TOutputIterator o_end)
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TOutputIterator, typename TCounter>
|
||||
void uninitialized_value_construct(TOutputIterator o_begin, TOutputIterator o_end, TCounter& count)
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TOutputIterator, typename TSize>
|
||||
TOutputIterator uninitialized_value_construct_n(TOutputIterator o_begin, TSize n)
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TOutputIterator, typename TSize, typename TCounter>
|
||||
TOutputIterator uninitialized_value_construct_n(TOutputIterator o_begin, TSize n, TCounter& count)
|
||||
|
||||
Creates values constructed with T().
|
||||
____________________________________________________________________________________________________
|
||||
unique_ptr
|
||||
Like std::unique_ptr, etl::unique_ptr is a smart pointer that owns and manages another object through a pointer and disposes of that object when the unique_ptr goes out of scope.
|
||||
|
||||
https://en.cppreference.com/w/cpp/memory/unique_ptr
|
||||
|
||||
template<typename T>
|
||||
class unique_ptr
|
||||
____________________________________________________________________________________________________
|
||||
template<typename T>
|
||||
class unique_ptr<T[]>
|
||||
____________________________________________________________________________________________________
|
||||
Memory clear
|
||||
|
||||
void memory_clear(volatile char* p, size_t n)
|
||||
|
||||
template <typename T>
|
||||
void memory_clear(volatile T &object)
|
||||
|
||||
A low level function that clears an object's memory to zero.
|
||||
|
||||
template <typename T>
|
||||
void memory_clear_range(volatile T* begin, size_t n)
|
||||
|
||||
template <typename T>
|
||||
void memory_clear_range(volatile T* begin, volatile T* end)
|
||||
|
||||
A low level function that clears a range to zero.
|
||||
____________________________________________________________________________________________________
|
||||
Memory set
|
||||
|
||||
void memory_set(volatile char* p, size_t n, char value)
|
||||
|
||||
template <typename T>
|
||||
void memory_set(volatile T &object, char value)
|
||||
|
||||
Low level functions that clear an object's memory to a value.
|
||||
|
||||
template <typename T>
|
||||
void memory_set_range(volatile T* begin, size_t n, char value)
|
||||
|
||||
template <typename T>
|
||||
void memory_set_range(volatile T* begin, volatile T* end, char value)
|
||||
|
||||
Low level functions that set a range to a value.
|
||||
____________________________________________________________________________________________________
|
||||
wipe_on_destruct
|
||||
|
||||
A template class that will wipe the derived objects storage to zero on destruction.
|
||||
Designed to eliminate sensitive data lurking around in memory after an object has been destructed.
|
||||
|
||||
template <typename T>
|
||||
struct wipe_on_destruct
|
||||
T is the derived class whose storage must be wiped.
|
||||
|
||||
Example
|
||||
|
||||
struct UserData : public etl::wipe_on_destruct<UserData>
|
||||
{
|
||||
char secret_passcode[16];
|
||||
char sensitive_user_name[16];
|
||||
};
|
||||
|
||||
When an instance of UserData is destructed, the memory that it occupied will be set to zero.
|
||||
____________________________________________________________________________________________________
|
||||
uninitialized_buffer
|
||||
|
||||
template <size_t VObject_Size, size_t VN_Objects, size_t VAlignment>
|
||||
class uninitialized_buffer
|
||||
Creates an uninitialized memory buffer of VN_Objects each of VObject_Size with alignment VAlignment.
|
||||
____________________________________________________________________________________________________
|
||||
uninitialized_buffer_of
|
||||
|
||||
template <typename T, size_t VN_Objects>
|
||||
class uninitialized_buffer_of
|
||||
Creates an uninitialized memory buffer of VN_Objects each of type T.
|
||||
____________________________________________________________________________________________________
|
||||
mem_copy
|
||||
20.26.0
|
||||
|
||||
template <typename TPointer>
|
||||
TPointer mem_copy(const TPointer sb, const TPointer se, TPointer db) ETL_NOEXCEPT
|
||||
Template wrapper for memcpy.
|
||||
Copies all of the bytes in the source range to the destination range.
|
||||
Type must be trivially copyable.
|
||||
sb Pointer to source begin.
|
||||
se Pointer to source end.
|
||||
db Pointer to destination begin.
|
||||
Returns a pointer to the destination.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TPointer>
|
||||
TPointer mem_copy(const TPointer sb, size_t n, TPointer db) ETL_NOEXCEPT
|
||||
Template wrapper for memcpy.
|
||||
Copies all of the bytes in the source range to the destination range.
|
||||
Type must be trivially copyable.
|
||||
sb Pointer to source begin.
|
||||
n Source length.
|
||||
db Pointer to destination begin.
|
||||
Returns a pointer to the destination.
|
||||
____________________________________________________________________________________________________
|
||||
mem_move
|
||||
20.26.0
|
||||
|
||||
template <typename TPointer>
|
||||
TPointer mem_move(const TPointer sb, const TPointer se, TPointer db) ETL_NOEXCEPT
|
||||
Template wrapper for memmove.
|
||||
Moves all of the bytes in the source range to the destination range.
|
||||
Type must be trivially copyable.
|
||||
sb Pointer to source begin.
|
||||
se Pointer to source end.
|
||||
db Pointer to destination begin.
|
||||
Returns a pointer to the destination.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TPointer>
|
||||
TPointer mem_move(const TPointer sb, size_t n, TPointer db) ETL_NOEXCEPT
|
||||
Template wrapper for memmove.
|
||||
Moves all of the bytes in the source range to the destination range.
|
||||
Type must be trivially copyable.
|
||||
sb Pointer to source begin.
|
||||
n Source length.
|
||||
db Pointer to destination begin.
|
||||
Returns a pointer to the destination.
|
||||
____________________________________________________________________________________________________
|
||||
mem_compare
|
||||
20.26.0
|
||||
|
||||
template <typename TPointer>
|
||||
TPointer mem_compare(const TPointer sb, const TPointer se, TPointer db) ETL_NOEXCEPT
|
||||
Template wrapper for memcmp.
|
||||
Searches all of the bytes in the range for value.
|
||||
Type must be trivially copyable.
|
||||
sb Pointer to source begin.
|
||||
se Pointer to source end.
|
||||
db Pointer to destination begin.
|
||||
Returns <0, 0, >0. See documentation for memcmp.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TPointer>
|
||||
TPointer mem_compare(const TPointer sb, size_t n, TPointer db) ETL_NOEXCEPT
|
||||
Template wrapper for memcmp.
|
||||
Type must be trivially copyable.
|
||||
sb Pointer to source begin.
|
||||
n Source length.
|
||||
db Pointer to destination begin.
|
||||
Returns <0, 0, >0. See documentation for memcmp.
|
||||
____________________________________________________________________________________________________
|
||||
mem_set
|
||||
20.26.0
|
||||
|
||||
template <typename TPointer, typename T>
|
||||
TPointer mem_set(const TPointer db, const TPointer de, T value) ETL_NOEXCEPT
|
||||
Template wrapper for memset.
|
||||
Sets all of the bytes in the range to value.
|
||||
Type must be trivially copyable.
|
||||
db Pointer to destination begin.
|
||||
de Pointer to destination end.
|
||||
value The value to write to the memory. This value is cast to char.
|
||||
Returns a pointer to the destination.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TPointer, typename T>
|
||||
TPointer mem_set(const TPointer db, size_t n, T value) ETL_NOEXCEPT
|
||||
Template wrapper for memset.
|
||||
Sets all of the bytes in the range to value.
|
||||
Type must be trivially copyable.
|
||||
db Pointer to destination begin.
|
||||
n Destination length.
|
||||
value The value to write to the memory. This value is cast to char.
|
||||
Returns a pointer to the destination.
|
||||
____________________________________________________________________________________________________
|
||||
mem_char
|
||||
20.26.0
|
||||
|
||||
template <typename TPointer, typename T>
|
||||
TPointer mem_char(const TPointer sb, const TPointer se, T value) ETL_NOEXCEPT
|
||||
Template wrapper for memchr.
|
||||
Searches all of the bytes in the range for value.
|
||||
Type must be trivially copyable.
|
||||
db Pointer to source begin.
|
||||
de Pointer to source begin.
|
||||
value The value to search for. This value is cast to char.
|
||||
Returns a pointer to the character or se if not found.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TPointer, typename T>
|
||||
TPointer mem_char(const TPointer sb, size_t n, T value) ETL_NOEXCEPT
|
||||
Template wrapper for memchr.
|
||||
Searches all of the bytes in the range for value.
|
||||
Type must be trivially copyable.
|
||||
db Pointer to destination begin.
|
||||
n Source length.
|
||||
value The value to search for. This value is cast to char.
|
||||
Returns a pointer to the character or sb + n if not found.
|
||||
|
||||
13
docs/raw/utilities/Mutex.txt
Normal file
13
docs/raw/utilities/Mutex.txt
Normal file
@ -0,0 +1,13 @@
|
||||
Mutex
|
||||
This header attempts to replicate std::mutex.
|
||||
|
||||
If ETL_CPP11_SUPPORTED and ETL_USING_STL are defined as 1 then etl::mutex will be defined in terms of std::mutex.
|
||||
Otherwise it will be implemented in terms of the built-in support, if available, from the compiler. For example, early GCC, Clang and Arm compilers will use the __sync built-ins.
|
||||
|
||||
If there is an ETL mutex type available for your platform then ETL_HAS_MUTEX will be set to 1, otherwise it will be set to 0.
|
||||
|
||||
The mutex implementation will normally be selected by the compiler being used.
|
||||
For FreeRTOS and CMSIS-RTOS2 you must define one of the following.
|
||||
ETL_TARGET_OS_FREERTOS
|
||||
ETL_TARGET_OS_CMSIS_OS2
|
||||
|
||||
63
docs/raw/utilities/Parameter Pack.txt
Normal file
63
docs/raw/utilities/Parameter Pack.txt
Normal file
@ -0,0 +1,63 @@
|
||||
Parameter Pack
|
||||
Compile time mapping of index to type and type to index for a template parameter pack.
|
||||
Deprecated: Use etl::type_list
|
||||
For C++11 or above
|
||||
____________________________________________________________________________________________________
|
||||
parameter_pack
|
||||
|
||||
template <typename... TTypes>
|
||||
class parameter_pack
|
||||
|
||||
Defines
|
||||
static constexpr size_t size = sizeof...(TTypes);
|
||||
|
||||
Template alias
|
||||
template <size_t Index, typename... TTypes>
|
||||
using parameter_pack_t
|
||||
= typename etl::parameter_pack<TTypes...>::template type_from_index_t<Index>;
|
||||
Type from index and type list.
|
||||
|
||||
For C++17 or above
|
||||
template <typename T, typename... TTypes>
|
||||
inline constexpr size_t parameter_pack_v
|
||||
= etl::parameter_pack<TTypes...>::template index_of_type<T>::value;
|
||||
Index from type and type list.
|
||||
|
||||
The class contains two nested templates.
|
||||
____________________________________________________________________________________________________
|
||||
index_of_type
|
||||
|
||||
template <typename T>
|
||||
class index_of_type
|
||||
|
||||
For C++17 or above
|
||||
template <typename T>
|
||||
static constexpr size_t index_of_type_v = index_of_type<T>::value;
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
type_from_index
|
||||
|
||||
template <size_t Index>
|
||||
class type_from_index
|
||||
|
||||
template <size_t Index>
|
||||
using type_from_index_t = typename type_from_index<Index>::type;
|
||||
____________________________________________________________________________________________________
|
||||
Examples
|
||||
|
||||
using Pack = etl::parameter_pack<char, short, int>;
|
||||
|
||||
constexpr size_t size = Pack::size; // size == 3
|
||||
|
||||
size_t indexChar = Pack::index_of_type_v<char>; // indexChar == 0
|
||||
size_t indexShort = Pack::index_of_type_v<short>; // indexShort == 1
|
||||
size_t indexInt = Pack::index_of_type_v<int>; // indexInt == 2
|
||||
size_t indexLong = Pack::index_of_type_v<long>; // Static assert
|
||||
// "T is not in parameter pack"
|
||||
|
||||
using type0 = typename Pack::type_from_index_t<0>; // type0 = char
|
||||
using type1 = typename Pack::type_from_index_t<1>; // type1 = short
|
||||
using type2 = typename Pack::type_from_index_t<2>; // type2 = int
|
||||
using type3 = typename Pack::type_from_index_t<3>; // Static assert
|
||||
// "Index out of bounds of parameter pack"
|
||||
|
||||
88
docs/raw/utilities/Reference Counted Objects.txt
Normal file
88
docs/raw/utilities/Reference Counted Objects.txt
Normal file
@ -0,0 +1,88 @@
|
||||
Reference Counted Objects
|
||||
|
||||
Reference counted objects types
|
||||
Defines the following classes.
|
||||
|
||||
etl::ireference_counter
|
||||
The interface of all reference counters.
|
||||
|
||||
etl::reference_counter<TCounter>
|
||||
A reference counter using TCounter as the counter.
|
||||
|
||||
etl::reference_counter<void>
|
||||
A null reference counter. The reference count always reports as 1.
|
||||
|
||||
etl::ireference_counted_object
|
||||
The interface of all reference counted object types.
|
||||
|
||||
etl::reference_counted_object<typename TObject, typename TCounter>
|
||||
Derived from etl::ireference_counted_object
|
||||
|
||||
etl::atomic_counted_object<typename TObject>
|
||||
A template alias of etl::reference_counted_object<typename TObject, etl::atomic_int32_t>
|
||||
____________________________________________________________________________________________________
|
||||
ireference_counter
|
||||
|
||||
etl::ireference_counter
|
||||
The interface of all reference counters.
|
||||
|
||||
virtual ~ireference_counter() {};
|
||||
virtual void set_reference_count(int32_t value) = 0;
|
||||
virtual void increment_reference_count() = 0;
|
||||
ETL_NODISCARD virtual int32_t decrement_reference_count() = 0;
|
||||
ETL_NODISCARD virtual int32_t get_reference_count() const = 0;
|
||||
____________________________________________________________________________________________________
|
||||
reference_counter
|
||||
|
||||
etl::reference_counter<TCounter>
|
||||
A reference counter that uses type TCounter to count.
|
||||
|
||||
etl::reference_counter<void>
|
||||
A dummy reference counter that always returns a count of 1.
|
||||
Used for persistent objects.
|
||||
____________________________________________________________________________________________________
|
||||
ireference_counted_object
|
||||
|
||||
etl::ireference_counted_object<typename TObject, typename TCounter>
|
||||
The interface of all reference counted object types.
|
||||
____________________________________________________________________________________________________
|
||||
virtual ~ireference_counted_object()
|
||||
____________________________________________________________________________________________________
|
||||
ETL_NODISCARD virtual etl::ireference_counter& get_reference_counter() = 0;
|
||||
Get a reference to the reference counter.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_NODISCARD virtual const etl::ireference_counter& get_reference_counter() const = 0;
|
||||
Get a const reference to the reference counter.
|
||||
____________________________________________________________________________________________________
|
||||
reference_counted_object
|
||||
|
||||
etl::reference_counted_object<typename TObject, typename TCounter>
|
||||
The implementation of a reference counted object.
|
||||
____________________________________________________________________________________________________
|
||||
reference_counted_object(const TObject& object)
|
||||
Constructs from an .
|
||||
The object is copied.
|
||||
____________________________________________________________________________________________________
|
||||
reference_counted_object()
|
||||
Constructs from an .
|
||||
The object is default constructed.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_NODISCARD TObject& get_object() ETL_OVERRIDE
|
||||
Get a reference to the object.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_NODISCARD const TObject& get_object() const ETL_OVERRIDE
|
||||
Get a const reference to the object.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_NODISCARD etl::ireference_counter& get_reference_counter() ETL_OVERRIDE
|
||||
Get a reference to the reference counter.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_NODISCARD const etl::ireference_counter& get_reference_counter() const ETL_OVERRIDE
|
||||
Get a const reference to the reference counter.
|
||||
____________________________________________________________________________________________________
|
||||
For C++11, with atomic support.
|
||||
|
||||
template <typename TObject>
|
||||
using atomic_counted_object = etl::reference_counted_object<TObject, etl::atomic_int32_t>;
|
||||
Defines an alias to a reference counted object that uses an atomic.
|
||||
|
||||
|
||||
79
docs/raw/utilities/Type List.txt
Normal file
79
docs/raw/utilities/Type List.txt
Normal file
@ -0,0 +1,79 @@
|
||||
Type List
|
||||
|
||||
Defines a tuple of types, but unlike a tuple, does not contain any values.
|
||||
This is an empty class.
|
||||
Valid for C++11 and above.
|
||||
____________________________________________________________________________________________________
|
||||
type_list
|
||||
|
||||
etl::type_select<typename... TTypes>
|
||||
Creates a tuple of types from a set of template type parameters.
|
||||
____________________________________________________________________________________________________
|
||||
Member types
|
||||
index_sequence_type
|
||||
The index_sequence type for this type_list.
|
||||
____________________________________________________________________________________________________
|
||||
Type list creation
|
||||
____________________________________________________________________________________________________
|
||||
Using global types
|
||||
|
||||
template <typename TTypeList, size_t... Indices>
|
||||
type_list_select
|
||||
Defines a new type_list by selecting types from a given type_list, according to an index sequence.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename... TTypeLists>
|
||||
type_list_cat
|
||||
Defines a new type list by concatenating a list of etl::type_list objects.
|
||||
std::tuple style access.
|
||||
____________________________________________________________________________________________________
|
||||
Type list properties
|
||||
____________________________________________________________________________________________________
|
||||
Using member types
|
||||
|
||||
static constexpr size_t size();
|
||||
Returns the number of types in the type list.
|
||||
____________________________________________________________________________________________________
|
||||
Using global types
|
||||
|
||||
template <typename TTypelist>
|
||||
type_list_size
|
||||
Defines value as the size of the type list.
|
||||
tuple style access.
|
||||
|
||||
template <typename TTypelist>
|
||||
type_list_size_v C++17 and above
|
||||
____________________________________________________________________________________________________
|
||||
etl::nth_type<size_t N, typename TTypeList>
|
||||
Defines the nth type in the type list.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TFromList, typename TToList>
|
||||
type_lists_are_convertible
|
||||
Checks that types in a type_list are convertible to the type in another.
|
||||
Defines value as true or false.
|
||||
20.43.0
|
||||
|
||||
template <typename TFromList, typename TToList>
|
||||
type_lists_are_convertible_v C++17 and above
|
||||
20.43.0
|
||||
____________________________________________________________________________________________________
|
||||
Examples
|
||||
|
||||
using TypeList1 = etl::type_list<char, short, int, long>
|
||||
using TypeList2 = etl::type_list<float, double>
|
||||
using TypeList3 = etl::type_list<unsigned char, unsigned short>
|
||||
____________________________________________________________________________________________________
|
||||
Using member types
|
||||
|
||||
// Get the size of TypeList1
|
||||
constexpr size_t typeList1Size = TypeList1::size();
|
||||
____________________________________________________________________________________________________
|
||||
Using tuple style global types
|
||||
|
||||
// Get the size of TypeList1
|
||||
constexpr size_t typeList1Size = etl::type_list_size_v<TypeList1>;
|
||||
|
||||
// Define the type list
|
||||
// etl::type_list<char, short, int, long, float, double, unsigned char, unsigned short>
|
||||
using Concatenated = etl::type_list_cat<TypeList1, TypeList2, TypeList3>
|
||||
|
||||
|
||||
155
docs/raw/utilities/Type Lookup.txt
Normal file
155
docs/raw/utilities/Type Lookup.txt
Normal file
@ -0,0 +1,155 @@
|
||||
Type Lookup
|
||||
Compile time mapping of id to type, type to id and type to type.
|
||||
This file is generated from type_lookup_generator.h and can be created by running generate_type_lookup.bat.
|
||||
|
||||
For a less complex solution for simple id to type lookup, see etl::type_select.
|
||||
____________________________________________________________________________________________________
|
||||
type_id_pair
|
||||
Support structure for type_id_lookup.
|
||||
|
||||
etl::type_id_pair<typename T, size_t ID>
|
||||
Defines:
|
||||
type The type.
|
||||
ID The id associated with the type.
|
||||
____________________________________________________________________________________________________
|
||||
type_type_pair
|
||||
Support structure for type_type_lookup.
|
||||
|
||||
etl::type_type_pair<typename T1, typename T2>
|
||||
|
||||
Defines:
|
||||
type1 The indexing type.
|
||||
type2 The associated type.
|
||||
____________________________________________________________________________________________________
|
||||
type_id_lookup
|
||||
Creates a class for compile time id to type and type to id mappings.
|
||||
|
||||
etl::type_id_lookup<typename T1, ...>
|
||||
The number of types that can be handled is determined by the generator.
|
||||
Each template parameter is a type_id_pair.
|
||||
|
||||
The class contains two nested templates
|
||||
____________________________________________________________________________________________________
|
||||
type_from_id
|
||||
Gets the type from the id.
|
||||
type_from_id<size_t ID>
|
||||
|
||||
Defines:
|
||||
type The associated type.
|
||||
|
||||
C++14 and above
|
||||
template <int ID>
|
||||
using type_from_id_t = typename type_from_id<ID>::type;
|
||||
____________________________________________________________________________________________________
|
||||
id_from_type
|
||||
Gets the id from the type.
|
||||
id_from_type<typename T>
|
||||
|
||||
Defines:
|
||||
ID The associated id.
|
||||
|
||||
C++ 17 and above
|
||||
template <typename T>
|
||||
constexpr size_t id_from_type_v = id_from_type<T>::value;
|
||||
____________________________________________________________________________________________________
|
||||
Static functions
|
||||
Gets the id from the type.
|
||||
template <typename T>
|
||||
static unsigned int get_id_from_type(const T&)
|
||||
|
||||
template <typename T>
|
||||
static unsigned int get_id_from_type()
|
||||
____________________________________________________________________________________________________
|
||||
type_type_lookup
|
||||
Creates a class for compile time type to type mapping.
|
||||
|
||||
etl::type_id_lookup<typename T1, ...>
|
||||
The number of types that can be handled is determined by the generator.
|
||||
Each template parameter is a type_id_pair.
|
||||
|
||||
The class contains one nested template.
|
||||
____________________________________________________________________________________________________
|
||||
type_from_type
|
||||
type_from_type<typename T>
|
||||
|
||||
Defines:
|
||||
type The associated type.
|
||||
|
||||
C++14 and above
|
||||
template <typename T>
|
||||
using type_from_type_t = typename type_from_type<T>::type;
|
||||
____________________________________________________________________________________________________
|
||||
nth_type
|
||||
Gets the nth type in a variadic type list.
|
||||
|
||||
template <size_t N, typename... TTypes>
|
||||
struct nth_type
|
||||
Defines member type as the nth type in the variadic type list.
|
||||
|
||||
template <size_t N, typename... TTypes>
|
||||
using nth_type_t = typename nth_type<N, TTypes...>::type;
|
||||
Type alias defined as the nth type in the variadic type list.
|
||||
____________________________________________________________________________________________________
|
||||
Examples
|
||||
____________________________________________________________________________________________________
|
||||
type_id_lookup
|
||||
enum
|
||||
{
|
||||
INT32 = 32,
|
||||
STRING = 1,
|
||||
UINT8 = 8,
|
||||
OTHER = 0
|
||||
};
|
||||
|
||||
typedef etl::type_id_pair<int32_t, INT32> TypeIdInt32;
|
||||
typedef etl::type_id_pair<uint8_t, UINT8> TypeIdUint8;
|
||||
typedef etl::type_id_pair<std::string, STRING> TypeIdString;
|
||||
|
||||
// Type from Id / Id from Type.
|
||||
typedef etl::type_id_lookup<TypeIdInt32, TypeIdString, TypeIdUint8> TypeIdLookup;
|
||||
|
||||
// int32_t
|
||||
typename TypeIdLookup::type_from_id_t<INT32>
|
||||
|
||||
// uint8_t
|
||||
typename TypeIdLookup::type_from_id_t<UINT8>
|
||||
|
||||
// std::string
|
||||
typename TypeIdLookup::type_from_id_t<STRING>
|
||||
|
||||
// Compile error
|
||||
typename TypeIdLookup::type_from_id_t<OTHER>
|
||||
|
||||
// INT32
|
||||
TypeIdLookup::id_from_type_v<int32_t>
|
||||
|
||||
// UINT8
|
||||
TypeIdLookup::id_from_type_v<uint8_t>
|
||||
|
||||
// STRING
|
||||
TypeIdLookup::id_from_type_v<std::string>
|
||||
|
||||
// Compile error
|
||||
TypeIdLookup::id_from_type_v<double>
|
||||
____________________________________________________________________________________________________
|
||||
type_type_lookup
|
||||
// Get the next larger type.
|
||||
typedef etl::type_type_pair<int16_t, int32_t> TypeInt16;
|
||||
typedef etl::type_type_pair<uint8_t, uint16_t> TypeUint8;
|
||||
typedef etl::type_type_pair<float, double> TypeFloat;
|
||||
|
||||
// Type from Type.
|
||||
etl::type_type_lookup<TypeInt16, TypeUint8, TypeFloat> TypeTypeLookup;
|
||||
|
||||
// int32_t
|
||||
typename TypeTypeLookup::type_from_type_t<int16_t>
|
||||
|
||||
// uint16_t
|
||||
typename TypeTypeLookup::type_from_type_t<uint8_t>
|
||||
|
||||
// double
|
||||
typename TypeTypeLookup::type_from_type_t<float>
|
||||
|
||||
// Compile error
|
||||
typename TypeTypeLookup::type_from_type_t<int32_t>
|
||||
|
||||
50
docs/raw/utilities/Type Select.txt
Normal file
50
docs/raw/utilities/Type Select.txt
Normal file
@ -0,0 +1,50 @@
|
||||
Type Select
|
||||
Compile time mapping of id to type. When etl::type_lookup is OTT.
|
||||
Type ids must be sequential from zero.
|
||||
|
||||
This file is generated from type_select_generator.h and can be created by running generate_type_select.bat.
|
||||
____________________________________________________________________________________________________
|
||||
type_select
|
||||
|
||||
Creates a class for compile time id to type.
|
||||
etl::type_select<typename T1, ...>
|
||||
|
||||
The number of types that can be handled is determined by the generator.
|
||||
The class contains a nested template.
|
||||
|
||||
select
|
||||
Gets the type from the id.
|
||||
select<const size_t ID>
|
||||
|
||||
Defines:
|
||||
type The associated type.
|
||||
|
||||
C++14 and above
|
||||
template <size_t ID>
|
||||
using select_t = typename select<ID>::type;
|
||||
____________________________________________________________________________________________________
|
||||
Examples
|
||||
|
||||
enum
|
||||
{
|
||||
INT32 = 0,
|
||||
STRING = 1,
|
||||
UINT8 = 2,
|
||||
OTHER = 3
|
||||
};
|
||||
|
||||
// Type from Id.
|
||||
typedef etl::type_select<int32_t, std::string, uint8_t> Types;
|
||||
|
||||
// int32_t
|
||||
typename Types::select_t<INT32>
|
||||
|
||||
// uint8_t
|
||||
typename Types::select_t<UINT8>
|
||||
|
||||
// std::string
|
||||
typename Types::select_t<STRING>
|
||||
|
||||
// Compile error
|
||||
typename Types::select_t<OTHER>
|
||||
|
||||
366
docs/raw/utilities/Utility.txt
Normal file
366
docs/raw/utilities/Utility.txt
Normal file
@ -0,0 +1,366 @@
|
||||
Utility
|
||||
|
||||
A few useful utility functions and classes.
|
||||
____________________________________________________________________________________________________
|
||||
pair
|
||||
template <typename T1, typename T2>
|
||||
struct pair
|
||||
A clone of std::pair
|
||||
|
||||
C++03
|
||||
template <typename T1, typename T2>
|
||||
pair<T1, T2> make_pair(T1 a, T2 b)
|
||||
|
||||
C++11 and above
|
||||
template <typename T1, typename T2>
|
||||
pair<T1, T2> make_pair(T1&& a, T2&& b)
|
||||
Returns a pair.
|
||||
____________________________________________________________________________________________________
|
||||
template <size_t Index, typename T1, typename T2>
|
||||
struct tuple_element<Index, ETL_OR_STD::pair<T1, T2>>
|
||||
Specialisation for pair.
|
||||
Gets the type in the pair at Index.
|
||||
Static asserts if Index is not 0 or 1.
|
||||
20.40.1
|
||||
|
||||
template <typename T1, typename T2>
|
||||
struct tuple_size<ETL_OR_STD::pair<T1, T2>>
|
||||
Specialisation for pair.
|
||||
Gets the size of the pair, which is always 2.
|
||||
20.40.1
|
||||
____________________________________________________________________________________________________
|
||||
Template deduction guides
|
||||
C++17 and above
|
||||
|
||||
template <typename T1, typename T2>
|
||||
pair(T1, T2) ->pair<T1, T2>;
|
||||
____________________________________________________________________________________________________
|
||||
exchange
|
||||
|
||||
template <typename T, typename U = T>
|
||||
T exchange(T& object, const U& new_value)
|
||||
Copies the new value to object and returns the old value.
|
||||
Note: This is not an atomic operation.
|
||||
__________________________________________________________________________________________________
|
||||
add_const
|
||||
|
||||
template <typename T>
|
||||
typename etl::add_const<T>::type& as_const(T& t)
|
||||
Returns a value of type T as a const T.
|
||||
__________________________________________________________________________________________________
|
||||
coordinate_2d
|
||||
|
||||
template <typename T>
|
||||
struct coordinate_2d
|
||||
|
||||
Member types
|
||||
T x;
|
||||
T y;
|
||||
__________________________________________________________________________________________________
|
||||
In_place disambiguation tags.
|
||||
|
||||
struct in_place_t
|
||||
|
||||
inline constexpr in_place_t in_place{}; // C++17
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T> struct in_place_type_t
|
||||
|
||||
template <typename T>
|
||||
inline constexpr in_place_type_t<T> in_place_type{}; // C++17
|
||||
____________________________________________________________________________________________________
|
||||
template <size_t I> struct in_place_index_t
|
||||
|
||||
template <size_t I>
|
||||
inline constexpr in_place_index_t<I> in_place_index{}; // C++17
|
||||
__________________________________________________________________________________________________
|
||||
declval
|
||||
|
||||
template <typename T>
|
||||
typename etl::add_rvalue_reference<T>::type declval() ETL_NOEXCEPT;
|
||||
C++11
|
||||
__________________________________________________________________________________________________
|
||||
functor
|
||||
For C++11 and above.
|
||||
20.27.0
|
||||
|
||||
template <typename TReturn, typename... TParams>
|
||||
class functor
|
||||
Wraps a free/global function in a functor.
|
||||
____________________________________________________________________________________________________
|
||||
constexpr functor(TReturn(*ptr_)(TParams...))
|
||||
Constructs a functor from a function pointer.
|
||||
____________________________________________________________________________________________________
|
||||
constexpr TReturn operator()(TParams... args) const
|
||||
Function operator.
|
||||
Calls the wrapped function with the forwarded parameters.
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
void int Function(int i)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
|
||||
// Note that the functor deduces the template parameters.
|
||||
constexpr etl::functor f(Function);
|
||||
__________________________________________________________________________________________________
|
||||
member_function_wrapper
|
||||
For C++11 and above.
|
||||
20.27.0
|
||||
|
||||
template <typename TReturn, typename... TParams>
|
||||
class member_function_wrapper<TReturn(TParams...)>
|
||||
Wraps a member function in a static member function.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T, T& Instance, TReturn(T::* Method)(TParams...)>
|
||||
static constexpr TReturn function(TParams... params)
|
||||
The static function that calls the member function.
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
class MyClass
|
||||
{
|
||||
public:
|
||||
|
||||
int MemberFunction(int i)
|
||||
{
|
||||
return 2 * i;
|
||||
}
|
||||
};
|
||||
|
||||
MyClass test;
|
||||
|
||||
constexpr int(*pf)(int)
|
||||
= &etl::member_function_wrapper<int(int)>::function<MyClass, test, &MyClass::MemberFunction>;
|
||||
|
||||
// Call
|
||||
int result = pf(1);
|
||||
__________________________________________________________________________________________________
|
||||
functor_wrapper
|
||||
For C++11 and above.
|
||||
20.27.0
|
||||
|
||||
template <typename TReturn, typename... TParams>
|
||||
class functor_wrapper<TReturn(TParams...)>
|
||||
Wraps a functor in a static member function.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TFunctor, TFunctor& Instance>
|
||||
static constexpr TReturn function(TParams... params)
|
||||
The static function that calls the member function.
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
class MyClass
|
||||
{
|
||||
public:
|
||||
|
||||
int operator()(int i)
|
||||
{
|
||||
return 2 * i;
|
||||
}
|
||||
};
|
||||
|
||||
MyClass test;
|
||||
|
||||
constexpr int(*pf)(int) = &etl::functor_wrapper<int(int)>::function<MyClass, test>;
|
||||
|
||||
// Call
|
||||
int result = pf(1);
|
||||
__________________________________________________________________________________________________
|
||||
functor_as_static
|
||||
For C++17 and above.
|
||||
20.40.0
|
||||
|
||||
Wraps a functor with a static free function at compile time.
|
||||
Creates a static member 'call' that calls the specified functor.
|
||||
|
||||
template <auto& Instance>
|
||||
struct functor_as_static
|
||||
____________________________________________________________________________________________________
|
||||
template <typename... TArgs>
|
||||
static constexpr auto call(TArgs&&... args)
|
||||
Member static function that calls the functor
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
struct Test
|
||||
{
|
||||
int operator()(int i)
|
||||
{
|
||||
return 2 * i;
|
||||
}
|
||||
};
|
||||
|
||||
Test test;
|
||||
|
||||
using fas_t = etl::functor_as_static<test>;
|
||||
fas_t::call(1));
|
||||
__________________________________________________________________________________________________
|
||||
member_function_as_static
|
||||
For C++17 and above.
|
||||
20.40.0
|
||||
|
||||
Wraps a member function with a static free function at compile time.
|
||||
Creates a static member function that calls the specified member function.
|
||||
|
||||
template <auto Method, auto& Instance>
|
||||
struct member_function_as_static
|
||||
____________________________________________________________________________________________________
|
||||
template <typename... TArgs>
|
||||
static constexpr auto call(TArgs&&... args)
|
||||
Member static function that calls the member function.
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
struct Test
|
||||
{
|
||||
int Function()(int i)
|
||||
{
|
||||
return 2 * i;
|
||||
}
|
||||
};
|
||||
|
||||
Test test;
|
||||
|
||||
using mfas_t = etl::functor_as_static<&Test::Function, test>;
|
||||
mfas_t::call(1));
|
||||
|
||||
__________________________________________________________________________________________________
|
||||
member_function_as_functor
|
||||
For C++17 and above.
|
||||
20.40.0
|
||||
|
||||
Wraps a member function with a functor at compile time.
|
||||
Creates a functor that calls the specified member function.
|
||||
|
||||
template <auto Method, auto& Instance>
|
||||
class member_function_as_functor
|
||||
|
||||
template <typename... TArgs>
|
||||
constexpr auto operator()(TArgs&&... args) const
|
||||
Calls the functor.
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
struct Test
|
||||
{
|
||||
int Function()(int i)
|
||||
{
|
||||
return 2 * i;
|
||||
}
|
||||
};
|
||||
|
||||
constexpr etl::member_function_as_functor<&Test::Function, test> mfaf;
|
||||
mfaf(1);
|
||||
__________________________________________________________________________________________________
|
||||
function_as_functor
|
||||
For C++17 and above.
|
||||
20.40.0
|
||||
|
||||
Wraps a function with a functor at compile time.
|
||||
Creates a functor that calls the specified free function.
|
||||
|
||||
template <auto Function>
|
||||
class function_as_functor
|
||||
____________________________________________________________________________________________________
|
||||
constexpr auto operator()(TArgs&&... args) const
|
||||
Calls the functor.
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
int Function()(int i)
|
||||
{
|
||||
return 2 * i;
|
||||
}
|
||||
|
||||
constexpr etl::function_as_functor<Function> faf;
|
||||
faf(1);
|
||||
__________________________________________________________________________________________________
|
||||
function_ptr_as_functor
|
||||
For C++11 and above.
|
||||
20.40.0
|
||||
|
||||
Wraps a function pointer with a functor at run time.
|
||||
Creates a functor that calls the specified free function.
|
||||
|
||||
template <typename TReturn, typename... TArgs>
|
||||
class function_ptr_as_functor
|
||||
____________________________________________________________________________________________________
|
||||
constexpr function_ptr_as_functor(TReturn(*ptr_)(TArgs...))
|
||||
Construct from a function pointer.
|
||||
____________________________________________________________________________________________________
|
||||
constexpr TReturn operator()(TArgs... args) const
|
||||
Function operator.
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
int Function()(int i)
|
||||
{
|
||||
return 2 * i;
|
||||
}
|
||||
|
||||
using function_type = decltype(Function);
|
||||
constexpr function_type* fptr = Function;
|
||||
constexpr etl::function_ptr_as_functor<function_type> fpaf(fptr)
|
||||
__________________________________________________________________________________________________
|
||||
integer_sequence
|
||||
20.14.0
|
||||
|
||||
template <typename T, T... Integers>
|
||||
class integer_sequence
|
||||
__________________________________________________________________________________________________
|
||||
index_sequence
|
||||
20.14.0
|
||||
|
||||
template <size_t... Indices>
|
||||
using index_sequence = etl::integer_sequence<size_t, Indices...>;
|
||||
|
||||
template <size_t N>
|
||||
make_index_sequence
|
||||
__________________________________________________________________________________________________
|
||||
select1st
|
||||
select2nd
|
||||
|
||||
select1st is a functor object that takes a single argument, a pair, and returns the pair::first element.
|
||||
select2nd is a functor object that takes a single argument, a pair, and returns the pair::second element.
|
||||
____________________________________________________________________________________________________
|
||||
size_of_type
|
||||
20.36.0
|
||||
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR size_t size_of_type()
|
||||
Returns the size of the type defined in T.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR size_t size_of_type(const T&)
|
||||
Returns the size of the type defined in T.
|
||||
____________________________________________________________________________________________________
|
||||
ETL_SIZE_OF_OBJECT_TYPE(Object, Type)
|
||||
Returns the size of Type defined in the declared type of Object.
|
||||
C++11 and above
|
||||
20.36.0
|
||||
|
||||
ETL_SIZE_OF_CLASS_TYPE(Class, Type)
|
||||
Returns the size of Type defined in Class.
|
||||
20.36.0
|
||||
____________________________________________________________________________________________________
|
||||
nontype_t
|
||||
20.43.0
|
||||
|
||||
Wraps a non-type template parameter as a type.
|
||||
Defines a value associated with the template type.
|
||||
|
||||
If ETL_FORCE_CPP11_NONTYPE is defined then the C++14 and below variant is used.
|
||||
|
||||
C++14 and below
|
||||
template <typename T, T Value>
|
||||
struct nontype_t;
|
||||
|
||||
using FortyTwo = etl::nontype_t<int, 42>;
|
||||
|
||||
C++17 and above
|
||||
template <auto Value>
|
||||
struct nontype_t;
|
||||
|
||||
using FortyTwo = etl::nontype_t<42>
|
||||
|
||||
27
docs/raw/utilities/Versions.txt
Normal file
27
docs/raw/utilities/Versions.txt
Normal file
@ -0,0 +1,27 @@
|
||||
Versions
|
||||
|
||||
As set of macros that allow the version of the ETL to be determined.
|
||||
|
||||
Definitions
|
||||
|
||||
ETL_VERSION
|
||||
ETL_VERSION_W
|
||||
ETL_VERSION_U16
|
||||
ETL_VERSION_U32
|
||||
ETL_VERSION_MAJOR
|
||||
ETL_VERSION_MINOR
|
||||
ETL_VERSION_PATCH
|
||||
ETL_VERSION_VALUE
|
||||
|
||||
Example values
|
||||
|
||||
#define ETL_VERSION "10.21.2"
|
||||
#define ETL_VERSION_W L"10.21.2"
|
||||
#define ETL_VERSION_U16 u"10.21.2"
|
||||
#define ETL_VERSION_U32 U"10.21.2"
|
||||
#define ETL_VERSION_MAJOR 10
|
||||
#define ETL_VERSION_MINOR 21
|
||||
#define ETL_VERSION_PATCH 2
|
||||
#define ETL_VERSION_VALUE 102102
|
||||
|
||||
|
||||
163
docs/raw/utilities/bit_stream_reader.txt
Normal file
163
docs/raw/utilities/bit_stream_reader.txt
Normal file
@ -0,0 +1,163 @@
|
||||
bit_stream_reader
|
||||
|
||||
A binary streaming utility that allows values to be read from an array of char or unsigned char using custom bits widths for efficient packing. Values may be streamed in either msb or lsb format.
|
||||
|
||||
Read functions come in both checked and unchecked forms.
|
||||
Unchecked reads return a value of the specified type.
|
||||
Checked reads assert that there is enough space to read the value, and return an etl::optional containing the type.
|
||||
|
||||
bool
|
||||
Stored as 1 bit.
|
||||
|
||||
Integrals
|
||||
By default, stored using full bit width, otherwise uses the specified width.
|
||||
|
||||
Custom types
|
||||
The user may create specializations of the non-member etl::read functions to stream custom types. Specialisations must be defined in the etl namespace.
|
||||
____________________________________________________________________________________________________
|
||||
Types
|
||||
|
||||
value_type char
|
||||
const_iterator const char*
|
||||
____________________________________________________________________________________________________
|
||||
Member functions
|
||||
|
||||
bit_stream_reader(etl::span<char> span, etl::endian stream_endianness)
|
||||
span
|
||||
A char span of the read buffer.
|
||||
stream_endianness
|
||||
The endianness of the stream.
|
||||
etl::endian::little or etl::endian::big
|
||||
____________________________________________________________________________________________________
|
||||
bit_stream_reader(etl::span<unsigned char> span, etl::endian stream_endianness)
|
||||
span
|
||||
An unsigned char span of the read buffer.
|
||||
stream_endianness
|
||||
The endianness of the stream.
|
||||
etl::endian::little or etl::endian::big
|
||||
____________________________________________________________________________________________________
|
||||
bit_stream_reader(void* begin, void* end, etl::endian stream_endianness)
|
||||
begin
|
||||
A pointer to the beginning of the read buffer.
|
||||
end
|
||||
A pointer to the beginning of the read buffer.
|
||||
stream_endianness
|
||||
The endianness of the stream.
|
||||
etl::endian::little or etl::endian::big
|
||||
____________________________________________________________________________________________________
|
||||
bit_stream_reader(void* begin, size_t length, etl::endian stream_endianness)
|
||||
begin
|
||||
A pointer to the beginning of the read buffer.
|
||||
length
|
||||
The length, in char, of the read buffer.
|
||||
stream_endianness
|
||||
The endianness of the stream.
|
||||
etl::endian::little or etl::endian::big
|
||||
____________________________________________________________________________________________________
|
||||
void restart()
|
||||
Sets the reader back to the beginning of the stream.
|
||||
____________________________________________________________________________________________________
|
||||
bool read_unchecked<bool>()
|
||||
Unchecked read for bool types.
|
||||
|
||||
etl::optional<bool> read<bool>()
|
||||
Checked read for bool types.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T>
|
||||
T read_unchecked(uint_least8_t nbits = CHAR_BIT * sizeof(T))
|
||||
Unchecked read.
|
||||
Enabled for integral types.
|
||||
|
||||
template <typename T>
|
||||
etl::optional<T> read(uint_least8_t nbits = CHAR_BIT * sizeof(T))
|
||||
Checked read.
|
||||
Enabled for integral types.
|
||||
____________________________________________________________________________________________________
|
||||
bool skip(size_t nbits)
|
||||
Skip forward in the stream by nbits.
|
||||
If there are not enough bits remaining in the stream it assert an etl::bit_stream_overflow and return false.
|
||||
____________________________________________________________________________________________________
|
||||
size_t size_bytes() const
|
||||
Returns the number of bytes in the stream buffer.
|
||||
____________________________________________________________________________________________________
|
||||
size_t size_bits() const
|
||||
Returns the number of bits in the stream buffer.
|
||||
____________________________________________________________________________________________________
|
||||
const_iterator begin() const
|
||||
const_iterator cbegin() const
|
||||
Returns start of the stream buffer.
|
||||
____________________________________________________________________________________________________
|
||||
const_iterator end() const
|
||||
const_iterator cend() const
|
||||
Returns end of the stream.
|
||||
____________________________________________________________________________________________________
|
||||
etl::span<const char> data() const
|
||||
Returns a span of whole the stream buffer.
|
||||
____________________________________________________________________________________________________
|
||||
Non-member functions
|
||||
|
||||
template <typename T>
|
||||
T read_unchecked(etl::bit_stream_reader& stream)
|
||||
Reads an unchecked type from a stream by calling stream.read_unchecked<T>()
|
||||
|
||||
template <typename T>
|
||||
T read_unchecked(etl::bit_stream_reader& stream, uint_least8_t nbits)
|
||||
Reads an unchecked type from a stream by calling stream.read_unchecked<T>(nbits)
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T>
|
||||
etl::optional<T> read(etl::bit_stream_reader& stream)
|
||||
Reads a checked type from a stream by calling stream.read<T>()
|
||||
|
||||
template <typename T>
|
||||
etl::optional<T> read(etl::bit_stream_reader& stream, uint_least8_t nbits)
|
||||
Reads a checked type from a stream by calling stream.read<T>(nbits)
|
||||
____________________________________________________________________________________________________
|
||||
template <>
|
||||
bool read_unchecked<bool>(etl::bit_stream_reader& stream)
|
||||
Specialisation for bool.
|
||||
Reads an unchecked bool from a stream by calling stream.read_unchecked<bool>()
|
||||
|
||||
template <>
|
||||
etl::optional<bool> read<bool>(etl::bit_stream_reader& stream)
|
||||
Specialisation for bool.
|
||||
Reads a checked bool from a stream by calling stream.read<bool>()
|
||||
____________________________________________________________________________________________________
|
||||
By specialisation of the templates, the user may create readers for custom types.
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
char c = 26; // 6 bits
|
||||
unsigned short s = 6742; // 13 bits
|
||||
int32_t i = 2448037; // 23 bits
|
||||
|
||||
struct CustomType
|
||||
{
|
||||
char c = -10; // 7 bits
|
||||
unsigned short s = 1878; // 11 bits
|
||||
int32_t i = -10836646; // 25 bits
|
||||
};
|
||||
|
||||
namespace etl
|
||||
{
|
||||
// Specialisation for Custom.
|
||||
// Must be defined in the etl namespace.
|
||||
template <>
|
||||
etl::optional<CustomType> read_unchecked<CustomType>(etl::bit_stream_reader& stream)
|
||||
{
|
||||
char c = stream.read_unchecked<char, 7U>();
|
||||
short s = stream.read_unchecked<short , 11U>();
|
||||
int32_t i = stream.read_unchecked<int32_t, 25U>();
|
||||
|
||||
return CustomType { c.value(), s.value(), i.value() };
|
||||
}
|
||||
}
|
||||
|
||||
std::array<char, 100U> storage; // Assume the buffer gets filled with bit stream data.
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size());
|
||||
|
||||
// Read unchecked values from the stream.
|
||||
char c = etl::read_unchecked<char>(bit_stream, 6U);
|
||||
unsigned short s = etl::read_unchecked<unsigned short>(bit_stream, 13U);
|
||||
CustomType custom = etl::read_unchecked<Custom>(bit_stream);
|
||||
int32_t i = etl::read_unchecked<>(bit_stream, 23U);
|
||||
|
||||
227
docs/raw/utilities/bit_stream_writer.txt
Normal file
227
docs/raw/utilities/bit_stream_writer.txt
Normal file
@ -0,0 +1,227 @@
|
||||
bit_stream_writer
|
||||
|
||||
A binary streaming utility that allows values to be written to an array of char or unsigned char using custom bits widths for efficient packing. Values may be streamed in either msb or lsb format.
|
||||
|
||||
Write functions come in both checked and unchecked forms.
|
||||
Unchecked writes return void.
|
||||
Checked writes assert that there is enough space to store the value, and return a bool indicating success or failure.
|
||||
|
||||
A callback delegate can be assigned that will be called with a span of filled bytes.
|
||||
If the callback is used then the stream is reset to empty or the last unfilled byte after each callback. This allows a very small buffer to be assigned.
|
||||
|
||||
bool
|
||||
Stored as 1 bit.
|
||||
|
||||
Integrals
|
||||
By default, stored using full bit width, otherwise uses the specified width.
|
||||
|
||||
Custom types
|
||||
The user may create specializations of the non-member etl::write functions to stream custom types. Specialisations must be defined in the etl namespace.
|
||||
____________________________________________________________________________________________________
|
||||
Types
|
||||
|
||||
value_type char
|
||||
iterator value_type*
|
||||
const_iterator const value_type*
|
||||
callback_parameter_type etl::span<value_type>
|
||||
callback_type etl::delegate<void(callback_parameter_type)>
|
||||
____________________________________________________________________________________________________
|
||||
Member functions
|
||||
|
||||
bit_stream_writer(etl::span<char> span, etl::endian stream_endianness, callback_type callback = callback_type())
|
||||
Construct from span.
|
||||
span
|
||||
A char span of the read buffer.
|
||||
stream_endianness
|
||||
The endianness of the stream.
|
||||
etl::endian::little or etl::endian::big
|
||||
callback
|
||||
An optional callback.
|
||||
____________________________________________________________________________________________________
|
||||
bit_stream_writer(etl::span<unsigned char> span, etl::endian stream_endianness, callback_type callback = callback_type())
|
||||
Construct from span.
|
||||
span
|
||||
A char span of the read buffer.
|
||||
stream_endianness
|
||||
The endianness of the stream.
|
||||
etl::endian::little or etl::endian::big
|
||||
callback
|
||||
An optional callback.
|
||||
____________________________________________________________________________________________________
|
||||
bit_stream_writer(void* begin, void* end, etl::endian stream_endianness, callback_type callback = callback_type())
|
||||
Construct from range.
|
||||
begin
|
||||
A pointer to the beginning of the read buffer.
|
||||
end
|
||||
A pointer to the beginning of the read buffer.
|
||||
stream_endianness
|
||||
The endianness of the stream.
|
||||
etl::endian::little or etl::endian::big
|
||||
callback
|
||||
An optional callback.
|
||||
____________________________________________________________________________________________________
|
||||
bit_stream_writer(void* begin, size_t length_chars, etl::endian stream_endianness, callback_type callback = callback_type())
|
||||
Construct from begin and length.
|
||||
begin
|
||||
A pointer to the beginning of the read buffer.
|
||||
length
|
||||
The length, in char, of the read buffer.
|
||||
stream_endianness
|
||||
The endianness of the stream.
|
||||
etl::endian::little or etl::endian::big
|
||||
____________________________________________________________________________________________________
|
||||
void restart()
|
||||
Sets the indexes back to the beginning of the stream.
|
||||
____________________________________________________________________________________________________
|
||||
size_t capacity_bytes() const
|
||||
Returns the maximum capacity in bytes.
|
||||
____________________________________________________________________________________________________
|
||||
size_t capacity_bits() const
|
||||
Returns the maximum capacity in bits.
|
||||
____________________________________________________________________________________________________
|
||||
bool empty() const
|
||||
Returns true if the bitsteam indexes have been reset
|
||||
____________________________________________________________________________________________________
|
||||
bool full() const
|
||||
Returns true if the bitsteam indexes have reached the end
|
||||
____________________________________________________________________________________________________
|
||||
void write_unchecked(bool value)
|
||||
Writes a boolean to the stream.
|
||||
____________________________________________________________________________________________________
|
||||
bool write(bool value)
|
||||
Writes a boolean to the stream.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T>
|
||||
void write_unchecked(T value, uint_least8_t nbits = CHAR_BIT * sizeof(T))
|
||||
Enabled for integral types.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T>
|
||||
bool write(T value, uint_least8_t nbits = CHAR_BIT * sizeof(T))
|
||||
Enabled for integral types.
|
||||
____________________________________________________________________________________________________
|
||||
bool skip(size_t nbits)
|
||||
Skip forward in the stream by nbits.
|
||||
If there are not enough bits remaining in the stream it assert an etl::bit_stream_overflow and return false.
|
||||
____________________________________________________________________________________________________
|
||||
size_t size_bytes() const
|
||||
Returns the number of bytes used in the stream.
|
||||
____________________________________________________________________________________________________
|
||||
size_t size_bits() const
|
||||
Returns the number of bits used in the stream.
|
||||
____________________________________________________________________________________________________
|
||||
template <size_t Nbits>
|
||||
size_t available() const
|
||||
The number of multiples of Nbits available in the stream.
|
||||
Compile time.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T>
|
||||
size_t available() const
|
||||
The number of T available in the stream.
|
||||
Compile time.
|
||||
____________________________________________________________________________________________________
|
||||
size_t available(size_t nbits) const
|
||||
The number of 'bit width' available in the stream.
|
||||
Run time.
|
||||
____________________________________________________________________________________________________
|
||||
size_t available_bits() const
|
||||
The number of bits left in the stream.
|
||||
____________________________________________________________________________________________________
|
||||
iterator begin()
|
||||
Returns start of the stream.
|
||||
____________________________________________________________________________________________________
|
||||
const_iterator begin() const
|
||||
Returns start of the stream.
|
||||
____________________________________________________________________________________________________
|
||||
const_iterator cbegin() const
|
||||
Returns start of the stream.
|
||||
____________________________________________________________________________________________________
|
||||
iterator end()
|
||||
Returns end of the stream.
|
||||
____________________________________________________________________________________________________
|
||||
const_iterator end() const
|
||||
Returns end of the stream.
|
||||
____________________________________________________________________________________________________
|
||||
const_iterator cend() const
|
||||
Returns end of the stream.
|
||||
____________________________________________________________________________________________________
|
||||
etl::span<char> used_data()
|
||||
Returns a span of the used portion of the stream.
|
||||
____________________________________________________________________________________________________
|
||||
etl::span<const char> used_data() const
|
||||
Returns a span of the used portion of the stream.
|
||||
____________________________________________________________________________________________________
|
||||
etl::span<char> data()
|
||||
Returns a span of whole the stream.
|
||||
____________________________________________________________________________________________________
|
||||
etl::span<const char> data() const
|
||||
Returns a span of whole the stream.
|
||||
____________________________________________________________________________________________________
|
||||
void flush()
|
||||
Flush the last byte, if partially filled, to the callback.
|
||||
This is only required when a callback delegate has been set.
|
||||
____________________________________________________________________________________________________
|
||||
void set_callback(callback_type callback_)
|
||||
Sets the delegate to call afer every write.
|
||||
____________________________________________________________________________________________________
|
||||
callback_type get_callback() const
|
||||
Gets the function to call afer every write.
|
||||
____________________________________________________________________________________________________
|
||||
Non-member functions
|
||||
|
||||
void write_unchecked(etl::bit_stream_writer& stream, bool value)
|
||||
Implementation of the write unchecked function.
|
||||
For bool types only.
|
||||
|
||||
bool write(etl::bit_stream_writer& stream, bool value)
|
||||
Implementation of the write function.
|
||||
For bool types only.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T>
|
||||
void write_unchecked(etl::bit_stream_writer& stream, const T& value, uint_least8_t nbits = CHAR_BIT * sizeof(T))
|
||||
Default implementation of the write function.
|
||||
For integral types only (but not bool).
|
||||
Overload this to support custom types.
|
||||
|
||||
template <typename T>
|
||||
bool write(etl::bit_stream_writer& stream, const T& value, uint_least8_t nbits = CHAR_BIT * sizeof(T))
|
||||
Default implementation of the write function.
|
||||
For integral types only (but not bool).
|
||||
Overload this to support custom types.
|
||||
____________________________________________________________________________________________________
|
||||
By specialisation of the templates, the user may create writers for custom types.
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
char c = 26; // 6 bits
|
||||
unsigned short s = 6742; // 13 bits
|
||||
int32_t i = 2448037; // 23 bits
|
||||
|
||||
struct CustomType
|
||||
{
|
||||
char c = -10; // 7 bits
|
||||
unsigned short s = 1878; // 11 bits
|
||||
int32_t i = -10836646; // 25 bits
|
||||
};
|
||||
|
||||
namespace etl
|
||||
{
|
||||
// Specialisation for Custom.
|
||||
// Must be defined in the etl namespace.
|
||||
template <>
|
||||
void write_unchecked<CustomType>(etl::bit_stream_reader& stream)
|
||||
{
|
||||
stream.write_unchecked<char, 7U>();
|
||||
stream.write_unchecked<short , 11U>();
|
||||
stream.write_unchecked<int32_t, 25U>();
|
||||
}
|
||||
}
|
||||
|
||||
std::array<char, 100U> storage; // Assume the buffer gets filled with bit stream data.
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size());
|
||||
|
||||
// Write unchecked values to the stream.
|
||||
etl::write_unchecked<char>(bit_stream, 6U);
|
||||
etl::write_unchecked<unsigned short>(bit_stream, 13U);
|
||||
etl::write_unchecked<Custom>(bit_stream);
|
||||
etl::write_unchecked<>(bit_stream, 23U);
|
||||
|
||||
80
docs/raw/utilities/byte.txt
Normal file
80
docs/raw/utilities/byte.txt
Normal file
@ -0,0 +1,80 @@
|
||||
byte
|
||||
20.24.0
|
||||
A type that implements the concept of byte
|
||||
|
||||
C++03
|
||||
Implemented as a class.
|
||||
Cannot be cast using static_cast.
|
||||
|
||||
C++11 or above
|
||||
Implemented as enum class.
|
||||
All functions are constexpr.
|
||||
____________________________________________________________________________________________________
|
||||
Constructors
|
||||
C++03
|
||||
byte()
|
||||
Constructs a default initialised byte.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename T>
|
||||
explicit byte(T v)
|
||||
Constructs a byte initialised to v.
|
||||
____________________________________________________________________________________________________
|
||||
Non-member functions
|
||||
|
||||
template <typename TInteger>
|
||||
constexpr TInteger to_integer(etl::byte b) noexcept
|
||||
Converts to an integral type.
|
||||
constexpr and noexcept for C++11 and above.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TInteger>
|
||||
constexpr etl::byte operator <<(etl::byte b, TInteger shift) noexcept
|
||||
Shifts the value of the byte to the left and returns the new byte.
|
||||
constexpr and noexcept for C++11 and above.
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TInteger>
|
||||
constexpr etl::byte operator >>(etl::byte b, TInteger shift) noexcept
|
||||
Shifts the value of the byte to the right and returns the new byte.
|
||||
constexpr and noexcept for C++11 and above.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TInteger>
|
||||
constexpr etl::byte& operator <<=(etl::byte& b, TInteger shift) noexcept
|
||||
Shifts the value of the byte to the left and returns a reference to the byte.
|
||||
constexpr and noexcept for C++11 and above.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TInteger>
|
||||
constexpr etl::byte& operator >>=(etl::byte& b, TInteger shift) noexcept
|
||||
Shifts the value of the byte to the right and returns a reference to the byte.
|
||||
constexpr and noexcept for C++11 and above.
|
||||
____________________________________________________________________________________________________
|
||||
constexpr etl::byte operator |(etl::byte lhs, etl::byte rhs) noexcept
|
||||
ORs the two bytes returns the new byte.
|
||||
constexpr and noexcept for C++11 and above.
|
||||
____________________________________________________________________________________________________
|
||||
constexpr etl::byte operator &(etl::byte lhs, etl::byte rhs) noexcept
|
||||
ANDs the two bytes returns the new byte.
|
||||
constexpr and noexcept for C++11 and above.
|
||||
____________________________________________________________________________________________________
|
||||
constexpr etl::byte operator ^(etl::byte lhs, etl::byte rhs) noexcept
|
||||
Exclusive ORs the two bytes returns the new byte.
|
||||
constexpr and noexcept for C++11 and above.
|
||||
____________________________________________________________________________________________________
|
||||
constexpr etl::byte& operator |=(etl::byte& lhs, etl::byte rhs) noexcept
|
||||
ORs the two bytes returns and a reference to the first parameter.
|
||||
constexpr for C++14 and above.
|
||||
noexcept for C++11 and above.
|
||||
____________________________________________________________________________________________________
|
||||
constexpr etl::byte& operator &=(etl::byte& lhs, etl::byte rhs) noexcept
|
||||
ANDs the two bytes returns and a reference to the first parameter.
|
||||
constexpr for C++14 and above.
|
||||
noexcept for C++11 and above.
|
||||
____________________________________________________________________________________________________
|
||||
constexpr etl::byte& operator ^=(etl::byte& lhs, etl::byte rhs) noexcept
|
||||
Exclusive ORs the two bytes and returns a reference to the first parameter.
|
||||
constexpr for C++14 and above.
|
||||
noexcept for C++11 and above.
|
||||
____________________________________________________________________________________________________
|
||||
constexpr etl::byte operator ~(etl::byte b) noexcept
|
||||
Negates the value of the byte and returns the new value.
|
||||
constexpr and noexcept for C++11 and above.
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user