rename chapters
51
Chapter16/fsm/libs/etl/.clang-format
Normal file
@@ -0,0 +1,51 @@
|
||||
---
|
||||
#------------------------------------
|
||||
# Configuration for clang-format v12
|
||||
#------------------------------------
|
||||
|
||||
Language: Cpp
|
||||
|
||||
SortIncludes: true
|
||||
|
||||
BasedOnStyle: Chromium
|
||||
|
||||
BinPackParameters: false
|
||||
BitFieldColonSpacing: Both
|
||||
|
||||
BreakBeforeBraces: Allman
|
||||
BreakConstructorInitializers: BeforeComma
|
||||
|
||||
AllowShortBlocksOnASingleLine: false
|
||||
AllowShortCaseLabelsOnASingleLine: true
|
||||
AllowShortFunctionsOnASingleLine: None
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
|
||||
AllowAllArgumentsOnNextLine: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: 'true'
|
||||
ConstructorInitializerIndentWidth: '2'
|
||||
|
||||
NamespaceIndentation: All
|
||||
IndentPPDirectives: BeforeHash
|
||||
PointerAlignment: Left
|
||||
ColumnLimit: '0'
|
||||
ContinuationIndentWidth: '2'
|
||||
UseTab: Never
|
||||
TabWidth: '2'
|
||||
IndentWidth: '2'
|
||||
AccessModifierOffset : '-2'
|
||||
IndentCaseLabels: false
|
||||
Cpp11BracedListStyle: 'true'
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveDeclarations: true
|
||||
|
||||
#------------------------------------
|
||||
# Configurations not supported by clang-format v12
|
||||
#------------------------------------
|
||||
# BreakInheritanceList: AfterComma
|
||||
# EmptyLineBeforeAccessModifier: Always
|
||||
# EmptyLineAfterAccessModifier: Always
|
||||
# ReferenceAlignment: Left
|
||||
|
||||
...
|
||||
82
Chapter16/fsm/libs/etl/CMakeLists.txt
Normal file
@@ -0,0 +1,82 @@
|
||||
#######################################################################
|
||||
# The Embedded Template Library (https://www.etlcpp.com/)
|
||||
#######################################################################
|
||||
cmake_minimum_required(VERSION 3.5.0)
|
||||
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/helpers.cmake)
|
||||
|
||||
set(MSG_PREFIX "etl |")
|
||||
determine_version_with_git(${GIT_DIR_LOOKUP_POLICY})
|
||||
if(NOT ETL_VERSION)
|
||||
determine_version_with_file("version.txt")
|
||||
endif()
|
||||
|
||||
project(etl VERSION ${ETL_VERSION} LANGUAGES CXX)
|
||||
|
||||
option(BUILD_TESTS "Build unit tests" OFF)
|
||||
option(NO_STL "No STL" OFF)
|
||||
# There is a bug on old gcc versions for some targets that causes all system headers
|
||||
# to be implicitly wrapped with 'extern "C"'
|
||||
# Users can add set(NO_SYSTEM_INCLUDE ON) to their top level CMakeLists.txt to work around this.
|
||||
option(NO_SYSTEM_INCLUDE "Do not include with -isystem" OFF)
|
||||
if (NO_SYSTEM_INCLUDE)
|
||||
set(INCLUDE_SPECIFIER "")
|
||||
else()
|
||||
set(INCLUDE_SPECIFIER "SYSTEM")
|
||||
endif()
|
||||
|
||||
add_library(${PROJECT_NAME} INTERFACE)
|
||||
# This allows users which use the add_subdirectory or FetchContent
|
||||
# to use the same target as users which use find_package
|
||||
add_library(etl::etl ALIAS ${PROJECT_NAME})
|
||||
|
||||
include(GNUInstallDirs)
|
||||
|
||||
target_include_directories(${PROJECT_NAME} ${INCLUDE_SPECIFIER} INTERFACE
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
||||
)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME} INTERFACE)
|
||||
|
||||
# only install if top level project
|
||||
if(${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
|
||||
# Steps here based on excellent guide: https://dominikberner.ch/cmake-interface-lib/
|
||||
# Which also details all steps
|
||||
include(CMakePackageConfigHelpers)
|
||||
install(TARGETS ${PROJECT_NAME}
|
||||
EXPORT ${PROJECT_NAME}Targets
|
||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
if(ETL_VERSION)
|
||||
# Generate the package configuration files using CMake provided macros
|
||||
write_basic_package_version_file(
|
||||
"${PROJECT_NAME}ConfigVersion.cmake"
|
||||
COMPATIBILITY SameMajorVersion
|
||||
ARCH_INDEPENDENT
|
||||
)
|
||||
endif()
|
||||
configure_package_config_file(
|
||||
"${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in"
|
||||
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
|
||||
INSTALL_DESTINATION
|
||||
${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)
|
||||
|
||||
# Install target file, then package configuration files, and finally the headers
|
||||
install(EXPORT ${PROJECT_NAME}Targets
|
||||
FILE ${PROJECT_NAME}Targets.cmake
|
||||
NAMESPACE ${PROJECT_NAME}::
|
||||
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)
|
||||
install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
|
||||
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
|
||||
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)
|
||||
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/etl DESTINATION include)
|
||||
|
||||
endif()
|
||||
|
||||
if (BUILD_TESTS)
|
||||
enable_testing()
|
||||
add_subdirectory(test)
|
||||
endif()
|
||||
2401
Chapter16/fsm/libs/etl/Doxyfile
Normal file
19
Chapter16/fsm/libs/etl/LICENSE
Normal file
@@ -0,0 +1,19 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
147
Chapter16/fsm/libs/etl/README.md
Normal file
@@ -0,0 +1,147 @@
|
||||
Embedded Template Library (ETL)
|
||||
-------------------------
|
||||
|
||||

|
||||
[](https://img.shields.io/github/release-date/jwellbelove/etl?color=%231182c3)
|
||||
[](https://en.wikipedia.org/wiki/C%2B%2B#Standardization)
|
||||
[](https://opensource.org/licenses/MIT)
|
||||

|
||||

|
||||

|
||||
|
||||

|
||||
[](https://ci.appveyor.com/project/jwellbelove/etl/branch/master)
|
||||
|
||||

|
||||

|
||||

|
||||

|
||||

|
||||
|
||||

|
||||

|
||||

|
||||

|
||||

|
||||
|
||||
[](https://www.codacy.com/manual/jwellbelove/etl?utm_source=github.com&utm_medium=referral&utm_content=ETLCPP/etl&utm_campaign=Badge_Grade)
|
||||
|
||||
[](https://www.etlcpp.com/sponsor.html)
|
||||
|
||||
[Project documentation](https://www.etlcpp.com/)
|
||||
|
||||
## Motivation
|
||||
|
||||
C++ is a great language to use for embedded applications and templates are a powerful aspect. The standard library can offer a great deal of well tested functionality, but there are some parts of the standard library that do not fit well with deterministic behaviour and limited resource requirements. These limitations usually preclude the use of dynamically allocated memory and containers with open ended sizes.
|
||||
|
||||
What is needed is a template library where the user can declare the size, or maximum size of any object upfront. Most embedded compilers do not currently support the standard beyond C++ 03, therefore excluding the programmer from using the enhanced features of the later library.
|
||||
|
||||
This is what the ETL attempts to achieve.
|
||||
|
||||
## Summary
|
||||
|
||||
The ETL is not designed to completely replace the STL, but complement it.
|
||||
Its design objective covers three areas.
|
||||
|
||||
- Create a set of containers where the size or maximum size is determined at compile time. These containers are direct equivalents of those supplied in the STL.
|
||||
- Be compatible with C++ 03 but implement as many of the C++ 11/14/17/20 additions as possible.
|
||||
- Add other useful components that are not present in the standard library.
|
||||
|
||||
The embedded template library has been designed for lower resource embedded applications.
|
||||
It contains a set of containers, algorithms and utilities, some of which emulate parts of the STL.
|
||||
There is no dynamic memory allocation. The library makes no use of the heap. All of the containers have a fixed capacity allowing all memory allocation to be determined at compile time.
|
||||
The library is intended for any compiler that supports C++98/03/11/14/17/20.
|
||||
|
||||
## Main features
|
||||
|
||||
- Cross platform. This library is not specific to any processor type.
|
||||
- No dynamic memory allocation
|
||||
- No RTTI required
|
||||
- Very little use of virtual functions. They are used only when they are absolutely necessary for the required functionality
|
||||
- A set of fixed capacity containers. (array, bitset, deque, forward_list, list, queue, stack, vector, map, set, etc.)
|
||||
- As the storage for all of the container types is allocated as a contiguous block, they are extremely cache friendly
|
||||
- Templated compile time constants
|
||||
- Templated design pattern base classes (Visitor, Observer)
|
||||
- Reverse engineered C++ 0x11 features (type traits, algorithms, containers etc.)
|
||||
- Type-safe enumerations
|
||||
- Type-safe typedefs
|
||||
- 8, 16, 32 & 64 bit CRC calculations
|
||||
- Checksums & hash functions
|
||||
- Variants (a type that can store many types in a type-safe interface)
|
||||
- Choice of asserts, exceptions, error handler or no checks on errors
|
||||
- Unit tested (currently over 9400 tests), using VS2022, GCC 12, Clang 14.
|
||||
- Many utilities for template support.
|
||||
- Easy to read and documented source.
|
||||
- Free support via email, GitHub and Slack
|
||||
|
||||
Any help porting the library to work under different platforms and compilers would be gratefully received.
|
||||
I am especially interested in people who are using Keil, IAR, Green Hills, TI Code Composer etc, bare metal or RTOS, and DSPs.
|
||||
|
||||
See (https://www.etlcpp.com) for up-to-date information.
|
||||
|
||||
## Installing this library
|
||||
|
||||
You can find the setup steps [here](https://www.etlcpp.com/setup.html).
|
||||
|
||||
### CMake
|
||||
|
||||
One way to use this library is to drop it somewhere in your project directory
|
||||
and then make the library available by using `add_subdirectory`
|
||||
|
||||
```cmake
|
||||
add_subdirectory(etl)
|
||||
add_executable(foo main.cpp)
|
||||
target_link_libraries(foo PRIVATE etl::etl)
|
||||
```
|
||||
|
||||
If ETL library is used as a Git submodule it may require additional configuration for proper ETL version resolution by allowing the lookup for Git folder outside of the library root directory.
|
||||
|
||||
```cmake
|
||||
set(GIT_DIR_LOOKUP_POLICY ALLOW_LOOKING_ABOVE_CMAKE_SOURCE_DIR)
|
||||
add_subdirectory(etl)
|
||||
```
|
||||
|
||||
If you want to install this library with CMake, you can perform the following steps. On Linux,
|
||||
super user rights might be required to install the library, so it might be necessary to add
|
||||
`sudo` before the last command:
|
||||
|
||||
```sh
|
||||
git clone https://github.com/ETLCPP/etl.git
|
||||
cd etl
|
||||
git checkout <targetVersion>
|
||||
cmake -B build .
|
||||
cmake --install build/
|
||||
```
|
||||
|
||||
After the library has been installed, you can use
|
||||
[find_package](https://cmake.org/cmake/help/latest/command/find_package.html) to use the library.
|
||||
Replace `<majorVersionRequirement>` with your desired major version:
|
||||
|
||||
```cmake
|
||||
find_package(etl <majorVersionRequirement>)
|
||||
add_executable(foo main.cpp)
|
||||
target_link_libraries(foo PRIVATE etl::etl)
|
||||
```
|
||||
|
||||
|
||||
Alternatively you can use [FetchContent](https://cmake.org/cmake/help/latest/module/FetchContent.html),
|
||||
replacing `<targetVersion>` with the version to install based on a git tag:
|
||||
|
||||
```sh
|
||||
Include(FetchContent)
|
||||
|
||||
FetchContent_Declare(
|
||||
etl
|
||||
GIT_REPOSITORY https://github.com/ETLCPP/etl
|
||||
GIT_TAG <targetVersion>
|
||||
)
|
||||
|
||||
FetchContent_MakeAvailable(etl)
|
||||
|
||||
add_executable(foo main.cpp)
|
||||
target_link_libraries(foo PRIVATE etl::etl)
|
||||
```
|
||||
|
||||
## Arduino library
|
||||
|
||||
The content of this repo is available as a library in the Arduino IDE (search for the "Embedded Template Library" in the IDE library manager). The Arduino library repository is available at ```https://github.com/ETLCPP/etl-arduino```, see there for more details.
|
||||
26
Chapter16/fsm/libs/etl/appveyor.yml
Normal file
@@ -0,0 +1,26 @@
|
||||
version: 1.0.{build}
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
image: Visual Studio 2022
|
||||
configuration:
|
||||
- Debug MSVC C++14
|
||||
- Debug MSVC C++14 - No STL
|
||||
- Debug MSVC C++17
|
||||
- Debug MSVC C++17 - No STL
|
||||
- Debug MSVC C++20
|
||||
- Debug MSVC C++20 - No STL
|
||||
clone_folder: c:\projects\etl
|
||||
install:
|
||||
- cmd: git submodule update --init --recursive
|
||||
build:
|
||||
project: test/vs2022/etl.vcxproj
|
||||
verbosity: minimal
|
||||
notifications:
|
||||
- provider: Webhook
|
||||
url: https://hooks.slack.com/services/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
|
||||
method: POST
|
||||
on_build_success: true
|
||||
on_build_failure: true
|
||||
on_build_status_changed: true
|
||||
|
||||
80
Chapter16/fsm/libs/etl/arduino/Embedded_Template_Library.h
Normal file
@@ -0,0 +1,80 @@
|
||||
|
||||
#ifndef ETL_EMBEDDED_TEMPLATE_LIBRARY_INCLUDED
|
||||
#define ETL_EMBEDDED_TEMPLATE_LIBRARY_INCLUDED
|
||||
|
||||
#if defined(TEENSYDUINO)
|
||||
|
||||
#if defined(__AVR_ATmega32U4__)
|
||||
#define ARDUINO_BOARD "Teensy 2.0"
|
||||
#elif defined(__AVR_AT90USB1286__)
|
||||
#define ARDUINO_BOARD "Teensy++ 2.0"
|
||||
#elif defined(__MK20DX128__)
|
||||
#define ARDUINO_BOARD "Teensy 3.0"
|
||||
#elif defined(__MK20DX256__)
|
||||
#define ARDUINO_BOARD "Teensy 3.2" // and Teensy 3.1
|
||||
#elif defined(__MKL26Z64__)
|
||||
#define ARDUINO_BOARD "Teensy LC"
|
||||
#elif defined(__MK64FX512__)
|
||||
#define ARDUINO_BOARD "Teensy 3.5"
|
||||
#elif defined(__MK66FX1M0__)
|
||||
#define ARDUINO_BOARD "Teensy 3.6"
|
||||
#else
|
||||
#define ARDUINO_BOARD "Unknown"
|
||||
#endif
|
||||
|
||||
#else // --------------- Arduino ------------------
|
||||
|
||||
#if defined(ARDUINO_AVR_ADK)
|
||||
#define ARDUINO_BOARD "Mega Adk"
|
||||
#elif defined(ARDUINO_AVR_BT)
|
||||
#define ARDUINO_BOARD "Bt"
|
||||
#elif defined(ARDUINO_AVR_DUEMILANOVE)
|
||||
#define ARDUINO_BOARD "Duemilanove"
|
||||
#elif defined(ARDUINO_AVR_ESPLORA)
|
||||
#define ARDUINO_BOARD "Esplora"
|
||||
#elif defined(ARDUINO_AVR_ETHERNET)
|
||||
#define ARDUINO_BOARD "Ethernet"
|
||||
#elif defined(ARDUINO_AVR_FIO)
|
||||
#define ARDUINO_BOARD "Fio"
|
||||
#elif defined(ARDUINO_AVR_GEMMA)
|
||||
#define ARDUINO_BOARD "Gemma"
|
||||
#elif defined(ARDUINO_AVR_LEONARDO)
|
||||
#define ARDUINO_BOARD "Leonardo"
|
||||
#elif defined(ARDUINO_AVR_LILYPAD)
|
||||
#define ARDUINO_BOARD "Lilypad"
|
||||
#elif defined(ARDUINO_AVR_LILYPAD_USB)
|
||||
#define ARDUINO_BOARD "Lilypad Usb"
|
||||
#elif defined(ARDUINO_AVR_MEGA)
|
||||
#define ARDUINO_BOARD "Mega"
|
||||
#elif defined(ARDUINO_AVR_MEGA2560)
|
||||
#define ARDUINO_BOARD "Mega 2560"
|
||||
#elif defined(ARDUINO_AVR_MICRO)
|
||||
#define ARDUINO_BOARD "Micro"
|
||||
#elif defined(ARDUINO_AVR_MINI)
|
||||
#define ARDUINO_BOARD "Mini"
|
||||
#elif defined(ARDUINO_AVR_NANO)
|
||||
#define ARDUINO_BOARD "Nano"
|
||||
#elif defined(ARDUINO_AVR_NG)
|
||||
#define ARDUINO_BOARD "NG"
|
||||
#elif defined(ARDUINO_AVR_PRO)
|
||||
#define ARDUINO_BOARD "Pro"
|
||||
#elif defined(ARDUINO_AVR_ROBOT_CONTROL)
|
||||
#define ARDUINO_BOARD "Robot Ctrl"
|
||||
#elif defined(ARDUINO_AVR_ROBOT_MOTOR)
|
||||
#define ARDUINO_BOARD "Robot Motor"
|
||||
#elif defined(ARDUINO_AVR_UNO)
|
||||
#define ARDUINO_BOARD "Uno"
|
||||
#elif defined(ARDUINO_AVR_YUN)
|
||||
#define ARDUINO_BOARD "Yun"
|
||||
#elif defined(ARDUINO_SAM_DUE)
|
||||
#define ARDUINO_BOARD "Due"
|
||||
#elif defined(ARDUINO_SAMD_ZERO)
|
||||
#define ARDUINO_BOARD "Zero"
|
||||
#elif defined(ARDUINO_ARC32_TOOLS)
|
||||
#define ARDUINO_BOARD "101"
|
||||
#else
|
||||
#define ARDUINO_BOARD "Unknown"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,12 @@
|
||||
#include "Embedded_Template_Library.h" // This is required for any more etl import when using Arduino IDE
|
||||
|
||||
void setup()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
// make sure that we do not rely on the STL
|
||||
#define ETL_NO_STL
|
||||
|
||||
#include "Embedded_Template_Library.h"
|
||||
#include "etl/vector.h"
|
||||
|
||||
template <typename T>
|
||||
void print_vector(etl::ivector<T> const & vec_in)
|
||||
{
|
||||
Serial.print(F("print vector content | size ")); Serial.print(vec_in.size()); Serial.print(F(" | capacity ")); Serial.println(vec_in.capacity());
|
||||
Serial.print(F("content | "));
|
||||
|
||||
for (T const & elem : vec_in)
|
||||
{
|
||||
Serial.print(elem);
|
||||
Serial.print(F(" | "));
|
||||
}
|
||||
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
delay(100);
|
||||
Serial.println(F("booted"));
|
||||
|
||||
etl::vector<int, 12> vec_int;
|
||||
|
||||
Serial.println(F("initialized vec_int"));
|
||||
print_vector(vec_int);
|
||||
|
||||
vec_int.push_back(1);
|
||||
vec_int.push_back(2);
|
||||
Serial.println(F("pushed to vec_int"));
|
||||
print_vector(vec_int);
|
||||
|
||||
vec_int.pop_back();
|
||||
Serial.println(F("pop from vec_int; returns no value"));
|
||||
print_vector(vec_int);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
}
|
||||
39
Chapter16/fsm/libs/etl/arduino/library-arduino.json
Normal file
@@ -0,0 +1,39 @@
|
||||
{
|
||||
"name": "Embedded Template Library ETL",
|
||||
"version": "20.39.0",
|
||||
"authors": {
|
||||
"name": "John Wellbelove",
|
||||
"email": "john.wellbelove@etlcpp.com"
|
||||
},
|
||||
"homepage": "https://www.etlcpp.com/",
|
||||
"license": "MIT",
|
||||
"description": "ETL. A C++ template library tailored for embedded systems. Directories formatted for Arduino",
|
||||
"keywords": "c-plus-plus, cpp, algorithms, containers, templates",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/ETLCPP/etl-arduino.git"
|
||||
},
|
||||
"build": {
|
||||
"includeDir": "include"
|
||||
},
|
||||
"export": {
|
||||
"include": [
|
||||
"include",
|
||||
"examples",
|
||||
"LICENSE",
|
||||
"README.md"
|
||||
],
|
||||
"exclude": [
|
||||
"include/etl/experimental",
|
||||
"include/etl/deprecated",
|
||||
"**/__vm",
|
||||
"**/.vs",
|
||||
"**/*.filters",
|
||||
"**/*.log",
|
||||
"**/*.tmp"
|
||||
]
|
||||
},
|
||||
"platforms": "*",
|
||||
"frameworks": "*"
|
||||
}
|
||||
|
||||
10
Chapter16/fsm/libs/etl/arduino/library-arduino.properties
Normal file
@@ -0,0 +1,10 @@
|
||||
name=Embedded Template Library ETL
|
||||
version=20.39.0
|
||||
author= John Wellbelove <john.wellbelove@etlcpp.com>
|
||||
maintainer=John Wellbelove <john.wellbelove@etlcpp.com>
|
||||
license=MIT
|
||||
sentence=ETL. A C++ template library tailored for embedded systems.
|
||||
paragraph=
|
||||
category=Other
|
||||
url=https://www.etlcpp.com/
|
||||
architectures=*
|
||||
284
Chapter16/fsm/libs/etl/cmake/GetGitRevisionDescription.cmake
Normal file
@@ -0,0 +1,284 @@
|
||||
# - Returns a version string from Git
|
||||
#
|
||||
# These functions force a re-configure on each git commit so that you can
|
||||
# trust the values of the variables in your build system.
|
||||
#
|
||||
# get_git_head_revision(<refspecvar> <hashvar> [ALLOW_LOOKING_ABOVE_CMAKE_SOURCE_DIR])
|
||||
#
|
||||
# Returns the refspec and sha hash of the current head revision
|
||||
#
|
||||
# git_describe(<var> [<additional arguments to git describe> ...])
|
||||
#
|
||||
# Returns the results of git describe on the source tree, and adjusting
|
||||
# the output so that it tests false if an error occurs.
|
||||
#
|
||||
# git_describe_working_tree(<var> [<additional arguments to git describe> ...])
|
||||
#
|
||||
# Returns the results of git describe on the working tree (--dirty option),
|
||||
# and adjusting the output so that it tests false if an error occurs.
|
||||
#
|
||||
# git_get_exact_tag(<var> [<additional arguments to git describe> ...])
|
||||
#
|
||||
# Returns the results of git describe --exact-match on the source tree,
|
||||
# and adjusting the output so that it tests false if there was no exact
|
||||
# matching tag.
|
||||
#
|
||||
# git_local_changes(<var>)
|
||||
#
|
||||
# Returns either "CLEAN" or "DIRTY" with respect to uncommitted changes.
|
||||
# Uses the return code of "git diff-index --quiet HEAD --".
|
||||
# Does not regard untracked files.
|
||||
#
|
||||
# Requires CMake 2.6 or newer (uses the 'function' command)
|
||||
#
|
||||
# Original Author:
|
||||
# 2009-2020 Ryan Pavlik <ryan.pavlik@gmail.com> <abiryan@ryand.net>
|
||||
# http://academic.cleardefinition.com
|
||||
#
|
||||
# Copyright 2009-2013, Iowa State University.
|
||||
# Copyright 2013-2020, Ryan Pavlik
|
||||
# Copyright 2013-2020, Contributors
|
||||
# SPDX-License-Identifier: BSL-1.0
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
if(__get_git_revision_description)
|
||||
return()
|
||||
endif()
|
||||
set(__get_git_revision_description YES)
|
||||
|
||||
# We must run the following at "include" time, not at function call time,
|
||||
# to find the path to this module rather than the path to a calling list file
|
||||
get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH)
|
||||
|
||||
# Function _git_find_closest_git_dir finds the next closest .git directory
|
||||
# that is part of any directory in the path defined by _start_dir.
|
||||
# The result is returned in the parent scope variable whose name is passed
|
||||
# as variable _git_dir_var. If no .git directory can be found, the
|
||||
# function returns an empty string via _git_dir_var.
|
||||
#
|
||||
# Example: Given a path C:/bla/foo/bar and assuming C:/bla/.git exists and
|
||||
# neither foo nor bar contain a file/directory .git. This will return
|
||||
# C:/bla/.git
|
||||
#
|
||||
function(_git_find_closest_git_dir _start_dir _git_dir_var)
|
||||
set(cur_dir "${_start_dir}")
|
||||
set(git_dir "${_start_dir}/.git")
|
||||
while(NOT EXISTS "${git_dir}")
|
||||
# .git dir not found, search parent directories
|
||||
set(git_previous_parent "${cur_dir}")
|
||||
get_filename_component(cur_dir "${cur_dir}" DIRECTORY)
|
||||
if(cur_dir STREQUAL git_previous_parent)
|
||||
# We have reached the root directory, we are not in git
|
||||
set(${_git_dir_var}
|
||||
""
|
||||
PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
set(git_dir "${cur_dir}/.git")
|
||||
endwhile()
|
||||
set(${_git_dir_var}
|
||||
"${git_dir}"
|
||||
PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(get_git_head_revision _refspecvar _hashvar)
|
||||
_git_find_closest_git_dir("${CMAKE_CURRENT_SOURCE_DIR}" GIT_DIR)
|
||||
|
||||
if("${ARGN}" STREQUAL "ALLOW_LOOKING_ABOVE_CMAKE_SOURCE_DIR")
|
||||
set(ALLOW_LOOKING_ABOVE_CMAKE_SOURCE_DIR TRUE)
|
||||
else()
|
||||
set(ALLOW_LOOKING_ABOVE_CMAKE_SOURCE_DIR FALSE)
|
||||
endif()
|
||||
if(NOT "${GIT_DIR}" STREQUAL "")
|
||||
file(RELATIVE_PATH _relative_to_source_dir "${CMAKE_SOURCE_DIR}"
|
||||
"${GIT_DIR}")
|
||||
if("${_relative_to_source_dir}" MATCHES "[.][.]" AND NOT ALLOW_LOOKING_ABOVE_CMAKE_SOURCE_DIR)
|
||||
# We've gone above the CMake root dir.
|
||||
set(GIT_DIR "")
|
||||
endif()
|
||||
endif()
|
||||
if("${GIT_DIR}" STREQUAL "")
|
||||
set(${_refspecvar}
|
||||
"GITDIR-NOTFOUND"
|
||||
PARENT_SCOPE)
|
||||
set(${_hashvar}
|
||||
"GITDIR-NOTFOUND"
|
||||
PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
|
||||
# Check if the current source dir is a git submodule or a worktree.
|
||||
# In both cases .git is a file instead of a directory.
|
||||
#
|
||||
if(NOT IS_DIRECTORY ${GIT_DIR})
|
||||
# The following git command will return a non empty string that
|
||||
# points to the super project working tree if the current
|
||||
# source dir is inside a git submodule.
|
||||
# Otherwise the command will return an empty string.
|
||||
#
|
||||
execute_process(
|
||||
COMMAND "${GIT_EXECUTABLE}" rev-parse
|
||||
--show-superproject-working-tree
|
||||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
OUTPUT_VARIABLE out
|
||||
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
if(NOT "${out}" STREQUAL "")
|
||||
# If out is empty, GIT_DIR/CMAKE_CURRENT_SOURCE_DIR is in a submodule
|
||||
file(READ ${GIT_DIR} submodule)
|
||||
string(REGEX REPLACE "gitdir: (.*)$" "\\1" GIT_DIR_RELATIVE
|
||||
${submodule})
|
||||
string(STRIP ${GIT_DIR_RELATIVE} GIT_DIR_RELATIVE)
|
||||
get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH)
|
||||
get_filename_component(GIT_DIR ${SUBMODULE_DIR}/${GIT_DIR_RELATIVE}
|
||||
ABSOLUTE)
|
||||
set(HEAD_SOURCE_FILE "${GIT_DIR}/HEAD")
|
||||
else()
|
||||
# GIT_DIR/CMAKE_CURRENT_SOURCE_DIR is in a worktree
|
||||
file(READ ${GIT_DIR} worktree_ref)
|
||||
# The .git directory contains a path to the worktree information directory
|
||||
# inside the parent git repo of the worktree.
|
||||
#
|
||||
string(REGEX REPLACE "gitdir: (.*)$" "\\1" git_worktree_dir
|
||||
${worktree_ref})
|
||||
string(STRIP ${git_worktree_dir} git_worktree_dir)
|
||||
_git_find_closest_git_dir("${git_worktree_dir}" GIT_DIR)
|
||||
set(HEAD_SOURCE_FILE "${git_worktree_dir}/HEAD")
|
||||
endif()
|
||||
else()
|
||||
set(HEAD_SOURCE_FILE "${GIT_DIR}/HEAD")
|
||||
endif()
|
||||
set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data")
|
||||
if(NOT EXISTS "${GIT_DATA}")
|
||||
file(MAKE_DIRECTORY "${GIT_DATA}")
|
||||
endif()
|
||||
|
||||
if(NOT EXISTS "${HEAD_SOURCE_FILE}")
|
||||
return()
|
||||
endif()
|
||||
set(HEAD_FILE "${GIT_DATA}/HEAD")
|
||||
configure_file("${HEAD_SOURCE_FILE}" "${HEAD_FILE}" COPYONLY)
|
||||
|
||||
configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in"
|
||||
"${GIT_DATA}/grabRef.cmake" @ONLY)
|
||||
include("${GIT_DATA}/grabRef.cmake")
|
||||
|
||||
set(${_refspecvar}
|
||||
"${HEAD_REF}"
|
||||
PARENT_SCOPE)
|
||||
set(${_hashvar}
|
||||
"${HEAD_HASH}"
|
||||
PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(git_describe _var)
|
||||
if(NOT GIT_FOUND)
|
||||
find_package(Git QUIET)
|
||||
endif()
|
||||
get_git_head_revision(refspec hash ${ARGN})
|
||||
if(NOT GIT_FOUND)
|
||||
set(${_var}
|
||||
"GIT-NOTFOUND"
|
||||
PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
if(NOT hash)
|
||||
set(${_var}
|
||||
"HEAD-HASH-NOTFOUND"
|
||||
PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
|
||||
# TODO sanitize
|
||||
#if((${ARGN}" MATCHES "&&") OR
|
||||
# (ARGN MATCHES "||") OR
|
||||
# (ARGN MATCHES "\\;"))
|
||||
# message("Please report the following error to the project!")
|
||||
# message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}")
|
||||
#endif()
|
||||
|
||||
#message(STATUS "Arguments to execute_process: ${ARGN}")
|
||||
|
||||
execute_process(
|
||||
COMMAND "${GIT_EXECUTABLE}" describe --tags --always ${hash} ${ARGN}
|
||||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
RESULT_VARIABLE res
|
||||
OUTPUT_VARIABLE out
|
||||
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
if(NOT res EQUAL 0)
|
||||
set(out "${out}-${res}-NOTFOUND")
|
||||
endif()
|
||||
|
||||
set(${_var}
|
||||
"${out}"
|
||||
PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(git_describe_working_tree _var)
|
||||
if(NOT GIT_FOUND)
|
||||
find_package(Git QUIET)
|
||||
endif()
|
||||
if(NOT GIT_FOUND)
|
||||
set(${_var}
|
||||
"GIT-NOTFOUND"
|
||||
PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
|
||||
execute_process(
|
||||
COMMAND "${GIT_EXECUTABLE}" describe --dirty ${ARGN}
|
||||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
RESULT_VARIABLE res
|
||||
OUTPUT_VARIABLE out
|
||||
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
if(NOT res EQUAL 0)
|
||||
set(out "${out}-${res}-NOTFOUND")
|
||||
endif()
|
||||
|
||||
set(${_var}
|
||||
"${out}"
|
||||
PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(git_get_exact_tag _var)
|
||||
git_describe(out --exact-match ${ARGN})
|
||||
set(${_var}
|
||||
"${out}"
|
||||
PARENT_SCOPE)
|
||||
endfunction()
|
||||
|
||||
function(git_local_changes _var)
|
||||
if(NOT GIT_FOUND)
|
||||
find_package(Git QUIET)
|
||||
endif()
|
||||
get_git_head_revision(refspec hash)
|
||||
if(NOT GIT_FOUND)
|
||||
set(${_var}
|
||||
"GIT-NOTFOUND"
|
||||
PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
if(NOT hash)
|
||||
set(${_var}
|
||||
"HEAD-HASH-NOTFOUND"
|
||||
PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
|
||||
execute_process(
|
||||
COMMAND "${GIT_EXECUTABLE}" diff-index --quiet HEAD --
|
||||
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
RESULT_VARIABLE res
|
||||
OUTPUT_VARIABLE out
|
||||
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
if(res EQUAL 0)
|
||||
set(${_var}
|
||||
"CLEAN"
|
||||
PARENT_SCOPE)
|
||||
else()
|
||||
set(${_var}
|
||||
"DIRTY"
|
||||
PARENT_SCOPE)
|
||||
endif()
|
||||
endfunction()
|
||||
@@ -0,0 +1,43 @@
|
||||
#
|
||||
# Internal file for GetGitRevisionDescription.cmake
|
||||
#
|
||||
# Requires CMake 2.6 or newer (uses the 'function' command)
|
||||
#
|
||||
# Original Author:
|
||||
# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
|
||||
# http://academic.cleardefinition.com
|
||||
# Iowa State University HCI Graduate Program/VRAC
|
||||
#
|
||||
# Copyright 2009-2012, Iowa State University
|
||||
# Copyright 2011-2015, Contributors
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
# SPDX-License-Identifier: BSL-1.0
|
||||
|
||||
set(HEAD_HASH)
|
||||
|
||||
file(READ "@HEAD_FILE@" HEAD_CONTENTS LIMIT 1024)
|
||||
|
||||
string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS)
|
||||
if(HEAD_CONTENTS MATCHES "ref")
|
||||
# named branch
|
||||
string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}")
|
||||
if(EXISTS "@GIT_DIR@/${HEAD_REF}")
|
||||
configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
|
||||
else()
|
||||
configure_file("@GIT_DIR@/packed-refs" "@GIT_DATA@/packed-refs" COPYONLY)
|
||||
file(READ "@GIT_DATA@/packed-refs" PACKED_REFS)
|
||||
if(${PACKED_REFS} MATCHES "([0-9a-z]*) ${HEAD_REF}")
|
||||
set(HEAD_HASH "${CMAKE_MATCH_1}")
|
||||
endif()
|
||||
endif()
|
||||
else()
|
||||
# detached HEAD
|
||||
configure_file("@GIT_DIR@/HEAD" "@GIT_DATA@/head-ref" COPYONLY)
|
||||
endif()
|
||||
|
||||
if(NOT HEAD_HASH)
|
||||
file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024)
|
||||
string(STRIP "${HEAD_HASH}" HEAD_HASH)
|
||||
endif()
|
||||
4
Chapter16/fsm/libs/etl/cmake/etlConfig.cmake.in
Normal file
@@ -0,0 +1,4 @@
|
||||
@PACKAGE_INIT@
|
||||
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
|
||||
check_required_components("@PROJECT_NAME@")
|
||||
35
Chapter16/fsm/libs/etl/cmake/helpers.cmake
Normal file
@@ -0,0 +1,35 @@
|
||||
function(determine_version_with_file VER_FILE_NAME)
|
||||
file(READ ${VER_FILE_NAME} ETL_VERSION_RAW)
|
||||
# Remove trailing whitespaces and/or newline
|
||||
string(STRIP ${ETL_VERSION_RAW} ETL_VERSION)
|
||||
set(ETL_VERSION ${ETL_VERSION} CACHE STRING
|
||||
"ETL version determined from version.txt" FORCE
|
||||
)
|
||||
message(STATUS "${MSG_PREFIX} Determined ETL version ${ETL_VERSION} from version.txt file")
|
||||
endfunction()
|
||||
|
||||
function(determine_version_with_git)
|
||||
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/GetGitRevisionDescription.cmake)
|
||||
git_describe(VERSION ${ARGN})
|
||||
string(FIND ${VERSION} "." VALID_VERSION)
|
||||
if(VALID_VERSION EQUAL -1)
|
||||
if(PROJECT_IS_TOP_LEVEL)
|
||||
# only warn if this is the top-level project, since we may be
|
||||
# building from a tarball as a subproject
|
||||
message(WARNING "Version string ${VERSION} retrieved with git describe is invalid")
|
||||
endif()
|
||||
return()
|
||||
endif()
|
||||
message(STATUS "${MSG_PREFIX} Version string determined with git describe: ${VERSION}")
|
||||
# Parse the version information into pieces.
|
||||
string(REGEX REPLACE "^([0-9]+)\\..*" "\\1" VERSION_MAJOR "${VERSION}")
|
||||
string(REGEX REPLACE "^[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${VERSION}")
|
||||
string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${VERSION}")
|
||||
string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.[0-9]+(.*)" "\\1" VERSION_SHA1 "${VERSION}")
|
||||
set(ETL_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
|
||||
|
||||
set(ETL_VERSION ${ETL_VERSION} CACHE STRING
|
||||
"ETL version determined with git describe" FORCE
|
||||
)
|
||||
message(STATUS "${MSG_PREFIX} Determined ETL version ${ETL_VERSION} from the git tag")
|
||||
endfunction()
|
||||
4
Chapter16/fsm/libs/etl/examples/ArmTimerCallbacks - C++/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
Objects/
|
||||
RTE/
|
||||
Listings/
|
||||
DebugConfig/
|
||||
@@ -0,0 +1,487 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
|
||||
<Project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="project_projx.xsd">
|
||||
|
||||
<SchemaVersion>2.1</SchemaVersion>
|
||||
|
||||
<Header>### uVision Project, (C) Keil Software</Header>
|
||||
|
||||
<Targets>
|
||||
<Target>
|
||||
<TargetName>Target 1</TargetName>
|
||||
<ToolsetNumber>0x4</ToolsetNumber>
|
||||
<ToolsetName>ARM-ADS</ToolsetName>
|
||||
<pCCUsed>5060750::V5.06 update 6 (build 750)::.\ARMCC</pCCUsed>
|
||||
<uAC6>0</uAC6>
|
||||
<TargetOption>
|
||||
<TargetCommonOption>
|
||||
<Device>STM32F401RETx</Device>
|
||||
<Vendor>STMicroelectronics</Vendor>
|
||||
<PackID>Keil.STM32F4xx_DFP.2.15.0</PackID>
|
||||
<PackURL>http://www.keil.com/pack/</PackURL>
|
||||
<Cpu>IRAM(0x20000000,0x18000) IROM(0x08000000,0x80000) CPUTYPE("Cortex-M4") FPU2 CLOCK(12000000) ELITTLE</Cpu>
|
||||
<FlashUtilSpec></FlashUtilSpec>
|
||||
<StartupFile></StartupFile>
|
||||
<FlashDriverDll>UL2CM3(-S0 -C0 -P0 -FD20000000 -FC1000 -FN1 -FF0STM32F4xx_512 -FS08000000 -FL080000 -FP0($$Device:STM32F401RETx$CMSIS\Flash\STM32F4xx_512.FLM))</FlashDriverDll>
|
||||
<DeviceId>0</DeviceId>
|
||||
<RegisterFile>$$Device:STM32F401RETx$Drivers\CMSIS\Device\ST\STM32F4xx\Include\stm32f4xx.h</RegisterFile>
|
||||
<MemoryEnv></MemoryEnv>
|
||||
<Cmp></Cmp>
|
||||
<Asm></Asm>
|
||||
<Linker></Linker>
|
||||
<OHString></OHString>
|
||||
<InfinionOptionDll></InfinionOptionDll>
|
||||
<SLE66CMisc></SLE66CMisc>
|
||||
<SLE66AMisc></SLE66AMisc>
|
||||
<SLE66LinkerMisc></SLE66LinkerMisc>
|
||||
<SFDFile>$$Device:STM32F401RETx$CMSIS\SVD\STM32F401xE.svd</SFDFile>
|
||||
<bCustSvd>0</bCustSvd>
|
||||
<UseEnv>0</UseEnv>
|
||||
<BinPath></BinPath>
|
||||
<IncludePath></IncludePath>
|
||||
<LibPath></LibPath>
|
||||
<RegisterFilePath></RegisterFilePath>
|
||||
<DBRegisterFilePath></DBRegisterFilePath>
|
||||
<TargetStatus>
|
||||
<Error>0</Error>
|
||||
<ExitCodeStop>0</ExitCodeStop>
|
||||
<ButtonStop>0</ButtonStop>
|
||||
<NotGenerated>0</NotGenerated>
|
||||
<InvalidFlash>1</InvalidFlash>
|
||||
</TargetStatus>
|
||||
<OutputDirectory>.\Objects\</OutputDirectory>
|
||||
<OutputName>ArmTimerCallbacks</OutputName>
|
||||
<CreateExecutable>1</CreateExecutable>
|
||||
<CreateLib>0</CreateLib>
|
||||
<CreateHexFile>0</CreateHexFile>
|
||||
<DebugInformation>1</DebugInformation>
|
||||
<BrowseInformation>1</BrowseInformation>
|
||||
<ListingPath>.\Listings\</ListingPath>
|
||||
<HexFormatSelection>1</HexFormatSelection>
|
||||
<Merge32K>0</Merge32K>
|
||||
<CreateBatchFile>0</CreateBatchFile>
|
||||
<BeforeCompile>
|
||||
<RunUserProg1>0</RunUserProg1>
|
||||
<RunUserProg2>0</RunUserProg2>
|
||||
<UserProg1Name></UserProg1Name>
|
||||
<UserProg2Name></UserProg2Name>
|
||||
<UserProg1Dos16Mode>0</UserProg1Dos16Mode>
|
||||
<UserProg2Dos16Mode>0</UserProg2Dos16Mode>
|
||||
<nStopU1X>0</nStopU1X>
|
||||
<nStopU2X>0</nStopU2X>
|
||||
</BeforeCompile>
|
||||
<BeforeMake>
|
||||
<RunUserProg1>0</RunUserProg1>
|
||||
<RunUserProg2>0</RunUserProg2>
|
||||
<UserProg1Name></UserProg1Name>
|
||||
<UserProg2Name></UserProg2Name>
|
||||
<UserProg1Dos16Mode>0</UserProg1Dos16Mode>
|
||||
<UserProg2Dos16Mode>0</UserProg2Dos16Mode>
|
||||
<nStopB1X>0</nStopB1X>
|
||||
<nStopB2X>0</nStopB2X>
|
||||
</BeforeMake>
|
||||
<AfterMake>
|
||||
<RunUserProg1>0</RunUserProg1>
|
||||
<RunUserProg2>0</RunUserProg2>
|
||||
<UserProg1Name></UserProg1Name>
|
||||
<UserProg2Name></UserProg2Name>
|
||||
<UserProg1Dos16Mode>0</UserProg1Dos16Mode>
|
||||
<UserProg2Dos16Mode>0</UserProg2Dos16Mode>
|
||||
<nStopA1X>0</nStopA1X>
|
||||
<nStopA2X>0</nStopA2X>
|
||||
</AfterMake>
|
||||
<SelectedForBatchBuild>0</SelectedForBatchBuild>
|
||||
<SVCSIdString></SVCSIdString>
|
||||
</TargetCommonOption>
|
||||
<CommonProperty>
|
||||
<UseCPPCompiler>0</UseCPPCompiler>
|
||||
<RVCTCodeConst>0</RVCTCodeConst>
|
||||
<RVCTZI>0</RVCTZI>
|
||||
<RVCTOtherData>0</RVCTOtherData>
|
||||
<ModuleSelection>0</ModuleSelection>
|
||||
<IncludeInBuild>1</IncludeInBuild>
|
||||
<AlwaysBuild>0</AlwaysBuild>
|
||||
<GenerateAssemblyFile>0</GenerateAssemblyFile>
|
||||
<AssembleAssemblyFile>0</AssembleAssemblyFile>
|
||||
<PublicsOnly>0</PublicsOnly>
|
||||
<StopOnExitCode>3</StopOnExitCode>
|
||||
<CustomArgument></CustomArgument>
|
||||
<IncludeLibraryModules></IncludeLibraryModules>
|
||||
<ComprImg>1</ComprImg>
|
||||
</CommonProperty>
|
||||
<DllOption>
|
||||
<SimDllName>SARMCM3.DLL</SimDllName>
|
||||
<SimDllArguments> -REMAP -MPU</SimDllArguments>
|
||||
<SimDlgDll>DCM.DLL</SimDlgDll>
|
||||
<SimDlgDllArguments>-pCM4</SimDlgDllArguments>
|
||||
<TargetDllName>SARMCM3.DLL</TargetDllName>
|
||||
<TargetDllArguments> -MPU</TargetDllArguments>
|
||||
<TargetDlgDll>TCM.DLL</TargetDlgDll>
|
||||
<TargetDlgDllArguments>-pCM4</TargetDlgDllArguments>
|
||||
</DllOption>
|
||||
<DebugOption>
|
||||
<OPTHX>
|
||||
<HexSelection>1</HexSelection>
|
||||
<HexRangeLowAddress>0</HexRangeLowAddress>
|
||||
<HexRangeHighAddress>0</HexRangeHighAddress>
|
||||
<HexOffset>0</HexOffset>
|
||||
<Oh166RecLen>16</Oh166RecLen>
|
||||
</OPTHX>
|
||||
</DebugOption>
|
||||
<Utilities>
|
||||
<Flash1>
|
||||
<UseTargetDll>1</UseTargetDll>
|
||||
<UseExternalTool>0</UseExternalTool>
|
||||
<RunIndependent>0</RunIndependent>
|
||||
<UpdateFlashBeforeDebugging>1</UpdateFlashBeforeDebugging>
|
||||
<Capability>1</Capability>
|
||||
<DriverSelection>4096</DriverSelection>
|
||||
</Flash1>
|
||||
<bUseTDR>1</bUseTDR>
|
||||
<Flash2>BIN\UL2CM3.DLL</Flash2>
|
||||
<Flash3>"" ()</Flash3>
|
||||
<Flash4></Flash4>
|
||||
<pFcarmOut></pFcarmOut>
|
||||
<pFcarmGrp></pFcarmGrp>
|
||||
<pFcArmRoot></pFcArmRoot>
|
||||
<FcArmLst>0</FcArmLst>
|
||||
</Utilities>
|
||||
<TargetArmAds>
|
||||
<ArmAdsMisc>
|
||||
<GenerateListings>0</GenerateListings>
|
||||
<asHll>1</asHll>
|
||||
<asAsm>1</asAsm>
|
||||
<asMacX>1</asMacX>
|
||||
<asSyms>1</asSyms>
|
||||
<asFals>1</asFals>
|
||||
<asDbgD>1</asDbgD>
|
||||
<asForm>1</asForm>
|
||||
<ldLst>0</ldLst>
|
||||
<ldmm>1</ldmm>
|
||||
<ldXref>1</ldXref>
|
||||
<BigEnd>0</BigEnd>
|
||||
<AdsALst>1</AdsALst>
|
||||
<AdsACrf>1</AdsACrf>
|
||||
<AdsANop>0</AdsANop>
|
||||
<AdsANot>0</AdsANot>
|
||||
<AdsLLst>1</AdsLLst>
|
||||
<AdsLmap>1</AdsLmap>
|
||||
<AdsLcgr>1</AdsLcgr>
|
||||
<AdsLsym>1</AdsLsym>
|
||||
<AdsLszi>1</AdsLszi>
|
||||
<AdsLtoi>1</AdsLtoi>
|
||||
<AdsLsun>1</AdsLsun>
|
||||
<AdsLven>1</AdsLven>
|
||||
<AdsLsxf>1</AdsLsxf>
|
||||
<RvctClst>0</RvctClst>
|
||||
<GenPPlst>0</GenPPlst>
|
||||
<AdsCpuType>"Cortex-M4"</AdsCpuType>
|
||||
<RvctDeviceName></RvctDeviceName>
|
||||
<mOS>0</mOS>
|
||||
<uocRom>0</uocRom>
|
||||
<uocRam>0</uocRam>
|
||||
<hadIROM>1</hadIROM>
|
||||
<hadIRAM>1</hadIRAM>
|
||||
<hadXRAM>0</hadXRAM>
|
||||
<uocXRam>0</uocXRam>
|
||||
<RvdsVP>2</RvdsVP>
|
||||
<RvdsMve>0</RvdsMve>
|
||||
<RvdsCdeCp>0</RvdsCdeCp>
|
||||
<hadIRAM2>0</hadIRAM2>
|
||||
<hadIROM2>0</hadIROM2>
|
||||
<StupSel>8</StupSel>
|
||||
<useUlib>0</useUlib>
|
||||
<EndSel>0</EndSel>
|
||||
<uLtcg>0</uLtcg>
|
||||
<nSecure>0</nSecure>
|
||||
<RoSelD>3</RoSelD>
|
||||
<RwSelD>3</RwSelD>
|
||||
<CodeSel>0</CodeSel>
|
||||
<OptFeed>0</OptFeed>
|
||||
<NoZi1>0</NoZi1>
|
||||
<NoZi2>0</NoZi2>
|
||||
<NoZi3>0</NoZi3>
|
||||
<NoZi4>0</NoZi4>
|
||||
<NoZi5>0</NoZi5>
|
||||
<Ro1Chk>0</Ro1Chk>
|
||||
<Ro2Chk>0</Ro2Chk>
|
||||
<Ro3Chk>0</Ro3Chk>
|
||||
<Ir1Chk>1</Ir1Chk>
|
||||
<Ir2Chk>0</Ir2Chk>
|
||||
<Ra1Chk>0</Ra1Chk>
|
||||
<Ra2Chk>0</Ra2Chk>
|
||||
<Ra3Chk>0</Ra3Chk>
|
||||
<Im1Chk>1</Im1Chk>
|
||||
<Im2Chk>0</Im2Chk>
|
||||
<OnChipMemories>
|
||||
<Ocm1>
|
||||
<Type>0</Type>
|
||||
<StartAddress>0x0</StartAddress>
|
||||
<Size>0x0</Size>
|
||||
</Ocm1>
|
||||
<Ocm2>
|
||||
<Type>0</Type>
|
||||
<StartAddress>0x0</StartAddress>
|
||||
<Size>0x0</Size>
|
||||
</Ocm2>
|
||||
<Ocm3>
|
||||
<Type>0</Type>
|
||||
<StartAddress>0x0</StartAddress>
|
||||
<Size>0x0</Size>
|
||||
</Ocm3>
|
||||
<Ocm4>
|
||||
<Type>0</Type>
|
||||
<StartAddress>0x0</StartAddress>
|
||||
<Size>0x0</Size>
|
||||
</Ocm4>
|
||||
<Ocm5>
|
||||
<Type>0</Type>
|
||||
<StartAddress>0x0</StartAddress>
|
||||
<Size>0x0</Size>
|
||||
</Ocm5>
|
||||
<Ocm6>
|
||||
<Type>0</Type>
|
||||
<StartAddress>0x0</StartAddress>
|
||||
<Size>0x0</Size>
|
||||
</Ocm6>
|
||||
<IRAM>
|
||||
<Type>0</Type>
|
||||
<StartAddress>0x20000000</StartAddress>
|
||||
<Size>0x18000</Size>
|
||||
</IRAM>
|
||||
<IROM>
|
||||
<Type>1</Type>
|
||||
<StartAddress>0x8000000</StartAddress>
|
||||
<Size>0x80000</Size>
|
||||
</IROM>
|
||||
<XRAM>
|
||||
<Type>0</Type>
|
||||
<StartAddress>0x0</StartAddress>
|
||||
<Size>0x0</Size>
|
||||
</XRAM>
|
||||
<OCR_RVCT1>
|
||||
<Type>1</Type>
|
||||
<StartAddress>0x0</StartAddress>
|
||||
<Size>0x0</Size>
|
||||
</OCR_RVCT1>
|
||||
<OCR_RVCT2>
|
||||
<Type>1</Type>
|
||||
<StartAddress>0x0</StartAddress>
|
||||
<Size>0x0</Size>
|
||||
</OCR_RVCT2>
|
||||
<OCR_RVCT3>
|
||||
<Type>1</Type>
|
||||
<StartAddress>0x0</StartAddress>
|
||||
<Size>0x0</Size>
|
||||
</OCR_RVCT3>
|
||||
<OCR_RVCT4>
|
||||
<Type>1</Type>
|
||||
<StartAddress>0x8000000</StartAddress>
|
||||
<Size>0x80000</Size>
|
||||
</OCR_RVCT4>
|
||||
<OCR_RVCT5>
|
||||
<Type>1</Type>
|
||||
<StartAddress>0x0</StartAddress>
|
||||
<Size>0x0</Size>
|
||||
</OCR_RVCT5>
|
||||
<OCR_RVCT6>
|
||||
<Type>0</Type>
|
||||
<StartAddress>0x0</StartAddress>
|
||||
<Size>0x0</Size>
|
||||
</OCR_RVCT6>
|
||||
<OCR_RVCT7>
|
||||
<Type>0</Type>
|
||||
<StartAddress>0x0</StartAddress>
|
||||
<Size>0x0</Size>
|
||||
</OCR_RVCT7>
|
||||
<OCR_RVCT8>
|
||||
<Type>0</Type>
|
||||
<StartAddress>0x0</StartAddress>
|
||||
<Size>0x0</Size>
|
||||
</OCR_RVCT8>
|
||||
<OCR_RVCT9>
|
||||
<Type>0</Type>
|
||||
<StartAddress>0x20000000</StartAddress>
|
||||
<Size>0x18000</Size>
|
||||
</OCR_RVCT9>
|
||||
<OCR_RVCT10>
|
||||
<Type>0</Type>
|
||||
<StartAddress>0x0</StartAddress>
|
||||
<Size>0x0</Size>
|
||||
</OCR_RVCT10>
|
||||
</OnChipMemories>
|
||||
<RvctStartVector></RvctStartVector>
|
||||
</ArmAdsMisc>
|
||||
<Cads>
|
||||
<interw>1</interw>
|
||||
<Optim>1</Optim>
|
||||
<oTime>0</oTime>
|
||||
<SplitLS>0</SplitLS>
|
||||
<OneElfS>1</OneElfS>
|
||||
<Strict>0</Strict>
|
||||
<EnumInt>0</EnumInt>
|
||||
<PlainCh>1</PlainCh>
|
||||
<Ropi>0</Ropi>
|
||||
<Rwpi>0</Rwpi>
|
||||
<wLevel>2</wLevel>
|
||||
<uThumb>0</uThumb>
|
||||
<uSurpInc>0</uSurpInc>
|
||||
<uC99>1</uC99>
|
||||
<uGnu>0</uGnu>
|
||||
<useXO>0</useXO>
|
||||
<v6Lang>3</v6Lang>
|
||||
<v6LangP>3</v6LangP>
|
||||
<vShortEn>1</vShortEn>
|
||||
<vShortWch>1</vShortWch>
|
||||
<v6Lto>0</v6Lto>
|
||||
<v6WtE>0</v6WtE>
|
||||
<v6Rtti>0</v6Rtti>
|
||||
<VariousControls>
|
||||
<MiscControls></MiscControls>
|
||||
<Define>__STDC_LIMIT_MACROS</Define>
|
||||
<Undefine></Undefine>
|
||||
<IncludePath>..\..\include;..\ArmTimerCallbacks - C++</IncludePath>
|
||||
</VariousControls>
|
||||
</Cads>
|
||||
<Aads>
|
||||
<interw>1</interw>
|
||||
<Ropi>0</Ropi>
|
||||
<Rwpi>0</Rwpi>
|
||||
<thumb>0</thumb>
|
||||
<SplitLS>0</SplitLS>
|
||||
<SwStkChk>0</SwStkChk>
|
||||
<NoWarn>0</NoWarn>
|
||||
<uSurpInc>0</uSurpInc>
|
||||
<useXO>0</useXO>
|
||||
<ClangAsOpt>4</ClangAsOpt>
|
||||
<VariousControls>
|
||||
<MiscControls></MiscControls>
|
||||
<Define></Define>
|
||||
<Undefine></Undefine>
|
||||
<IncludePath></IncludePath>
|
||||
</VariousControls>
|
||||
</Aads>
|
||||
<LDads>
|
||||
<umfTarg>0</umfTarg>
|
||||
<Ropi>0</Ropi>
|
||||
<Rwpi>0</Rwpi>
|
||||
<noStLib>0</noStLib>
|
||||
<RepFail>1</RepFail>
|
||||
<useFile>0</useFile>
|
||||
<TextAddressRange>0x08000000</TextAddressRange>
|
||||
<DataAddressRange>0x20000000</DataAddressRange>
|
||||
<pXoBase></pXoBase>
|
||||
<ScatterFile></ScatterFile>
|
||||
<IncludeLibs></IncludeLibs>
|
||||
<IncludeLibsPath></IncludeLibsPath>
|
||||
<Misc></Misc>
|
||||
<LinkerInputFile></LinkerInputFile>
|
||||
<DisabledWarnings></DisabledWarnings>
|
||||
</LDads>
|
||||
</TargetArmAds>
|
||||
</TargetOption>
|
||||
<Groups>
|
||||
<Group>
|
||||
<GroupName>Source Group 1</GroupName>
|
||||
<Files>
|
||||
<File>
|
||||
<FileName>main.cpp</FileName>
|
||||
<FileType>8</FileType>
|
||||
<FilePath>.\main.cpp</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>etl_profile.h</FileName>
|
||||
<FileType>5</FileType>
|
||||
<FilePath>.\etl_profile.h</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
<GroupName>::Board Support</GroupName>
|
||||
</Group>
|
||||
<Group>
|
||||
<GroupName>::CMSIS</GroupName>
|
||||
</Group>
|
||||
<Group>
|
||||
<GroupName>::Device</GroupName>
|
||||
</Group>
|
||||
</Groups>
|
||||
</Target>
|
||||
</Targets>
|
||||
|
||||
<RTE>
|
||||
<apis>
|
||||
<api Capiversion="1.0.0" Cclass="Board Support" Cgroup="Buttons" exclusive="0">
|
||||
<package name="MDK-Middleware" schemaVersion="1.4" url="http://www.keil.com/pack/" vendor="Keil" version="7.4.1"/>
|
||||
<targetInfos>
|
||||
<targetInfo name="Target 1"/>
|
||||
</targetInfos>
|
||||
</api>
|
||||
<api Capiversion="1.0.0" Cclass="Board Support" Cgroup="LED" exclusive="0">
|
||||
<package name="MDK-Middleware" schemaVersion="1.4" url="http://www.keil.com/pack/" vendor="Keil" version="7.4.1"/>
|
||||
<targetInfos>
|
||||
<targetInfo name="Target 1"/>
|
||||
</targetInfos>
|
||||
</api>
|
||||
</apis>
|
||||
<components>
|
||||
<component Cclass="CMSIS" Cgroup="CORE" Cvendor="ARM" Cversion="5.4.0" condition="ARMv6_7_8-M Device">
|
||||
<package name="CMSIS" schemaVersion="1.3" url="http://www.keil.com/pack/" vendor="ARM" version="5.7.0"/>
|
||||
<targetInfos>
|
||||
<targetInfo name="Target 1"/>
|
||||
</targetInfos>
|
||||
</component>
|
||||
<component Capiversion="1.00" Cbundle="NUCLEO-F401RE" Cclass="Board Support" Cgroup="Buttons" Cvendor="Keil" Cversion="1.1.0" condition="F401RE CMSIS Device">
|
||||
<package name="STM32NUCLEO_BSP" schemaVersion="1.2" url="http://www.keil.com/pack/" vendor="Keil" version="1.6.0"/>
|
||||
<targetInfos>
|
||||
<targetInfo name="Target 1"/>
|
||||
</targetInfos>
|
||||
</component>
|
||||
<component Capiversion="1.00" Cbundle="NUCLEO-F401RE" Cclass="Board Support" Cgroup="LED" Cvendor="Keil" Cversion="1.1.0" condition="F401RE CMSIS Device">
|
||||
<package name="STM32NUCLEO_BSP" schemaVersion="1.2" url="http://www.keil.com/pack/" vendor="Keil" version="1.6.0"/>
|
||||
<targetInfos>
|
||||
<targetInfo name="Target 1"/>
|
||||
</targetInfos>
|
||||
</component>
|
||||
<component Cclass="Device" Cgroup="Startup" Cvendor="Keil" Cversion="2.6.3" condition="STM32F4 CMSIS">
|
||||
<package name="STM32F4xx_DFP" schemaVersion="1.6.3" url="http://www.keil.com/pack/" vendor="Keil" version="2.15.0"/>
|
||||
<targetInfos>
|
||||
<targetInfo name="Target 1"/>
|
||||
</targetInfos>
|
||||
</component>
|
||||
</components>
|
||||
<files>
|
||||
<file attr="config" category="source" condition="STM32F401xE_ARMCC" name="Drivers\CMSIS\Device\ST\STM32F4xx\Source\Templates\arm\startup_stm32f401xe.s" version="2.6.0">
|
||||
<instance index="0">RTE\Device\STM32F401RETx\startup_stm32f401xe.s</instance>
|
||||
<component Cclass="Device" Cgroup="Startup" Cvendor="Keil" Cversion="2.6.3" condition="STM32F4 CMSIS"/>
|
||||
<package name="STM32F4xx_DFP" schemaVersion="1.6.3" url="http://www.keil.com/pack/" vendor="Keil" version="2.15.0"/>
|
||||
<targetInfos>
|
||||
<targetInfo name="Target 1"/>
|
||||
</targetInfos>
|
||||
</file>
|
||||
<file attr="config" category="source" name="Drivers\CMSIS\Device\ST\STM32F4xx\Source\Templates\system_stm32f4xx.c" version="2.6.0">
|
||||
<instance index="0">RTE\Device\STM32F401RETx\system_stm32f4xx.c</instance>
|
||||
<component Cclass="Device" Cgroup="Startup" Cvendor="Keil" Cversion="2.6.3" condition="STM32F4 CMSIS"/>
|
||||
<package name="STM32F4xx_DFP" schemaVersion="1.6.3" url="http://www.keil.com/pack/" vendor="Keil" version="2.15.0"/>
|
||||
<targetInfos>
|
||||
<targetInfo name="Target 1"/>
|
||||
</targetInfos>
|
||||
</file>
|
||||
</files>
|
||||
</RTE>
|
||||
|
||||
<LayerInfo>
|
||||
<Layers>
|
||||
<Layer>
|
||||
<LayName><Project Info></LayName>
|
||||
<LayDesc></LayDesc>
|
||||
<LayUrl></LayUrl>
|
||||
<LayKeys></LayKeys>
|
||||
<LayCat></LayCat>
|
||||
<LayLic></LayLic>
|
||||
<LayTarg>0</LayTarg>
|
||||
<LayPrjMark>1</LayPrjMark>
|
||||
</Layer>
|
||||
</Layers>
|
||||
</LayerInfo>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,15 @@
|
||||
|
||||
#ifndef __ETL_PROFILE_H__
|
||||
#define __ETL_PROFILE_H__
|
||||
|
||||
#define ETL_VERBOSE_ERRORS
|
||||
#define ETL_CHECK_PUSH_POP
|
||||
#define ETL_ISTRING_REPAIR_ENABLE
|
||||
#define ETL_IVECTOR_REPAIR_ENABLE
|
||||
#define ETL_IDEQUE_REPAIR_ENABLE
|
||||
#define ETL_CALLBACK_TIMER_USE_ATOMIC_LOCK
|
||||
#define ETL_NO_STL
|
||||
|
||||
//#include "etl/profiles/auto.h"
|
||||
|
||||
#endif
|
||||
167
Chapter16/fsm/libs/etl/examples/ArmTimerCallbacks - C++/main.cpp
Normal file
@@ -0,0 +1,167 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
//#if (__cplusplus < 201103L)
|
||||
extern "C"
|
||||
{
|
||||
//#endif
|
||||
#include "Board_LED.h" // ::Board Support:LED
|
||||
#include "Board_Buttons.h" // ::Board Support:Buttons
|
||||
//#if (__cplusplus < 201103L)
|
||||
}
|
||||
//#endif
|
||||
|
||||
#include "stm32f4xx.h" // Device header
|
||||
|
||||
#include "etl/function.h"
|
||||
#include "etl/callback_timer.h"
|
||||
#include "etl/vector.h"
|
||||
#include "etl/iterator.h"
|
||||
#include "etl/binary.h"
|
||||
|
||||
struct FP
|
||||
{
|
||||
void (*function)();
|
||||
};
|
||||
|
||||
static etl::vector<FP, 10> power_callbacks;
|
||||
|
||||
void register_poweroff_callback(void (*function)())
|
||||
{
|
||||
FP fp = { function };
|
||||
power_callbacks.push_back(fp);
|
||||
}
|
||||
|
||||
const int N_TIMERS = 4;
|
||||
|
||||
etl::callback_timer<N_TIMERS> callback_timer;
|
||||
|
||||
etl::timer::id::type short_toggle;
|
||||
etl::timer::id::type long_toggle;
|
||||
etl::timer::id::type start_timers;
|
||||
etl::timer::id::type swap_timers;
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* SystemCoreClockConfigure: configure SystemCoreClock using HSI
|
||||
(HSE is not populated on Nucleo board)
|
||||
*----------------------------------------------------------------------------*/
|
||||
void SystemCoreClockConfigure(void) {
|
||||
|
||||
RCC->CR |= ((uint32_t)RCC_CR_HSION); // Enable HSI
|
||||
while ((RCC->CR & RCC_CR_HSIRDY) == 0); // Wait for HSI Ready
|
||||
|
||||
RCC->CFGR = RCC_CFGR_SW_HSI; // HSI is system clock
|
||||
while ((RCC->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_HSI); // Wait for HSI used as system clock
|
||||
|
||||
FLASH->ACR = FLASH_ACR_PRFTEN; // Enable Prefetch Buffer
|
||||
FLASH->ACR |= FLASH_ACR_ICEN; // Instruction cache enable
|
||||
FLASH->ACR |= FLASH_ACR_DCEN; // Data cache enable
|
||||
FLASH->ACR |= FLASH_ACR_LATENCY_5WS; // Flash 5 wait state
|
||||
|
||||
RCC->CFGR |= RCC_CFGR_HPRE_DIV1; // HCLK = SYSCLK
|
||||
RCC->CFGR |= RCC_CFGR_PPRE1_DIV4; // APB1 = HCLK/4
|
||||
RCC->CFGR |= RCC_CFGR_PPRE2_DIV2; // APB2 = HCLK/2
|
||||
|
||||
RCC->CR &= ~RCC_CR_PLLON; // Disable PLL
|
||||
|
||||
// PLL configuration: VCO = HSI/M * N, Sysclk = VCO/P
|
||||
RCC->PLLCFGR = ( 16ul | // PLL_M = 16
|
||||
(384ul << 6U) | // PLL_N = 384
|
||||
( 3ul << 16U) | // PLL_P = 8
|
||||
(RCC_PLLCFGR_PLLSRC_HSI) | // PLL_SRC = HSI
|
||||
( 8ul << 24U) ); // PLL_Q = 8
|
||||
|
||||
RCC->CR |= RCC_CR_PLLON; // Enable PLL
|
||||
while((RCC->CR & RCC_CR_PLLRDY) == 0) __NOP(); // Wait till PLL is ready
|
||||
|
||||
RCC->CFGR &= ~RCC_CFGR_SW; // Select PLL as system clock source
|
||||
RCC->CFGR |= RCC_CFGR_SW_PLL;
|
||||
while ((RCC->CFGR & RCC_CFGR_SWS) != RCC_CFGR_SWS_PLL); // Wait till PLL is system clock src
|
||||
}
|
||||
|
||||
void StartTimers()
|
||||
{
|
||||
callback_timer.start(short_toggle);
|
||||
callback_timer.start(swap_timers);
|
||||
}
|
||||
|
||||
void SwapTimers()
|
||||
{
|
||||
static bool state = false;
|
||||
|
||||
if (!state)
|
||||
{
|
||||
callback_timer.stop(short_toggle);
|
||||
callback_timer.start(long_toggle);
|
||||
}
|
||||
else
|
||||
{
|
||||
callback_timer.start(short_toggle);
|
||||
callback_timer.stop(long_toggle);
|
||||
}
|
||||
|
||||
state = !state;
|
||||
|
||||
callback_timer.start(swap_timers);
|
||||
}
|
||||
|
||||
void LedToggle()
|
||||
{
|
||||
static bool state = false;
|
||||
|
||||
if (state)
|
||||
{
|
||||
LED_On(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
LED_Off(0);
|
||||
}
|
||||
|
||||
state = !state;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
SystemCoreClockConfigure(); // configure HSI as System Clock
|
||||
SystemCoreClockUpdate();
|
||||
|
||||
LED_Initialize();
|
||||
Buttons_Initialize();
|
||||
|
||||
// The LEDs will start flashing fast after 2 seconds.
|
||||
// After another 5 seconds they will start flashing slower.
|
||||
short_toggle = callback_timer.register_timer(LedToggle, 50, etl::timer::mode::REPEATING);
|
||||
long_toggle = callback_timer.register_timer(LedToggle, 100, etl::timer::mode::REPEATING);
|
||||
start_timers = callback_timer.register_timer(StartTimers, 2000, etl::timer::mode::SINGLE_SHOT);
|
||||
swap_timers = callback_timer.register_timer(SwapTimers, 1500, etl::timer::mode::SINGLE_SHOT);
|
||||
|
||||
SysTick_Config(SystemCoreClock / 1000);
|
||||
|
||||
callback_timer.enable(true);
|
||||
|
||||
callback_timer.start(start_timers);
|
||||
|
||||
while (true)
|
||||
{
|
||||
__NOP();
|
||||
}
|
||||
}
|
||||
|
||||
extern "C"
|
||||
{
|
||||
void SysTick_Handler()
|
||||
{
|
||||
const uint32_t TICK = 1U;
|
||||
static uint32_t nticks = TICK;
|
||||
|
||||
if (callback_timer.tick(nticks))
|
||||
{
|
||||
nticks = TICK;
|
||||
}
|
||||
else
|
||||
{
|
||||
nticks += TICK;
|
||||
}
|
||||
}
|
||||
}
|
||||
2
Chapter16/fsm/libs/etl/examples/Blink/Blink1/__vm/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
*.vsarduino.h
|
||||
*.vmps.xml
|
||||
53
Chapter16/fsm/libs/etl/examples/BlinkList/BlinkList.ino
Normal file
@@ -0,0 +1,53 @@
|
||||
//***********************************************************************************
|
||||
// A version of the Blink demo, but with delays stored in two instances of etl::list
|
||||
//***********************************************************************************
|
||||
|
||||
#undef min
|
||||
#undef max
|
||||
|
||||
#include <list.h>
|
||||
#include <container.h>
|
||||
|
||||
void setup()
|
||||
{
|
||||
// initialize digital pin 13 as an output.
|
||||
pinMode(13, OUTPUT);
|
||||
}
|
||||
|
||||
void iterate(const etl::ilist<int>& delays)
|
||||
{
|
||||
etl::ilist<int>::const_iterator itr;
|
||||
|
||||
// Iterate through the list.
|
||||
itr = delays.begin();
|
||||
|
||||
while (itr != delays.end())
|
||||
{
|
||||
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
|
||||
delay(100); // wait
|
||||
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
|
||||
delay(*itr++); // wait
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
int delay_times1[] = { 900, 800, 700, 600, 500, 400, 300, 200, 100 };
|
||||
int delay_times2[] = { 400, 300, 200, 100 };
|
||||
|
||||
// Fill the first delay list, then reverse it.
|
||||
// Notice how we don't have to know the size of the array!
|
||||
const size_t size1 = sizeof(etl::array_size(delay_times1));
|
||||
etl::list<int, size1> delays1(etl::begin(delay_times1), etl::end(delay_times1));
|
||||
delays1.reverse();
|
||||
|
||||
// Fill the second delay list,
|
||||
const size_t size2 = sizeof(etl::array_size(delay_times2));
|
||||
etl::list<int, size2> delays2(etl::begin(delay_times2), etl::end(delay_times2));
|
||||
|
||||
while (true)
|
||||
{
|
||||
iterate(delays1);
|
||||
iterate(delays2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.24720.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BlinkList", "BlinkList.vcxproj", "{C5F80730-F44F-4478-BDAE-6634EFC2CA88}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{C5F80730-F44F-4478-BDAE-6634EFC2CA88}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{C5F80730-F44F-4478-BDAE-6634EFC2CA88}.Debug|x86.Build.0 = Debug|Win32
|
||||
{C5F80730-F44F-4478-BDAE-6634EFC2CA88}.Release|x86.ActiveCfg = Release|Win32
|
||||
{C5F80730-F44F-4478-BDAE-6634EFC2CA88}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,28 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\BlinkList.ino" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="__vm\.VisualMicro.vsarduino.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="__vm\.BlinkList.vsarduino.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
1
Chapter16/fsm/libs/etl/examples/BlinkList/VisualMicro/__vm/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*.vsarduino.h
|
||||
1
Chapter16/fsm/libs/etl/examples/BlinkList/__vm/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*.vmps.xml
|
||||
39
Chapter16/fsm/libs/etl/examples/Debounce/Debounce.ino
Normal file
@@ -0,0 +1,39 @@
|
||||
//***********************************************************************************
|
||||
// A debounce demo that reads a key and toggles the LED.
|
||||
// Set the pin to the correct one for your key.
|
||||
//***********************************************************************************
|
||||
|
||||
#include <debounce.h>
|
||||
|
||||
const int SAMPLE_TIME = 1; // The sample time in ms.
|
||||
const int DEBOUNCE_COUNT = 50; // The number of samples that must agree before a key state change is recognised. 50 = 50ms for 1ms sample time.
|
||||
const int HOLD_COUNT = 1000; // The number of samples that must agree before a key held state is recognised. 1000 = 1s for 1ms sample time.
|
||||
const int REPEAT_COUNT = 200; // The number of samples that must agree before a key repeat state is recognised. 200 = 200ms for 1ms sample time.
|
||||
const int KEY = XX; // The pin that the key is attached to.
|
||||
|
||||
void setup()
|
||||
{
|
||||
// Initialize LED pin as an output and set off.
|
||||
pinMode(LED_BUILTIN , OUTPUT);
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
|
||||
// Initialize KEY pin as an input.
|
||||
pinMode(KEY, INPUT);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
static int led_state = LOW;
|
||||
static etl::debounce<DEBOUNCE_COUNT, HOLD_COUNT, REPEAT_COUNT> key_state;
|
||||
|
||||
if (key_state.add(digitalRead(KEY) == HIGH)) // Assumes 'HIGH' is 'pressed' and 'LOW' is 'released'.
|
||||
{
|
||||
if (key_state.is_set())
|
||||
{
|
||||
led_state = (led_state == LOW ? HIGH : LOW); // Toggle the LED state on every validated press or repeat.
|
||||
digitalWrite(LED_BUILTIN, led_state);
|
||||
}
|
||||
}
|
||||
|
||||
delay(SAMPLE_TIME); // Wait 1ms
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
cmake_minimum_required(VERSION 3.5.0)
|
||||
project(FunctionInterruptSimulation)
|
||||
|
||||
add_definitions(-DETL_DEBUG)
|
||||
|
||||
include_directories(${UTPP_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/../../include)
|
||||
|
||||
set(SOURCE_FILES FunctionInterruptSimulation.cpp)
|
||||
|
||||
add_executable(FunctionInterruptSimulation ${SOURCE_FILES})
|
||||
target_include_directories(FunctionInterruptSimulation
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
set_property(TARGET FunctionInterruptSimulation PROPERTY CXX_STANDARD 17)
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "etl/delegate.h"
|
||||
#include "etl/delegate_service.h"
|
||||
|
||||
enum VectorId
|
||||
{
|
||||
TIM1_CC_IRQ_HANDLER = 42,
|
||||
TIM2_IRQ_HANDLER = 43,
|
||||
TIM3_IRQ_HANDLER = 44,
|
||||
USART1_IRQ_HANDLER = 52,
|
||||
USART2_IRQ_HANDLER = 53,
|
||||
VECTOR_ID_END,
|
||||
VECTOR_ID_OFFSET = TIM1_CC_IRQ_HANDLER,
|
||||
VECTOR_ID_RANGE = VECTOR_ID_END - VECTOR_ID_OFFSET
|
||||
};
|
||||
|
||||
typedef etl::delegate_service<VECTOR_ID_RANGE, VECTOR_ID_OFFSET> InterruptVectors;
|
||||
|
||||
// Ensure that the callback service is initialised before use.
|
||||
InterruptVectors& GetInterruptVectorsInstance()
|
||||
{
|
||||
static InterruptVectors interruptVectors;
|
||||
|
||||
return interruptVectors;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
{
|
||||
InterruptVectors& interruptVectors = GetInterruptVectorsInstance();
|
||||
|
||||
// Function called from the timer1 interrupt vector.
|
||||
void TIM1_CC_IRQHandler()
|
||||
{
|
||||
interruptVectors.call<TIM1_CC_IRQ_HANDLER>();
|
||||
}
|
||||
|
||||
// Function called from the timer2 interrupt vector.
|
||||
void TIM2_IRQHandler()
|
||||
{
|
||||
interruptVectors.call<TIM2_IRQ_HANDLER>();
|
||||
}
|
||||
|
||||
// Function called from the timer3 interrupt vector.
|
||||
void TIM3_IRQHandler()
|
||||
{
|
||||
interruptVectors.call<TIM3_IRQ_HANDLER>();
|
||||
}
|
||||
|
||||
// Function called from the usart1 interrupt vector.
|
||||
void USART1_IRQHandler()
|
||||
{
|
||||
interruptVectors.call<USART1_IRQ_HANDLER>();
|
||||
}
|
||||
|
||||
// Function called from the usart2 interrupt vector.
|
||||
void USART2_IRQHandler()
|
||||
{
|
||||
interruptVectors.call<USART2_IRQ_HANDLER>();
|
||||
}
|
||||
}
|
||||
|
||||
//********************************
|
||||
// Timer driver.
|
||||
//********************************
|
||||
class Timer
|
||||
{
|
||||
public:
|
||||
|
||||
// Handler for interrupts from the timer.
|
||||
void InterruptHandler(const size_t id)
|
||||
{
|
||||
std::cout << "Timer interrupt (member) : ID " << id << "\n";
|
||||
}
|
||||
};
|
||||
|
||||
//********************************
|
||||
// Free function timer driver.
|
||||
//********************************
|
||||
void FreeTimerInterruptHandler(const size_t id)
|
||||
{
|
||||
std::cout << "Timer interrupt (free) : ID " << id << "\n";
|
||||
}
|
||||
|
||||
//********************************
|
||||
// UART driver.
|
||||
//********************************
|
||||
class Uart
|
||||
{
|
||||
public:
|
||||
|
||||
// Constructor.
|
||||
Uart(int port_id, size_t interruptId)
|
||||
: port_id(port_id),
|
||||
callback(etl::delegate<void(size_t)>::create<Uart, &Uart::InterruptHandler>(*this))
|
||||
{
|
||||
GetInterruptVectorsInstance().register_delegate(interruptId, callback);
|
||||
}
|
||||
|
||||
// Handler for interrupts from the UART.
|
||||
void InterruptHandler(const size_t id)
|
||||
{
|
||||
std::cout << "UART" << port_id << " : ID " << id << "\n";
|
||||
}
|
||||
|
||||
etl::delegate<void(size_t)> callback;
|
||||
|
||||
int port_id;
|
||||
};
|
||||
|
||||
void UnhandledInterrupt(const size_t id)
|
||||
{
|
||||
std::cout << "Unhandled Interrupt : ID " << id << "\n";
|
||||
}
|
||||
|
||||
// Declare the driver instances.
|
||||
Timer timer;
|
||||
Uart uart1(0, USART1_IRQ_HANDLER);
|
||||
Uart uart2(1, USART2_IRQ_HANDLER);
|
||||
|
||||
// Declare a global callback for the timer.
|
||||
// Uses the most efficient callback type for a class, as everything is known at compile time.
|
||||
etl::delegate<void(size_t)> timer_member_callback = etl::delegate<void(size_t)>::create<Timer, timer, &Timer::InterruptHandler>();
|
||||
|
||||
// Declare the callbacks for the free functions.
|
||||
etl::delegate<void(size_t)> timer_free_callback = etl::delegate<void(size_t)>::create<FreeTimerInterruptHandler>();
|
||||
etl::delegate<void(size_t)> unhandled_callback = etl::delegate<void(size_t)>::create<UnhandledInterrupt>();
|
||||
|
||||
//********************************
|
||||
// Test it out.
|
||||
//********************************
|
||||
int main()
|
||||
{
|
||||
// Setup the callbacks.
|
||||
InterruptVectors& interruptVectors = GetInterruptVectorsInstance();
|
||||
|
||||
interruptVectors.register_delegate<TIM1_CC_IRQ_HANDLER>(timer_member_callback);
|
||||
interruptVectors.register_delegate<TIM2_IRQ_HANDLER>(timer_free_callback);
|
||||
interruptVectors.register_unhandled_delegate(unhandled_callback);
|
||||
|
||||
// Simulate the interrupts.
|
||||
TIM1_CC_IRQHandler();
|
||||
TIM2_IRQHandler();
|
||||
USART1_IRQHandler();
|
||||
USART2_IRQHandler();
|
||||
TIM3_IRQHandler(); // Unhandled!
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
///\file
|
||||
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
https://www.etlcpp.com
|
||||
|
||||
Copyright(c) 2017 jwellbelove
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __ETL_PROFILE_H__
|
||||
#define __ETL_PROFILE_H__
|
||||
|
||||
#define ETL_THROW_EXCEPTIONS
|
||||
#define ETL_VERBOSE_ERRORS
|
||||
#define ETL_CHECK_PUSH_POP
|
||||
#define ETL_ISTRING_REPAIR_ENABLE
|
||||
#define ETL_IVECTOR_REPAIR_ENABLE
|
||||
#define ETL_IDEQUE_REPAIR_ENABLE
|
||||
#define ETL_IN_UNIT_TEST
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include "profiles/msvc_x86.h"
|
||||
#else
|
||||
#include "profiles/gcc_windows_x86.h"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1 @@
|
||||
*.VC.opendb
|
||||
@@ -0,0 +1 @@
|
||||
*.VC.opendb
|
||||
@@ -0,0 +1,31 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26730.16
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FunctionInterruptSimulation-Delegates", "FunctionInterruptSimulation-Delegates.vcxproj", "{5157DB15-C255-4E47-9FB1-AF388437F90F}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Debug|x64.Build.0 = Debug|x64
|
||||
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Debug|x86.Build.0 = Debug|Win32
|
||||
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Release|x64.ActiveCfg = Release|x64
|
||||
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Release|x64.Build.0 = Release|x64
|
||||
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Release|x86.ActiveCfg = Release|Win32
|
||||
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {260225EB-60CB-44CC-A60C-16A23BBC10EB}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,156 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\FunctionInterruptSimulation.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\etl_profile.h" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>15.0</VCProjectVersion>
|
||||
<ProjectGuid>{5157DB15-C255-4E47-9FB1-AF388437F90F}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>FunctionInterruptSimulation</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>../../../src</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>../../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,31 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26730.16
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FunctionInterruptSimulation-Delegates", "FunctionInterruptSimulation-Delegates.vcxproj", "{5157DB15-C255-4E47-9FB1-AF388437F90F}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Debug|x64.Build.0 = Debug|x64
|
||||
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Debug|x86.Build.0 = Debug|Win32
|
||||
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Release|x64.ActiveCfg = Release|x64
|
||||
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Release|x64.Build.0 = Release|x64
|
||||
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Release|x86.ActiveCfg = Release|Win32
|
||||
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {260225EB-60CB-44CC-A60C-16A23BBC10EB}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,157 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\FunctionInterruptSimulation.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\etl_profile.h" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>15.0</VCProjectVersion>
|
||||
<ProjectGuid>{5157DB15-C255-4E47-9FB1-AF388437F90F}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>FunctionInterruptSimulation</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>../../../src</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>../../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,17 @@
|
||||
cmake_minimum_required(VERSION 3.5.0)
|
||||
project(FunctionInterruptSimulation)
|
||||
|
||||
add_definitions(-DETL_DEBUG)
|
||||
|
||||
include_directories(${UTPP_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/../../include)
|
||||
|
||||
set(SOURCE_FILES FunctionInterruptSimulation.cpp)
|
||||
|
||||
add_executable(FunctionInterruptSimulation ${SOURCE_FILES})
|
||||
target_include_directories(FunctionInterruptSimulation
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
set_property(TARGET FunctionInterruptSimulation PROPERTY CXX_STANDARD 17)
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "etl/function.h"
|
||||
#include "etl/callback_service.h"
|
||||
|
||||
enum VectorId
|
||||
{
|
||||
TIM1_CC_IRQ_HANDLER = 42,
|
||||
TIM2_IRQ_HANDLER = 43,
|
||||
TIM3_IRQ_HANDLER = 44,
|
||||
USART1_IRQ_HANDLER = 52,
|
||||
USART2_IRQ_HANDLER = 53,
|
||||
VECTOR_ID_END,
|
||||
VECTOR_ID_OFFSET = TIM1_CC_IRQ_HANDLER,
|
||||
VECTOR_ID_RANGE = VECTOR_ID_END - VECTOR_ID_OFFSET
|
||||
};
|
||||
|
||||
typedef etl::callback_service<VECTOR_ID_RANGE, VECTOR_ID_OFFSET> InterruptVectors;
|
||||
|
||||
// Ensure that the callback service is initialised before use.
|
||||
InterruptVectors& GetInterruptVectorsInstance()
|
||||
{
|
||||
static InterruptVectors interruptVectors;
|
||||
|
||||
return interruptVectors;
|
||||
}
|
||||
|
||||
extern "C"
|
||||
{
|
||||
InterruptVectors& interruptVectors = GetInterruptVectorsInstance();
|
||||
|
||||
// Function called from the timer1 interrupt vector.
|
||||
void TIM1_CC_IRQHandler()
|
||||
{
|
||||
interruptVectors.callback<TIM1_CC_IRQ_HANDLER>();
|
||||
}
|
||||
|
||||
// Function called from the timer2 interrupt vector.
|
||||
void TIM2_IRQHandler()
|
||||
{
|
||||
interruptVectors.callback<TIM2_IRQ_HANDLER>();
|
||||
}
|
||||
|
||||
// Function called from the timer3 interrupt vector.
|
||||
void TIM3_IRQHandler()
|
||||
{
|
||||
interruptVectors.callback<TIM3_IRQ_HANDLER>();
|
||||
}
|
||||
|
||||
// Function called from the usart1 interrupt vector.
|
||||
void USART1_IRQHandler()
|
||||
{
|
||||
interruptVectors.callback<USART1_IRQ_HANDLER>();
|
||||
}
|
||||
|
||||
// Function called from the usart2 interrupt vector.
|
||||
void USART2_IRQHandler()
|
||||
{
|
||||
interruptVectors.callback<USART2_IRQ_HANDLER>();
|
||||
}
|
||||
}
|
||||
|
||||
//********************************
|
||||
// Timer driver.
|
||||
//********************************
|
||||
class Timer
|
||||
{
|
||||
public:
|
||||
|
||||
// Handler for interrupts from the timer.
|
||||
void InterruptHandler(const size_t id)
|
||||
{
|
||||
std::cout << "Timer interrupt (member) : ID " << id << "\n";
|
||||
}
|
||||
};
|
||||
|
||||
//********************************
|
||||
// Free function timer driver.
|
||||
//********************************
|
||||
void FreeTimerInterruptHandler(const size_t id)
|
||||
{
|
||||
std::cout << "Timer interrupt (free) : ID " << id << "\n";
|
||||
}
|
||||
|
||||
//********************************
|
||||
// UART driver.
|
||||
//********************************
|
||||
class Uart
|
||||
{
|
||||
public:
|
||||
|
||||
// Constructor.
|
||||
Uart(int port_id, int interruptId)
|
||||
: port_id(port_id),
|
||||
callback(*this)
|
||||
{
|
||||
GetInterruptVectorsInstance().register_callback(interruptId, callback);
|
||||
}
|
||||
|
||||
// Handler for interrupts from the UART.
|
||||
void InterruptHandler(const size_t id)
|
||||
{
|
||||
std::cout << "UART" << port_id << " : ID " << id << "\n";
|
||||
}
|
||||
|
||||
etl::function_mp<Uart, size_t, &Uart::InterruptHandler> callback;
|
||||
|
||||
int port_id;
|
||||
};
|
||||
|
||||
void UnhandledInterrupt(const size_t id)
|
||||
{
|
||||
std::cout << "Unhandled Interrupt : ID " << id << "\n";
|
||||
}
|
||||
|
||||
// Declare the driver instances.
|
||||
Timer timer;
|
||||
Uart uart1(0, USART1_IRQ_HANDLER);
|
||||
Uart uart2(1, USART2_IRQ_HANDLER);
|
||||
|
||||
// Declare a global callback for the timer.
|
||||
// Uses the most efficient callback type for a class, as everything is known at compile time.
|
||||
etl::function_imp<Timer, size_t, timer, &Timer::InterruptHandler> timer_member_callback;
|
||||
|
||||
// Declare the callbacks for the free functions.
|
||||
etl::function_fp<size_t, FreeTimerInterruptHandler> timer_free_callback;
|
||||
etl::function_fp<size_t, UnhandledInterrupt> unhandled_callback;
|
||||
|
||||
//********************************
|
||||
// Test it out.
|
||||
//********************************
|
||||
int main()
|
||||
{
|
||||
// Setup the callbacks.
|
||||
InterruptVectors& interruptVectors = GetInterruptVectorsInstance();
|
||||
|
||||
interruptVectors.register_callback<TIM1_CC_IRQ_HANDLER>(timer_member_callback);
|
||||
interruptVectors.register_callback<TIM2_IRQ_HANDLER>(timer_free_callback);
|
||||
interruptVectors.register_unhandled_callback(unhandled_callback);
|
||||
|
||||
// Simulate the interrupts.
|
||||
TIM1_CC_IRQHandler();
|
||||
TIM2_IRQHandler();
|
||||
USART1_IRQHandler();
|
||||
USART2_IRQHandler();
|
||||
TIM3_IRQHandler(); // Unhandled!
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
///\file
|
||||
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
https://www.etlcpp.com
|
||||
|
||||
Copyright(c) 2017 jwellbelove
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __ETL_PROFILE_H__
|
||||
#define __ETL_PROFILE_H__
|
||||
|
||||
#define ETL_THROW_EXCEPTIONS
|
||||
#define ETL_VERBOSE_ERRORS
|
||||
#define ETL_CHECK_PUSH_POP
|
||||
#define ETL_ISTRING_REPAIR_ENABLE
|
||||
#define ETL_IVECTOR_REPAIR_ENABLE
|
||||
#define ETL_IDEQUE_REPAIR_ENABLE
|
||||
#define ETL_IN_UNIT_TEST
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include "profiles/msvc_x86.h"
|
||||
#else
|
||||
#include "profiles/gcc_windows_x86.h"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,31 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26730.16
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FunctionInterruptSimulation", "FunctionInterruptSimulation.vcxproj", "{5157DB15-C255-4E47-9FB1-AF388437F90F}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Debug|x64.Build.0 = Debug|x64
|
||||
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Debug|x86.Build.0 = Debug|Win32
|
||||
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Release|x64.ActiveCfg = Release|x64
|
||||
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Release|x64.Build.0 = Release|x64
|
||||
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Release|x86.ActiveCfg = Release|Win32
|
||||
{5157DB15-C255-4E47-9FB1-AF388437F90F}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {260225EB-60CB-44CC-A60C-16A23BBC10EB}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,156 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\FunctionInterruptSimulation.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\etl_profile.h" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>15.0</VCProjectVersion>
|
||||
<ProjectGuid>{5157DB15-C255-4E47-9FB1-AF388437F90F}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>FunctionInterruptSimulation</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>../../../src</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>../../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\FunctionInterruptSimulation.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\etl_profile.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,12 @@
|
||||
cmake_minimum_required(VERSION 3.5.0)
|
||||
project(etl_mutex_router LANGUAGES CXX)
|
||||
|
||||
add_executable(etl_mutex_router MutexMessageRouter.cpp)
|
||||
|
||||
target_compile_definitions(etl_mutex_router PRIVATE -DETL_DEBUG)
|
||||
|
||||
target_include_directories(etl_mutex_router
|
||||
PRIVATE
|
||||
${PROJECT_SOURCE_DIR}/../../include)
|
||||
|
||||
set_property(TARGET etl_mutex_router PROPERTY CXX_STANDARD 17)
|
||||
@@ -0,0 +1,110 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include <atomic>
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
|
||||
#include "etl/mutex.h"
|
||||
#include "etl/message.h"
|
||||
#include "etl/message_router.h"
|
||||
|
||||
//*************************************
|
||||
struct Message1 : public etl::message<1>
|
||||
{
|
||||
};
|
||||
|
||||
//*************************************
|
||||
struct Message2 : public etl::message<2>
|
||||
{
|
||||
};
|
||||
|
||||
//*************************************
|
||||
class Router : public etl::message_router<Router, Message1, Message2>
|
||||
{
|
||||
public:
|
||||
|
||||
using base_t = etl::message_router<Router, Message1, Message2>;
|
||||
|
||||
//*****************
|
||||
// Overridden receive that protects access with mutexes
|
||||
void receive(const etl::imessage& msg) override
|
||||
{
|
||||
access.lock();
|
||||
base_t::receive(msg); // Send it to the message_router's receive.
|
||||
access.unlock();
|
||||
}
|
||||
|
||||
//*****************
|
||||
void on_receive(const Message1&)
|
||||
{
|
||||
result.append("Message1\n");
|
||||
}
|
||||
|
||||
//*****************
|
||||
void on_receive(const Message2&)
|
||||
{
|
||||
result.append("Message2\n");
|
||||
}
|
||||
|
||||
//*****************
|
||||
void on_receive_unknown(const etl::imessage&)
|
||||
{
|
||||
}
|
||||
|
||||
std::string result;
|
||||
|
||||
private:
|
||||
|
||||
etl::mutex access;
|
||||
};
|
||||
|
||||
//*************************************
|
||||
etl::atomic<bool> start = false;
|
||||
Router router;
|
||||
|
||||
//*************************************
|
||||
void thread1()
|
||||
{
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
while (!start.load());
|
||||
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
std::this_thread::sleep_for(1ms);
|
||||
router.receive(Message1());
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************
|
||||
void thread2()
|
||||
{
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
while (!start.load());
|
||||
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
std::this_thread::sleep_for(1ms);
|
||||
router.receive(Message2());
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************
|
||||
int main()
|
||||
{
|
||||
std::thread t1(thread1);
|
||||
std::thread t2(thread2);
|
||||
|
||||
start.store(true);
|
||||
|
||||
t1.join();
|
||||
t2.join();
|
||||
|
||||
std::cout << router.result << "\n";
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.7.34009.444
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MutexMessageRouter", "MutexMessageRouter.vcxproj", "{23AD62D5-C3B6-48B0-BF0D-E349FEB3F338}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{23AD62D5-C3B6-48B0-BF0D-E349FEB3F338}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{23AD62D5-C3B6-48B0-BF0D-E349FEB3F338}.Debug|x64.Build.0 = Debug|x64
|
||||
{23AD62D5-C3B6-48B0-BF0D-E349FEB3F338}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{23AD62D5-C3B6-48B0-BF0D-E349FEB3F338}.Debug|x86.Build.0 = Debug|Win32
|
||||
{23AD62D5-C3B6-48B0-BF0D-E349FEB3F338}.Release|x64.ActiveCfg = Release|x64
|
||||
{23AD62D5-C3B6-48B0-BF0D-E349FEB3F338}.Release|x64.Build.0 = Release|x64
|
||||
{23AD62D5-C3B6-48B0-BF0D-E349FEB3F338}.Release|x86.ActiveCfg = Release|Win32
|
||||
{23AD62D5-C3B6-48B0-BF0D-E349FEB3F338}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {8AA5CBFE-B15F-4262-97AE-C12F7266BD85}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,140 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>17.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectGuid>{23ad62d5-c3b6-48b0-bf0d-e349feb3f338}</ProjectGuid>
|
||||
<RootNamespace>MutexMessageRouter</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>../../include;</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>../../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="MutexMessageRouter.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Text Include="CMakeLists.txt" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
17
Chapter16/fsm/libs/etl/examples/QueuedFSM/CMakeLists.txt
Normal file
@@ -0,0 +1,17 @@
|
||||
cmake_minimum_required(VERSION 3.5.0)
|
||||
project(queued_fsm)
|
||||
|
||||
add_definitions(-DETL_DEBUG)
|
||||
|
||||
include_directories(${UTPP_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/../../include)
|
||||
|
||||
set(SOURCE_FILES QueuedFSM.cpp)
|
||||
|
||||
add_executable(queued_fsm ${SOURCE_FILES})
|
||||
target_include_directories(queued_fsm
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
set_property(TARGET queued_fsm PROPERTY CXX_STANDARD 17)
|
||||
|
||||
288
Chapter16/fsm/libs/etl/examples/QueuedFSM/QueuedFSM.cpp
Normal file
@@ -0,0 +1,288 @@
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
https://www.etlcpp.com
|
||||
|
||||
Copyright(c) 2020 jwellbelove
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
//*****************************************************************************
|
||||
// This example demonstrates the basic method to queue messages to an etl::fsm
|
||||
// derived class.
|
||||
//*****************************************************************************
|
||||
|
||||
#include "etl/queue.h"
|
||||
#include "etl/fsm.h"
|
||||
#include "etl/message_packet.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
//*****************************************************************************
|
||||
// The messages.
|
||||
//*****************************************************************************
|
||||
struct Message1 : public etl::message<1>
|
||||
{
|
||||
Message1(int i_)
|
||||
: i(i_)
|
||||
{
|
||||
}
|
||||
|
||||
int i;
|
||||
};
|
||||
|
||||
struct Message2 : public etl::message<2>
|
||||
{
|
||||
Message2(double d_)
|
||||
: d(d_)
|
||||
{
|
||||
}
|
||||
|
||||
double d;
|
||||
};
|
||||
|
||||
struct Message3 : public etl::message<3>
|
||||
{
|
||||
Message3(const std::string& s_)
|
||||
: s(s_)
|
||||
{
|
||||
}
|
||||
|
||||
std::string s;
|
||||
};
|
||||
|
||||
struct Message4 : public etl::message<4>
|
||||
{
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
STATE1,
|
||||
STATE2
|
||||
};
|
||||
|
||||
//*****************************************************************************
|
||||
// The Finite State Machine.
|
||||
//*****************************************************************************
|
||||
class Fsm : public etl::fsm
|
||||
{
|
||||
public:
|
||||
|
||||
//***************************************************************************
|
||||
// Constructor.
|
||||
//***************************************************************************
|
||||
Fsm()
|
||||
: fsm(1)
|
||||
{
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
// The overridden virtual receive function.
|
||||
//***************************************************************************
|
||||
void receive(const etl::imessage& msg_) override
|
||||
{
|
||||
if (accepts(msg_))
|
||||
{
|
||||
// Place in queue.
|
||||
queue.emplace(msg_);
|
||||
|
||||
std::cout << "Queueing message " << int(msg_.get_message_id()) << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Ignoring message " << int(msg_.get_message_id()) << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
// The method to call to handle any queued messages.
|
||||
//***************************************************************************
|
||||
void process_queue()
|
||||
{
|
||||
while (!queue.empty())
|
||||
{
|
||||
message_packet& packet = queue.front();
|
||||
etl::imessage& msg = packet.get();
|
||||
std::cout << "Processing message " << int(msg.get_message_id()) << std::endl;
|
||||
|
||||
// Call the base class's receive function.
|
||||
// This will route it to the correct 'on_event' handler.
|
||||
etl::fsm::receive(msg);
|
||||
|
||||
queue.pop();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
typedef etl::message_packet< Message1, Message2, Message3, Message4> message_packet;
|
||||
|
||||
// The queue of message items.
|
||||
etl::queue<message_packet, 10> queue;
|
||||
};
|
||||
|
||||
//*****************************************************************************
|
||||
// State 1.
|
||||
//*****************************************************************************
|
||||
class State1 : public etl::fsm_state<Fsm, State1, STATE1, Message1, Message2, Message3>
|
||||
{
|
||||
public:
|
||||
|
||||
//***************************************************************************
|
||||
// When we enter this state.
|
||||
//***************************************************************************
|
||||
etl::fsm_state_id_t on_enter_state() override
|
||||
{
|
||||
std::cout << " S1 : Enter state" << std::endl;
|
||||
return STATE1;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
void on_exit_state() override
|
||||
{
|
||||
std::cout << " S1 : Exit state" << std::endl;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
etl::fsm_state_id_t on_event(const Message1& msg)
|
||||
{
|
||||
std::cout << " S1 : Received message " << int(msg.get_message_id()) << " : '" << msg.i << "'" << std::endl;
|
||||
std::cout.flush();
|
||||
return STATE1;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
etl::fsm_state_id_t on_event(const Message2& msg)
|
||||
{
|
||||
std::cout << " S1 : Received message " << int(msg.get_message_id()) << " : '" << msg.d << "'" << std::endl;
|
||||
std::cout.flush();
|
||||
return STATE1;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
etl::fsm_state_id_t on_event(const Message3& msg)
|
||||
{
|
||||
std::cout << " S1 : Received message " << int(msg.get_message_id()) << " : '" << msg.s << "'" << std::endl;
|
||||
std::cout.flush();
|
||||
return STATE1;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
etl::fsm_state_id_t on_event_unknown(const etl::imessage& msg)
|
||||
{
|
||||
std::cout << " S1 : Received unknown message " << int(msg.get_message_id()) << std::endl;
|
||||
std::cout.flush();
|
||||
return STATE2;
|
||||
}
|
||||
};
|
||||
|
||||
//*****************************************************************************
|
||||
// State 2.
|
||||
//*****************************************************************************
|
||||
class State2 : public etl::fsm_state<Fsm, State2, STATE2, Message1, Message2, Message3>
|
||||
{
|
||||
public:
|
||||
|
||||
//***************************************************************************
|
||||
etl::fsm_state_id_t on_enter_state() override
|
||||
{
|
||||
std::cout << " S2 : Enter state" << std::endl;
|
||||
return STATE2;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
// When we enter this state.
|
||||
//***************************************************************************
|
||||
void on_exit_state() override
|
||||
{
|
||||
std::cout << " S2 : Exit state" << std::endl;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
etl::fsm_state_id_t on_event(const Message1& msg)
|
||||
{
|
||||
std::cout << " S2 : Received message " << int(msg.get_message_id()) << " : '" << msg.i << "'" << std::endl;
|
||||
return STATE2;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
etl::fsm_state_id_t on_event(const Message2& msg)
|
||||
{
|
||||
std::cout << " S2 : Received message " << int(msg.get_message_id()) << " : '" << msg.d << "'" << std::endl;
|
||||
return STATE2;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
etl::fsm_state_id_t on_event(const Message3& msg)
|
||||
{
|
||||
std::cout << " S2 : Received message " << int(msg.get_message_id()) << " : '" << msg.s << "'" << std::endl;
|
||||
return STATE2;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
etl::fsm_state_id_t on_event_unknown(const etl::imessage& msg)
|
||||
{
|
||||
std::cout << " S2 : Received unknown message " << int(msg.get_message_id()) << std::endl;
|
||||
return STATE1;
|
||||
}
|
||||
};
|
||||
|
||||
//*****************************************************************************
|
||||
// The test application.
|
||||
//*****************************************************************************
|
||||
int main()
|
||||
{
|
||||
Fsm fsm;
|
||||
|
||||
State1 state1;
|
||||
State2 state2;
|
||||
|
||||
// The list of states.
|
||||
etl::ifsm_state* state_list[] = { &state1, &state2 };
|
||||
|
||||
// Define some messages.
|
||||
Message1 m1(1);
|
||||
Message2 m2(1.2);
|
||||
Message3 m3("Hello");
|
||||
|
||||
// Set up the FSM
|
||||
fsm.set_states(state_list, 2);
|
||||
fsm.start();
|
||||
|
||||
// Queue all of the messages.
|
||||
etl::send_message(fsm, m1);
|
||||
etl::send_message(fsm, Message1(2));
|
||||
etl::send_message(fsm, m2);
|
||||
etl::send_message(fsm, Message2(3.4));
|
||||
etl::send_message(fsm, m3);
|
||||
etl::send_message(fsm, Message3("World"));
|
||||
etl::send_message(fsm, Message4());
|
||||
|
||||
std::cout << std::endl;
|
||||
|
||||
// De-queue them
|
||||
fsm.process_queue();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
43
Chapter16/fsm/libs/etl/examples/QueuedFSM/etl_profile.h
Normal file
@@ -0,0 +1,43 @@
|
||||
///\file
|
||||
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
https://www.etlcpp.com
|
||||
|
||||
Copyright(c) 2020 jwellbelove
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __ETL_PROFILE_H__
|
||||
#define __ETL_PROFILE_H__
|
||||
|
||||
#define ETL_THROW_EXCEPTIONS
|
||||
#define ETL_VERBOSE_ERRORS
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#include "etl/profiles/msvc_x86.h"
|
||||
#elif defined(__GNUC__)
|
||||
#include "etl/profiles/gcc_generic.h"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,30 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26730.10
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "QueuedFSM", "QueuedFSM.vcxproj", "{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Debug|x86.Build.0 = Debug|Win32
|
||||
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Release|x64.ActiveCfg = Release|x64
|
||||
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Release|x64.Build.0 = Release|x64
|
||||
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Release|x86.ActiveCfg = Release|Win32
|
||||
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {98B87835-6672-45D4-95BF-CC5C22C87D2C}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,160 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>15.0</VCProjectVersion>
|
||||
<ProjectGuid>{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>QueuedFSM</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>../../../include;../vs2017</AdditionalIncludeDirectories>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>../../../include;../vs2017</AdditionalIncludeDirectories>
|
||||
<PrecompiledHeaderFile />
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\QueuedFSM.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\etl_profile.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\QueuedFSM.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\etl_profile.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,17 @@
|
||||
cmake_minimum_required(VERSION 3.5.0)
|
||||
project(queued_message_router)
|
||||
|
||||
add_definitions(-DETL_DEBUG)
|
||||
|
||||
include_directories(${UTPP_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/../../include)
|
||||
|
||||
set(SOURCE_FILES QueuedMessageRouter.cpp)
|
||||
|
||||
add_executable(queued_message_router ${SOURCE_FILES})
|
||||
target_include_directories(queued_message_router
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
set_property(TARGET queued_message_router PROPERTY CXX_STANDARD 17)
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
|
||||
#include "etl/queue.h"
|
||||
#include "etl/message_router.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
//*****************************************************************************
|
||||
// The messages.
|
||||
//*****************************************************************************
|
||||
struct Message1 : public etl::message<1>
|
||||
{
|
||||
Message1(int i_)
|
||||
: i(i_)
|
||||
{
|
||||
}
|
||||
|
||||
int i;
|
||||
};
|
||||
|
||||
struct Message2 : public etl::message<2>
|
||||
{
|
||||
Message2(double d_)
|
||||
: d(d_)
|
||||
{
|
||||
}
|
||||
|
||||
double d;
|
||||
};
|
||||
|
||||
struct Message3 : public etl::message<3>
|
||||
{
|
||||
Message3(const std::string& s_)
|
||||
: s(s_)
|
||||
{
|
||||
}
|
||||
|
||||
std::string s;
|
||||
};
|
||||
|
||||
struct Message4 : public etl::message<4>
|
||||
{
|
||||
};
|
||||
|
||||
//*****************************************************************************
|
||||
// The message router.
|
||||
// Handles message types Message1, Message2, Message3.
|
||||
//*****************************************************************************
|
||||
class Router : public etl::message_router<Router, Message1, Message2, Message3>
|
||||
{
|
||||
public:
|
||||
|
||||
typedef etl::message_router<Router, Message1, Message2, Message3> Base_t;
|
||||
|
||||
using Base_t::receive;
|
||||
|
||||
//***************************************************************************
|
||||
Router()
|
||||
: message_router(1)
|
||||
{
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
// Override the base class's receive function.
|
||||
void receive(const etl::imessage& msg_)
|
||||
{
|
||||
if (accepts(msg_))
|
||||
{
|
||||
// Place in queue.
|
||||
queue.emplace(msg_);
|
||||
|
||||
std::cout << "Queueing message " << int(msg_.get_message_id()) << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Ignoring message " << int(msg_.get_message_id()) << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
void process_queue()
|
||||
{
|
||||
while (!queue.empty())
|
||||
{
|
||||
message_packet& packet = queue.front();
|
||||
etl::imessage& msg = packet.get();
|
||||
std::cout << "Processing message " << int(msg.get_message_id()) << std::endl;
|
||||
|
||||
// Call the base class's receive function.
|
||||
// This will route it to the correct on_receive handler.
|
||||
Base_t::receive(msg);
|
||||
|
||||
queue.pop();
|
||||
}
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
void on_receive(const Message1& msg)
|
||||
{
|
||||
std::cout << " Received message " << int(msg.get_message_id()) << " : '" << msg.i << "'" << std::endl;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
void on_receive(const Message2& msg)
|
||||
{
|
||||
std::cout << " Received message " << int(msg.get_message_id()) << " : '" << msg.d << "'" << std::endl;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
void on_receive(const Message3& msg)
|
||||
{
|
||||
std::cout << " Received message " << int(msg.get_message_id()) << " : '" << msg.s << "'" << std::endl;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
void on_receive_unknown(const etl::imessage& msg)
|
||||
{
|
||||
std::cout << " Received unknown message " << int(msg.get_message_id()) << std::endl;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
etl::queue<message_packet, 10> queue;
|
||||
};
|
||||
|
||||
//*****************************************************************************
|
||||
// The test application.
|
||||
//*****************************************************************************
|
||||
int main()
|
||||
{
|
||||
Router router;
|
||||
|
||||
Message1 m1(1);
|
||||
Message2 m2(1.2);
|
||||
Message3 m3("Hello");
|
||||
|
||||
etl::send_message(router, m1);
|
||||
etl::send_message(router, Message1(2));
|
||||
etl::send_message(router, m2);
|
||||
etl::send_message(router, Message2(3.4));
|
||||
etl::send_message(router, m3);
|
||||
etl::send_message(router, Message3("World"));
|
||||
etl::send_message(router, Message4());
|
||||
|
||||
std::cout << std::endl;
|
||||
|
||||
router.process_queue();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
///\file
|
||||
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
https://www.etlcpp.com
|
||||
|
||||
Copyright(c) 2017 jwellbelove
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __ETL_PROFILE_H__
|
||||
#define __ETL_PROFILE_H__
|
||||
|
||||
#define ETL_THROW_EXCEPTIONS
|
||||
#define ETL_VERBOSE_ERRORS
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#include "etl/profiles/msvc_x86.h"
|
||||
#else
|
||||
#include "etl/profiles/gcc_windows_x86.h"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,31 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26730.10
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "QueuedMessageRouter", "QueuedMessageRouter.vcxproj", "{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Debug|x64.Build.0 = Debug|x64
|
||||
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Debug|x86.Build.0 = Debug|Win32
|
||||
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Release|x64.ActiveCfg = Release|x64
|
||||
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Release|x64.Build.0 = Release|x64
|
||||
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Release|x86.ActiveCfg = Release|Win32
|
||||
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {98B87835-6672-45D4-95BF-CC5C22C87D2C}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,158 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>15.0</VCProjectVersion>
|
||||
<ProjectGuid>{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>QueuedMessageRouter</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>../../../include;../vs2017</AdditionalIncludeDirectories>
|
||||
<PrecompiledHeaderFile />
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\QueuedMessageRouter.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\etl_profile.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
17
Chapter16/fsm/libs/etl/examples/Scheduler/CMakeLists.txt
Normal file
@@ -0,0 +1,17 @@
|
||||
cmake_minimum_required(VERSION 3.5.0)
|
||||
project(scheduler)
|
||||
|
||||
add_definitions(-DETL_DEBUG)
|
||||
|
||||
include_directories(${UTPP_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/../../include)
|
||||
|
||||
set(SOURCE_FILES Scheduler.cpp)
|
||||
|
||||
add_executable(scheduler ${SOURCE_FILES})
|
||||
target_include_directories(scheduler
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
set_property(TARGET scheduler PROPERTY CXX_STANDARD 17)
|
||||
|
||||
184
Chapter16/fsm/libs/etl/examples/Scheduler/Scheduler.cpp
Normal file
@@ -0,0 +1,184 @@
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
https://www.etlcpp.com
|
||||
|
||||
Copyright(c) 2020 jwellbelove
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
//*****************************************************************************
|
||||
// This example demonstrates the basic method to schedule tasks.
|
||||
// Experiment with the different scheduling policies.
|
||||
//*****************************************************************************
|
||||
|
||||
#include "etl/scheduler.h"
|
||||
#include "etl/task.h"
|
||||
#include "etl/function.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
//*****************************************************************************
|
||||
// Task 1. Lowest priority.
|
||||
//*****************************************************************************
|
||||
class Task1 : public etl::task
|
||||
{
|
||||
public:
|
||||
|
||||
//*************************************
|
||||
Task1()
|
||||
: task(1)
|
||||
, work(3)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//*************************************
|
||||
uint32_t task_request_work() const
|
||||
{
|
||||
return work; // How much work do we still have to do? This could be a message queue length.
|
||||
}
|
||||
|
||||
//*************************************
|
||||
void task_process_work()
|
||||
{
|
||||
std::cout << "Task1 : Process work : " << work << std::endl;
|
||||
--work;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
uint32_t work;
|
||||
};
|
||||
|
||||
//*****************************************************************************
|
||||
// Task 2. Highest priority.
|
||||
//*****************************************************************************
|
||||
class Task2 : public etl::task
|
||||
{
|
||||
public:
|
||||
|
||||
//*************************************
|
||||
Task2()
|
||||
: task(2)
|
||||
, work(4)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//*************************************
|
||||
uint32_t task_request_work() const
|
||||
{
|
||||
return work; // How much work do we still have to do? This could be a message queue length.
|
||||
}
|
||||
|
||||
//*************************************
|
||||
void task_process_work()
|
||||
{
|
||||
std::cout << "Task2 : Process work : " << work << std::endl;
|
||||
--work;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
uint32_t work;
|
||||
};
|
||||
|
||||
//*****************************************************************************
|
||||
// The idle handler.
|
||||
//*****************************************************************************
|
||||
class Idle
|
||||
{
|
||||
public:
|
||||
|
||||
//*************************************
|
||||
Idle(etl::ischeduler& scheduler_)
|
||||
: scheduler(scheduler_)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//*************************************
|
||||
void IdleCallback()
|
||||
{
|
||||
std::cout << "Idle callback" << std::endl;
|
||||
scheduler.exit_scheduler();
|
||||
std::cout << "Exiting the scheduler" << std::endl;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
etl::ischeduler& scheduler;
|
||||
};
|
||||
|
||||
//*****************************************************************************
|
||||
// The watchdog handler.
|
||||
//*****************************************************************************
|
||||
void WatchdogCallback()
|
||||
{
|
||||
std::cout << "Watchdog callback" << std::endl;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
// The scheduler.
|
||||
// Maximum of two tasks.
|
||||
//
|
||||
// Try the other scheduler policies to see how scheduling differs.
|
||||
// etl::scheduler_policy_sequential_single
|
||||
// etl::scheduler_policy_sequential_multiple
|
||||
// etl::scheduler_policy_highest_priority
|
||||
// etl::scheduler_policy_most_work
|
||||
//*****************************************************************************
|
||||
class Scheduler : public etl::scheduler<etl::scheduler_policy_sequential_single, 2>
|
||||
{
|
||||
};
|
||||
|
||||
//*****************************************************************************
|
||||
// The test application.
|
||||
//*****************************************************************************
|
||||
int main()
|
||||
{
|
||||
Scheduler scheduler;
|
||||
|
||||
Task1 task1;
|
||||
Task2 task2;
|
||||
|
||||
Idle idleHandler(scheduler);
|
||||
|
||||
etl::function_mv<Idle, &Idle::IdleCallback> idleCallback(idleHandler); // Member function, no parameters, returning void.
|
||||
etl::function_fv<WatchdogCallback> watchdogCallback; // Global function, no parameters, returning void.
|
||||
|
||||
scheduler.add_task(task1);
|
||||
scheduler.add_task(task2);
|
||||
scheduler.set_idle_callback(idleCallback);
|
||||
scheduler.set_watchdog_callback(watchdogCallback);
|
||||
|
||||
std::cout << "Starting the scheduler" << std::endl;
|
||||
|
||||
scheduler.start();
|
||||
|
||||
std::cout << "Exiting the application" << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
43
Chapter16/fsm/libs/etl/examples/Scheduler/etl_profile.h
Normal file
@@ -0,0 +1,43 @@
|
||||
///\file
|
||||
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
https://www.etlcpp.com
|
||||
|
||||
Copyright(c) 2020 jwellbelove
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __ETL_PROFILE_H__
|
||||
#define __ETL_PROFILE_H__
|
||||
|
||||
#define ETL_THROW_EXCEPTIONS
|
||||
#define ETL_VERBOSE_ERRORS
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#include "etl/profiles/msvc_x86.h"
|
||||
#elif defined(__GNUC__)
|
||||
#include "etl/profiles/gcc_generic.h"
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,30 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26730.10
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Scheduler", "Scheduler.vcxproj", "{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Debug|x86.Build.0 = Debug|Win32
|
||||
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Release|x64.ActiveCfg = Release|x64
|
||||
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Release|x64.Build.0 = Release|x64
|
||||
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Release|x86.ActiveCfg = Release|Win32
|
||||
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {98B87835-6672-45D4-95BF-CC5C22C87D2C}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,160 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>15.0</VCProjectVersion>
|
||||
<ProjectGuid>{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>Scheduler</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0.18362.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v141</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>../../../include;../vs2017</AdditionalIncludeDirectories>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>../../../include;../vs2017</AdditionalIncludeDirectories>
|
||||
<PrecompiledHeaderFile />
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\Scheduler.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\etl_profile.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,30 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26730.10
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Scheduler", "Scheduler.vcxproj", "{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Debug|x86.Build.0 = Debug|Win32
|
||||
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Release|x64.ActiveCfg = Release|x64
|
||||
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Release|x64.Build.0 = Release|x64
|
||||
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Release|x86.ActiveCfg = Release|Win32
|
||||
{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {98B87835-6672-45D4-95BF-CC5C22C87D2C}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,160 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>15.0</VCProjectVersion>
|
||||
<ProjectGuid>{2BB47D48-5EFC-4C38-B2BE-002172F00E3B}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>Scheduler</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>../../../include;../vs2017</AdditionalIncludeDirectories>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>../../../include;../vs2017</AdditionalIncludeDirectories>
|
||||
<PrecompiledHeaderFile />
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AdditionalIncludeDirectories>%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\Scheduler.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\etl_profile.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
17
Chapter16/fsm/libs/etl/examples/SharedMessage/CMakeLists.txt
Normal file
@@ -0,0 +1,17 @@
|
||||
cmake_minimum_required(VERSION 3.5.0)
|
||||
project(SharedMessage)
|
||||
|
||||
add_definitions(-DETL_DEBUG)
|
||||
|
||||
include_directories(${UTPP_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/../../include)
|
||||
|
||||
set(SOURCE_FILES SharedMessage.cpp)
|
||||
|
||||
add_executable(SharedMessage ${SOURCE_FILES})
|
||||
target_include_directories(SharedMessage
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
set_property(TARGET SharedMessage PROPERTY CXX_STANDARD 17)
|
||||
|
||||
285
Chapter16/fsm/libs/etl/examples/SharedMessage/SharedMessage.cpp
Normal file
@@ -0,0 +1,285 @@
|
||||
//*****************************************************************************
|
||||
// Shared message example
|
||||
//*****************************************************************************
|
||||
|
||||
#include "etl/shared_message.h"
|
||||
#include "etl/message.h"
|
||||
#include "etl/reference_counted_message_pool.h"
|
||||
#include "etl/message_router.h"
|
||||
#include "etl/message_bus.h"
|
||||
#include "etl/fixed_sized_memory_block_allocator.h"
|
||||
#include "etl/queue.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <atomic>
|
||||
#include <string>
|
||||
#include <mutex>
|
||||
|
||||
constexpr etl::message_router_id_t RouterId1 = 1U;
|
||||
constexpr etl::message_router_id_t RouterId2 = 2U;
|
||||
|
||||
//*****************************************************************************
|
||||
// Message1
|
||||
//*****************************************************************************
|
||||
struct Message1 : public etl::message<1>
|
||||
{
|
||||
Message1(std::string s_)
|
||||
: s(s_)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::string s;
|
||||
};
|
||||
|
||||
//*****************************************************************************
|
||||
// Message2
|
||||
//*****************************************************************************
|
||||
struct Message2 : public etl::message<2>
|
||||
{
|
||||
Message2(std::string s_)
|
||||
: s(s_)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::string s;
|
||||
char data[100];
|
||||
};
|
||||
|
||||
//*****************************************************************************
|
||||
// Message3
|
||||
//*****************************************************************************
|
||||
struct Message3 : public etl::message<3>
|
||||
{
|
||||
Message3(std::string s_)
|
||||
: s(s_)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::string s;
|
||||
};
|
||||
|
||||
//*****************************************************************************
|
||||
// Prints the shared message
|
||||
//*****************************************************************************
|
||||
void Print(const std::string& prefix, etl::shared_message sm)
|
||||
{
|
||||
std::cout << prefix << " : Message Id = " << int(sm.get_message().get_message_id()) << "\n";
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
// This router accepts Message1, Message2 and Message3 types.
|
||||
// If a shared message it received, it will be processed immediately.
|
||||
//*****************************************************************************
|
||||
class MessageRouter1 : public etl::message_router<MessageRouter1, Message1, Message2, Message3>
|
||||
{
|
||||
public:
|
||||
|
||||
//****************************************
|
||||
MessageRouter1()
|
||||
: message_router(RouterId1)
|
||||
{
|
||||
}
|
||||
|
||||
//****************************************
|
||||
void on_receive(const Message1& msg)
|
||||
{
|
||||
std::cout << "MessageRouter1 : on_receive Message1 : " << msg.s << "\n";
|
||||
}
|
||||
|
||||
//****************************************
|
||||
void on_receive(const Message2& msg)
|
||||
{
|
||||
std::cout << "MessageRouter1 : on_receive Message2 : " << msg.s << "\n";
|
||||
}
|
||||
|
||||
//****************************************
|
||||
void on_receive(const Message3& msg)
|
||||
{
|
||||
std::cout << "MessageRouter1 : on_receive Message3 : " << msg.s << "\n";
|
||||
}
|
||||
|
||||
//****************************************
|
||||
void on_receive_unknown(const etl::imessage& msg)
|
||||
{
|
||||
std::cout << "MessageRouter1 : on_receive Unknown\n";
|
||||
}
|
||||
};
|
||||
|
||||
//*****************************************************************************
|
||||
// This router accepts Message1, Message2 and Message3 types.
|
||||
// If a shared message it received it will queue them.
|
||||
// The messages will be processed when process_queue() is called.
|
||||
//*****************************************************************************
|
||||
class MessageRouter2 : public etl::message_router<MessageRouter2, Message1, Message2, Message3>
|
||||
{
|
||||
public:
|
||||
|
||||
using base_t = etl::message_router<MessageRouter2, Message1, Message2, Message3>;
|
||||
|
||||
//****************************************
|
||||
MessageRouter2()
|
||||
: message_router(RouterId2)
|
||||
{
|
||||
}
|
||||
|
||||
using base_t::receive;
|
||||
|
||||
//****************************************
|
||||
// Overridden receive.
|
||||
// Puts the shared messages into a queue.
|
||||
void receive(etl::shared_message shared_msg) override
|
||||
{
|
||||
if (!queue.full())
|
||||
{
|
||||
Print("MessageRouter2 : Queueing shared message", shared_msg);
|
||||
|
||||
queue.push(shared_msg);
|
||||
}
|
||||
}
|
||||
|
||||
//****************************************
|
||||
// Processes the queued shared messages.
|
||||
void process_queue()
|
||||
{
|
||||
while (!queue.empty())
|
||||
{
|
||||
// Get the shared message from the queue.
|
||||
etl::shared_message shared_msg = queue.front();
|
||||
|
||||
Print("MessageRouter2 : Process queued shared message", shared_msg);
|
||||
|
||||
// Send it to the base implementation for routing.
|
||||
base_t::receive(shared_msg);
|
||||
|
||||
queue.pop();
|
||||
}
|
||||
}
|
||||
|
||||
//****************************************
|
||||
void on_receive(const Message1& msg)
|
||||
{
|
||||
std::cout << "MessageRouter2 : on_receive Message1 : " << msg.s << "\n";
|
||||
}
|
||||
|
||||
//****************************************
|
||||
void on_receive(const Message2& msg)
|
||||
{
|
||||
std::cout << "MessageRouter2 : on_receive Message2 : " << msg.s << "\n";
|
||||
}
|
||||
|
||||
//****************************************
|
||||
void on_receive(const Message3& msg)
|
||||
{
|
||||
std::cout << "MessageRouter2 : on_receive Message3 : " << msg.s << "\n";
|
||||
}
|
||||
|
||||
//****************************************
|
||||
void on_receive_unknown(const etl::imessage& msg)
|
||||
{
|
||||
std::cout << "MessageRouter2 : on_receive Unknown\n";
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
etl::queue<etl::shared_message, 10> queue;
|
||||
};
|
||||
|
||||
//*****************************************************************************
|
||||
// A message bus that can accommodate two subscribers.
|
||||
//*****************************************************************************
|
||||
struct Bus : public etl::message_bus<2U>
|
||||
{
|
||||
};
|
||||
|
||||
//*****************************************************************************
|
||||
// Define the routers and bus.
|
||||
//*****************************************************************************
|
||||
MessageRouter1 router1;
|
||||
MessageRouter2 router2;
|
||||
Bus bus;
|
||||
|
||||
//*****************************************************************************
|
||||
// The thread safe message pool. Uses atomic uint32_t for counting.
|
||||
class MessagePool : public etl::reference_counted_message_pool<std::atomic_int32_t>
|
||||
{
|
||||
public:
|
||||
|
||||
MessagePool(etl::imemory_block_allocator& allocator)
|
||||
: reference_counted_message_pool(allocator)
|
||||
{
|
||||
}
|
||||
|
||||
// Called before the memory block allocator is accessed.
|
||||
void lock() override
|
||||
{
|
||||
mut.lock();
|
||||
}
|
||||
|
||||
// Called after the memory block allocator has been accessed.
|
||||
void unlock() override
|
||||
{
|
||||
mut.unlock();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
std::mutex mut;
|
||||
};
|
||||
|
||||
//*****************************************************************************
|
||||
// The memory block allocator that supplies the pool with memory
|
||||
// to store reference counted messages in.
|
||||
|
||||
// The reference counted message parameters type for the messages we will use.
|
||||
using message_parameters_small = MessagePool::pool_message_parameters<Message1, Message3>;
|
||||
using message_parameters_large = MessagePool::pool_message_parameters<Message2>;
|
||||
|
||||
constexpr size_t max_size_small = message_parameters_small::max_size;
|
||||
constexpr size_t max_alignment_small = message_parameters_small::max_alignment;
|
||||
|
||||
constexpr size_t max_size_large = message_parameters_large::max_size;
|
||||
constexpr size_t max_alignment_large = message_parameters_large::max_alignment;
|
||||
|
||||
// A fixed memory block allocator for 4 items, using the parameters from the smaller messages.
|
||||
etl::fixed_sized_memory_block_allocator<max_size_small, max_alignment_small, 4U> memory_allocator;
|
||||
|
||||
// A fixed memory block allocator for 4 items, using the parameters from the larger message.
|
||||
etl::fixed_sized_memory_block_allocator<max_size_large, max_alignment_large, 4U> memory_allocator_successor;
|
||||
|
||||
//*****************************************************************************
|
||||
// The pool that supplies reference counted messages.
|
||||
// Uses memory_allocator as its allocator.
|
||||
//*****************************************************************************
|
||||
MessagePool message_pool(memory_allocator);
|
||||
|
||||
//*****************************************************************************
|
||||
// A statically allocated reference counted message that is never allocated or released by a pool.
|
||||
// Contains a copy of Message3("Three").
|
||||
//*****************************************************************************
|
||||
etl::persistent_message<Message3> pm3(Message3("Three"));
|
||||
|
||||
//*****************************************************************************
|
||||
int main()
|
||||
{
|
||||
// If memory_allocator can't allocate, then try memory_allocator_successor.
|
||||
memory_allocator.set_successor(memory_allocator_successor);
|
||||
|
||||
Message1 m1("One");
|
||||
Message2 m2("Two");
|
||||
|
||||
etl::shared_message sm1(message_pool, m1); // Created a shared message by allocating a reference counted message from message_pool containing a copy of m1.
|
||||
etl::shared_message sm2(message_pool, m2); // Created a shared message by allocating a reference counted message from message_pool containing a copy of m2.
|
||||
etl::shared_message sm3(pm3); // Created a shared message from a statically allocated persistent message.
|
||||
|
||||
bus.subscribe(router1); // Subscribe router1 to the bus.
|
||||
bus.subscribe(router2); // Subscribe router2 to the bus.
|
||||
|
||||
bus.receive(sm1); // Send sm1 to the bus for distribution to the routers.
|
||||
bus.receive(sm2); // Send sm2 to the bus for distribution to the routers.
|
||||
bus.receive(sm3); // Send sm3 to the bus for distribution to the routers.
|
||||
|
||||
router2.process_queue(); // Allow router2 to process its queued messages.
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.30804.86
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SharedMessage", "SharedMessage.vcxproj", "{0BDB4F2A-47E7-4105-A66A-6DFF8A76587B}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{0BDB4F2A-47E7-4105-A66A-6DFF8A76587B}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{0BDB4F2A-47E7-4105-A66A-6DFF8A76587B}.Debug|x64.Build.0 = Debug|x64
|
||||
{0BDB4F2A-47E7-4105-A66A-6DFF8A76587B}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{0BDB4F2A-47E7-4105-A66A-6DFF8A76587B}.Debug|x86.Build.0 = Debug|Win32
|
||||
{0BDB4F2A-47E7-4105-A66A-6DFF8A76587B}.Release|x64.ActiveCfg = Release|x64
|
||||
{0BDB4F2A-47E7-4105-A66A-6DFF8A76587B}.Release|x64.Build.0 = Release|x64
|
||||
{0BDB4F2A-47E7-4105-A66A-6DFF8A76587B}.Release|x86.ActiveCfg = Release|Win32
|
||||
{0BDB4F2A-47E7-4105-A66A-6DFF8A76587B}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {F7B7515D-19FA-42D4-9BA2-5F85A7FB7779}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
@@ -0,0 +1,165 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>16.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectGuid>{0bdb4f2a-47e7-4105-a66a-6dff8a76587b}</ProjectGuid>
|
||||
<RootNamespace>SharedMessage</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>D:\Users\John\Documents\Programming\GitHub\etl\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="SharedMessage.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\include\etl\atomic.h" />
|
||||
<ClInclude Include="..\..\include\etl\fixed_sized_memory_block_allocator.h" />
|
||||
<ClInclude Include="..\..\include\etl\imemory_block_allocator.h" />
|
||||
<ClInclude Include="..\..\include\etl\ireference_counted_message_pool.h" />
|
||||
<ClInclude Include="..\..\include\etl\message.h" />
|
||||
<ClInclude Include="..\..\include\etl\message_bus.h" />
|
||||
<ClInclude Include="..\..\include\etl\message_router.h" />
|
||||
<ClInclude Include="..\..\include\etl\message_types.h" />
|
||||
<ClInclude Include="..\..\include\etl\reference_counted_message.h" />
|
||||
<ClInclude Include="..\..\include\etl\reference_counted_message_pool.h" />
|
||||
<ClInclude Include="..\..\include\etl\reference_counted_object.h" />
|
||||
<ClInclude Include="..\..\include\etl\shared_message.h" />
|
||||
<ClInclude Include="..\..\include\etl\successor.h" />
|
||||
<ClInclude Include="etl_profile.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
7
Chapter16/fsm/libs/etl/examples/platformio/.gitignore
vendored
Normal 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
|
||||
16
Chapter16/fsm/libs/etl/examples/platformio/README.md
Normal 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.
|
||||
@@ -0,0 +1 @@
|
||||
#include "etl/profiles/etl_profile.h"
|
||||
27
Chapter16/fsm/libs/etl/examples/platformio/platformio.ini
Normal 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
|
||||
|
||||
142
Chapter16/fsm/libs/etl/examples/platformio/src/main.cpp
Normal 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;
|
||||
}
|
||||
BIN
Chapter16/fsm/libs/etl/images/ArcticCodeVault.png
Normal file
|
After Width: | Height: | Size: 64 KiB |
BIN
Chapter16/fsm/libs/etl/images/ArcticCodeVaultTransparent.png
Normal file
|
After Width: | Height: | Size: 66 KiB |
9
Chapter16/fsm/libs/etl/images/Coverty Shields.txt
Normal file
@@ -0,0 +1,9 @@
|
||||
<a href="https://scan.coverity.com/projects/embedded-template-library">
|
||||
<img alt="Coverity Scan Build Status"
|
||||
src="https://scan.coverity.com/projects/30565/badge.svg"/>
|
||||
</a>
|
||||
|
||||
<a href="https://scan.coverity.com/projects/embedded-template-library">
|
||||
<img alt="Coverity Scan Build Status"
|
||||
src="https://img.shields.io/coverity/scan/30565.svg"/>
|
||||
</a>
|
||||
BIN
Chapter16/fsm/libs/etl/images/etl-round.png
Normal file
|
After Width: | Height: | Size: 33 KiB |
BIN
Chapter16/fsm/libs/etl/images/etl.ico
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
Chapter16/fsm/libs/etl/images/etl.png
Normal file
|
After Width: | Height: | Size: 20 KiB |
BIN
Chapter16/fsm/libs/etl/images/etl.xar
Normal file
BIN
Chapter16/fsm/libs/etl/images/etl16.png
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
Chapter16/fsm/libs/etl/images/etl32.png
Normal file
|
After Width: | Height: | Size: 19 KiB |
BIN
Chapter16/fsm/libs/etl/images/etl48.png
Normal file
|
After Width: | Height: | Size: 24 KiB |
BIN
Chapter16/fsm/libs/etl/images/etl64.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
Chapter16/fsm/libs/etl/images/favicon-32.png
Normal file
|
After Width: | Height: | Size: 19 KiB |
BIN
Chapter16/fsm/libs/etl/images/favicon-64.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
Chapter16/fsm/libs/etl/images/favicon.ico
Normal file
|
After Width: | Height: | Size: 1.1 KiB |
96
Chapter16/fsm/libs/etl/include/etl/absolute.h
Normal file
@@ -0,0 +1,96 @@
|
||||
///\file
|
||||
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
https://www.etlcpp.com
|
||||
|
||||
Copyright(c) 2018 John Wellbelove
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef ETL_ABSOLUTE_INCLUDED
|
||||
#define ETL_ABSOLUTE_INCLUDED
|
||||
|
||||
#include "type_traits.h"
|
||||
#include "integral_limits.h"
|
||||
|
||||
namespace etl
|
||||
{
|
||||
//***************************************************************************
|
||||
// For signed types.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR
|
||||
typename etl::enable_if<etl::is_signed<T>::value, T>::type
|
||||
absolute(T value) ETL_NOEXCEPT
|
||||
{
|
||||
return (value < T(0)) ? -value : value;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
// For unsigned types.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR
|
||||
typename etl::enable_if<etl::is_unsigned<T>::value, T>::type
|
||||
absolute(T value) ETL_NOEXCEPT
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
// For signed types.
|
||||
// Returns the result as the unsigned type.
|
||||
//***************************************************************************
|
||||
#if ETL_USING_CPP11
|
||||
template <typename T, typename TReturn = typename etl::make_unsigned<T>::type>
|
||||
#else
|
||||
template <typename T, typename TReturn>
|
||||
#endif
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR
|
||||
typename etl::enable_if<etl::is_signed<T>::value, TReturn>::type
|
||||
absolute_unsigned(T value) ETL_NOEXCEPT
|
||||
{
|
||||
return (value == etl::integral_limits<T>::min) ? (etl::integral_limits<TReturn>::max / 2U) + 1U
|
||||
: (value < T(0)) ? TReturn(-value) : TReturn(value);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
// For unsigned types.
|
||||
// Returns the result as the unsigned type.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR
|
||||
typename etl::enable_if<etl::is_unsigned<T>::value, T>::type
|
||||
absolute_unsigned(T value) ETL_NOEXCEPT
|
||||
{
|
||||
return etl::absolute(value);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
3425
Chapter16/fsm/libs/etl/include/etl/algorithm.h
Normal file
339
Chapter16/fsm/libs/etl/include/etl/alignment.h
Normal file
@@ -0,0 +1,339 @@
|
||||
///\file
|
||||
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
https://www.etlcpp.com
|
||||
|
||||
Copyright(c) 2014 John Wellbelove
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef ETL_ALIGNMENT_INCLUDED
|
||||
#define ETL_ALIGNMENT_INCLUDED
|
||||
|
||||
#include "platform.h"
|
||||
#include "type_traits.h"
|
||||
#include "static_assert.h"
|
||||
#include "error_handler.h"
|
||||
#include "exception.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
///\defgroup alignment alignment
|
||||
/// Creates a variable of the specified type at the specified alignment.
|
||||
/// \ingroup utilities
|
||||
|
||||
namespace etl
|
||||
{
|
||||
//***************************************************************************
|
||||
/// Exception base for alignment
|
||||
//***************************************************************************
|
||||
class alignment_exception : public etl::exception
|
||||
{
|
||||
public:
|
||||
|
||||
alignment_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
|
||||
: exception(reason_, file_name_, line_number_)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
/// Memory misalignment exception.
|
||||
//***************************************************************************
|
||||
class alignment_error : public alignment_exception
|
||||
{
|
||||
public:
|
||||
|
||||
alignment_error(string_type file_name_, numeric_type line_number_)
|
||||
: alignment_exception(ETL_ERROR_TEXT("alignment:error", ETL_ALIGNMENT_FILE_ID"A"), file_name_, line_number_)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//*****************************************************************************
|
||||
/// Check that 'p' has 'required_alignment'.
|
||||
//*****************************************************************************
|
||||
inline bool is_aligned(void* p, size_t required_alignment)
|
||||
{
|
||||
uintptr_t address = reinterpret_cast<uintptr_t>(p);
|
||||
return (address % required_alignment) == 0U;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
/// Check that 'p' has 'Alignment'.
|
||||
//*****************************************************************************
|
||||
template <size_t Alignment>
|
||||
bool is_aligned(void* p)
|
||||
{
|
||||
uintptr_t address = reinterpret_cast<uintptr_t>(p);
|
||||
return (address % Alignment) == 0U;
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
/// Check that 'p' has the alignment of 'T'.
|
||||
//*****************************************************************************
|
||||
template <typename T>
|
||||
bool is_aligned(void* p)
|
||||
{
|
||||
return is_aligned<etl::alignment_of<T>::value>(p);
|
||||
}
|
||||
|
||||
namespace private_alignment
|
||||
{
|
||||
#if ETL_USING_CPP11
|
||||
//***************************************************************************
|
||||
// Matcher.
|
||||
//***************************************************************************
|
||||
template <bool Is_Match, size_t Alignment, typename... TRest>
|
||||
class type_with_alignment_matcher;
|
||||
|
||||
// Matching alignment.
|
||||
template <size_t Alignment, typename T1, typename... TRest>
|
||||
class type_with_alignment_matcher<true, Alignment, T1, TRest...>
|
||||
{
|
||||
public:
|
||||
|
||||
typedef T1 type;
|
||||
};
|
||||
|
||||
// Non-matching alignment
|
||||
template <size_t Alignment, typename T1, typename T2, typename... TRest>
|
||||
class type_with_alignment_matcher <false, Alignment, T1, T2, TRest...>
|
||||
{
|
||||
public:
|
||||
|
||||
typedef typename type_with_alignment_matcher < Alignment <= etl::alignment_of<T2>::value , Alignment, T2, TRest... > ::type type;
|
||||
};
|
||||
|
||||
// Non-matching alignment, none left.
|
||||
template <size_t Alignment, typename T1>
|
||||
class type_with_alignment_matcher <false, Alignment, T1>
|
||||
{
|
||||
public:
|
||||
|
||||
typedef char type;
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
// Helper.
|
||||
//***************************************************************************
|
||||
template <size_t Alignment, typename T1, typename... T>
|
||||
class type_with_alignment_helper
|
||||
{
|
||||
public:
|
||||
|
||||
typedef typename type_with_alignment_matcher<Alignment <= etl::alignment_of<T1>::value, Alignment, T1, T...>::type type;
|
||||
};
|
||||
#else
|
||||
//***************************************************************************
|
||||
// Matcher.
|
||||
//***************************************************************************
|
||||
template <bool Is_Match, const size_t Alignment, typename T1 = void, typename T2 = void, typename T3 = void, typename T4 = void,
|
||||
typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void>
|
||||
class type_with_alignment_matcher;
|
||||
|
||||
// Matching alignment.
|
||||
template <size_t Alignment, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
|
||||
class type_with_alignment_matcher <true, Alignment, T1, T2, T3, T4, T5, T6, T7, T8>
|
||||
{
|
||||
public:
|
||||
|
||||
typedef T1 type;
|
||||
};
|
||||
|
||||
// Non-matching alignment.
|
||||
template <size_t Alignment, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
|
||||
class type_with_alignment_matcher <false, Alignment, T1, T2, T3, T4, T5, T6, T7, T8>
|
||||
{
|
||||
public:
|
||||
|
||||
typedef typename type_with_alignment_matcher<Alignment <= etl::alignment_of<T2>::value, Alignment, T2, T3, T4, T5, T6, T7, T8, void>::type type;
|
||||
};
|
||||
|
||||
// Non-matching alignment, none left.
|
||||
template <size_t Alignment>
|
||||
class type_with_alignment_matcher <false, Alignment, void, void, void, void, void, void, void, void>
|
||||
{
|
||||
public:
|
||||
|
||||
typedef char type;
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
// Helper.
|
||||
//***************************************************************************
|
||||
template <size_t Alignment, typename T1, typename T2 = void, typename T3 = void, typename T4 = void,
|
||||
typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void>
|
||||
class type_with_alignment_helper
|
||||
{
|
||||
public:
|
||||
|
||||
typedef typename type_with_alignment_matcher<Alignment <= etl::alignment_of<T1>::value, Alignment, T1, T2, T3, T4, T5, T6, T7, T8>::type type;
|
||||
};
|
||||
#endif
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Gets a type that has the same as the specified alignment.
|
||||
///\ingroup alignment
|
||||
//***************************************************************************
|
||||
template <size_t Alignment>
|
||||
class type_with_alignment
|
||||
{
|
||||
public:
|
||||
|
||||
#if ETL_USING_CPP11
|
||||
typedef struct { alignas(Alignment) char dummy; } type;
|
||||
#else
|
||||
#if ETL_NOT_USING_64BIT_TYPES
|
||||
typedef typename private_alignment::type_with_alignment_helper<Alignment, int_least8_t, int_least16_t, int32_t, float, double, void*>::type type;
|
||||
#else
|
||||
typedef typename private_alignment::type_with_alignment_helper<Alignment, int_least8_t, int_least16_t, int32_t, int64_t, float, double, void*>::type type;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
ETL_STATIC_ASSERT(etl::alignment_of<type>::value == Alignment, "Unable to create the type with the specified alignment");
|
||||
};
|
||||
|
||||
#if ETL_USING_CPP11
|
||||
template <size_t Alignment>
|
||||
using type_with_alignment_t = typename type_with_alignment<Alignment>::type;
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// Aligned storage
|
||||
/// Length should be determined in terms of sizeof()
|
||||
///\ingroup alignment
|
||||
//***************************************************************************
|
||||
template <size_t Length, const size_t Alignment>
|
||||
struct aligned_storage
|
||||
{
|
||||
struct type
|
||||
{
|
||||
//type()
|
||||
// : data()
|
||||
//{
|
||||
//}
|
||||
|
||||
/// Convert to T reference.
|
||||
template <typename T>
|
||||
operator T& ()
|
||||
{
|
||||
ETL_STATIC_ASSERT((etl::is_same<T*, void*>:: value || ((Alignment % etl::alignment_of<T>::value) == 0)), "Incompatible alignment");
|
||||
T* t = *this;
|
||||
return *t;
|
||||
}
|
||||
|
||||
/// Convert to const T reference.
|
||||
template <typename T>
|
||||
operator const T& () const
|
||||
{
|
||||
ETL_STATIC_ASSERT((etl::is_same<T*, void*>:: value || ((Alignment % etl::alignment_of<T>::value) == 0)), "Incompatible alignment");
|
||||
const T* t = *this;
|
||||
return *t;
|
||||
}
|
||||
|
||||
/// Convert to T pointer.
|
||||
template <typename T>
|
||||
operator T* ()
|
||||
{
|
||||
ETL_STATIC_ASSERT((etl::is_same<T*, void*>:: value || ((Alignment % etl::alignment_of<T>::value) == 0)), "Incompatible alignment");
|
||||
return reinterpret_cast<T*>(data);
|
||||
}
|
||||
|
||||
/// Convert to const T pointer.
|
||||
template <typename T>
|
||||
operator const T* () const
|
||||
{
|
||||
ETL_STATIC_ASSERT((etl::is_same<T*, void*>:: value || ((Alignment % etl::alignment_of<T>::value) == 0)), "Incompatible alignment");
|
||||
return reinterpret_cast<const T*>(data);
|
||||
}
|
||||
|
||||
/// Get address as T reference.
|
||||
template <typename T>
|
||||
T& get_reference()
|
||||
{
|
||||
ETL_STATIC_ASSERT((etl::is_same<T*, void*>:: value || ((Alignment % etl::alignment_of<T>::value) == 0)), "Incompatible alignment");
|
||||
T* t = *this;
|
||||
return *t;
|
||||
}
|
||||
|
||||
/// Get address as const T reference.
|
||||
template <typename T>
|
||||
const T& get_reference() const
|
||||
{
|
||||
ETL_STATIC_ASSERT((etl::is_same<T*, void*>:: value || ((Alignment % etl::alignment_of<T>::value) == 0)), "Incompatible alignment");
|
||||
const T* t = *this;
|
||||
return *t;
|
||||
}
|
||||
|
||||
/// Get address as T pointer.
|
||||
template <typename T>
|
||||
T* get_address()
|
||||
{
|
||||
ETL_STATIC_ASSERT((etl::is_same<T*, void*>:: value || ((Alignment % etl::alignment_of<T>::value) == 0)), "Incompatible alignment");
|
||||
return reinterpret_cast<T*>(data);
|
||||
}
|
||||
|
||||
/// Get address as const T pointer.
|
||||
template <typename T>
|
||||
const T* get_address() const
|
||||
{
|
||||
ETL_STATIC_ASSERT((etl::is_same<T*, void*>:: value || ((Alignment % etl::alignment_of<T>::value) == 0)), "Incompatible alignment");
|
||||
return reinterpret_cast<const T*>(data);
|
||||
}
|
||||
|
||||
#if ETL_USING_CPP11 && !defined(ETL_COMPILER_ARM5)
|
||||
alignas(Alignment) char data[Length];
|
||||
#else
|
||||
union
|
||||
{
|
||||
char data[Length];
|
||||
typename etl::type_with_alignment<Alignment>::type etl_alignment_type; // A POD type that has the same alignment as Alignment.
|
||||
};
|
||||
#endif
|
||||
};
|
||||
};
|
||||
|
||||
#if ETL_USING_CPP11
|
||||
template <size_t Length, const size_t Alignment>
|
||||
using aligned_storage_t = typename aligned_storage<Length, Alignment>::type;
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// Aligned storage as
|
||||
///\ingroup alignment
|
||||
//***************************************************************************
|
||||
template <size_t Length, typename T>
|
||||
struct aligned_storage_as : public etl::aligned_storage<Length, etl::alignment_of<T>::value>
|
||||
{
|
||||
};
|
||||
|
||||
#if ETL_USING_CPP11
|
||||
template <size_t Length, typename T>
|
||||
using aligned_storage_as_t = typename aligned_storage_as<Length, T>::type;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
741
Chapter16/fsm/libs/etl/include/etl/array.h
Normal file
@@ -0,0 +1,741 @@
|
||||
///\file
|
||||
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
https://www.etlcpp.com
|
||||
|
||||
Copyright(c) 2014 John Wellbelove
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef ETL_ARRAY_INCLUDED
|
||||
#define ETL_ARRAY_INCLUDED
|
||||
|
||||
#include "platform.h"
|
||||
#include "algorithm.h"
|
||||
#include "iterator.h"
|
||||
#include "functional.h"
|
||||
#include "exception.h"
|
||||
#include "type_traits.h"
|
||||
#include "parameter_type.h"
|
||||
#include "static_assert.h"
|
||||
#include "error_handler.h"
|
||||
#include "nth_type.h"
|
||||
#include "initializer_list.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
///\defgroup array array
|
||||
/// A replacement for std::array if you haven't got C++0x11.
|
||||
///\ingroup containers
|
||||
|
||||
namespace etl
|
||||
{
|
||||
//***************************************************************************
|
||||
///\ingroup array
|
||||
/// The base class for array exceptions.
|
||||
//***************************************************************************
|
||||
class array_exception : public exception
|
||||
{
|
||||
public:
|
||||
|
||||
array_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
|
||||
: exception(reason_, file_name_, line_number_)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
///\ingroup array
|
||||
/// The out of range exceptions.
|
||||
//***************************************************************************
|
||||
class array_out_of_range : public array_exception
|
||||
{
|
||||
public:
|
||||
|
||||
array_out_of_range(string_type file_name_, numeric_type line_number_)
|
||||
: array_exception("array:range", file_name_, line_number_)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
///\ingroup array
|
||||
/// A replacement for std::array if you haven't got C++0x11.
|
||||
//***************************************************************************
|
||||
template <typename T, size_t SIZE_>
|
||||
class array
|
||||
{
|
||||
private:
|
||||
|
||||
typedef typename etl::parameter_type<T>::type parameter_t;
|
||||
|
||||
public:
|
||||
|
||||
static ETL_CONSTANT size_t SIZE = SIZE_;
|
||||
|
||||
typedef T value_type;
|
||||
typedef size_t size_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
typedef T& reference;
|
||||
typedef const T& const_reference;
|
||||
typedef T* pointer;
|
||||
typedef const T* const_pointer;
|
||||
typedef T* iterator;
|
||||
typedef const T* const_iterator;
|
||||
typedef ETL_OR_STD::reverse_iterator<iterator> reverse_iterator;
|
||||
typedef ETL_OR_STD::reverse_iterator<const_iterator> const_reverse_iterator;
|
||||
|
||||
//*************************************************************************
|
||||
// Element access
|
||||
//*************************************************************************
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a reference to the value at index 'i'.
|
||||
///\param i The index of the element to access.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
reference at(size_t i)
|
||||
{
|
||||
ETL_ASSERT(i < SIZE, ETL_ERROR(array_out_of_range));
|
||||
|
||||
return _buffer[i];
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a const reference to the value at index 'i'.
|
||||
///\param i The index of the element to access.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
const_reference at(size_t i) const
|
||||
{
|
||||
ETL_ASSERT(i < SIZE, ETL_ERROR(array_out_of_range));
|
||||
|
||||
return _buffer[i];
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// [] operator.
|
||||
/// Returns a reference to the value at index 'i'.
|
||||
///\param i The index of the element to access.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
reference operator[](size_t i)
|
||||
{
|
||||
return _buffer[i];
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// [] operator.
|
||||
/// Returns a const reference to the value at index 'i'.
|
||||
///\param i The index of the element to access.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR const_reference operator[](size_t i) const
|
||||
{
|
||||
return _buffer[i];
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a reference to the first element.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
reference front()
|
||||
{
|
||||
return _buffer[0];
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a const reference to the first element.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR const_reference front() const
|
||||
{
|
||||
return _buffer[0];
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a reference to the last element.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
reference back()
|
||||
{
|
||||
return _buffer[SIZE - 1];
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a const reference to the last element.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR const_reference back() const
|
||||
{
|
||||
return _buffer[SIZE - 1];
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a pointer to the first element of the internal buffer.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
pointer data() ETL_NOEXCEPT
|
||||
{
|
||||
return &_buffer[0];
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a const pointer to the first element of the internal buffer.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR const_pointer data() const ETL_NOEXCEPT
|
||||
{
|
||||
return &_buffer[0];
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
// Iterators
|
||||
//*************************************************************************
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns an iterator to the beginning of the array.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
iterator begin() ETL_NOEXCEPT
|
||||
{
|
||||
return &_buffer[0];
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a const iterator to the beginning of the array.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR const_iterator begin() const ETL_NOEXCEPT
|
||||
{
|
||||
return &_buffer[0];
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a const iterator to the beginning of the array.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR const_iterator cbegin() const ETL_NOEXCEPT
|
||||
{
|
||||
return begin();
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns an iterator to the end of the array.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
iterator end() ETL_NOEXCEPT
|
||||
{
|
||||
return _buffer + SIZE;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a const iterator to the end of the array.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR const_iterator end() const ETL_NOEXCEPT
|
||||
{
|
||||
return _buffer + SIZE;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
// Returns a const iterator to the end of the array.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR const_iterator cend() const ETL_NOEXCEPT
|
||||
{
|
||||
return _buffer + SIZE;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
// Returns an reverse iterator to the reverse beginning of the array.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
reverse_iterator rbegin() ETL_NOEXCEPT
|
||||
{
|
||||
return reverse_iterator(end());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a const reverse iterator to the reverse beginning of the array.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR const_reverse_iterator rbegin() const ETL_NOEXCEPT
|
||||
{
|
||||
return const_reverse_iterator(end());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a const reverse iterator to the reverse beginning of the array.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR const_reverse_iterator crbegin() const ETL_NOEXCEPT
|
||||
{
|
||||
return const_reverse_iterator(end());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a reverse iterator to the end of the array.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
reverse_iterator rend() ETL_NOEXCEPT
|
||||
{
|
||||
return reverse_iterator(begin());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a const reverse iterator to the end of the array.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR const_reverse_iterator rend() const ETL_NOEXCEPT
|
||||
{
|
||||
return const_reverse_iterator(begin());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a const reverse iterator to the end of the array.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR const_reverse_iterator crend() const ETL_NOEXCEPT
|
||||
{
|
||||
return const_reverse_iterator(begin());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
// Capacity
|
||||
//*************************************************************************
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns <b>true</b> if the array size is zero.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR bool empty() const ETL_NOEXCEPT
|
||||
{
|
||||
return (SIZE == 0);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns the size of the array.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR size_t size() const ETL_NOEXCEPT
|
||||
{
|
||||
return SIZE;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns the maximum possible size of the array.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR size_t max_size() const ETL_NOEXCEPT
|
||||
{
|
||||
return SIZE;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
// Operations
|
||||
//*************************************************************************
|
||||
|
||||
//*************************************************************************
|
||||
/// Fills the array with the specified value.
|
||||
///\param value The value to fill the array with.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14 void fill(parameter_t value)
|
||||
{
|
||||
etl::fill(_buffer, _buffer + SIZE, value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Swaps the contents of this array and another.
|
||||
///\param other A reference to the other array.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14 void swap(array& other) ETL_NOEXCEPT
|
||||
{
|
||||
using ETL_OR_STD::swap; // Allow ADL
|
||||
|
||||
for (size_t i = 0UL; i < SIZE; ++i)
|
||||
{
|
||||
swap(_buffer[i], other._buffer[i]);
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Fills the array from the range.
|
||||
/// If the range is smaller than the array then the unused array elements are left unmodified.
|
||||
///\param first The iterator to the first item in the range.
|
||||
///\param last The iterator to one past the final item in the range.
|
||||
///\return An iterator to the first unassigned array element, or end().
|
||||
//*************************************************************************
|
||||
template <typename TIterator>
|
||||
iterator assign(TIterator first, const TIterator last)
|
||||
{
|
||||
return etl::copy_s(first, last, begin(), end());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Fills the array from the range.
|
||||
/// If the range is smaller than the array then the unused array elements are initialised with the supplied value.
|
||||
///\param first The iterator to the first item in the range.
|
||||
///\param last The iterator to one past the final item in the range.
|
||||
///\return An iterator to the first array element set to 'value', or end().
|
||||
//*************************************************************************
|
||||
template <typename TIterator>
|
||||
iterator assign(TIterator first, const TIterator last, parameter_t value)
|
||||
{
|
||||
// Copy from the range.
|
||||
iterator p = etl::copy_s(first, last, begin(), end());
|
||||
|
||||
// Initialise any that are left.
|
||||
etl::fill(p, end(), value);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Inserts a value into the array.
|
||||
///\param position The index of the position to insert at.
|
||||
///\param value The value to insert.
|
||||
//*************************************************************************
|
||||
inline iterator insert_at(size_t position, parameter_t value)
|
||||
{
|
||||
return insert(begin() + position, value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Inserts a value into the array.
|
||||
///\param position The iterator to the position to insert at.
|
||||
///\param value The value to insert.
|
||||
//*************************************************************************
|
||||
iterator insert(const_iterator position, parameter_t value)
|
||||
{
|
||||
iterator p = to_iterator(position);
|
||||
|
||||
etl::move_backward(p, end() - 1, end());
|
||||
*p = value;
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Insert into the array from the range.
|
||||
///\param position The position to insert at.
|
||||
///\param first The iterator to the first item in the range.
|
||||
///\param last The iterator to one past the final item in the range.
|
||||
//*************************************************************************
|
||||
template <typename TIterator>
|
||||
inline iterator insert_at(size_t position, TIterator first, const TIterator last)
|
||||
{
|
||||
return insert(begin() + position, first, last);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Insert into the array from the range.
|
||||
///\param position The position to insert at.
|
||||
///\param first The iterator to the first item in the range.
|
||||
///\param last The iterator to one past the final item in the range.
|
||||
//*************************************************************************
|
||||
template <typename TIterator>
|
||||
iterator insert(const_iterator position, TIterator first, const TIterator last)
|
||||
{
|
||||
iterator p = to_iterator(position);
|
||||
iterator result(p);
|
||||
|
||||
size_t source_size = etl::distance(first, last);
|
||||
size_t destination_space = etl::distance(position, cend());
|
||||
|
||||
// Do we need to move anything?
|
||||
if (source_size < destination_space)
|
||||
{
|
||||
size_t length = SIZE - (etl::distance(begin(), p) + source_size);
|
||||
etl::move_backward(p, p + length, end());
|
||||
}
|
||||
|
||||
// Copy from the range.
|
||||
etl::copy_s(first, last, p, end());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Erases a value from the array.
|
||||
/// After erase, the last value in the array will be unmodified.
|
||||
///\param position The index of the position to erase at.
|
||||
//*************************************************************************
|
||||
inline iterator erase_at(size_t position)
|
||||
{
|
||||
return erase(begin() + position);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Erases a value from the array.
|
||||
/// After erase, the last value in the array will be unmodified.
|
||||
///\param position The iterator to the position to erase at.
|
||||
//*************************************************************************
|
||||
iterator erase(const_iterator position)
|
||||
{
|
||||
iterator p = to_iterator(position);
|
||||
etl::move(p + 1, end(), p);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Erases a range of values from the array.
|
||||
/// After erase, the last values in the array will be unmodified.
|
||||
///\param first The first item to erase.
|
||||
///\param last The one past the last item to erase.
|
||||
//*************************************************************************
|
||||
iterator erase_range(size_t first, size_t last)
|
||||
{
|
||||
return erase(begin() + first, begin() + last);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Erases a range of values from the array.
|
||||
/// After erase, the last values in the array will be unmodified.
|
||||
///\param first The first item to erase.
|
||||
///\param last The one past the last item to erase.
|
||||
//*************************************************************************
|
||||
iterator erase(const_iterator first, const_iterator last)
|
||||
{
|
||||
iterator p = to_iterator(first);
|
||||
etl::move(last, cend(), p);
|
||||
return p;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Erases a value from the array.
|
||||
///\param position The index of the position to erase at.
|
||||
///\param value The value to use to overwrite the last element in the array.
|
||||
//*************************************************************************
|
||||
inline iterator erase_at(size_t position, parameter_t value)
|
||||
{
|
||||
return erase(begin() + position, value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Erases a value from the array.
|
||||
///\param position The iterator to the position to erase at.
|
||||
///\param value The value to use to overwrite the last element in the array.
|
||||
//*************************************************************************
|
||||
iterator erase(const_iterator position, parameter_t value)
|
||||
{
|
||||
iterator p = to_iterator(position);
|
||||
|
||||
etl::move(p + 1, end(), p);
|
||||
back() = value;
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Erases a range of values from the array.
|
||||
///\param first The first item to erase.
|
||||
///\param last The one past the last item to erase.
|
||||
///\param value The value to use to overwrite the last elements in the array.
|
||||
//*************************************************************************
|
||||
iterator erase_range(size_t first, size_t last, parameter_t value)
|
||||
{
|
||||
return erase(begin() + first, begin() + last, value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Erases a range of values from the array.
|
||||
///\param position The iterator to the position to erase at.
|
||||
///\param value The value to use to overwrite the last elements in the array.
|
||||
//*************************************************************************
|
||||
iterator erase(const_iterator first, const_iterator last, parameter_t value)
|
||||
{
|
||||
iterator p = to_iterator(first);
|
||||
|
||||
p = etl::move(last, cend(), p);
|
||||
etl::fill(p, end(), value);
|
||||
|
||||
return to_iterator(first);
|
||||
}
|
||||
|
||||
/// The array data.
|
||||
T _buffer[SIZE];
|
||||
|
||||
private:
|
||||
|
||||
//*************************************************************************
|
||||
/// Convert from const_iterator to iterator
|
||||
//*************************************************************************
|
||||
iterator to_iterator(const_iterator itr) const
|
||||
{
|
||||
return const_cast<iterator>(itr);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, size_t SIZE_>
|
||||
ETL_CONSTANT size_t array<T, SIZE_>::SIZE;
|
||||
|
||||
//*************************************************************************
|
||||
/// Template deduction guides.
|
||||
//*************************************************************************
|
||||
#if ETL_USING_CPP17
|
||||
template <typename... T>
|
||||
array(T...) -> array<typename etl::common_type<T...>::type, sizeof...(T)>;
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
/// Make
|
||||
//*************************************************************************
|
||||
#if ETL_HAS_INITIALIZER_LIST
|
||||
template <typename T, typename... TValues>
|
||||
constexpr auto make_array(TValues&&... values) -> etl::array<T, sizeof...(TValues)>
|
||||
{
|
||||
return { etl::forward<T>(values)... };
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
/// Overloaded swap for etl::array<T, SIZE>
|
||||
///\param lhs The first array.
|
||||
///\param rhs The second array.
|
||||
//*************************************************************************
|
||||
template <typename T, const size_t SIZE>
|
||||
void swap(etl::array<T, SIZE> &lhs, etl::array<T, SIZE> &rhs)
|
||||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Equal operator.
|
||||
///\param lhs The first array.
|
||||
///\param rhs The second array.
|
||||
///\return <b>true</b> if the arrays are equal, otherwise <b>false</b>
|
||||
//*************************************************************************
|
||||
template <typename T, size_t SIZE>
|
||||
bool operator ==(const etl::array<T, SIZE>& lhs, const etl::array<T, SIZE>& rhs)
|
||||
{
|
||||
return etl::equal(lhs.cbegin(), lhs.cend(), rhs.cbegin());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Not equal operator.
|
||||
///\param lhs The first array.
|
||||
///\param rhs The second array.
|
||||
///\return <b>true</b> if the arrays are not equal, otherwise <b>false</b>
|
||||
//*************************************************************************
|
||||
template <typename T, size_t SIZE>
|
||||
bool operator !=(const etl::array<T, SIZE>& lhs, const etl::array<T, SIZE>& rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Less than operator.
|
||||
///\param lhs The first array.
|
||||
///\param rhs The second array.
|
||||
///\return <b>true</b> if the first array is lexicographically less than the second, otherwise <b>false</b>
|
||||
//*************************************************************************
|
||||
template <typename T, size_t SIZE>
|
||||
bool operator <(const etl::array<T, SIZE>& lhs, const etl::array<T, SIZE>& rhs)
|
||||
{
|
||||
return etl::lexicographical_compare(lhs.cbegin(),
|
||||
lhs.cend(),
|
||||
rhs.cbegin(),
|
||||
rhs.cend());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Less than or equal operator.
|
||||
///\param lhs The first array.
|
||||
///\param rhs The second array.
|
||||
///\return <b>true</b> if the first array is lexicographically less than or equal to the second, otherwise <b>false</b>
|
||||
//*************************************************************************
|
||||
template <typename T, size_t SIZE>
|
||||
bool operator <=(const etl::array<T, SIZE>& lhs, const etl::array<T, SIZE>& rhs)
|
||||
{
|
||||
return !(lhs > rhs);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Greater than operator.
|
||||
///\param lhs The first array.
|
||||
///\param rhs The second array.
|
||||
///\return <b>true</b> if the first array is lexicographically greater than the second, otherwise <b>false</b>
|
||||
template <typename T, size_t SIZE>
|
||||
//*************************************************************************
|
||||
bool operator >(const etl::array<T, SIZE>& lhs, const etl::array<T, SIZE>& rhs)
|
||||
{
|
||||
return (rhs < lhs);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Greater than or equal operator.
|
||||
///\param lhs The first array.
|
||||
///\param rhs The second array.
|
||||
///\return <b>true</b> if the first array is lexicographically greater than or equal to the second, otherwise <b>false</b>
|
||||
//*************************************************************************
|
||||
template <typename T, size_t SIZE>
|
||||
bool operator >=(const etl::array<T, SIZE>& lhs, const etl::array<T, SIZE>& rhs)
|
||||
{
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Gets a reference to an element in the array.
|
||||
///\tparam I The index.
|
||||
///\tparam T The type.
|
||||
///\tparam MAXN The array size.
|
||||
///\param a The array.
|
||||
///\return A reference to the element
|
||||
//*************************************************************************
|
||||
template <size_t I, typename T, size_t MAXN>
|
||||
inline T& get(array<T, MAXN>& a)
|
||||
{
|
||||
ETL_STATIC_ASSERT(I < MAXN, "Index out of bounds");
|
||||
return a[I];
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Gets a const reference to an element in the array.
|
||||
///\tparam I The index.
|
||||
///\tparam T The type.
|
||||
///\tparam MAXN The array size.
|
||||
///\param a The array.
|
||||
///\return A const reference to the element
|
||||
//*************************************************************************
|
||||
template <size_t I, typename T, size_t MAXN>
|
||||
inline const T& get(const array<T, MAXN>& a)
|
||||
{
|
||||
ETL_STATIC_ASSERT(I < MAXN, "Index out of bounds");
|
||||
return a[I];
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
655
Chapter16/fsm/libs/etl/include/etl/array_view.h
Normal file
@@ -0,0 +1,655 @@
|
||||
///\file
|
||||
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
https://www.etlcpp.com
|
||||
|
||||
Copyright(c) 2017 John Wellbelove
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef ETL_ARRAY_VIEW_INCLUDED
|
||||
#define ETL_ARRAY_VIEW_INCLUDED
|
||||
|
||||
#include "platform.h"
|
||||
#include "memory.h"
|
||||
#include "array.h"
|
||||
#include "iterator.h"
|
||||
#include "error_handler.h"
|
||||
#include "exception.h"
|
||||
#include "nullptr.h"
|
||||
#include "hash.h"
|
||||
#include "algorithm.h"
|
||||
#include "type_traits.h"
|
||||
|
||||
#if ETL_USING_STL && ETL_USING_CPP11
|
||||
#include <array>
|
||||
#endif
|
||||
|
||||
///\defgroup array array
|
||||
/// A wrapper for arrays
|
||||
///\ingroup containers
|
||||
|
||||
namespace etl
|
||||
{
|
||||
//***************************************************************************
|
||||
/// The base class for array_view exceptions.
|
||||
//***************************************************************************
|
||||
class array_view_exception : public exception
|
||||
{
|
||||
public:
|
||||
|
||||
array_view_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
|
||||
: exception(reason_, file_name_, line_number_)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
///\ingroup stack
|
||||
/// The exception thrown when the index is out of bounds.
|
||||
//***************************************************************************
|
||||
class array_view_bounds : public array_view_exception
|
||||
{
|
||||
public:
|
||||
|
||||
array_view_bounds(string_type file_name_, numeric_type line_number_)
|
||||
: array_view_exception(ETL_ERROR_TEXT("array_view:bounds", ETL_ARRAY_VIEW_FILE_ID"A"), file_name_, line_number_)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
///\ingroup stack
|
||||
/// The exception thrown when the view is uninitialised.
|
||||
//***************************************************************************
|
||||
class array_view_uninitialised : public array_view_exception
|
||||
{
|
||||
public:
|
||||
|
||||
array_view_uninitialised(string_type file_name_, numeric_type line_number_)
|
||||
: array_view_exception(ETL_ERROR_TEXT("array_view:uninitialised", ETL_ARRAY_VIEW_FILE_ID"B"), file_name_, line_number_)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
/// Array view.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
class array_view
|
||||
{
|
||||
public:
|
||||
|
||||
typedef T value_type;
|
||||
typedef size_t size_type;
|
||||
typedef const T& const_reference;
|
||||
typedef const T* const_pointer;
|
||||
typedef const T* const_iterator;
|
||||
typedef ETL_OR_STD::reverse_iterator<const_iterator> const_reverse_iterator;
|
||||
|
||||
#if defined(ETL_ARRAY_VIEW_IS_MUTABLE)
|
||||
typedef T* pointer;
|
||||
typedef T& reference;
|
||||
typedef T* iterator;
|
||||
typedef ETL_OR_STD::reverse_iterator<iterator> reverse_iterator;
|
||||
#else
|
||||
typedef const_pointer pointer;
|
||||
typedef const_reference reference;
|
||||
typedef const_pointer iterator;
|
||||
typedef const_reverse_iterator reverse_iterator;
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
/// Default constructor.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR array_view()
|
||||
: mbegin(ETL_NULLPTR),
|
||||
mend(ETL_NULLPTR)
|
||||
{
|
||||
}
|
||||
|
||||
#if ETL_USING_CPP11
|
||||
//*************************************************************************
|
||||
/// Construct from etl::array.
|
||||
//*************************************************************************
|
||||
template <typename U, size_t N, typename = typename etl::enable_if<etl::is_same<etl::remove_cv_t<T>, etl::remove_cv_t<U>>::value, void>::type>
|
||||
ETL_CONSTEXPR array_view(etl::array<U, N>& a) ETL_NOEXCEPT
|
||||
: mbegin(a.data())
|
||||
, mend(a.data() + a.size())
|
||||
{
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Construct from etl::array.
|
||||
//*************************************************************************
|
||||
template <typename U, size_t N, typename = typename etl::enable_if<etl::is_same<etl::remove_cv_t<T>, etl::remove_cv_t<U>>::value, void>::type>
|
||||
ETL_CONSTEXPR array_view(const etl::array<U, N>& a) ETL_NOEXCEPT
|
||||
: mbegin(a.data())
|
||||
, mend(a.data() + a.size())
|
||||
{
|
||||
}
|
||||
#else
|
||||
//*************************************************************************
|
||||
/// Construct from etl::array.
|
||||
//*************************************************************************
|
||||
template <typename U, size_t N>
|
||||
ETL_CONSTEXPR array_view(etl::array<U, N>& a, typename etl::enable_if<etl::is_same<typename etl::remove_cv<T>::type, typename etl::remove_cv<U>::type>::value, void>::type* = 0) ETL_NOEXCEPT
|
||||
: mbegin(a.data())
|
||||
, mend(a.data() + a.size())
|
||||
{
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Construct from etl::array.
|
||||
//*************************************************************************
|
||||
template <typename U, size_t N>
|
||||
ETL_CONSTEXPR array_view(const etl::array<U, N>& a, typename etl::enable_if<etl::is_same<typename etl::remove_cv<T>::type, typename etl::remove_cv<U>::type>::value, void>::type* = 0) ETL_NOEXCEPT
|
||||
: mbegin(a.data())
|
||||
, mend(a.data() + a.size())
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ETL_USING_STL && ETL_USING_CPP11
|
||||
//*************************************************************************
|
||||
/// Construct from std::array.
|
||||
//*************************************************************************
|
||||
template <typename U, size_t N, typename = typename etl::enable_if<etl::is_same<etl::remove_cv_t<T>, etl::remove_cv_t<U>>::value, void>::type>
|
||||
ETL_CONSTEXPR array_view(std::array<U, N>& a) ETL_NOEXCEPT
|
||||
: mbegin(a.data())
|
||||
, mend(a.data() + a.size())
|
||||
{
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Construct from std::array.
|
||||
//*************************************************************************
|
||||
template <typename U, size_t N, typename = typename etl::enable_if<etl::is_same<etl::remove_cv_t<T>, etl::remove_cv_t<U>>::value, void>::type>
|
||||
ETL_CONSTEXPR array_view(const std::array<U, N>& a) ETL_NOEXCEPT
|
||||
: mbegin(a.data())
|
||||
, mend(a.data() + a.size())
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ETL_USING_CPP11
|
||||
//*************************************************************************
|
||||
/// Construct from a container or other type that supports
|
||||
/// data() and size() member functions.
|
||||
//*************************************************************************
|
||||
template <typename TContainer, typename = typename etl::enable_if<!etl::is_pointer<etl::remove_reference_t<TContainer>>::value &&
|
||||
!etl::is_array<etl::remove_reference_t<TContainer>>::value &&
|
||||
etl::is_same<etl::remove_cv_t<T>, etl::remove_cv_t<typename etl::remove_reference_t<TContainer>::value_type>>::value, void>::type>
|
||||
ETL_CONSTEXPR array_view(TContainer&& a) ETL_NOEXCEPT
|
||||
: mbegin(a.data())
|
||||
, mend(a.data() + a.size())
|
||||
{
|
||||
}
|
||||
#else
|
||||
//*************************************************************************
|
||||
/// Construct from a container or other type that supports
|
||||
/// data() and size() member functions.
|
||||
//*************************************************************************
|
||||
template <typename TContainer>
|
||||
ETL_CONSTEXPR array_view(TContainer& a, typename etl::enable_if<!etl::is_pointer<typename etl::remove_reference<TContainer>::type>::value &&
|
||||
!etl::is_array<TContainer>::value &&
|
||||
etl::is_same<typename etl::remove_cv<T>::type, typename etl::remove_cv<typename etl::remove_reference<TContainer>::type::value_type>::type>::value, void>::type* = 0) ETL_NOEXCEPT
|
||||
: mbegin(a.data())
|
||||
, mend(a.data() + a.size())
|
||||
{
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Construct from a container or other type that supports
|
||||
/// data() and size() member functions.
|
||||
//*************************************************************************
|
||||
template <typename TContainer>
|
||||
ETL_CONSTEXPR array_view(const TContainer& a, typename etl::enable_if<!etl::is_pointer<typename etl::remove_reference<TContainer>::type>::value &&
|
||||
!etl::is_array<TContainer>::value &&
|
||||
etl::is_same<typename etl::remove_cv<T>::type, typename etl::remove_cv<typename etl::remove_reference<TContainer>::type::value_type>::type>::value, void>::type* = 0) ETL_NOEXCEPT
|
||||
: mbegin(a.data())
|
||||
, mend(a.data() + a.size())
|
||||
{
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
/// Construct from iterators
|
||||
//*************************************************************************
|
||||
template <typename TIterator>
|
||||
ETL_CONSTEXPR array_view(const TIterator begin_, const TIterator end_)
|
||||
: mbegin(etl::addressof(*begin_)),
|
||||
mend(etl::addressof(*begin_) + etl::distance(begin_, end_))
|
||||
{
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Construct from C array
|
||||
//*************************************************************************
|
||||
template <typename TIterator,
|
||||
typename TSize>
|
||||
ETL_CONSTEXPR array_view(const TIterator begin_, const TSize size_)
|
||||
: mbegin(etl::addressof(*begin_)),
|
||||
mend(etl::addressof(*begin_) + size_)
|
||||
{
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Construct from C array
|
||||
//*************************************************************************
|
||||
template<size_t Array_Size>
|
||||
ETL_CONSTEXPR array_view(T(&begin_)[Array_Size])
|
||||
: mbegin(begin_),
|
||||
mend(begin_ + Array_Size)
|
||||
{
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Copy constructor
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR array_view(const array_view& other)
|
||||
: mbegin(other.mbegin),
|
||||
mend(other.mend)
|
||||
{
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a reference to the first element.
|
||||
//*************************************************************************
|
||||
reference front()
|
||||
{
|
||||
return *mbegin;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a const reference to the first element.
|
||||
//*************************************************************************
|
||||
const_reference front() const
|
||||
{
|
||||
return *mbegin;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a reference to the last element.
|
||||
//*************************************************************************
|
||||
reference back()
|
||||
{
|
||||
return *(mend - 1);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a const reference to the last element.
|
||||
//*************************************************************************
|
||||
const_reference back() const
|
||||
{
|
||||
return *(mend - 1);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a pointer to the first element of the internal storage.
|
||||
//*************************************************************************
|
||||
pointer data()
|
||||
{
|
||||
return mbegin;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a const pointer to the first element of the internal storage.
|
||||
//*************************************************************************
|
||||
const_pointer data() const
|
||||
{
|
||||
return mbegin;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns an iterator to the beginning of the array.
|
||||
//*************************************************************************
|
||||
iterator begin()
|
||||
{
|
||||
return mbegin;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a const iterator to the beginning of the array.
|
||||
//*************************************************************************
|
||||
const_iterator begin() const
|
||||
{
|
||||
return mbegin;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a const iterator to the beginning of the array.
|
||||
//*************************************************************************
|
||||
const_iterator cbegin() const
|
||||
{
|
||||
return mbegin;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns an iterator to the end of the array.
|
||||
//*************************************************************************
|
||||
iterator end()
|
||||
{
|
||||
return mend;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a const iterator to the end of the array.
|
||||
//*************************************************************************
|
||||
const_iterator end() const
|
||||
{
|
||||
return mend;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
// Returns a const iterator to the end of the array.
|
||||
//*************************************************************************
|
||||
const_iterator cend() const
|
||||
{
|
||||
return mend;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
// Returns an reverse iterator to the reverse beginning of the array.
|
||||
//*************************************************************************
|
||||
reverse_iterator rbegin()
|
||||
{
|
||||
return reverse_iterator(mend);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a const reverse iterator to the reverse beginning of the array.
|
||||
//*************************************************************************
|
||||
const_reverse_iterator rbegin() const
|
||||
{
|
||||
return const_reverse_iterator(mend);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a const reverse iterator to the reverse beginning of the array.
|
||||
//*************************************************************************
|
||||
const_reverse_iterator crbegin() const
|
||||
{
|
||||
return const_reverse_iterator(mend);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a reverse iterator to the end of the array.
|
||||
//*************************************************************************
|
||||
reverse_iterator rend()
|
||||
{
|
||||
return reverse_iterator(mbegin);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a const reverse iterator to the end of the array.
|
||||
//*************************************************************************
|
||||
const_reverse_iterator rend() const
|
||||
{
|
||||
return const_reverse_iterator(mbegin);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a const reverse iterator to the end of the array.
|
||||
//*************************************************************************
|
||||
const_reverse_iterator crend() const
|
||||
{
|
||||
return const_reverse_iterator(mbegin);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns <b>true</b> if the array size is zero.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR bool empty() const
|
||||
{
|
||||
return (mbegin == mend);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns the size of the array.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR size_t size() const
|
||||
{
|
||||
return static_cast<size_t>(mend - mbegin);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns the maximum possible size of the array.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR size_t max_size() const
|
||||
{
|
||||
return size();
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Assign from a view.
|
||||
//*************************************************************************
|
||||
array_view& operator=(const array_view& other)
|
||||
{
|
||||
mbegin = other.mbegin;
|
||||
mend = other.mend;
|
||||
return *this;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Assign from iterators
|
||||
//*************************************************************************
|
||||
template <typename TIterator>
|
||||
void assign(const TIterator begin_, const TIterator end_)
|
||||
{
|
||||
mbegin = etl::addressof(*begin_);
|
||||
mend = etl::addressof(*begin_) + etl::distance(begin_, end_);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Assign from iterator and size.
|
||||
//*************************************************************************
|
||||
template <typename TIterator,
|
||||
typename TSize>
|
||||
void assign(const TIterator begin_, const TSize size_)
|
||||
{
|
||||
mbegin = etl::addressof(*begin_);
|
||||
mend = etl::addressof(*begin_) + size_;
|
||||
}
|
||||
|
||||
#if defined(ETL_ARRAY_VIEW_IS_MUTABLE)
|
||||
//*************************************************************************
|
||||
/// Returns a reference to the indexed value.
|
||||
//*************************************************************************
|
||||
reference operator[](const size_t i)
|
||||
{
|
||||
return mbegin[i];
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a const reference to the indexed value.
|
||||
//*************************************************************************
|
||||
const_reference operator[](const size_t i) const
|
||||
{
|
||||
return mbegin[i];
|
||||
}
|
||||
|
||||
#if defined(ETL_ARRAY_VIEW_IS_MUTABLE)
|
||||
//*************************************************************************
|
||||
/// Returns a reference to the indexed value.
|
||||
//*************************************************************************
|
||||
reference at(const size_t i)
|
||||
{
|
||||
ETL_ASSERT((mbegin != ETL_NULLPTR && mend != ETL_NULLPTR), ETL_ERROR(array_view_uninitialised));
|
||||
ETL_ASSERT(i < size(), ETL_ERROR(array_view_bounds));
|
||||
return mbegin[i];
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a const reference to the indexed value.
|
||||
//*************************************************************************
|
||||
const_reference at(const size_t i) const
|
||||
{
|
||||
ETL_ASSERT((mbegin != ETL_NULLPTR && mend != ETL_NULLPTR), ETL_ERROR(array_view_uninitialised));
|
||||
ETL_ASSERT(i < size(), ETL_ERROR(array_view_bounds));
|
||||
return mbegin[i];
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Swaps with another array_view.
|
||||
//*************************************************************************
|
||||
void swap(array_view& other)
|
||||
{
|
||||
using ETL_OR_STD::swap; // Allow ADL
|
||||
|
||||
swap(mbegin, other.mbegin);
|
||||
swap(mend, other.mend);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Shrinks the view by moving its start forward.
|
||||
//*************************************************************************
|
||||
void remove_prefix(const size_type n)
|
||||
{
|
||||
if (n < size())
|
||||
mbegin += n;
|
||||
else
|
||||
mbegin = mend;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Shrinks the view by moving its end backward.
|
||||
//*************************************************************************
|
||||
void remove_suffix(const size_type n)
|
||||
{
|
||||
if (n < size())
|
||||
mend -= n;
|
||||
else
|
||||
mend = mbegin;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Fills the array.
|
||||
//*************************************************************************
|
||||
void fill(const T& value)
|
||||
{
|
||||
etl::fill(begin(), end(), value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Equality for array views.
|
||||
//*************************************************************************
|
||||
friend bool operator == (const array_view<T>& lhs, const array_view<T>& rhs)
|
||||
{
|
||||
return (lhs.size() == rhs.size()) &&
|
||||
etl::equal(lhs.begin(), lhs.end(), rhs.begin());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Inequality for array views.
|
||||
//*************************************************************************
|
||||
friend bool operator != (const array_view<T>& lhs, const array_view<T>& rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Less-than for array views.
|
||||
//*************************************************************************
|
||||
friend bool operator < (const array_view<T>& lhs, const array_view<T>& rhs)
|
||||
{
|
||||
return etl::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Greater-than for array views.
|
||||
//*************************************************************************
|
||||
friend bool operator > (const array_view<T>& lhs, const array_view<T>& rhs)
|
||||
{
|
||||
return rhs < lhs;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Less-than-equal for array views.
|
||||
//*************************************************************************
|
||||
friend bool operator <= (const array_view<T>& lhs, const array_view<T>& rhs)
|
||||
{
|
||||
return !(lhs > rhs);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Greater-than-equal for array views.
|
||||
//*************************************************************************
|
||||
friend bool operator >= (const array_view<T>& lhs, const array_view<T>& rhs)
|
||||
{
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
pointer mbegin;
|
||||
pointer mend;
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
/// Template deduction guides.
|
||||
//*************************************************************************
|
||||
#if ETL_USING_CPP17
|
||||
template <typename TArray>
|
||||
array_view(TArray& a)
|
||||
-> array_view<typename TArray::value_type>;
|
||||
|
||||
template <typename TIterator>
|
||||
array_view(const TIterator begin_, const TIterator end_)
|
||||
-> array_view<etl::remove_pointer_t<TIterator>>;
|
||||
|
||||
template <typename TIterator,
|
||||
typename TSize>
|
||||
array_view(const TIterator begin_, const TSize size_)
|
||||
-> array_view<etl::remove_pointer_t<TIterator>>;
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
/// Hash function.
|
||||
//*************************************************************************
|
||||
#if ETL_USING_8BIT_TYPES
|
||||
template <typename T>
|
||||
struct hash<etl::array_view<T> >
|
||||
{
|
||||
size_t operator()(const etl::array_view<T>& view) const
|
||||
{
|
||||
return etl::private_hash::generic_hash<size_t>(reinterpret_cast<const uint8_t*>(view.data()),
|
||||
reinterpret_cast<const uint8_t*>(view.data() + view.size()));
|
||||
}
|
||||
};
|
||||
#endif
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Swaps the values.
|
||||
//*************************************************************************
|
||||
template <typename T>
|
||||
void swap(etl::array_view<T>& lhs, etl::array_view<T>& rhs)
|
||||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
|
||||
#endif
|
||||
418
Chapter16/fsm/libs/etl/include/etl/array_wrapper.h
Normal file
@@ -0,0 +1,418 @@
|
||||
///\file
|
||||
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
https://www.etlcpp.com
|
||||
|
||||
Copyright(c) 2017 John Wellbelove
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef ETL_ARRAY_WRAPPER_INCLUDED
|
||||
#define ETL_ARRAY_WRAPPER_INCLUDED
|
||||
|
||||
#include "platform.h"
|
||||
#include "iterator.h"
|
||||
#include "error_handler.h"
|
||||
#include "exception.h"
|
||||
#include "hash.h"
|
||||
#include "parameter_type.h"
|
||||
#include "algorithm.h"
|
||||
|
||||
///\defgroup array array
|
||||
/// A wrapper for arrays
|
||||
///\ingroup containers
|
||||
|
||||
namespace etl
|
||||
{
|
||||
//***************************************************************************
|
||||
/// The base class for array_wrapper exceptions.
|
||||
//***************************************************************************
|
||||
class array_wrapper_exception : public exception
|
||||
{
|
||||
public:
|
||||
|
||||
array_wrapper_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
|
||||
: exception(reason_, file_name_, line_number_)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
///\ingroup stack
|
||||
/// The exception thrown when the index is out of bounds.
|
||||
//***************************************************************************
|
||||
class array_wrapper_bounds : public array_wrapper_exception
|
||||
{
|
||||
public:
|
||||
|
||||
array_wrapper_bounds(string_type file_name_, numeric_type line_number_)
|
||||
: array_wrapper_exception(ETL_ERROR_TEXT("array_wrapper:bounds", ETL_ARRAY_WRAPPER_FILE_ID"A"), file_name_, line_number_)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
/// Array wrapper.
|
||||
//***************************************************************************
|
||||
template <typename T, size_t SIZE_, T(&ARRAY_)[SIZE_]>
|
||||
class array_wrapper
|
||||
{
|
||||
public:
|
||||
|
||||
typedef T value_type;
|
||||
typedef size_t size_type;
|
||||
typedef T& reference;
|
||||
typedef const T& const_reference;
|
||||
typedef T* pointer;
|
||||
typedef const T* const_pointer;
|
||||
typedef T* iterator;
|
||||
typedef const T* const_iterator;
|
||||
typedef ETL_OR_STD::reverse_iterator<iterator> reverse_iterator;
|
||||
typedef ETL_OR_STD::reverse_iterator<const_iterator> const_reverse_iterator;
|
||||
|
||||
typedef typename etl::parameter_type<T>::type parameter_t;
|
||||
|
||||
// Indexes for positions in the array.
|
||||
enum
|
||||
{
|
||||
SIZE = SIZE_,
|
||||
MAX_SIZE = SIZE_,
|
||||
FRONT = 0,
|
||||
BACK = SIZE - 1,
|
||||
BEGIN = 0,
|
||||
END = SIZE,
|
||||
RBEGIN = SIZE - 1,
|
||||
REND = -1
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a reference to the first element.
|
||||
//*************************************************************************
|
||||
reference front()
|
||||
{
|
||||
return *&ARRAY_[FRONT];
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a const reference to the first element.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR const_reference front() const
|
||||
{
|
||||
return *&ARRAY_[FRONT];
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a reference to the last element.
|
||||
//*************************************************************************
|
||||
reference back()
|
||||
{
|
||||
return *&ARRAY_[BACK];
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a const reference to the last element.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR const_reference back() const
|
||||
{
|
||||
return *&ARRAY_[BACK];
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a pointer to the first element of the internal storage.
|
||||
//*************************************************************************
|
||||
pointer data()
|
||||
{
|
||||
return &ARRAY_[BEGIN];
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a const pointer to the first element of the internal storage.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR const_pointer data() const
|
||||
{
|
||||
return &ARRAY_[BEGIN];
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns an iterator to the beginning of the array.
|
||||
//*************************************************************************
|
||||
iterator begin()
|
||||
{
|
||||
return &ARRAY_[BEGIN];
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a const iterator to the beginning of the array.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR const_iterator begin() const
|
||||
{
|
||||
return &ARRAY_[BEGIN];
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a const iterator to the beginning of the array.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR const_iterator cbegin() const
|
||||
{
|
||||
return &ARRAY_[BEGIN];
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns an iterator to the end of the array.
|
||||
//*************************************************************************
|
||||
iterator end()
|
||||
{
|
||||
return &ARRAY_[END];
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a const iterator to the end of the array.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR const_iterator end() const
|
||||
{
|
||||
return &ARRAY_[END];
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
// Returns a const iterator to the end of the array.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR const_iterator cend() const
|
||||
{
|
||||
return &ARRAY_[END];
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
// Returns an reverse iterator to the reverse beginning of the array.
|
||||
//*************************************************************************
|
||||
reverse_iterator rbegin()
|
||||
{
|
||||
return reverse_iterator(&ARRAY_[END]);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a const reverse iterator to the reverse beginning of the array.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR const_reverse_iterator rbegin() const
|
||||
{
|
||||
return const_reverse_iterator(&ARRAY_[END]);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a const reverse iterator to the reverse beginning of the array.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR const_reverse_iterator crbegin() const
|
||||
{
|
||||
return const_reverse_iterator(&ARRAY_[END]);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a reverse iterator to the end of the array.
|
||||
//*************************************************************************
|
||||
reverse_iterator rend()
|
||||
{
|
||||
return reverse_iterator(&ARRAY_[BEGIN]);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a const reverse iterator to the end of the array.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR const_reverse_iterator rend() const
|
||||
{
|
||||
return const_reverse_iterator(&ARRAY_[BEGIN]);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a const reverse iterator to the end of the array.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR const_reverse_iterator crend() const
|
||||
{
|
||||
return const_reverse_iterator(&ARRAY_[BEGIN]);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns the size of the array.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR size_t size() const
|
||||
{
|
||||
return SIZE;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns the maximum possible size of the array.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR size_t max_size() const
|
||||
{
|
||||
return MAX_SIZE;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a reference to the indexed value.
|
||||
//*************************************************************************
|
||||
reference operator[](size_t i)
|
||||
{
|
||||
return ARRAY_[i];
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a const reference to the indexed value.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR const_reference operator[](size_t i) const
|
||||
{
|
||||
return ARRAY_[i];
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a reference to the indexed value.
|
||||
//*************************************************************************
|
||||
reference at(size_t i)
|
||||
{
|
||||
ETL_ASSERT(i < SIZE, ETL_ERROR(etl::array_wrapper_bounds));
|
||||
return ARRAY_[i];
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a const reference to the indexed value.
|
||||
//*************************************************************************
|
||||
const_reference at(size_t i) const
|
||||
{
|
||||
ETL_ASSERT(i < SIZE, ETL_ERROR(etl::array_wrapper_bounds));
|
||||
return ARRAY_[i];
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Fills the array.
|
||||
//*************************************************************************
|
||||
void fill(parameter_t value)
|
||||
{
|
||||
etl::fill(begin(), end(), value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Swaps the contents of arrays.
|
||||
//*************************************************************************
|
||||
template <typename U, U(&ARRAYOTHER)[SIZE_]>
|
||||
typename etl::enable_if<etl::is_same<T, U>::value, void>::type
|
||||
swap(etl::array_wrapper<U, SIZE_, ARRAYOTHER>& other)
|
||||
{
|
||||
using ETL_OR_STD::swap; // Allow ADL
|
||||
|
||||
for (size_t i = 0UL; i < SIZE; ++i)
|
||||
{
|
||||
swap(ARRAY_[i], other.begin()[i]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
/// Equality for array wrappers.
|
||||
//*************************************************************************
|
||||
template <typename TL, typename TR, size_t SIZEL, size_t SIZER, TL(&ARRAYL)[SIZEL], TR(&ARRAYR)[SIZER]>
|
||||
bool operator == (const etl::array_wrapper<TL, SIZEL, ARRAYL>& lhs,
|
||||
const etl::array_wrapper<TR, SIZER, ARRAYR>& rhs)
|
||||
{
|
||||
return (SIZEL == SIZER) && etl::equal(lhs.begin(), lhs.end(), rhs.begin());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Inequality for array wrapper.
|
||||
//*************************************************************************
|
||||
template <typename TL, typename TR, size_t SIZEL, size_t SIZER, TL(&ARRAYL)[SIZEL], TR(&ARRAYR)[SIZER]>
|
||||
bool operator != (const etl::array_wrapper<TL, SIZEL, ARRAYL>& lhs,
|
||||
const etl::array_wrapper<TR, SIZER, ARRAYR>& rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Less-than for array wrapper.
|
||||
//*************************************************************************
|
||||
template <typename TL, typename TR, size_t SIZEL, size_t SIZER, TL(&ARRAYL)[SIZEL], TR(&ARRAYR)[SIZER]>
|
||||
bool operator < (const etl::array_wrapper<TL, SIZEL, ARRAYL>& lhs,
|
||||
const etl::array_wrapper<TR, SIZER, ARRAYR>& rhs)
|
||||
{
|
||||
return etl::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Greater-than for array wrapper.
|
||||
//*************************************************************************
|
||||
template <typename TL, typename TR, size_t SIZEL, size_t SIZER, TL(&ARRAYL)[SIZEL], TR(&ARRAYR)[SIZER]>
|
||||
bool operator > (const etl::array_wrapper<TL, SIZEL, ARRAYL>& lhs,
|
||||
const etl::array_wrapper<TR, SIZER, ARRAYR>& rhs)
|
||||
{
|
||||
return rhs < lhs;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Less-than-equal for array wrapper.
|
||||
//*************************************************************************
|
||||
template <typename TL, typename TR, size_t SIZEL, size_t SIZER, TL(&ARRAYL)[SIZEL], TR(&ARRAYR)[SIZER]>
|
||||
bool operator <= (const etl::array_wrapper<TL, SIZEL, ARRAYL>& lhs,
|
||||
const etl::array_wrapper<TR, SIZER, ARRAYR>& rhs)
|
||||
{
|
||||
return !(lhs > rhs);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Greater-than-equal for array wrapper.
|
||||
//*************************************************************************
|
||||
template <typename TL, typename TR, size_t SIZEL, size_t SIZER, TL(&ARRAYL)[SIZEL], TR(&ARRAYR)[SIZER]>
|
||||
bool operator >= (const etl::array_wrapper<TL, SIZEL, ARRAYL>& lhs,
|
||||
const etl::array_wrapper<TR, SIZER, ARRAYR>& rhs)
|
||||
{
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Hash function.
|
||||
//*************************************************************************
|
||||
#if ETL_USING_8BIT_TYPES
|
||||
template <typename T, size_t SIZE, T(&ARRAY)[SIZE]>
|
||||
struct hash<etl::array_wrapper<T, SIZE, ARRAY> >
|
||||
{
|
||||
size_t operator()(const etl::array_wrapper<T, SIZE, ARRAY>& aw) const
|
||||
{
|
||||
const uint8_t* pb = reinterpret_cast<const uint8_t*>(aw.data());
|
||||
const uint8_t* pe = pb + (SIZE * sizeof(T));
|
||||
|
||||
return etl::private_hash::generic_hash<size_t>(pb, pe);
|
||||
}
|
||||
};
|
||||
#endif
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Swap.
|
||||
//*************************************************************************
|
||||
template <typename T, size_t SIZE, T(&ARRAYL)[SIZE], T(&ARRAYR)[SIZE]>
|
||||
void swap(etl::array_wrapper<T, SIZE, ARRAYL>& lhs,
|
||||
etl::array_wrapper<T, SIZE, ARRAYR>& rhs)
|
||||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
|
||||
#define ETL_ARRAY_WRAPPER(arraytype, arrayobject) etl::array_wrapper<arraytype, ETL_ARRAY_SIZE(arrayobject), arrayobject>
|
||||
|
||||
#endif
|
||||
|
||||
48
Chapter16/fsm/libs/etl/include/etl/atomic.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
https://www.etlcpp.com
|
||||
|
||||
Copyright(c) 2017 John Wellbelove
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef ETL_ATOMIC_INCLUDED
|
||||
#define ETL_ATOMIC_INCLUDED
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#if ETL_HAS_ATOMIC
|
||||
#if (ETL_USING_CPP11 && (ETL_USING_STL || defined(ETL_IN_UNIT_TEST)))
|
||||
#include "atomic/atomic_std.h"
|
||||
#elif defined(ETL_COMPILER_ARM5)
|
||||
#include "atomic/atomic_arm.h"
|
||||
#elif defined(ETL_COMPILER_ARM6)
|
||||
#include "atomic/atomic_arm.h"
|
||||
#elif defined(ETL_COMPILER_GCC)
|
||||
#include "atomic/atomic_gcc_sync.h"
|
||||
#elif defined(ETL_COMPILER_CLANG)
|
||||
#include "atomic/atomic_clang_sync.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif
|
||||
34
Chapter16/fsm/libs/etl/include/etl/atomic/atomic_arm.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
https://www.etlcpp.com
|
||||
|
||||
Copyright(c) 2017 John Wellbelove
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef ETL_ATOMIC_ARM_INCLUDED
|
||||
#define ETL_ATOMIC_ARM_INCLUDED
|
||||
|
||||
#include "atomic_gcc_sync.h"
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,34 @@
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
https://www.etlcpp.com
|
||||
|
||||
Copyright(c) 2017 John Wellbelove
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef ETL_ATOMIC_CLANG_INCLUDED
|
||||
#define ETL_ATOMIC_CLANG_INCLUDED
|
||||
|
||||
#include "atomic_gcc_sync.h"
|
||||
|
||||
#endif
|
||||
2236
Chapter16/fsm/libs/etl/include/etl/atomic/atomic_gcc_sync.h
Normal file
120
Chapter16/fsm/libs/etl/include/etl/atomic/atomic_std.h
Normal file
@@ -0,0 +1,120 @@
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
https://www.etlcpp.com
|
||||
|
||||
Copyright(c) 2018 John Wellbelove
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef ETL_ATOMIC_STD_INCLUDED
|
||||
#define ETL_ATOMIC_STD_INCLUDED
|
||||
|
||||
#include "../platform.h"
|
||||
#include "../nullptr.h"
|
||||
#include "../char_traits.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace etl
|
||||
{
|
||||
//***************************************************************************
|
||||
// ETL Atomic type for compilers that support std::atomic.
|
||||
// etl::atomic is a simple wrapper around std::atomic.
|
||||
//***************************************************************************
|
||||
|
||||
template <typename T>
|
||||
using atomic = std::atomic<T>;
|
||||
|
||||
using memory_order = std::memory_order;
|
||||
|
||||
static ETL_CONSTANT etl::memory_order memory_order_relaxed = std::memory_order_relaxed;
|
||||
static ETL_CONSTANT etl::memory_order memory_order_consume = std::memory_order_consume;
|
||||
static ETL_CONSTANT etl::memory_order memory_order_acquire = std::memory_order_acquire;
|
||||
static ETL_CONSTANT etl::memory_order memory_order_release = std::memory_order_release;
|
||||
static ETL_CONSTANT etl::memory_order memory_order_acq_rel = std::memory_order_acq_rel;
|
||||
static ETL_CONSTANT etl::memory_order memory_order_seq_cst = std::memory_order_seq_cst;
|
||||
|
||||
using atomic_bool = std::atomic<bool>;
|
||||
using atomic_char = std::atomic<char>;
|
||||
using atomic_schar = std::atomic<signed char>;
|
||||
using atomic_uchar = std::atomic<unsigned char>;
|
||||
using atomic_short = std::atomic<short>;
|
||||
using atomic_ushort = std::atomic<unsigned short>;
|
||||
using atomic_int = std::atomic<int>;
|
||||
using atomic_uint = std::atomic<unsigned int>;
|
||||
using atomic_long = std::atomic<long>;
|
||||
using atomic_ulong = std::atomic<unsigned long>;
|
||||
using atomic_llong = std::atomic<long long>;
|
||||
using atomic_ullong = std::atomic<unsigned long long>;
|
||||
using atomic_wchar_t = std::atomic<wchar_t>;
|
||||
#if ETL_HAS_NATIVE_CHAR8_T
|
||||
using atomic_char8_t = std::atomic<char8_t>;
|
||||
#endif
|
||||
#if ETL_HAS_NATIVE_CHAR16_T
|
||||
using atomic_char16_t = std::atomic<char16_t>;
|
||||
#endif
|
||||
#if ETL_HAS_NATIVE_CHAR32_T
|
||||
using atomic_char32_t = std::atomic<char32_t>;
|
||||
#endif
|
||||
#if ETL_USING_8BIT_TYPES
|
||||
using atomic_uint8_t = std::atomic<uint8_t>;
|
||||
using atomic_int8_t = std::atomic<int8_t>;
|
||||
#endif
|
||||
using atomic_uint16_t = std::atomic<uint16_t>;
|
||||
using atomic_int16_t = std::atomic<int16_t>;
|
||||
using atomic_uint32_t = std::atomic<uint32_t>;
|
||||
using atomic_int32_t = std::atomic<int32_t>;
|
||||
#if ETL_USING_64BIT_TYPES
|
||||
using atomic_uint64_t = std::atomic<uint64_t>;
|
||||
using atomic_int64_t = std::atomic<int64_t>;
|
||||
#endif
|
||||
using atomic_int_least8_t = std::atomic<int_least8_t>;
|
||||
using atomic_uint_least8_t = std::atomic<uint_least8_t>;
|
||||
using atomic_int_least16_t = std::atomic<int_least16_t>;
|
||||
using atomic_uint_least16_t = std::atomic<uint_least16_t>;
|
||||
using atomic_int_least32_t = std::atomic<int_least32_t>;
|
||||
using atomic_uint_least32_t = std::atomic<uint_least32_t>;
|
||||
#if ETL_USING_64BIT_TYPES
|
||||
using atomic_int_least64_t = std::atomic<int_least64_t>;
|
||||
using atomic_uint_least64_t = std::atomic<uint_least64_t>;
|
||||
#endif
|
||||
using atomic_int_fast8_t = std::atomic<int_fast8_t>;
|
||||
using atomic_uint_fast8_t = std::atomic<uint_fast8_t>;
|
||||
using atomic_int_fast16_t = std::atomic<int_fast16_t>;
|
||||
using atomic_uint_fast16_t = std::atomic<uint_fast16_t>;
|
||||
using atomic_int_fast32_t = std::atomic<int_fast32_t>;
|
||||
using atomic_uint_fast32_t = std::atomic<uint_fast32_t>;
|
||||
#if ETL_USING_64BIT_TYPES
|
||||
using atomic_int_fast64_t = std::atomic<int_fast64_t>;
|
||||
using atomic_uint_fast64_t = std::atomic<uint_fast64_t>;
|
||||
#endif
|
||||
using atomic_intptr_t = std::atomic<intptr_t>;
|
||||
using atomic_uintptr_t = std::atomic<uintptr_t>;
|
||||
using atomic_size_t = std::atomic<size_t>;
|
||||
using atomic_ptrdiff_t = std::atomic<ptrdiff_t>;
|
||||
using atomic_intmax_t = std::atomic<intmax_t>;
|
||||
using atomic_uintmax_t = std::atomic<uintmax_t>;
|
||||
}
|
||||
|
||||
#endif
|
||||
218
Chapter16/fsm/libs/etl/include/etl/base64.h
Normal file
@@ -0,0 +1,218 @@
|
||||
///\file
|
||||
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
Embedded Template Library.
|
||||
https://github.com/ETLCPP/etl
|
||||
https://www.etlcpp.com
|
||||
Copyright(c) 2024 John Wellbelove
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions :
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef ETL_BASE64_INCLUDED
|
||||
#define ETL_BASE64_INCLUDED
|
||||
|
||||
#include "platform.h"
|
||||
#include "static_assert.h"
|
||||
#include "exception.h"
|
||||
#include "error_handler.h"
|
||||
#include "type_traits.h"
|
||||
#include "enum_type.h"
|
||||
#include "integral_limits.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/**************************************************************************************************************************************************************************
|
||||
* See https://en.wikipedia.org/wiki/Base64
|
||||
*
|
||||
* Encoding Encoding characters Separate encoding of lines Decoding non-encoding characters
|
||||
* 62nd 63rd Pad Separators Length Checksum
|
||||
* RFC 1421 : Base64 for Privacy - Enhanced Mail(deprecated) + / = mandatory CR + LF 64, or lower for the last line No No
|
||||
* RFC 2045 : Base64 transfer encoding for MIME + / = mandatory CR + LF At most 76 No Discarded
|
||||
* RFC 2152 : Base64 for UTF - 7 + / No No No
|
||||
* RFC 3501 : Base64 encoding for IMAP mailbox names + , No No No
|
||||
* RFC 4648 : base64(standard)[a] + / = optional No No
|
||||
* RFC 4648 : base64url(URL - and filename - safe standard) - _ = optional No No
|
||||
**************************************************************************************************************************************************************************/
|
||||
|
||||
namespace etl
|
||||
{
|
||||
//***************************************************************************
|
||||
/// Exception base for base64
|
||||
//***************************************************************************
|
||||
class base64_exception : public etl::exception
|
||||
{
|
||||
public:
|
||||
|
||||
base64_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
|
||||
: exception(reason_, file_name_, line_number_)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
/// buffer overflow exception.
|
||||
//***************************************************************************
|
||||
class base64_overflow : public base64_exception
|
||||
{
|
||||
public:
|
||||
|
||||
base64_overflow(string_type file_name_, numeric_type line_number_)
|
||||
: base64_exception(ETL_ERROR_TEXT("base64:overflow", ETL_BASE64_FILE_ID"A"), file_name_, line_number_)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
/// Illegal character exception.
|
||||
//***************************************************************************
|
||||
class base64_invalid_data : public base64_exception
|
||||
{
|
||||
public:
|
||||
|
||||
base64_invalid_data(string_type file_name_, numeric_type line_number_)
|
||||
: base64_exception(ETL_ERROR_TEXT("base64:invalid data", ETL_BASE64_FILE_ID"B"), file_name_, line_number_)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
/// Invalid decode input length exception.
|
||||
//***************************************************************************
|
||||
class base64_invalid_decode_input_length : public base64_exception
|
||||
{
|
||||
public:
|
||||
|
||||
base64_invalid_decode_input_length(string_type file_name_, numeric_type line_number_)
|
||||
: base64_exception(ETL_ERROR_TEXT("base64:invalid decode input length", ETL_BASE64_FILE_ID"C"), file_name_, line_number_)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
/// Common Base64 definitions
|
||||
//***************************************************************************
|
||||
class base64
|
||||
{
|
||||
public:
|
||||
|
||||
struct Encoding
|
||||
{
|
||||
enum enum_type
|
||||
{
|
||||
//RFC_1421, // Not implemented
|
||||
//RFC_2045, // Not implemented
|
||||
RFC_2152,
|
||||
RFC_3501,
|
||||
RFC_4648,
|
||||
RFC_4648_PADDING,
|
||||
RFC_4648_URL,
|
||||
RFC_4648_URL_PADDING,
|
||||
};
|
||||
|
||||
ETL_DECLARE_ENUM_TYPE(Encoding, int)
|
||||
//ETL_ENUM_TYPE(RFC_1421, "RFC_1421") // Not implemented
|
||||
//ETL_ENUM_TYPE(RFC_2045, "RFC_2045") // Not implemented
|
||||
ETL_ENUM_TYPE(RFC_2152, "RFC_2152")
|
||||
ETL_ENUM_TYPE(RFC_3501, "RFC_3501")
|
||||
ETL_ENUM_TYPE(RFC_4648, "RFC_4648")
|
||||
ETL_ENUM_TYPE(RFC_4648_PADDING, "RFC_4648_PADDING")
|
||||
ETL_ENUM_TYPE(RFC_4648_URL, "RFC_4648_URL")
|
||||
ETL_ENUM_TYPE(RFC_4648_URL_PADDING, "RFC_4648_URL_PADDING")
|
||||
ETL_END_ENUM_TYPE
|
||||
};
|
||||
|
||||
struct Padding
|
||||
{
|
||||
enum enum_type
|
||||
{
|
||||
No_Padding = 0,
|
||||
Use_Padding = 1
|
||||
};
|
||||
|
||||
ETL_DECLARE_ENUM_TYPE(Padding, bool)
|
||||
ETL_ENUM_TYPE(No_Padding, "No_Padding")
|
||||
ETL_ENUM_TYPE(Use_Padding, "Use_Padding")
|
||||
ETL_END_ENUM_TYPE
|
||||
};
|
||||
|
||||
struct Non_Coding_Characters
|
||||
{
|
||||
enum enum_type
|
||||
{
|
||||
Ignore = 0,
|
||||
Reject = 1
|
||||
};
|
||||
|
||||
ETL_DECLARE_ENUM_TYPE(Non_Coding_Characters, bool)
|
||||
ETL_ENUM_TYPE(Ignore, "Ignore")
|
||||
ETL_ENUM_TYPE(Reject, "Reject")
|
||||
ETL_END_ENUM_TYPE
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
Invalid_Data = etl::integral_limits<int>::max,
|
||||
Min_Encode_Buffer_Size = 4,
|
||||
Min_Decode_Buffer_Size = 3
|
||||
};
|
||||
|
||||
protected:
|
||||
|
||||
ETL_CONSTEXPR14
|
||||
base64(const char* encoder_table_,
|
||||
bool use_padding_)
|
||||
: encoder_table(encoder_table_)
|
||||
, use_padding(use_padding_)
|
||||
{
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
// Character set for RFC-1421, RFC-2045, RFC-2152 and RFC-4648
|
||||
//*************************************************************************
|
||||
static
|
||||
ETL_CONSTEXPR14
|
||||
const char* character_set_1()
|
||||
{
|
||||
return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
// Character set for RFC-4648-URL
|
||||
//*************************************************************************
|
||||
static
|
||||
ETL_CONSTEXPR14
|
||||
const char* character_set_2()
|
||||
{
|
||||
return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
// Character set for RFC-3501-URL
|
||||
//*************************************************************************
|
||||
static
|
||||
ETL_CONSTEXPR14
|
||||
const char* character_set_3()
|
||||
{
|
||||
return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,";
|
||||
}
|
||||
|
||||
const char* encoder_table;
|
||||
const bool use_padding;
|
||||
};
|
||||
}
|
||||
#endif
|
||||