From 2ef7a29cdde4168f45f6ab4d20dd4012a4675db8 Mon Sep 17 00:00:00 2001 From: Niklas Hauser Date: Tue, 12 Oct 2021 22:44:20 +0200 Subject: [PATCH] [example] Add ETL examples with assertion Co-authored-by: Raphael Lehmann --- examples/generic/etl/main.cpp | 44 ++++++++++++++++++++++++++++++++ examples/generic/etl/project.xml | 10 ++++++++ examples/linux/etl/main.cpp | 36 ++++++++++++++++++++++++++ examples/linux/etl/project.xml | 13 ++++++++++ 4 files changed, 103 insertions(+) create mode 100644 examples/generic/etl/main.cpp create mode 100644 examples/generic/etl/project.xml create mode 100644 examples/linux/etl/main.cpp create mode 100644 examples/linux/etl/project.xml diff --git a/examples/generic/etl/main.cpp b/examples/generic/etl/main.cpp new file mode 100644 index 0000000000..29cfe118ca --- /dev/null +++ b/examples/generic/etl/main.cpp @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2021, Raphael Lehmann + * + * This file is part of the modm project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#include + +using namespace std::chrono_literals; + +int main() +{ + Board::initialize(); + + while (true) + { + // Create an unordered_map of three strings (that map to strings) + etl::unordered_map u = { + {15, std::numbers::pi}, + {42, std::numbers::e}, + {87, std::numbers::sqrt2} + }; + + if (Board::Button::read()) { + // Access non-existant element causing an assertion + MODM_LOG_INFO << u[12]; + } + + MODM_LOG_INFO << "Iterate and print keys and values using structured binding (since C++17):\n"; + for( const auto& [key, value] : u ) { + MODM_LOG_INFO << "Key:[" << key << "] Value:[" << value << "]\n"; + } + + modm::delay(5000ms); + } + + return 0; +} diff --git a/examples/generic/etl/project.xml b/examples/generic/etl/project.xml new file mode 100644 index 0000000000..6292a7cbb4 --- /dev/null +++ b/examples/generic/etl/project.xml @@ -0,0 +1,10 @@ + + modm:nucleo-f439zi + + + + + modm:etl + modm:build:scons + + diff --git a/examples/linux/etl/main.cpp b/examples/linux/etl/main.cpp new file mode 100644 index 0000000000..518e879758 --- /dev/null +++ b/examples/linux/etl/main.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2021, Raphael Lehmann + * + * This file is part of the modm project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#include +#include + +using namespace std::chrono_literals; + +int main() +{ + // Create an unordered_map of three strings (that map to strings) + etl::unordered_map u = { + {15, std::numbers::pi}, + {42, std::numbers::e}, + {87, std::numbers::sqrt2} + }; + + MODM_LOG_INFO << "Iterate and print keys and values using structured binding (since C++17):\n"; + for( const auto& [key, value] : u ) { + MODM_LOG_INFO << "Key:[" << key << "] Value:[" << value << "]\n"; + } + + // Access non-existant element causing an assertion + MODM_LOG_INFO << u[12]; + + return 0; +} diff --git a/examples/linux/etl/project.xml b/examples/linux/etl/project.xml new file mode 100644 index 0000000000..d776773bbc --- /dev/null +++ b/examples/linux/etl/project.xml @@ -0,0 +1,13 @@ + + + + + + + + modm:etl + modm:debug + modm:platform:core + modm:build:scons + +