mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
Converted more documentation pages
Modified the site CSS
This commit is contained in:
parent
3dcff26123
commit
2bf8fd1359
4
docs/Messaging/_index.md
Normal file
4
docs/Messaging/_index.md
Normal file
@ -0,0 +1,4 @@
|
||||
---
|
||||
title: "Messaging"
|
||||
weight: 100
|
||||
---
|
||||
@ -1,78 +1,146 @@
|
||||
Message Broker
|
||||
---
|
||||
title: "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.
|
||||
{{< callout type="info">}}
|
||||
Header: `message_broker.h`
|
||||
{{< /callout >}}
|
||||
|
||||
Derived from imessage_router
|
||||
____________________________________________________________________________________________________
|
||||
Types
|
||||
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
|
||||
|
||||
```cpp
|
||||
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
|
||||
```
|
||||
|
||||
## subscription
|
||||
A nested class of `etl::message_broker`.
|
||||
The base for broker subscription information.
|
||||
Derive from this to define your subscription class.
|
||||
See Example.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
subscription(etl::imessage_router& router)
|
||||
```
|
||||
Constructor.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
virtual message_id_span_t message_id_list() const = 0;
|
||||
```
|
||||
Override this to return a span of message ids.
|
||||
|
||||
## message_broker
|
||||
|
||||
```cpp
|
||||
message_broker()
|
||||
The broker is constructed with an id of etl::imessage_router::MESSAGE_BROKER.
|
||||
____________________________________________________________________________________________________
|
||||
```
|
||||
The broker is constructed with an id of `etl::imessage_router::MESSAGE_BROKER`.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
message_broker(etl::imessage_router& successor)
|
||||
The broker is constructed with an id of etl::imessage_router::MESSAGE_BROKER.
|
||||
```
|
||||
The broker is constructed with an id of `etl::imessage_router::MESSAGE_BROKER`.
|
||||
Sets the successor.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
message_broker(etl::message_router_id_t id)
|
||||
```
|
||||
The broker is constructed with the specified id.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
message_broker(etl::message_router_id_t id, etl::imessage_router& successor)
|
||||
The broker is constructed with the specified id.
|
||||
```
|
||||
The broker is constructed with the specified id.
|
||||
Sets the successor.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
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.
|
||||
```
|
||||
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.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
void unsubscribe(etl::imessage_router& router)
|
||||
Unsubscribes the specified etl::imessage_router derived class from the bus.
|
||||
```
|
||||
Unsubscribes the specified `etl::imessage_router` derived class from the bus.
|
||||
Does not unsubscribe from nested buses.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
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.
|
||||
```
|
||||
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.
|
||||
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
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
bool accepts(etl::message_id_t id) const
|
||||
```
|
||||
Always returns `true`.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
void clear()
|
||||
```
|
||||
Clears the broker of all subscribers.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_DEPRECATED bool is_null_router() const ETL_OVERRIDE
|
||||
```
|
||||
Always returns `false`.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
bool is_producer() const ETL_OVERRIDE
|
||||
```
|
||||
Always returns `true`.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
bool is_consumer() const ETL_OVERRIDE
|
||||
```
|
||||
Always returns `true`.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
bool empty() const
|
||||
```
|
||||
Returns `true` is the are are no subscribers.
|
||||
|
||||
## Example
|
||||
```cpp
|
||||
// Some router ids.
|
||||
enum
|
||||
{
|
||||
@ -145,4 +213,4 @@ 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
|
||||
|
||||
```
|
||||
206
docs/Messaging/message-bus.md
Normal file
206
docs/Messaging/message-bus.md
Normal file
@ -0,0 +1,206 @@
|
||||
---
|
||||
title: "message_bus"
|
||||
---
|
||||
|
||||
{{< callout type="info">}}
|
||||
Header: `message_broker.h`
|
||||
Since: `20.33.0`
|
||||
{{< /callout >}}
|
||||
|
||||
Message Bus
|
||||
|
||||
This page documents version `20.0.0` and above.
|
||||
|
||||
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
|
||||
|
||||
```cpp
|
||||
bool subscribe(etl::imessage_router& router)
|
||||
```
|
||||
Subscribes an `etl::imessage_router` derived class to the bus.
|
||||
Returns `true` on success.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
void unsubscribe(etl::imessage_router& router)
|
||||
```
|
||||
Unsubscribes the specified `etl::imessage_router` derived class from the bus.
|
||||
Does not unsubscribe from nested buses.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
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()`.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
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.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
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.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
bool accepts(etl::message_id_t id) const
|
||||
```
|
||||
Always returns `true`.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
size_t size() const
|
||||
```
|
||||
Returns the number of subscribers.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
void clear()
|
||||
```
|
||||
Clears the bus of all subscribers.
|
||||
|
||||
Message buses inherit all of the public functions of `etl::imessage_router`.
|
||||
|
||||
## Errors
|
||||
|
||||
```cpp
|
||||
message_bus_exception
|
||||
```
|
||||
Base error class for `etl::message_bus`. Inherits from `etl::exception`.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
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`.
|
||||
|
||||
```cpp
|
||||
template <const uint_least8_t MAX_ROUTERS>
|
||||
class message_bus
|
||||
```
|
||||
`MAX_ROUTERS` The maximum number of routers that can be subscribed.
|
||||
|
||||
## Member functions
|
||||
|
||||
```cpp
|
||||
message_bus()
|
||||
```
|
||||
Constructs a message bus.
|
||||
Message buses always have a router id of `etl::imessage::MESSAGE_BUS`.
|
||||
|
||||
```cpp
|
||||
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
|
||||
```cpp
|
||||
// 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
|
||||
```
|
||||
155
docs/Messaging/message-packet.md
Normal file
155
docs/Messaging/message-packet.md
Normal file
@ -0,0 +1,155 @@
|
||||
---
|
||||
title: "message_packet"
|
||||
---
|
||||
|
||||
{{< callout type="info">}}
|
||||
Header: `message_packet.h`
|
||||
{{< /callout >}}
|
||||
|
||||
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 required to have a virtual destructor.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
message_packet()
|
||||
```
|
||||
Default constructs a message packet.
|
||||
`is_valid()` returns `false`.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
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.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
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.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
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.
|
||||
Since: `20.22.0`
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <typename TMessage>
|
||||
explicit message_packet(TMessage&&)
|
||||
```
|
||||
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.
|
||||
Since: `20.22.0`
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
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.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
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.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
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.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
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.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
etl::imessage& get()
|
||||
const etl::imessage& get() const
|
||||
```
|
||||
Returns a reference to an `etl::imessage`.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
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
|
||||
```cpp
|
||||
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.
|
||||
```
|
||||
111
docs/Messaging/messages.md
Normal file
111
docs/Messaging/messages.md
Normal file
@ -0,0 +1,111 @@
|
||||
---
|
||||
title: "Messages"
|
||||
---
|
||||
|
||||
{{< callout type="info">}}
|
||||
Header: `message.h`
|
||||
{{< /callout >}}
|
||||
|
||||
Message types used for many of the framework classes.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
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.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
etl::message_router_id_t
|
||||
```
|
||||
The type used for message router ids.
|
||||
Can hold a value between 0 and 255.
|
||||
|
||||
---
|
||||
|
||||
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.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
etl::message_id_t get_message_id() const ETL_NOEXCEPT = 0;
|
||||
```
|
||||
Returns the id of the message.
|
||||
|
||||
---
|
||||
|
||||
## message
|
||||
|
||||
```cpp
|
||||
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`.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ID
|
||||
```
|
||||
The id of the message as an enum.
|
||||
Can be accessed by `etl::message` instances.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
TParent
|
||||
```
|
||||
The class that it inherits from. It must ultimately derive from `etl::imessage`.
|
||||
The default is `etl::imessage`.
|
||||
|
||||
---
|
||||
|
||||
## Example
|
||||
|
||||
```cpp
|
||||
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);
|
||||
```
|
||||
78
docs/Messaging/shared-message.md
Normal file
78
docs/Messaging/shared-message.md
Normal file
@ -0,0 +1,78 @@
|
||||
---
|
||||
title: "shared_message"
|
||||
---
|
||||
|
||||
{{< callout type="info">}}
|
||||
Header: `shared_message.h`
|
||||
{{< /callout >}}
|
||||
|
||||
Shared Messages
|
||||
|
||||
The type used to encapsulate reference counted messages.
|
||||
Shared messages are usually passed by value.
|
||||
|
||||
See the Shared Message Tutorial
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
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.
|
||||
|
||||
```cpp
|
||||
template <typename TMessage>
|
||||
etl::ireference_counted_message* allocate(const TMessage& message)
|
||||
```
|
||||
---
|
||||
|
||||
```cpp
|
||||
explicit shared_message(etl::ireference_coutnted_message& message)
|
||||
```
|
||||
Construct from a reference counted message.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
shared_message(const etl::shared_message& other)
|
||||
```
|
||||
Copy constructor.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
shared_message& operator =(const etl::shared_message& other)
|
||||
```
|
||||
Assignment operator.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
~shared_message()
|
||||
```
|
||||
Destructor.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_NODISCARD etl::imessage& get_message()
|
||||
```
|
||||
Gets a reference to the contained message.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_NODISCARD const etl::imessage& get_message() const
|
||||
```
|
||||
Gets a const reference to the contained message.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_NODISCARD uint32_t get_reference_count() const
|
||||
```
|
||||
Gets the current reference count for this shared message.
|
||||
4
docs/frameworks/_index.md
Normal file
4
docs/frameworks/_index.md
Normal file
@ -0,0 +1,4 @@
|
||||
---
|
||||
title: "Frameworks"
|
||||
weight: 100
|
||||
---
|
||||
@ -1,57 +1,80 @@
|
||||
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.
|
||||
---
|
||||
title: "callback_service"
|
||||
---
|
||||
|
||||
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.
|
||||
{{< callout type="info">}}
|
||||
Header: `callback_service.h`
|
||||
{{< /callout >}}
|
||||
|
||||
There are functions that use both runtime and compile time checks of the callback id.
|
||||
Compile time is preferable.
|
||||
____________________________________________________________________________________________________
|
||||
Member functions
|
||||
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.
|
||||
|
||||
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
|
||||
|
||||
```cpp
|
||||
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.
|
||||
|
||||
RANGE The id range of the callbacks.
|
||||
OFFSET The starting id for the range.
|
||||
____________________________________________________________________________________________________
|
||||
It can allow abstraction between low level events such as interrupts and their application dependent handlers.
|
||||
|
||||
```cpp
|
||||
callback_service()
|
||||
|
||||
Sets all of the callbacks to route to the unhandled callback.
|
||||
```
|
||||
Sets all of the callbacks to route to the unhandled callback.
|
||||
Sets the unhandled callback to default (do nothing).
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <const size_t ID>
|
||||
void register_callback(etl::ifunction<size_t>& callback)
|
||||
|
||||
Registers callback with the id specified in the template parameter.
|
||||
```
|
||||
Registers callback with the id specified in the template parameter.
|
||||
A compile time error will occur if the id is out of range.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
void register_callback(size_t id, etl::ifunction<size_t>& callback)
|
||||
|
||||
Registers callback with the id specified in the template parameter.
|
||||
```
|
||||
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)
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
void register_unhandled_callback(etl::ifunction<size_t>& callback)
|
||||
```
|
||||
Registers the callback to be used for unhandled ids.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
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.
|
||||
```
|
||||
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.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
void callback(const size_t id)
|
||||
|
||||
Calls the callback associated with the 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
|
||||
## Example
|
||||
|
||||
See the example project in `examples\FunctionInterruptSimulation`.
|
||||
211
docs/frameworks/cooperative-scheduler.md
Normal file
211
docs/frameworks/cooperative-scheduler.md
Normal file
@ -0,0 +1,211 @@
|
||||
---
|
||||
title: "scheduler"
|
||||
---
|
||||
|
||||
{{< callout type="info">}}
|
||||
Header: `scheduler.h`
|
||||
{{< /callout >}}
|
||||
|
||||
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
|
||||
```cpp
|
||||
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
|
||||
```cpp
|
||||
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
|
||||
```cpp
|
||||
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
|
||||
```cpp
|
||||
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.
|
||||
```cpp
|
||||
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.
|
||||
```cpp
|
||||
ischeduler()
|
||||
```
|
||||
Constructor
|
||||
|
||||
```cpp
|
||||
void set_idle_callback(etl::ifunction<void>& callback)
|
||||
```
|
||||
Sets the function to be called when idle.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
void set_watchdog_callback(etl::ifunction<void>& callback)
|
||||
```
|
||||
Sets the function to be called to reset the watchdog.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
void set_scheduler_running(bool scheduler_running)
|
||||
```
|
||||
Sets the running state of the scheduler.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
bool scheduler_is_running() const;
|
||||
```
|
||||
Gets the running state of the scheduler.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
void exit_scheduler()
|
||||
```
|
||||
Instructs the scheduler to exit after the next idle call.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
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.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
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.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
virtual void start()
|
||||
```
|
||||
Starts the scheduler.
|
||||
|
||||
## scheduler
|
||||
Inherits from `etl::ischeduler`.
|
||||
|
||||
```cpp
|
||||
template <typename TSchedulerPolicy, size_t MAX_TASKS_>
|
||||
class scheduler
|
||||
```
|
||||
`TSchedulerPolicy` The policy to use schedule tasks.
|
||||
`MAX_TASKS` The maximum number of tasks to schedule.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
scheduler()
|
||||
```
|
||||
Constructor.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
void start()
|
||||
```
|
||||
Starts the scheduler.
|
||||
Emits an `etl::scheduler_no_tasks_exception` if there are no tasks in the list.
|
||||
|
||||
## Errors
|
||||
|
||||
```cpp
|
||||
scheduler_exception
|
||||
```
|
||||
Inherits from `etl::exception`
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
scheduler_no_tasks_exception
|
||||
```
|
||||
Inherits from `etl::scheduler_exception`
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
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`.
|
||||
@ -1,15 +1,21 @@
|
||||
Finite State Machine
|
||||
---
|
||||
title: "Finite State Machine"
|
||||
---
|
||||
|
||||
This page documents version 20.0.0 and above.
|
||||
For version 19.x.x or earlier see this page.
|
||||
{{< callout type="info">}}
|
||||
Header: `fsm.h`
|
||||
{{< /callout >}}
|
||||
|
||||
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 page documents version `20.0.0` and above.
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
The on_event functions are not virtual. The template class uses CRTP to directly call the derived class's functions.
|
||||
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 with either O(1) or O(N) rather than scanning a lookup table and calling indirectly through function pointers.
|
||||
|
||||
Defines the following classes:-
|
||||
The `on_event` functions are not virtual. The template class uses [CRTP](https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern) to directly call the derived class's functions.
|
||||
|
||||
**Defines the following classes**
|
||||
```cpp
|
||||
etl::ifsm_state
|
||||
etl::fsm_state <<template>>
|
||||
etl::fsm
|
||||
@ -17,188 +23,291 @@ etl::fsm_exception
|
||||
etl::fsm_null_state_exception
|
||||
etl::fsm_state_id_exception
|
||||
etl::fsm_state_list_exception
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
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
|
||||
```
|
||||
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`.
|
||||
Since: `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
|
||||
Note: This header is a generated from `fsm_generator.h`. For C++03, to handle more than the standard 16 message types then a new one must be generated.
|
||||
|
||||
## Types
|
||||
|
||||
```cpp
|
||||
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.
|
||||
____________________________________________________________________________________________________
|
||||
```
|
||||
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.
|
||||
|
||||
```cpp
|
||||
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.
|
||||
---
|
||||
|
||||
```cpp
|
||||
etl::fsm_state_id_t get_state_id() const
|
||||
```
|
||||
Returns the id of the state.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
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.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
virtual fsm_state_id_t on_enter_state()
|
||||
By default returns No_State_Change.
|
||||
```
|
||||
By default returns `No_State_Change`.
|
||||
The derived state should override this to provide alternative behaviour.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
virtual void on_exit_state()
|
||||
By default does nothing.
|
||||
```
|
||||
By default does nothing.
|
||||
The derived state should override this to provide alternative behaviour.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
```cpp
|
||||
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.
|
||||
____________________________________________________________________________________________________
|
||||
```
|
||||
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.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
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.
|
||||
```
|
||||
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
|
||||
This is only of use when used with an `etl::hsfm` instance.
|
||||
|
||||
## Constants
|
||||
|
||||
```cpp
|
||||
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.
|
||||
## fsm_state
|
||||
A templated state base. Inherits from `etl::ifsm_state`.
|
||||
|
||||
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.
|
||||
## Template parameters
|
||||
|
||||
**For C++03**
|
||||
|
||||
`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++11 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++11 or greater.
|
||||
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.
|
||||
|
||||
```cpp
|
||||
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.
|
||||
____________________________________________________________________________________________________
|
||||
```
|
||||
`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.
|
||||
|
||||
---
|
||||
|
||||
```c++
|
||||
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.
|
||||
```
|
||||
`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
|
||||
|
||||
## Member Functions
|
||||
|
||||
```cpp
|
||||
TContext& get_fsm_context() const
|
||||
Gets a reference to the FSM context.
|
||||
This is the class that was derived from etl::fsm.
|
||||
____________________________________________________________________________________________________
|
||||
Enumerations
|
||||
```
|
||||
Gets a reference to the FSM context.
|
||||
This is the class that was derived from `etl::fsm`.
|
||||
|
||||
STATE_ID The id of this state.
|
||||
____________________________________________________________________________________________________
|
||||
fsm
|
||||
The state machine.
|
||||
Inherits from etl::imessage_router.
|
||||
____________________________________________________________________________________________________
|
||||
## Enumerations
|
||||
|
||||
`STATE_ID` The id of this state.
|
||||
|
||||
## fsm
|
||||
The state machine.
|
||||
Inherits from `etl::imessage_router`.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
fsm(etl::message_router_id_t id)
|
||||
Constructor.
|
||||
Sets the router id for the FSM.
|
||||
```
|
||||
Constructor.
|
||||
Sets the router id for the FSM.
|
||||
The FSM is not started.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
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.
|
||||
```
|
||||
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
|
||||
____________________________________________________________________________________________________
|
||||
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`
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
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.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
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.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
void receive(const etl::imessage& message)
|
||||
```
|
||||
Top level message handler for the FSM.
|
||||
___________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
void receive(etl::message_router_id_t destination_router_id,
|
||||
const etl::imessage& message)
|
||||
Top level message handler for the FSM.
|
||||
```
|
||||
Top level message handler for the FSM.
|
||||
If the destination id is not the FSM's id, then the message is ignored.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
bool accepts(etl::message_id_t id) const
|
||||
```
|
||||
Returns `true`.
|
||||
|
||||
Returns true.
|
||||
____________________________________________________________________________________________________
|
||||
---
|
||||
|
||||
```cpp
|
||||
etl::fsm_state_id_t get_state_id() const
|
||||
```
|
||||
Gets the current state id.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
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.
|
||||
____________________________________________________________________________________________________
|
||||
```
|
||||
Gets a reference to the current state interface.
|
||||
Emits an `etl::etl::fsm_null_state_exception` if the current state is null.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
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.
|
||||
____________________________________________________________________________________________________
|
||||
```
|
||||
Gets a const reference to the current state interface.
|
||||
Emits an `etl::etl::fsm_null_state_exception` if the current state is null.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
bool is_started() const
|
||||
```
|
||||
Checks if the FSM has been started.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
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.
|
||||
____________________________________________________________________________________________________
|
||||
```
|
||||
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`.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
etl::fsm_state_id_t transition_to(etl::fsm_state_id_t new_state_id)
|
||||
Invokes a state transition.
|
||||
```
|
||||
Invokes a state transition.
|
||||
Returns the new state id.
|
||||
____________________________________________________________________________________________________
|
||||
Errors
|
||||
|
||||
## Errors
|
||||
```cpp
|
||||
fsm_exception
|
||||
Inherits from etl::exception
|
||||
```
|
||||
Inherits from `etl::exception`.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
fsm_null_state_exception
|
||||
Inherits from etl::fsm_exception
|
||||
```
|
||||
Inherits from `etl::fsm_exception`
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
fsm_state_id_exception
|
||||
Inherits from etl::fsm_exception
|
||||
```
|
||||
Inherits from `etl::fsm_exception`
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
fsm_state_list_exception
|
||||
Inherits from etl::fsm_exception
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
```
|
||||
Inherits from `etl::fsm_exception`
|
||||
|
||||
An example of a queued FSM can be found in the repository in examples\QueuedFSM
|
||||
____________________________________________________________________________________________________
|
||||
## Example
|
||||
An example of a queued FSM can be found in the repository in `examples\QueuedFSM`
|
||||
|
||||
```cpp
|
||||
const etl::message_router_id_t MOTOR_CONTROL = 0;
|
||||
|
||||
//***************************************************************************
|
||||
@ -430,5 +539,4 @@ motorControl.receive(Start());
|
||||
|
||||
// Receive a Stop(emergency) event. The next state is 'IDLE'.
|
||||
motorControl.receive(Stop(true));
|
||||
|
||||
|
||||
```
|
||||
|
Before Width: | Height: | Size: 44 KiB After Width: | Height: | Size: 44 KiB |
100
docs/frameworks/hierarchical-finite-state-machine.md
Normal file
100
docs/frameworks/hierarchical-finite-state-machine.md
Normal file
@ -0,0 +1,100 @@
|
||||
---
|
||||
title: "Hierarchical Finite State Machine"
|
||||
---
|
||||
|
||||
{{< callout type="info">}}
|
||||
Header: `hfsm.h`
|
||||
Since: `20.10.0`
|
||||
{{< /callout >}}
|
||||
|
||||
Hierarchical Finite State Machine
|
||||
|
||||
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`.
|
||||
|
||||
```cpp
|
||||
hfsm(etl::message_router_id_t id)
|
||||
```
|
||||
Constructor.
|
||||
Sets the router id for the HFSM.
|
||||
The HFSM is not started.
|
||||
|
||||
```cpp
|
||||
void receive(const etl::imessage& message)
|
||||
```
|
||||
Top level message handler for the HFSM.
|
||||
|
||||
## Errors
|
||||
Additional errors to `etl::fsm`.
|
||||
|
||||
```cpp
|
||||
fsm_state_composite_state_change_forbidden
|
||||
```
|
||||
Inherits from `etl::fsm_exception`
|
||||
|
||||
**Example**
|
||||
|
||||

|
||||
|
||||
**The states**
|
||||
```cpp
|
||||
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));
|
||||
```
|
||||
75
docs/frameworks/task.md
Normal file
75
docs/frameworks/task.md
Normal file
@ -0,0 +1,75 @@
|
||||
---
|
||||
title: "task"
|
||||
---
|
||||
|
||||
{{< callout type="info">}}
|
||||
Header: `task.h`
|
||||
{{< /callout >}}
|
||||
|
||||
The base for tasks controlled by `etl::scheduler`.
|
||||
|
||||
## Types
|
||||
|
||||
`etl::task_priority_t`
|
||||
The type for task priorities.
|
||||
|
||||
## task
|
||||
|
||||
```cpp
|
||||
task(task_priority_t priority)
|
||||
```
|
||||
Constructor.
|
||||
Sets the task priority.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
virtual ~task();
|
||||
```
|
||||
Virtual destructor
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
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.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
virtual void task_process_work() = 0;
|
||||
```
|
||||
The derived task must override this.
|
||||
The task should process one unit of work.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
virtual void on_task_added()
|
||||
```
|
||||
The derived task may override this.
|
||||
By default, does nothing.
|
||||
Since: `19.4.0`
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
void set_task_running(bool task_running)
|
||||
```
|
||||
Enables/disables the task from processing work.
|
||||
Enabled by default.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
bool task_is_running() const;
|
||||
```
|
||||
Returns `true` if the task is in the 'running' state.
|
||||
|
||||
```cpp
|
||||
etl::task_priority_t get_task_priority() const
|
||||
```
|
||||
Returns the priority of the task.
|
||||
53
docs/patterns/singleton-base.md
Normal file
53
docs/patterns/singleton-base.md
Normal file
@ -0,0 +1,53 @@
|
||||
---
|
||||
title: "singleton_base"
|
||||
---
|
||||
|
||||
{{< callout type="info">}}
|
||||
Header: `singleton_base.h`
|
||||
{{< /callout >}}
|
||||
|
||||
Allows creation of a singleton base class.
|
||||
|
||||
```cpp
|
||||
etl::singleton_base<typename T>
|
||||
```
|
||||
`T` The type to use as a singleton.
|
||||
|
||||
The class derived derived from this must call the constructor with the instance of itself.
|
||||
Multiple calls to the constructor will result in an `etl::singleton_base_already_created` assertion.
|
||||
|
||||
Before the constructor Is called, the singleton is in the invalid state.
|
||||
|
||||
See also `etl::singleton`
|
||||
|
||||
## Static functions
|
||||
|
||||
```cpp
|
||||
static T& instance()
|
||||
```
|
||||
Returns a reference to the one instance of `T`.
|
||||
Asserts an `etl::singleton_base_not_created` if the instance has not been attached.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
static bool is_valid()
|
||||
```
|
||||
Returns `true` if the instance is has been attached, otherwise `false`.
|
||||
|
||||
## Example
|
||||
|
||||
```cpp
|
||||
class MyType : public etl::singleton_base<MyType>
|
||||
{
|
||||
MyType()
|
||||
: etl::singleton_base<MyType>(*this)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
bool is_valid;
|
||||
is_valid = MyType::is_valid(); // true
|
||||
|
||||
MyType& mt = MyType::instance(); // Get the instance
|
||||
```
|
||||
@ -1,62 +1,107 @@
|
||||
Singleton
|
||||
---
|
||||
title: "singleton"
|
||||
---
|
||||
|
||||
Allows creation of a singleton, with deterministic construction and destruction.
|
||||
{{< callout type="info">}}
|
||||
Header: `singleton.h`
|
||||
{{< /callout >}}
|
||||
|
||||
Allows creation of a singleton, with deterministic construction and destruction.
|
||||
|
||||
```cpp
|
||||
etl::singleton<typename T>
|
||||
T The type to use as a singleton.
|
||||
```
|
||||
`T` The type to use as a singleton.
|
||||
|
||||
Before create Is called, the singleton is in the invalid state.
|
||||
Before create Is called, the singleton is in the invalid state.
|
||||
|
||||
See also etl::singleton_base
|
||||
____________________________________________________________________________________________________
|
||||
Static functions
|
||||
See also `etl::singleton_base`.
|
||||
|
||||
C++03 and below.
|
||||
## Static functions
|
||||
|
||||
**C++03 and below.**
|
||||
```cpp
|
||||
static void create()
|
||||
Creates the singleton. Default constructs the instance.
|
||||
Sets the singleton to the valid state.
|
||||
Only the first call to create is effective.
|
||||
Must be called before any calls to instance().
|
||||
```
|
||||
Creates the singleton. Default constructs the instance.
|
||||
Sets the singleton to the valid state.
|
||||
Only the first call to create is effective.
|
||||
Must be called before any calls to `instance()`.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <typename T1>
|
||||
static void create(const T1& p1)
|
||||
```
|
||||
Construct from 1 parameter.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <typename T1, typename T2>
|
||||
static void create(const T1& p1, const T2& p2)
|
||||
```
|
||||
Construct from 2 parameters.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <typename T1, typename T2, typename T3>
|
||||
static void create(const T1& p1, const T2& p2, const T3& p3)
|
||||
```
|
||||
Construct from 3 parameters.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <typename T1, typename T2, typename T3, typename T4>
|
||||
static void create(const T1& p1, const T2& p2, const T3& p3, const T4& p4)
|
||||
```
|
||||
Construct from 4 parameters.
|
||||
____________________________________________________________________________________________________
|
||||
C++11 and above.
|
||||
|
||||
---
|
||||
|
||||
**C++11 and above.**
|
||||
```cpp
|
||||
template <typename... TArgs>
|
||||
static void create(TArgs&&... args)
|
||||
Creates the singleton and constructs the type using the supplied parameters.
|
||||
Sets the singleton to the valid state.
|
||||
Only the first successful call to create is effective. Does nothing if the singleton is already valid.
|
||||
Must be called before any calls to instance().
|
||||
____________________________________________________________________________________________________
|
||||
static T& instance()
|
||||
Returns a reference to the one instance of T.
|
||||
Asserts an etl::singleton_not_created if create has not been called.
|
||||
____________________________________________________________________________________________________
|
||||
static void destroy()
|
||||
Calls the destructor of the instance.
|
||||
Sets the singleton to the invalid state.
|
||||
Only the first successful call to destroy is effective. Does nothing if the singleton is already invalid.
|
||||
____________________________________________________________________________________________________
|
||||
static bool is_valid()
|
||||
Returns true if the instance is valid.
|
||||
Returns false before create and after destroy are called.
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
```
|
||||
Creates the singleton and constructs the type using the supplied parameters.
|
||||
Sets the singleton to the valid state.
|
||||
Only the first successful call to create is effective. Does nothing if the singleton is already valid.
|
||||
Must be called before any calls to `instance()`.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
static T& instance()
|
||||
```
|
||||
Returns a reference to the one instance of `T`.
|
||||
Asserts an `etl::singleton_not_created` if create has not been called.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
static void destroy()
|
||||
```
|
||||
Calls the destructor of the instance.
|
||||
Sets the singleton to the invalid state.
|
||||
Only the first successful call to destroy is effective. Does nothing if the singleton is already invalid.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
static bool is_valid()
|
||||
```
|
||||
Returns `true` if the instance is valid.
|
||||
Returns `false` before `create` and after `destroy` are called.
|
||||
|
||||
---
|
||||
|
||||
## Example
|
||||
|
||||
```cpp
|
||||
class MyType;
|
||||
using MySingleton = etl::singleton<MyType>;
|
||||
bool is_valid;
|
||||
@ -73,7 +118,4 @@ is_valid = MySingleton::is_valid(); // true
|
||||
|
||||
MySingleton::destroy(); // Destruct the instance
|
||||
is_valid = MySingleton::is_valid(); // false
|
||||
|
||||
|
||||
|
||||
|
||||
```
|
||||
@ -1,66 +1,82 @@
|
||||
Visitor
|
||||
A set of template classes to enable the easy creation of objects using the Visitor pattern.
|
||||
The purpose of these classes is to create a base classes with pure virtual functions for each supplied type.
|
||||
Any derived class that tries to instantiate an object from it will then be forced to supply an overridden version for each and every function. See the tutorial.
|
||||
---
|
||||
title: "visitor"
|
||||
---
|
||||
|
||||
There are two templated classes:-
|
||||
{{< callout type="info">}}
|
||||
Header: `visitor.h`
|
||||
{{< /callout >}}
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
visitable
|
||||
The visitable base class.
|
||||
A set of template classes to enable the easy creation of objects using the Visitor pattern.
|
||||
The purpose of these classes is to create a base classes with pure virtual functions for each supplied type.
|
||||
Any derived class that tries to instantiate an object from it will then be forced to supply an overridden version for each and every function.
|
||||
|
||||
Classes derived from this are visitable by the types declared in the template parameter list. A pure virtual accept function will be created for each visitor type.
|
||||
There are two templated classes; `visitor` and `visitable`.
|
||||
|
||||
C++03
|
||||
## visitable
|
||||
The visitable base class.
|
||||
|
||||
Classes derived from this are visitable by the types declared in the template parameter list. A pure virtual `accept` function will be created for each visitor type.
|
||||
|
||||
**C++03**
|
||||
Up to four visitor types may be specified.
|
||||
|
||||
```cpp
|
||||
template <typename T1, typename T2 = void, typename T3 = void, typename T4 = void>
|
||||
class visitable
|
||||
class visitable;
|
||||
```
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
C++11 and above
|
||||
**C++11 and above**
|
||||
Any number of visitor types may be specified.
|
||||
|
||||
```cpp
|
||||
template <typename... Types>
|
||||
class visitable;
|
||||
```
|
||||
|
||||
____________________________________________________________________________________________________
|
||||
visitor
|
||||
The visitor base class.
|
||||
Classes derived from this can be passed to objects derived from visitable.
|
||||
A pure virtual visit function will be created for each specified type.
|
||||
## visitor
|
||||
The visitor base class.
|
||||
Classes derived from this can be passed to objects derived from `visitable`.
|
||||
A pure virtual `visit` function will be created for each specified type.
|
||||
|
||||
C++03
|
||||
**C++03**
|
||||
Up to sixteen types may be specified in the template parameter list
|
||||
|
||||
```cpp
|
||||
template <typename T1, typename T2 = void, typename T3 = void, typename T4 = void,
|
||||
typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void,
|
||||
0 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 visitor
|
||||
____________________________________________________________________________________________________
|
||||
C++11 and above
|
||||
Any number of types may be specified.
|
||||
class visitor;
|
||||
```
|
||||
|
||||
**C++11 and above**
|
||||
Any number of types may be specified.
|
||||
|
||||
```cpp
|
||||
template <typename... Types>
|
||||
class visitor
|
||||
____________________________________________________________________________________________________
|
||||
is_visitor
|
||||
Detects whether a type is a visitor.
|
||||
20.37.0
|
||||
class visitor;
|
||||
```
|
||||
|
||||
## is_visitor
|
||||
Detects whether a type is a visitor.
|
||||
Since: `20.37.0`.
|
||||
|
||||
```cpp
|
||||
template <typename T>
|
||||
struct is_visitor;
|
||||
Derived from etl::bool_constant
|
||||
____________________________________________________________________________________________________
|
||||
C++17 and above.
|
||||
```
|
||||
Derived from `etl::bool_constant`
|
||||
|
||||
**C++17 and above**
|
||||
```cpp
|
||||
template <typename T>
|
||||
struct is_visitor_v;
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
```
|
||||
|
||||
Before 20.37.0
|
||||
## Example
|
||||
|
||||
Before: `20.37.0`
|
||||
```cpp
|
||||
All arguments are passed by reference.
|
||||
|
||||
class Square;
|
||||
@ -115,10 +131,14 @@ Triangle triangle;
|
||||
square.accept(visitor); // visitor's visit(Square) is called.
|
||||
circle.accept(visitor); // visitor's visit(Circle&) is called.
|
||||
triangle.accept(visitor); // visitor's visit(const Triangle&) is called.
|
||||
____________________________________________________________________________________________________
|
||||
From 20.37.0
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
Since: `20.37.0`
|
||||
Arguments are passed according to the template parameters.
|
||||
|
||||
```cpp
|
||||
class Square;
|
||||
class Circle;
|
||||
class Triangle;
|
||||
@ -171,5 +191,4 @@ Triangle triangle;
|
||||
square.accept(visitor); // visitor's visit(Square) is called.
|
||||
circle.accept(visitor); // visitor's visit(Circle&) is called.
|
||||
triangle.accept(visitor); // visitor's visit(const Triangle&) is called.
|
||||
|
||||
|
||||
```
|
||||
@ -1,183 +0,0 @@
|
||||
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
|
||||
|
||||
@ -1,98 +0,0 @@
|
||||
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));
|
||||
|
||||
@ -1,157 +0,0 @@
|
||||
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
|
||||
|
||||
@ -1,82 +0,0 @@
|
||||
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);
|
||||
|
||||
@ -1,38 +0,0 @@
|
||||
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.
|
||||
|
||||
@ -1,41 +0,0 @@
|
||||
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.
|
||||
|
||||
|
||||
@ -1,103 +0,0 @@
|
||||
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.
|
||||
|
||||
|
||||
@ -1,41 +0,0 @@
|
||||
Singleton Base
|
||||
|
||||
Allows creation of a singleton base class.
|
||||
|
||||
etl::singleton_base<typename T>
|
||||
T The type to use as a singleton.
|
||||
|
||||
The class derived derived from this must call the constructor with the instance of itself.
|
||||
Mutiple call to the constructor will result in an etl::singleton_base_already_created assertion.
|
||||
|
||||
Before the constructor Is called, the singleton is in the invalid state.
|
||||
|
||||
See also etl::singleton
|
||||
____________________________________________________________________________________________________
|
||||
Static functions
|
||||
|
||||
static T& instance()
|
||||
Returns a reference to the one instance of T.
|
||||
Asserts an etl::singleton_base_not_created if the instance has not been attached.
|
||||
____________________________________________________________________________________________________
|
||||
static bool is_valid()
|
||||
Returns true if the instance is has been attached, otherwise false.
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
|
||||
class MyType : public etl::singleton_base<MyType>
|
||||
{
|
||||
MyType()
|
||||
: etl::singleton_base<MyType>(*this)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
bool is_valid;
|
||||
is_valid = MyType::is_valid(); // true
|
||||
|
||||
MyType& mt = MyType::instance(); // Get the instance
|
||||
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -2,6 +2,10 @@
|
||||
title: "string_stream"
|
||||
---
|
||||
|
||||
{{< callout type="info">}}
|
||||
Header: `string_stream.h`
|
||||
{{< /callout >}}
|
||||
|
||||
## Streaming types
|
||||
`string_stream`
|
||||
`wstring_stream`
|
||||
|
||||
@ -1,27 +1,39 @@
|
||||
string_view
|
||||
---
|
||||
title: "basic_string_view"
|
||||
---
|
||||
|
||||
This class implements a view in to a range of a C string, etl::string (+ variants), std::string (+ variants).
|
||||
{{< callout type="info">}}
|
||||
Header: `string_view.h`
|
||||
Similar to:
|
||||
`std::basic_string_view`
|
||||
`std::string_view`
|
||||
`std::wstring_view`
|
||||
`std::u8string_view`
|
||||
`std::u16string_view`
|
||||
`std::u32string_view`
|
||||
{{< /callout >}}
|
||||
|
||||
STL equivalents:
|
||||
std::basic_string_view
|
||||
std::string_view
|
||||
std::wstring_view
|
||||
std::u16string_view
|
||||
std::u32string_view
|
||||
____________________________________________________________________________________________________
|
||||
Classes
|
||||
This class implements a view in to a range of a `C` string, `etl::string` (+ variants), `std::string` (+ variants).
|
||||
|
||||
## Classes
|
||||
|
||||
```cpp
|
||||
etl::basic_string_view<typename T, typename TTraits = etl::char_traits<T>>
|
||||
____________________________________________________________________________________________________
|
||||
Typedefs
|
||||
```
|
||||
|
||||
etl::string_view<typename T>
|
||||
etl::wstring_view<typename T>
|
||||
etl::u16string_view<typename T>
|
||||
etl::u32string_view<typename T>
|
||||
____________________________________________________________________________________________________
|
||||
Member types
|
||||
## Types
|
||||
|
||||
```cpp
|
||||
etl::string_view
|
||||
etl::wstring_view
|
||||
etl::u8string_view;
|
||||
etl::u16string_view
|
||||
etl::u32string_view
|
||||
```
|
||||
|
||||
## Member types
|
||||
|
||||
```cpp
|
||||
value_type T
|
||||
size_type std::size_t
|
||||
difference_type std::ptrdiff_t
|
||||
@ -33,128 +45,209 @@ iterator Random access iterator
|
||||
const_iterator Constant random access iterator
|
||||
reverse_iterator std::reverse_iterator<iterator>
|
||||
const_reverse_iterator std::reverse_iterator<const_iterator>
|
||||
____________________________________________________________________________________________________
|
||||
Constants
|
||||
```
|
||||
|
||||
## Constants
|
||||
|
||||
```cpp
|
||||
size_t npos
|
||||
An end of view indicator by the functions that expect a view index.
|
||||
```
|
||||
**Description**
|
||||
An end of view indicator by the functions that expect a view index.
|
||||
An error indicator for functions that return a view index.
|
||||
____________________________________________________________________________________________________
|
||||
Constructors
|
||||
|
||||
## Constructors
|
||||
|
||||
```cpp
|
||||
ETL_CONSTEXPR basic_string_view()
|
||||
```
|
||||
**Description**
|
||||
Default constructor.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_CONSTEXPR basic_string_view(const T* begin, size_t size)
|
||||
```
|
||||
**Description**
|
||||
Construct from a start and size.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_CONSTEXPR basic_string_view(const T* begin)
|
||||
```
|
||||
**Description**
|
||||
Construct from a zero terminated string.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_CONSTEXPR basic_string_view(const etl::basic_string_view& other)
|
||||
```
|
||||
**Description**
|
||||
Copy constructor.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
ETL_CONSTEXPR basic_string_view(const std::basic_string_view& other)
|
||||
Construct from std::basic_string_view.
|
||||
For C++17 and STL only.
|
||||
20.39.5 and above.
|
||||
____________________________________________________________________________________________________
|
||||
Modifiers
|
||||
## Modifiers
|
||||
|
||||
```cpp
|
||||
void remove_prefix(size_t n)
|
||||
Shrinks the view from the front.
|
||||
```
|
||||
**Description**
|
||||
Shrinks the view from the front.
|
||||
Undefined behaviour if n is larger than the string.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
void remove_suffix(size_t n)
|
||||
Shrinks the view from the back.
|
||||
```
|
||||
**Description**
|
||||
Shrinks the view from the back.
|
||||
Undefined behaviour if n is larger than the string.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
void swap(etl::basic_string_view<T, TTraits>& view)
|
||||
```
|
||||
**Description**
|
||||
Swaps with another view.
|
||||
____________________________________________________________________________________________________
|
||||
Element access
|
||||
|
||||
## Element access
|
||||
|
||||
```cpp
|
||||
const T& at(size_t i) const
|
||||
Returns a const reference to the indexed element.
|
||||
Emits an etl::string_view_uninitialised if the view is not initialised.
|
||||
Emits an etl::string_view_bounds if the index is not in range.
|
||||
```
|
||||
**Description**
|
||||
Returns a const reference to the indexed element.
|
||||
Emits an `etl::string_view_uninitialised` if the view is not initialised.
|
||||
Emits an `etl::string_view_bounds` if the index is not in range.
|
||||
If asserts or exceptions are not enabled then undefined behaviour occurs.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
const_reference operator[](size_t i) const
|
||||
Returns a const reference to the indexed element.
|
||||
```
|
||||
**Description**
|
||||
Returns a const reference to the indexed element.
|
||||
Undefined behaviour if the string is empty.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
const_reference front() const
|
||||
```
|
||||
**Description**
|
||||
Returns a const reference to the first element.
|
||||
Undefined behaviour if the string is empty.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
const_reference back() const
|
||||
```
|
||||
**Description**
|
||||
Returns a const reference to the last element.
|
||||
Undefined behaviour if the string is empty.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
const_pointer data() const
|
||||
```
|
||||
**Description**
|
||||
Returns a const pointer to the first element.
|
||||
Undefined behaviour if the string is empty.
|
||||
____________________________________________________________________________________________________
|
||||
Iterators
|
||||
|
||||
## Iterators
|
||||
|
||||
```cpp
|
||||
const_iterator begin() const
|
||||
const_iterator cbegin() const
|
||||
```
|
||||
**Description**
|
||||
Returns an iterator to the beginning of the string view.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
const_iterator end() const
|
||||
const_iterator cend() const
|
||||
```
|
||||
**Description**
|
||||
Returns an iterator to the end of the string view.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
const_iterator rbegin() const
|
||||
const_iterator crbegin() const
|
||||
```
|
||||
**Description**
|
||||
Returns a reverse iterator to the beginning of the string view.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
const_iterator rend() const
|
||||
const_iterator crend() const
|
||||
```
|
||||
**Description**
|
||||
Returns a reverse iterator to the end of the string view.
|
||||
____________________________________________________________________________________________________
|
||||
Operations
|
||||
|
||||
## Operations
|
||||
|
||||
```cpp
|
||||
size_t copy(T* destination, size_t count, size_t position = 0) const
|
||||
```
|
||||
**Description**
|
||||
Copies the sub-string at position for count characters or size() - count, whichever smaller, to the string pointed to by destination.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
basic_string_view substr(size_t position = 0, size_t count = npos) const
|
||||
```
|
||||
**Description**
|
||||
Returns a view which is the sub-string at position for count characters or size() - count, whichever smaller.
|
||||
____________________________________________________________________________________________________
|
||||
Capacity
|
||||
|
||||
## Capacity
|
||||
|
||||
```cpp
|
||||
bool empty() const
|
||||
```
|
||||
**Description**
|
||||
Returns true if the size of the string view is zero, otherwise false.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
size_t size() const
|
||||
```
|
||||
**Description**
|
||||
Returns the size of the view.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
size_t length() const
|
||||
```
|
||||
**Description**
|
||||
Alternative for size().
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
size_t max_size() const
|
||||
```
|
||||
**Description**
|
||||
Returns the maximum possible size of the view.
|
||||
____________________________________________________________________________________________________
|
||||
Compare
|
||||
|
||||
## Compare
|
||||
|
||||
```cpp
|
||||
int compare(basic_string_view v) const
|
||||
int compare(size_t position1, size_t count1, basic_string_view view) const
|
||||
int compare(size_t position1, size_t count1,
|
||||
@ -163,86 +256,138 @@ int compare(size_t position1, size_t count1,
|
||||
int compare(const T* text) const
|
||||
int compare(size_t position1, size_t count, const T* text) const
|
||||
int compare(size_t position1, size_t count1, const T* text, size_t count2) const
|
||||
```
|
||||
**Description**
|
||||
Compares two character sequences.
|
||||
____________________________________________________________________________________________________
|
||||
Search
|
||||
|
||||
## Search
|
||||
|
||||
```cpp
|
||||
bool starts_with(etl::basic_string_view view) const
|
||||
bool starts_with(T x) const
|
||||
bool starts_with(const T* x) const
|
||||
```
|
||||
**Description**
|
||||
Checks if the string view begins with the given prefix.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
bool ends_with(etl::basic_string_view view) const
|
||||
bool ends_with(T x) const
|
||||
bool ends_with(const T* x) const
|
||||
```
|
||||
**Description**
|
||||
Checks if the string view ends with the given prefix.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
size_t find(basic_string_view view, size_type position = 0) const
|
||||
size_t find(T c, size_t position = 0) const
|
||||
size_t find(const T* text, size_t position, size_t count) const
|
||||
size_t find(const T* text, size_t position = 0) const;
|
||||
```
|
||||
**Description**
|
||||
Finds the first sub-string equal to the given character sequence.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
size_t rfind(basic_string_view view, size_t position = npos) const
|
||||
size_t rfind(T c, size_t position = npos) const
|
||||
size_t rfind(const T* text, size_t position, size_t count) const
|
||||
size_t rfind(const T* text, size_t position = npos) const
|
||||
```
|
||||
**Description**
|
||||
Finds the last sub-string equal to the given character sequence.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
size_t find_first_of(basic_string_view view, size_t position = 0) const
|
||||
size_t find_first_of(T c, size_t position = 0) const
|
||||
size_t find_first_of(const T* text, size_t position, size_t count) const
|
||||
size_t find_first_of(const T* text, size_t position = 0) const
|
||||
```
|
||||
**Description**
|
||||
Finds the first character equal to any of the characters in the given character sequence.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
size_t find_last_of(basic_string_view view, size_t position = npos) const
|
||||
size_t find_last_of(T c, size_t position = npos) const
|
||||
size_t find_last_of(const T* text, size_t position, size_type count) const
|
||||
size_t find_last_of(const T* text, size_t position = npos) const
|
||||
```
|
||||
**Description**
|
||||
Finds the last character equal to any of the characters in the given character sequence.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
size_t find_first_not_of(basic_string_view view, size_t position = 0) const
|
||||
size_t find_first_not_of(T c, size_t position = 0) const
|
||||
size_t find_first_not_of(const T* text, size_t position, size_t count) const
|
||||
size_t find_first_not_of(const T* text, size_t position = 0) const
|
||||
```
|
||||
**Description**
|
||||
Finds the first character not equal to any of the characters in the given character sequence.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
size_t find_last_not_of(basic_string_view view, size_t position = npos) const
|
||||
size_t find_last_not_of(T c, size_t position = npos) const
|
||||
size_t find_last_not_of(const T* text, size_t position, size_t count) const
|
||||
size_t find_last_not_of(const T* text, size_t position = npos) const
|
||||
```
|
||||
**Description**
|
||||
Finds the first character not equal to any of the characters in the given character sequence.
|
||||
____________________________________________________________________________________________________
|
||||
Non-member functions
|
||||
Lexicographically comparisons
|
||||
|
||||
== true if the contents of the string views are equal, otherwise false.
|
||||
!= true if the contents of the string views are not equal, otherwise false.
|
||||
< true if the contents of the lhs are lexicographically less than the contents of the rhs, otherwise false.
|
||||
<= true if the contents of the lhs are lexicographically less than or equal to the contents of the rhs, otherwise false.
|
||||
> true if the contents of the lhs are lexicographically greater than the contents of the rhs, otherwise false.
|
||||
>= true if the contents of the lhs are lexicographically greater than or equal to the contents of the rhs, otherwise false
|
||||
## Non-member functions
|
||||
**Lexicographically comparisons**
|
||||
|
||||
`==` `true` if the contents of the string views are equal,
|
||||
otherwise `false`.
|
||||
|
||||
`!=` `true` if the contents of the string views are not equal,
|
||||
otherwise `false`.
|
||||
|
||||
`< ` `true` if the contents of the lhs are lexicographically less than the contents of the rhs,
|
||||
otherwise `false`.
|
||||
|
||||
`<=` `true` if the contents of the lhs are lexicographically less than or equal to the contents of the rhs,
|
||||
otherwise `false`.
|
||||
|
||||
`> ` `true` if the contents of the lhs are lexicographically greater than the contents of the rhs,
|
||||
otherwise `false`.
|
||||
|
||||
`>=` `true` if the contents of the lhs are lexicographically greater than or equal to the contents of the rhs,
|
||||
otherwise `false`.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
void swap(etl::basic_string_view<T, TTraits> lhs,
|
||||
etl::basic_string_view<T, TTraits> rhs)
|
||||
```
|
||||
Swaps two views.
|
||||
____________________________________________________________________________________________________
|
||||
Hash
|
||||
|
||||
## Hash
|
||||
|
||||
```cpp
|
||||
etl::hash<etl::string_view>
|
||||
etl::hash<etl::wstring_view>
|
||||
etl::hash<etl::u8string_view>
|
||||
etl::hash<etl::u16string_view>
|
||||
etl::hash<etl::u32string_view>
|
||||
____________________________________________________________________________________________________
|
||||
Example
|
||||
---
|
||||
|
||||
**Example**
|
||||
|
||||
```cpp
|
||||
etl::string<10> greeting("Hello World");
|
||||
|
||||
using View = etl::string_view;
|
||||
@ -257,4 +402,4 @@ void Print(const View& view)
|
||||
Print(view); // Prints "llo Wo"
|
||||
|
||||
size_t hashvalue = etl::hash<View>()(view);
|
||||
|
||||
```
|
||||
@ -1,220 +1,340 @@
|
||||
to_arithmetic
|
||||
---
|
||||
title: "to_arithmetic"
|
||||
---
|
||||
|
||||
Functions that will convert a text representation of an arithmetic type to a value.
|
||||
Converts from binary, octal, decimal and hex integrals, and decimal floating point types.
|
||||
Supports conversion from char, wchar_t, char16_t and char32_t strings.
|
||||
The numeric strings must not contain leading or trailing non-numeric characters. It is the responsibility of the user to select the valid character range.
|
||||
Integral types may be constexpr.
|
||||
____________________________________________________________________________________________________
|
||||
to_arithmetic_status
|
||||
An ETL enum type that defines the following enumeration values.
|
||||
The are the values that may be set as the error code in to_arithmetic_result.
|
||||
{{< callout type="info">}}
|
||||
Header: `to_arithmetic.h`
|
||||
{{< /callout >}}
|
||||
|
||||
Functions that will convert a text representation of an arithmetic type to a value.
|
||||
Converts from binary, octal, decimal and hex integrals, and decimal floating point types.
|
||||
Supports conversion from `char`, `wchar_t`, `char8_t`, `char16_t`, and `char32_t` strings.
|
||||
The numeric strings must not contain leading or trailing non-numeric characters. It is the responsibility of the user to select the valid character range.
|
||||
Integral types may be `constexpr`.
|
||||
|
||||
## to_arithmetic_status
|
||||
An ETL enum type that defines the following enumeration values.
|
||||
The are the values that may be set as the error code in to_arithmetic_result.
|
||||
|
||||
```cpp
|
||||
Valid
|
||||
Invalid_Radix
|
||||
Invalid_Format
|
||||
Invalid_Float
|
||||
Signed_To_Unsigned
|
||||
Overflow
|
||||
____________________________________________________________________________________________________
|
||||
to_arithmetic_result
|
||||
The result type returned from etl::to_arithmetic.
|
||||
```
|
||||
|
||||
## to_arithmetic_result
|
||||
The result type returned from `etl::to_arithmetic`.
|
||||
|
||||
```cpp
|
||||
template <typename TValue>
|
||||
to_arithmetic_result
|
||||
____________________________________________________________________________________________________
|
||||
Types
|
||||
```
|
||||
|
||||
**Types**
|
||||
```cpp
|
||||
value_type TValue
|
||||
error_type etl::to_arithmetic_status
|
||||
unexpected_type etl::unexpected<etl::to_arithmetic_status>
|
||||
____________________________________________________________________________________________________
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_CONSTEXPR14
|
||||
to_arithmetic_result()
|
||||
```
|
||||
Default constructor.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_CONSTEXPR14
|
||||
to_arithmetic_result(const to_arithmetic_result& other)
|
||||
```
|
||||
Copy constructor.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
bool has_value() const
|
||||
Returns true if the result has a valid value.
|
||||
If false then the value is undefined.
|
||||
____________________________________________________________________________________________________
|
||||
```
|
||||
Returns `true` if the result has a valid value.
|
||||
If `false` then the value is undefined.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
operator bool() const
|
||||
Returns true if the result has a valid value.
|
||||
If false then the value is undefined.
|
||||
____________________________________________________________________________________________________
|
||||
```
|
||||
Returns `true` if the result has a valid value.
|
||||
If `false` then the value is undefined.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
value_type value() const
|
||||
Returns the value, if valid.
|
||||
```
|
||||
Returns the value, if valid.
|
||||
Otherwise undefined.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
operator value_type() const
|
||||
Returns the value, if valid.
|
||||
```
|
||||
Returns the value, if valid.
|
||||
Otherwise undefined.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
error_type error() const
|
||||
Returns the conversion status.
|
||||
One of the following:-
|
||||
```
|
||||
Returns the conversion status.
|
||||
One of the following:-
|
||||
```cpp
|
||||
Valid
|
||||
Invalid_Radix
|
||||
Invalid_Format
|
||||
Invalid_Float
|
||||
Signed_To_Unsigned
|
||||
Overflow
|
||||
____________________________________________________________________________________________________
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_CONSTEXPR14
|
||||
to_arithmetic_result& operator =(value_type value)
|
||||
```
|
||||
Assign from a value_type.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_CONSTEXPR14
|
||||
to_arithmetic_result& operator =(unexpected_type status)
|
||||
```
|
||||
Assign from an unexpected_type.
|
||||
____________________________________________________________________________________________________
|
||||
to_arithmetic
|
||||
Convert a string to an integral or floating point value.
|
||||
Supports:
|
||||
etl::string_view (etl::basic_string_view<TChar>)
|
||||
const pointer (to char, wchar_t, char16_t, char32_t) + length
|
||||
etl::string, etl::wstring, etl::u16string or etl::u32string
|
||||
|
||||
---
|
||||
|
||||
## to_arithmetic
|
||||
Convert a string to an integral or floating point value.
|
||||
Supports:
|
||||
`etl::string_view` (`etl::basic_string_view<TChar>`)
|
||||
const pointer (to `char`, `wchar_t`, `char8_t`, `char16_t`, `char32_t`) + length
|
||||
`etl::string`, `etl::wstring`, `etl::u8string`, `etl::u16string`, or `etl::u32string`.
|
||||
|
||||
```cpp
|
||||
template <typename TValue, typename TChar>
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
etl::to_arithmetic_result<TValue> to_arithmetic(const etl::basic_string_view<TChar>& view)
|
||||
```
|
||||
Text to integral or floating point from view and default decimal radix.
|
||||
____________________________________________________________________________________________________
|
||||
template <typename TValue, typename TChar>
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <typename TValue, typename TChar>
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
etl::to_arithmetic_result<TValue> to_arithmetic(etl::basic_string_view<TChar> view,
|
||||
const etl::radix::value_type radix)
|
||||
Text to integral from view and radix value type.
|
||||
radix may be one of the following:-
|
||||
```
|
||||
Text to integral from view and radix value type.
|
||||
radix may be one of the following:-
|
||||
```cpp
|
||||
etl::radix::binary
|
||||
etl::radix::octal
|
||||
etl::radix::decimal
|
||||
etl::radix::hex
|
||||
____________________________________________________________________________________________________
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
etl::to_arithmetic_result<TValue> to_arithmetic(const etl::basic_string_view<TChar>& view,
|
||||
const etl::private_basic_format_spec::base_spec& spec)
|
||||
Text to integral from view and radix format spec.
|
||||
spec may be one of the following:-
|
||||
```
|
||||
Text to integral from view and radix format spec.
|
||||
spec may be one of the following:-
|
||||
```cpp
|
||||
etl::bin
|
||||
etl::oct
|
||||
etl::dec
|
||||
etl::hex
|
||||
____________________________________________________________________________________________________
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <typename TValue, typename TChar>
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
etl::to_arithmetic_result<TValue> to_arithmetic(const TChar* cp,
|
||||
size_t length)
|
||||
```
|
||||
Text to integral or floating point from pointer, length and default decimal radix.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <typename TValue, typename TChar>
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
etl::to_arithmetic_result<TValue> to_arithmetic(const TChar* cp,
|
||||
size_t length,
|
||||
const etl::radix::value_type radix)
|
||||
Text to integral from pointer, length and radix value type.
|
||||
radix may be one of the following:-
|
||||
```
|
||||
Text to integral from pointer, length and radix value type.
|
||||
radix may be one of the following:-
|
||||
```cpp
|
||||
etl::radix::binary
|
||||
etl::radix::octal
|
||||
etl::radix::decimal
|
||||
etl::radix::hex
|
||||
____________________________________________________________________________________________________
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <typename TValue, typename TChar>
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
etl::to_arithmetic_result<TValue> to_arithmetic(const TChar* cp,
|
||||
size_t length,
|
||||
const etl::private_basic_format_spec::base_spec& spec)
|
||||
Text to integral from pointer, length and radix format spec.
|
||||
spec may be one of the following:-
|
||||
```
|
||||
Text to integral from pointer, length and radix format spec.
|
||||
spec may be one of the following:-
|
||||
```cpp
|
||||
etl::bin
|
||||
etl::oct
|
||||
etl::dec
|
||||
etl::hex
|
||||
____________________________________________________________________________________________________
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <typename TValue, typename TChar>
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
etl::to_arithmetic_result<TValue> to_arithmetic(const etl::ibasic_string<TChar>& str)
|
||||
```
|
||||
Text to integral or floating point from string and default decimal radix.
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <typename TValue, typename TChar>
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
etl::to_arithmetic_result<TValue> to_arithmetic(const etl::ibasic_string<TChar>& str,
|
||||
const etl::radix::value_type radix)
|
||||
Text to integral from string and radix value type.
|
||||
radix may be one of the following:-
|
||||
```
|
||||
Text to integral from string and radix value type.
|
||||
radix may be one of the following:-
|
||||
```cpp
|
||||
etl::radix::binary
|
||||
etl::radix::octal
|
||||
etl::radix::decimal
|
||||
etl::radix::hex
|
||||
____________________________________________________________________________________________________
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <typename TValue, typename TChar>
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
etl::to_arithmetic_result<TValue> to_arithmetic(const etl::ibasic_string<TChar>& str,
|
||||
const etl::private_basic_format_spec::base_spec& spec)
|
||||
Text to integral from string and radix format spec.
|
||||
spec may be one of the following:-
|
||||
```
|
||||
Text to integral from string and radix format spec.
|
||||
spec may be one of the following:-
|
||||
```cpp
|
||||
etl::bin
|
||||
etl::oct
|
||||
etl::dec
|
||||
etl::hex
|
||||
____________________________________________________________________________________________________
|
||||
Non-member functions
|
||||
```
|
||||
|
||||
## Non-member functions
|
||||
|
||||
```cpp
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR14 bool operator ==(const etl::to_arithmetic_result<T>& lhs,
|
||||
const etl::to_arithmetic_result<T>& rhs)
|
||||
```
|
||||
Equality test for etl::to_arithmetic_result
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <typename T, typename U>
|
||||
ETL_CONSTEXPR14 bool operator ==(const etl::to_arithmetic_result<T>& lhs,
|
||||
const U& rhs)
|
||||
```
|
||||
Equality test for etl::to_arithmetic_result
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <typename T, typename U>
|
||||
ETL_CONSTEXPR14 bool operator ==(const T& lhs,
|
||||
const etl::to_arithmetic_result<U>& rhs)
|
||||
```
|
||||
Equality test for etl::to_arithmetic_result
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR14 bool operator !=(const etl::to_arithmetic_result<T>& lhs,
|
||||
const etl::to_arithmetic_result<T>& rhs)
|
||||
```
|
||||
Inequality test for etl::to_arithmetic_result
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <typename T, typename U>
|
||||
ETL_CONSTEXPR14 bool operator !=(const etl::to_arithmetic_result<T>& lhs,
|
||||
const U& rhs)
|
||||
```
|
||||
Inequality test for etl::to_arithmetic_result
|
||||
____________________________________________________________________________________________________
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <typename T, typename U>
|
||||
ETL_CONSTEXPR14 bool operator !=(const T& lhs,
|
||||
const etl::to_arithmetic_result<T>& rhs)
|
||||
```
|
||||
Inequality test for etl::to_arithmetic_result
|
||||
____________________________________________________________________________________________________
|
||||
Examples
|
||||
|
||||
Valid conversions
|
||||
## Examples
|
||||
|
||||
**Valid conversions**
|
||||
```cpp
|
||||
const char* BinaryText("1010011");
|
||||
const etl::string<3> OctalText("123");
|
||||
const etl::string<4> DecimalText(" 83 ");
|
||||
@ -233,8 +353,11 @@ int v3 = etl::to_arithmetic<int>(view);
|
||||
|
||||
// From hex string. Base 16 radix.
|
||||
int v4 = etl::to_arithmetic<int>(HexText, 16);
|
||||
____________________________________________________________________________________________________
|
||||
Invalid conversions
|
||||
```
|
||||
---
|
||||
|
||||
**Invalid conversions**
|
||||
```cpp
|
||||
const etl::string<10> Text1("abcd");
|
||||
const etl::string<10> Text2(" 83 ");
|
||||
const etl::string<10> Text3("-83");
|
||||
@ -254,5 +377,4 @@ result = etl::to_arithmetic<uint32_t>(Text3); // etl::to_arithmetic_status::Si
|
||||
result = etl::to_arithmetic<int32_t>(Text4); // etl::to_arithmetic_status::Overflow
|
||||
|
||||
result = etl::to_arithmetic<float>(Text5); // etl::to_arithmetic_status::Overflow
|
||||
|
||||
|
||||
```
|
||||
@ -1,58 +1,77 @@
|
||||
to_string
|
||||
---
|
||||
title: "to_string"
|
||||
---
|
||||
|
||||
Functions that will render a text representation of bools, integrals, floating point, strings, string views and pointers.
|
||||
Uses etl::basic_format_spec to define the required formatting.
|
||||
{{< callout type="info">}}
|
||||
Header: `to_string.h`
|
||||
{{< /callout >}}
|
||||
|
||||
It will convert to any of the ETL string types.
|
||||
____________________________________________________________________________________________________
|
||||
Functions that will render a text representation of bools, integrals, floating point, strings, string views and pointers.
|
||||
Uses `etl::basic_format_spec` to define the required formatting.
|
||||
|
||||
Default format specification
|
||||
Where StringType is etl::istring, etl::iwstring, etl::iu16string or etl::iu32string
|
||||
It will convert to any of the ETL string types.
|
||||
|
||||
## Default format specification
|
||||
Where `StringType` is `etl::istring`, `etl::iwstring`, `etl::iu8string`, `etl::iu16string` or `etl::iu32string`.
|
||||
|
||||
```cpp
|
||||
template <typename T>
|
||||
const StringType& to_string(const T value,
|
||||
StringType& str,
|
||||
const bool append = false)
|
||||
```
|
||||
|
||||
20.17.0
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <typename T> // Where T is an integral
|
||||
const StringType& to_string(const T value,
|
||||
uint32_t denominator_exponent,
|
||||
StringType& str,
|
||||
const bool append = false)
|
||||
```
|
||||
|
||||
value The value to convert to a string.
|
||||
str The string in with to place the rendered text.
|
||||
append If true then appends the text to the current string's content. Default false.
|
||||
____________________________________________________________________________________________________
|
||||
`value` The value to convert to a string.
|
||||
`str` The string in with to place the rendered text.
|
||||
`append` If true then appends the text to the current string's content. Default `false`.
|
||||
Since: `20.17.0`
|
||||
|
||||
Supplied format specification
|
||||
Where StringType is etl::istring, etl::iwstring, etl::iu16string or etl::iu32string
|
||||
Where FormatType is etl::format_spec, etl::wformat_spec, etl::u16format_spec or etl::u32format_spec
|
||||
## Supplied format specification
|
||||
Where `StringType` is `etl::istring`, `etl::iwstring`, `etl::iu8string`, `etl::iu16string` or `etl::iu32string`.
|
||||
Where `FormatType` is `etl::format_spec`, `etl::wformat_spec`, `etl::u8format_spec`, `etl::u16format_spec` or `etl::u32format_spec`
|
||||
|
||||
```cpp
|
||||
template <typename T>
|
||||
const StringType& to_string(const T value,
|
||||
StringType& str,
|
||||
const FormatType& format,
|
||||
const bool append = false)
|
||||
```
|
||||
|
||||
20.17.0
|
||||
template <typename T> // Where T is an integral
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <typename T>
|
||||
const StringType& to_string(const T value,
|
||||
uint32_t denominator_exponent,
|
||||
StringType& str,
|
||||
const FormatType& format,
|
||||
const bool append = false)
|
||||
```
|
||||
|
||||
value The value to convert to a string.
|
||||
denominator_exponent The exponent of the value that is used to divide the value.
|
||||
str The string in with to place the rendered text.
|
||||
format The format specification.
|
||||
append If true then appends the text to the current string's content. Default false.
|
||||
____________________________________________________________________________________________________
|
||||
Examples
|
||||
`value` The value to convert to a string.
|
||||
`denominator_exponent` The exponent of the value that is used to divide the value.
|
||||
`str` The string in with to place the rendered text.
|
||||
`format` The format specification.
|
||||
`append` If `true` then appends the text to the current string's content. Default `false`.
|
||||
Since: `20.17.0`
|
||||
|
||||
Format as a hex character, minimum fill width of 8, fill with zeros
|
||||
---
|
||||
|
||||
## Examples
|
||||
|
||||
Format as a hex character, minimum fill width of 8, fill with zeros
|
||||
```cpp
|
||||
etl::format_spec format;
|
||||
|
||||
// Format as a hex character, minimum fill width of 8, fill with zeros.
|
||||
@ -62,7 +81,7 @@ etl::string<8> text;
|
||||
|
||||
// 'text' is set to "00123456"
|
||||
etl::to_string(1193046, text, format);
|
||||
____________________________________________________________________________________________________
|
||||
---
|
||||
Format minimum fill width of 8, fill with space and three decimal digits
|
||||
etl::format_spec format;
|
||||
|
||||
@ -73,16 +92,16 @@ etl::string<8> text;
|
||||
|
||||
// 'text' is set to " 3.142"
|
||||
etl::to_string(3.1415, text, format);
|
||||
____________________________________________________________________________________________________
|
||||
---
|
||||
Format a floating point number
|
||||
etl::string<19> text = "The result is ";
|
||||
|
||||
etl::to_string(3.1415, text, etl::format_spec().precision(3), true);
|
||||
// 'text' is set to "The result is 3.142"
|
||||
____________________________________________________________________________________________________
|
||||
---
|
||||
Format an integral number and divide by 10000
|
||||
etl::string<19> text = "The result is ";
|
||||
|
||||
etl::to_string(31415, 4U, text, etl::format_spec().precision(3), true);
|
||||
// 'text' is set to "The result is 3.142"
|
||||
|
||||
```
|
||||
@ -10,10 +10,9 @@ html:not(.dark) .highlight .chroma .cpf {
|
||||
}
|
||||
|
||||
html:not(.dark) h1 {
|
||||
color: coral !important;
|
||||
color: white !important;
|
||||
width: 100%;
|
||||
background-color: rgb(246, 246, 246) !important;
|
||||
border: black solid 3px !important;
|
||||
background-color: royalblue !important;
|
||||
padding: 0.5rem 0.5rem !important;
|
||||
}
|
||||
|
||||
@ -118,10 +117,10 @@ html.dark .hx\:dark\:bg-dark {
|
||||
|
||||
html.dark h1
|
||||
{
|
||||
color: coral !important;
|
||||
color: white !important;
|
||||
width: 100%;
|
||||
background-color: rgb(50, 50, 50) !important;
|
||||
border: lightgrey solid 2px !important;
|
||||
#background-color: rgb(50, 50, 50) !important;
|
||||
background-color: #7099c7 !important;
|
||||
padding: 0.5rem 0.5rem !important;
|
||||
}
|
||||
|
||||
@ -296,9 +295,10 @@ h1 {
|
||||
font-family: Roboto, sans-serif !important;
|
||||
font-style: i !important;
|
||||
font-weight: 500 !important;
|
||||
font-size: 180% !important;
|
||||
margin-top: 0.5em !important;
|
||||
margin-bottom: 0.0em !important;
|
||||
border-radius: 0.75rem !important;
|
||||
border-radius: 0.5rem !important;
|
||||
}
|
||||
|
||||
h2 {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user