git subrepo clone --branch=20.41.6 git@github.com:ETLCPP/etl.git components/etl

subrepo:
  subdir:   "components/etl"
  merged:   "be5537ec"
upstream:
  origin:   "git@github.com:ETLCPP/etl.git"
  branch:   "20.41.6"
  commit:   "be5537ec"
git-subrepo:
  version:  "0.4.9"
  origin:   "???"
  commit:   "???"
This commit is contained in:
Attila Body 2025-06-11 11:25:49 +02:00
parent 931c4def56
commit 11c24647ea
Signed by: abody
GPG key ID: BD0C6214E68FB5CF
1296 changed files with 801882 additions and 0 deletions

View file

@ -0,0 +1,7 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
.vscode/settings.json
lib/etl

View file

@ -0,0 +1,7 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
]
}

View file

@ -0,0 +1,16 @@
ETL PlatformIO demo
===================
> Template to demonstrate how to use ETL with PlatformIO.
1. Open this folder in VSCode and agree if it suggests to install extension.
2. Use `Terminal -> Run Build Task... -> PlatformIO: Build` menu to compile.
3. Run `.pio/Build/native/program`.
## Details
Use `platformio.ini` for example, see comments inside.
`include` folder contains config, required for `etl`. All is as transparent
as possible. Set all additional variables via `build_flags` option in
`platform.ini`. Currently only `PROFILE_GCC_GENERIC` set to make things work.

View file

@ -0,0 +1 @@
#include "etl/profiles/etl_profile.h"

View file

@ -0,0 +1,27 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; http://docs.platformio.org/page/projectconf.html
[platformio]
default_envs = native
[env:native]
platform = native
build_flags =
; ETL configs in `include` folder are minimalistic. Here we can set all
; additional definitions to keep everything in one place and customize values
; for different target platforms
-D PROFILE_GCC_GENERIC
lib_deps =
; Define ETL dependency for this demo. You can use versions from PIO registry,
; or git repository with specific branch, tag or commit. See PIO docs for
; details.
;Embedded Template Library=https://github.com/ETLCPP/etl/archive/master.zip
Embedded Template Library@^14.31.2

View file

@ -0,0 +1,142 @@
#include <iostream>
#include "etl/observer.h"
// Position data.
struct Position
{
int x;
int y;
};
// Button data.
struct Button
{
enum
{
Down,
Up
};
int state;
};
// Wheel data.
struct Wheel
{
int delta;
};
// Definition of a mouse observer.
typedef etl::observer<const Position&, Button, Wheel> Mouse_Observer;
// Definition of an event handler for mouse notifications.
class Event_Handler1 : public Mouse_Observer
{
public:
// Handle a position notification.
void notification(const Position& position)
{
std::cout << "Event_Handler1 : Position = " << position.x << "," << position.y << "\n";
}
// Handle a button notification.
void notification(Button button)
{
std::cout << "Event_Handler1 : Button = " << ((button.state == Button::Up) ? "Up\n" : "Down\n");
}
// Handle a wheel notification.
void notification(Wheel wheel)
{
std::cout << "Event_Handler1 : Wheel delta = " << wheel.delta << "\n";
}
};
// Definition of a second event handler for mouse notifications.
class Event_Handler2 : public Mouse_Observer
{
public:
// Handler a position notification.
void notification(const Position& position)
{
std::cout << "Event_Handler2 : Position = " << position.x << "," << position.y << "\n";
}
// Handle a button notification.
void notification(Button button)
{
std::cout << "Event_Handler2 : Button = " << ((button.state == Button::Up) ? "Up\n" : "Down\n");
}
// Handle a wheel notification.
void notification(Wheel wheel)
{
// Not interested in wheel deltas.
}
};
// The observable mouse driver.
const int MAX_MOUSE_OBSERVERS = 2;
class Mouse_Driver : public etl::observable<Mouse_Observer, MAX_MOUSE_OBSERVERS>
{
public:
// Notify observers about a position event.
void Position_Event()
{
Position position = { 100, 200 };
notify_observers(position);
}
// Notify observers about a button up event.
void Button_Event_Up()
{
Button button = { Button::Up };
notify_observers(button);
}
// Notify observers about a button down event.
void Button_Event_Down()
{
Button button = { Button::Down };
notify_observers(button);
}
// Notify observers about a wheel up event.
void Wheel_Event_Up()
{
Wheel wheel = { 50 };
notify_observers(wheel);
}
// Notify observers about a wheel down event.
void Wheel_Event_Down()
{
Wheel wheel = { -25 };
notify_observers(wheel);
}
};
int main()
{
Mouse_Driver mouse_driver;
Event_Handler1 event_handler1;
Event_Handler2 event_handler2;
// Tell the mouse driver about the observers.
mouse_driver.add_observer(event_handler1);
mouse_driver.add_observer(event_handler2);
// Generate some events.
mouse_driver.Button_Event_Down();
mouse_driver.Button_Event_Up();
mouse_driver.Position_Event();
mouse_driver.Wheel_Event_Down();
mouse_driver.Wheel_Event_Up();
return 0;
}