mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
Merge branch 'development' into delegate-from-non-capturing-lambda
# Conflicts: # include/etl/private/delegate_cpp11.h # test/test_delegate.cpp
This commit is contained in:
commit
e61589ebf2
211
.clang-format
211
.clang-format
@ -1,57 +1,184 @@
|
||||
---
|
||||
#------------------------------------
|
||||
# Configuration for clang-format v12
|
||||
#------------------------------------
|
||||
BasedOnStyle: LLVM
|
||||
Standard: Auto # let the formatter accept any C++ standard
|
||||
|
||||
Language: Cpp
|
||||
# =============================================================================
|
||||
# Indentation
|
||||
# =============================================================================
|
||||
TabWidth: 2
|
||||
ContinuationIndentWidth: 2
|
||||
ConstructorInitializerIndentWidth: 2
|
||||
NamespaceIndentation: All # everything inside namespace is indented
|
||||
IndentCaseLabels: true # case labels at switch-body indent level
|
||||
IndentCaseBlocks: true # indent block inside case label
|
||||
IndentExternBlock: Indent
|
||||
IndentWrappedFunctionNames: true # keep function name at same indent as return type
|
||||
IndentPPDirectives: BeforeHash # nested #if / #include get indented before the #
|
||||
PPIndentWidth: 2
|
||||
|
||||
BasedOnStyle: Chromium
|
||||
# =============================================================================
|
||||
# Braces & line-break style
|
||||
# =============================================================================
|
||||
BreakBeforeBraces: Allman
|
||||
BreakConstructorInitializers: BeforeComma # colon on new line, commas lead
|
||||
BreakInheritanceList: BeforeComma
|
||||
BreakBeforeBinaryOperators: NonAssignment
|
||||
BreakStringLiterals: false
|
||||
AlwaysBreakTemplateDeclarations: Yes # template <…> always on its own line
|
||||
BreakAfterAttributes: Always
|
||||
|
||||
SortIncludes: true
|
||||
IncludeBlocks: Preserve
|
||||
# =============================================================================
|
||||
# Short statements
|
||||
# =============================================================================
|
||||
AllowShortBlocksOnASingleLine: Empty
|
||||
AllowShortFunctionsOnASingleLine: Empty # only empty bodies: void f() {}
|
||||
AllowShortCaseLabelsOnASingleLine: true # case X: stmt; break; on one line
|
||||
AllowShortLoopsOnASingleLine: true
|
||||
AllowShortLambdasOnASingleLine: Inline
|
||||
|
||||
# =============================================================================
|
||||
# Empty lines
|
||||
# =============================================================================
|
||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||
EmptyLineBeforeAccessModifier: Always # blank line before public:/private:/protected:
|
||||
EmptyLineAfterAccessModifier: Always # blank line after public:/private:/protected:
|
||||
InsertNewlineAtEOF: true
|
||||
|
||||
# =============================================================================
|
||||
# Spacing
|
||||
# =============================================================================
|
||||
SpacesInAngles: Leave # preserve C++03 "> >" vs C++11 ">>"
|
||||
SpacesInContainerLiterals: false
|
||||
|
||||
# =============================================================================
|
||||
# Alignment
|
||||
# =============================================================================
|
||||
PointerAlignment: Left # T* ptr, const T& ref
|
||||
ReferenceAlignment: Left
|
||||
AlignConsecutiveAssignments: true
|
||||
AlignConsecutiveDeclarations: true
|
||||
AlignConsecutiveBitFields: true
|
||||
AlignConsecutiveMacros: true # align macro bodies
|
||||
|
||||
# =============================================================================
|
||||
# Line length and wrapping
|
||||
# =============================================================================
|
||||
ColumnLimit: 150
|
||||
ReflowComments: true # preserve hand-formatted comment rulers
|
||||
AlignEscapedNewlines: Left
|
||||
|
||||
# =============================================================================
|
||||
# Includes
|
||||
# =============================================================================
|
||||
IncludeCategories:
|
||||
- Regex: '^(<|")(.*/)?platform\.h(>|")$'
|
||||
Priority: -1
|
||||
- Regex: 'private'
|
||||
Priority: 1
|
||||
- Regex: '.*'
|
||||
Priority: 2
|
||||
Priority: 0
|
||||
|
||||
BinPackParameters: false
|
||||
BitFieldColonSpacing: Both
|
||||
# =============================================================================
|
||||
# Arguments, parameters and constructor initialisers
|
||||
# =============================================================================
|
||||
PackConstructorInitializers: Never # each initialiser on its own line
|
||||
|
||||
BreakBeforeBraces: Allman
|
||||
BreakConstructorInitializers: BeforeComma
|
||||
# =============================================================================
|
||||
# Namespaces and using declarations
|
||||
# =============================================================================
|
||||
SortUsingDeclarations: Lexicographic
|
||||
|
||||
AllowShortBlocksOnASingleLine: false
|
||||
AllowShortCaseLabelsOnASingleLine: true
|
||||
AllowShortFunctionsOnASingleLine: None
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
# =============================================================================
|
||||
# Macro-aware formatting
|
||||
# =============================================================================
|
||||
# ETL-specific macros that should be treated as statement-level constructs
|
||||
StatementMacros:
|
||||
- ETL_DECLARE_DEBUG_COUNT
|
||||
- ETL_INCREMENT_DEBUG_COUNT
|
||||
- ETL_DECREMENT_DEBUG_COUNT
|
||||
- ETL_ADD_DEBUG_COUNT
|
||||
- ETL_STATIC_ASSERT
|
||||
- ETL_ASSERT
|
||||
- ETL_ASSERT_OR_RETURN
|
||||
- ETL_ASSERT_OR_RETURN_VALUE
|
||||
- ETL_ASSERT_FAIL
|
||||
- ETL_ASSERT_FAIL_AND_RETURN
|
||||
- ETL_ASSERT_FAIL_AND_RETURN_VALUE
|
||||
- ETL_MOVE
|
||||
- ETL_ENUM_CLASS
|
||||
- ETL_ENUM_CLASS_TYPE
|
||||
- ETL_IF_CONSTEXPR
|
||||
|
||||
AllowAllArgumentsOnNextLine: true
|
||||
AllowAllParametersOfDeclarationOnNextLine: true
|
||||
# Macros that behave like attributes or specifiers.
|
||||
AttributeMacros:
|
||||
- ETL_NORETURN
|
||||
- ETL_FINAL
|
||||
- ETL_OVERRIDE
|
||||
- ETL_EXPLICIT
|
||||
- ETL_DELETE
|
||||
- ETL_CONSTANT
|
||||
- ETL_CONSTEXPR
|
||||
- ETL_CONSTEXPR11
|
||||
- ETL_CONSTEXPR14
|
||||
- ETL_CONSTEXPR17
|
||||
- ETL_CONSTEXPR20
|
||||
- ETL_CONSTEXPR23
|
||||
- ETL_CONSTEVAL
|
||||
- ETL_NODISCARD
|
||||
- ETL_NORETURN
|
||||
- ETL_DEPRECATED
|
||||
- ETL_DEPRECATED_REASON
|
||||
- ETL_LIKELY
|
||||
- ETL_UNLIKELY
|
||||
- ETL_FALLTHROUGH
|
||||
- ETL_MAYBE_UNUSED
|
||||
- ETL_INLINE_VAR
|
||||
- ETL_ASSUME
|
||||
- ETL_LVALUE_REF_QUALIFIER
|
||||
- ETL_RVALUE_REF_QUALIFIER
|
||||
- ETL_NOEXCEPT
|
||||
- ETL_NOEXCEPT_EXPR
|
||||
- ETL_NOEXCEPT_IF
|
||||
- ETL_NOEXCEPT_FROM
|
||||
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: 'true'
|
||||
ConstructorInitializerIndentWidth: '2'
|
||||
Macros:
|
||||
- ETL_NORETURN=[[noreturn]]
|
||||
- ETL_FINAL=final
|
||||
- ETL_OVERRIDE=override
|
||||
- ETL_EXPLICIT=explicit
|
||||
- ETL_DELETE=delete
|
||||
- ETL_CONSTANT=const
|
||||
- ETL_CONSTEXPR=constexpr
|
||||
- ETL_CONSTEXPR11=constexpr
|
||||
- ETL_CONSTEXPR14=constexpr
|
||||
- ETL_CONSTEXPR17=constexpr
|
||||
- ETL_CONSTEXPR20=constexpr
|
||||
- ETL_CONSTEXPR23=constexpr
|
||||
- ETL_CONSTEVAL=consteval
|
||||
- ETL_NODISCARD=[[nodiscard]]
|
||||
- ETL_NORETURN=[[noreturn]]
|
||||
- ETL_DEPRECATED=[[deprecated]]
|
||||
# - ETL_DEPRECATED_REASON=[[deprecated(%0)]] # Hangs with clang-format 18
|
||||
- ETL_LIKELY=[[likely]]
|
||||
- ETL_UNLIKELY=[[unlikely]]
|
||||
- ETL_FALLTHROUGH=[[fallthrough]]
|
||||
- ETL_MAYBE_UNUSED=[[maybe_unused]]
|
||||
- ETL_INLINE_VAR=inline
|
||||
- ETL_ASSUME=[[assume(&0)]]
|
||||
- ETL_LVALUE_REF_QUALIFIER=&
|
||||
- ETL_RVALUE_REF_QUALIFIER=&&
|
||||
- ETL_NOEXCEPT=noexcept
|
||||
# - ETL_NOEXCEPT_EXPR=noexcept(&0)) # Hangs with clang-format 18
|
||||
# - ETL_NOEXCEPT_IF=noexcept(&0) # Hangs with clang-format 18
|
||||
# - ETL_NOEXCEPT_FROM=noexcept(&0) # Hangs with clang-format 18
|
||||
|
||||
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
|
||||
# Macros that behave like type names
|
||||
TypenameMacros:
|
||||
- ETL_OR_STD
|
||||
|
||||
#------------------------------------
|
||||
# Configurations not supported by clang-format v12
|
||||
#------------------------------------
|
||||
# BreakInheritanceList: AfterComma
|
||||
# EmptyLineBeforeAccessModifier: Always
|
||||
# EmptyLineAfterAccessModifier: Always
|
||||
# ReferenceAlignment: Left
|
||||
|
||||
...
|
||||
# Do not reformat these macros — they contain DSL-like content
|
||||
WhitespaceSensitiveMacros:
|
||||
- ETL_ERROR_TEXT
|
||||
- ETL_DECLARE_ENUM_TYPE
|
||||
- ETL_ENUM_TYPE
|
||||
- ETL_END_ENUM_TYPE
|
||||
|
||||
@ -1,20 +1,61 @@
|
||||
ARG BASE_IMAGE_NAME="clang:latest"
|
||||
ARG BASE_IMAGE_NAME="mcr.microsoft.com/devcontainers/cpp:2@sha256:a5eb5a1e9109af88bf82ebb0f71903608a68144851ed1e4b852e31b251ac59c6"
|
||||
|
||||
FROM ${BASE_IMAGE_NAME}
|
||||
|
||||
ARG REINSTALL_CMAKE_VERSION_FROM_SOURCE="3.31.7"
|
||||
ARG DEBIAN_SNAPSHOT="20260223T000000Z"
|
||||
|
||||
# Optionally install the cmake for vcpkg
|
||||
COPY ./reinstall-cmake.sh /tmp/
|
||||
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
|
||||
|
||||
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
|
||||
ENV LANG=C.UTF-8 \
|
||||
LC_ALL=C.UTF-8 \
|
||||
TZ=UTC
|
||||
|
||||
RUN set -eux \
|
||||
&& export DEBIAN_FRONTEND=noninteractive \
|
||||
&& if [[ "${DEBIAN_SNAPSHOT}" != "none" ]]; then \
|
||||
snapshot_main="http://snapshot.debian.org/archive/debian/${DEBIAN_SNAPSHOT}"; \
|
||||
snapshot_security="http://snapshot.debian.org/archive/debian-security/${DEBIAN_SNAPSHOT}"; \
|
||||
if [[ -f /etc/apt/sources.list.d/debian.sources ]]; then \
|
||||
sed -ri "s|^URIs: https?://deb.debian.org/debian$|URIs: ${snapshot_main}|g" /etc/apt/sources.list.d/debian.sources; \
|
||||
sed -ri "s|^URIs: https?://deb.debian.org/debian-security$|URIs: ${snapshot_security}|g" /etc/apt/sources.list.d/debian.sources; \
|
||||
elif [[ -f /etc/apt/sources.list ]] || compgen -G "/etc/apt/sources.list.d/*.list" > /dev/null; then \
|
||||
for list_file in /etc/apt/sources.list /etc/apt/sources.list.d/*.list; do \
|
||||
[[ -f "${list_file}" ]] || continue; \
|
||||
sed -ri "s|https?://deb.debian.org/debian|${snapshot_main}|g" "${list_file}"; \
|
||||
sed -ri "s|https?://security.debian.org/debian-security|${snapshot_security}|g" "${list_file}"; \
|
||||
sed -ri "s|https?://deb.debian.org/debian-security|${snapshot_security}|g" "${list_file}"; \
|
||||
done; \
|
||||
else \
|
||||
echo "ERROR: DEBIAN_SNAPSHOT='${DEBIAN_SNAPSHOT}' is set, but no supported apt source files were found."; \
|
||||
echo "Expected /etc/apt/sources.list.d/debian.sources or one or more .list files under /etc/apt/."; \
|
||||
exit 1; \
|
||||
fi; \
|
||||
printf 'Acquire::Check-Valid-Until "false";\n' > /etc/apt/apt.conf.d/99snapshot; \
|
||||
fi \
|
||||
&& apt-get update \
|
||||
&& apt-get -y install --no-install-recommends \
|
||||
python3-full \
|
||||
python3-pip \
|
||||
git \
|
||||
wget \
|
||||
python3-cogapp \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
cmake \
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
&& if pip help install | grep -q '\-\-break-system-packages'; then \
|
||||
pip install --no-cache-dir --break-system-packages cogapp; \
|
||||
else \
|
||||
pip install --no-cache-dir cogapp; \
|
||||
fi
|
||||
|
||||
RUN if [ "${REINSTALL_CMAKE_VERSION_FROM_SOURCE}" != "none" ]; then \
|
||||
chmod +x /tmp/reinstall-cmake.sh && /tmp/reinstall-cmake.sh ${REINSTALL_CMAKE_VERSION_FROM_SOURCE}; \
|
||||
fi \
|
||||
&& rm -f /tmp/reinstall-cmake.sh
|
||||
RUN set -eux \
|
||||
&& echo "Pip version: " \
|
||||
&& pip --version \
|
||||
&& echo "Cogapp version: " \
|
||||
&& pip show cogapp \
|
||||
&& echo "Git version: " \
|
||||
&& git --version \
|
||||
&& echo "Wget version: " \
|
||||
&& wget --version \
|
||||
&& echo "Cmake version: " \
|
||||
&& cmake --version \
|
||||
&& echo "Make version: " \
|
||||
&& make --version
|
||||
|
||||
@ -5,7 +5,8 @@
|
||||
"build": {
|
||||
"dockerfile": "../Dockerfile",
|
||||
"args": {
|
||||
"BASE_IMAGE_NAME": "silkeh/clang:10"
|
||||
"BASE_IMAGE_NAME": "silkeh/clang:10",
|
||||
"DEBIAN_SNAPSHOT": "none"
|
||||
},
|
||||
"context": "../context"
|
||||
}
|
||||
|
||||
@ -5,7 +5,8 @@
|
||||
"build": {
|
||||
"dockerfile": "../Dockerfile",
|
||||
"args": {
|
||||
"BASE_IMAGE_NAME": "silkeh/clang:11"
|
||||
"BASE_IMAGE_NAME": "silkeh/clang:11",
|
||||
"DEBIAN_SNAPSHOT": "none"
|
||||
},
|
||||
"context": "../context"
|
||||
}
|
||||
|
||||
@ -5,7 +5,8 @@
|
||||
"build": {
|
||||
"dockerfile": "../Dockerfile",
|
||||
"args": {
|
||||
"BASE_IMAGE_NAME": "silkeh/clang:12"
|
||||
"BASE_IMAGE_NAME": "silkeh/clang:12",
|
||||
"DEBIAN_SNAPSHOT": "none"
|
||||
},
|
||||
"context": "../context"
|
||||
}
|
||||
|
||||
@ -5,7 +5,8 @@
|
||||
"build": {
|
||||
"dockerfile": "../Dockerfile",
|
||||
"args": {
|
||||
"BASE_IMAGE_NAME": "silkeh/clang:13"
|
||||
"BASE_IMAGE_NAME": "silkeh/clang:13",
|
||||
"DEBIAN_SNAPSHOT": "none"
|
||||
},
|
||||
"context": "../context"
|
||||
}
|
||||
|
||||
@ -5,7 +5,8 @@
|
||||
"build": {
|
||||
"dockerfile": "../Dockerfile",
|
||||
"args": {
|
||||
"BASE_IMAGE_NAME": "silkeh/clang:14"
|
||||
"BASE_IMAGE_NAME": "silkeh/clang:14",
|
||||
"DEBIAN_SNAPSHOT": "none"
|
||||
},
|
||||
"context": "../context"
|
||||
}
|
||||
|
||||
@ -5,7 +5,8 @@
|
||||
"build": {
|
||||
"dockerfile": "../Dockerfile",
|
||||
"args": {
|
||||
"BASE_IMAGE_NAME": "silkeh/clang:15"
|
||||
"BASE_IMAGE_NAME": "silkeh/clang:15",
|
||||
"DEBIAN_SNAPSHOT": "none"
|
||||
},
|
||||
"context": "../context"
|
||||
}
|
||||
|
||||
@ -5,7 +5,8 @@
|
||||
"build": {
|
||||
"dockerfile": "../Dockerfile",
|
||||
"args": {
|
||||
"BASE_IMAGE_NAME": "silkeh/clang:16"
|
||||
"BASE_IMAGE_NAME": "silkeh/clang:16",
|
||||
"DEBIAN_SNAPSHOT": "none"
|
||||
},
|
||||
"context": "../context"
|
||||
}
|
||||
|
||||
@ -5,7 +5,8 @@
|
||||
"build": {
|
||||
"dockerfile": "../Dockerfile",
|
||||
"args": {
|
||||
"BASE_IMAGE_NAME": "silkeh/clang:17"
|
||||
"BASE_IMAGE_NAME": "silkeh/clang:17",
|
||||
"DEBIAN_SNAPSHOT": "none"
|
||||
},
|
||||
"context": "../context"
|
||||
}
|
||||
|
||||
@ -5,7 +5,8 @@
|
||||
"build": {
|
||||
"dockerfile": "../Dockerfile",
|
||||
"args": {
|
||||
"BASE_IMAGE_NAME": "silkeh/clang:18-bullseye"
|
||||
"BASE_IMAGE_NAME": "silkeh/clang:18-bullseye",
|
||||
"DEBIAN_SNAPSHOT": "none"
|
||||
},
|
||||
"context": "../context"
|
||||
}
|
||||
|
||||
@ -5,7 +5,8 @@
|
||||
"build": {
|
||||
"dockerfile": "../Dockerfile",
|
||||
"args": {
|
||||
"BASE_IMAGE_NAME": "silkeh/clang:19-bullseye"
|
||||
"BASE_IMAGE_NAME": "silkeh/clang:19-bullseye",
|
||||
"DEBIAN_SNAPSHOT": "none"
|
||||
},
|
||||
"context": "../context"
|
||||
}
|
||||
|
||||
@ -5,7 +5,8 @@
|
||||
"build": {
|
||||
"dockerfile": "../Dockerfile",
|
||||
"args": {
|
||||
"BASE_IMAGE_NAME": "silkeh/clang:20-bullseye"
|
||||
"BASE_IMAGE_NAME": "silkeh/clang:20-bullseye",
|
||||
"DEBIAN_SNAPSHOT": "none"
|
||||
},
|
||||
"context": "../context"
|
||||
}
|
||||
|
||||
13
.devcontainer/clang21/devcontainer.json
Normal file
13
.devcontainer/clang21/devcontainer.json
Normal file
@ -0,0 +1,13 @@
|
||||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
|
||||
// README at: https://github.com/devcontainers/templates/tree/main/src/cpp
|
||||
{
|
||||
"name": "Clang 21",
|
||||
"build": {
|
||||
"dockerfile": "../Dockerfile",
|
||||
"args": {
|
||||
"BASE_IMAGE_NAME": "silkeh/clang:21-bullseye",
|
||||
"DEBIAN_SNAPSHOT": "none"
|
||||
},
|
||||
"context": "../context"
|
||||
}
|
||||
}
|
||||
@ -5,7 +5,8 @@
|
||||
"build": {
|
||||
"dockerfile": "../Dockerfile",
|
||||
"args": {
|
||||
"BASE_IMAGE_NAME": "silkeh/clang:7"
|
||||
"BASE_IMAGE_NAME": "silkeh/clang:7",
|
||||
"DEBIAN_SNAPSHOT": "none"
|
||||
},
|
||||
"context": "../context"
|
||||
}
|
||||
|
||||
@ -5,7 +5,8 @@
|
||||
"build": {
|
||||
"dockerfile": "../Dockerfile",
|
||||
"args": {
|
||||
"BASE_IMAGE_NAME": "silkeh/clang:8"
|
||||
"BASE_IMAGE_NAME": "silkeh/clang:8",
|
||||
"DEBIAN_SNAPSHOT": "none"
|
||||
},
|
||||
"context": "../context"
|
||||
}
|
||||
|
||||
@ -5,7 +5,8 @@
|
||||
"build": {
|
||||
"dockerfile": "../Dockerfile",
|
||||
"args": {
|
||||
"BASE_IMAGE_NAME": "silkeh/clang:9"
|
||||
"BASE_IMAGE_NAME": "silkeh/clang:9",
|
||||
"DEBIAN_SNAPSHOT": "none"
|
||||
},
|
||||
"context": "../context"
|
||||
}
|
||||
|
||||
@ -5,7 +5,8 @@
|
||||
"build": {
|
||||
"dockerfile": "./Dockerfile",
|
||||
"args": {
|
||||
"BASE_IMAGE_NAME": "mcr.microsoft.com/devcontainers/cpp:debian-12"
|
||||
"BASE_IMAGE_NAME": "mcr.microsoft.com/devcontainers/cpp:2@sha256:a5eb5a1e9109af88bf82ebb0f71903608a68144851ed1e4b852e31b251ac59c6",
|
||||
"DEBIAN_SNAPSHOT": "20260223T000000Z"
|
||||
},
|
||||
"context": "./context"
|
||||
}
|
||||
|
||||
@ -5,7 +5,8 @@
|
||||
"build": {
|
||||
"dockerfile": "../Dockerfile",
|
||||
"args": {
|
||||
"BASE_IMAGE_NAME": "gcc:9"
|
||||
"BASE_IMAGE_NAME": "gcc:9",
|
||||
"DEBIAN_SNAPSHOT": "none"
|
||||
},
|
||||
"context": "../context"
|
||||
}
|
||||
|
||||
@ -5,7 +5,8 @@
|
||||
"build": {
|
||||
"dockerfile": "../Dockerfile",
|
||||
"args": {
|
||||
"BASE_IMAGE_NAME": "gcc:10"
|
||||
"BASE_IMAGE_NAME": "gcc:10",
|
||||
"DEBIAN_SNAPSHOT": "none"
|
||||
},
|
||||
"context": "../context"
|
||||
}
|
||||
|
||||
@ -5,7 +5,8 @@
|
||||
"build": {
|
||||
"dockerfile": "../Dockerfile",
|
||||
"args": {
|
||||
"BASE_IMAGE_NAME": "gcc:11"
|
||||
"BASE_IMAGE_NAME": "gcc:11",
|
||||
"DEBIAN_SNAPSHOT": "none"
|
||||
},
|
||||
"context": "../context"
|
||||
}
|
||||
|
||||
@ -5,7 +5,8 @@
|
||||
"build": {
|
||||
"dockerfile": "../Dockerfile",
|
||||
"args": {
|
||||
"BASE_IMAGE_NAME": "gcc:12"
|
||||
"BASE_IMAGE_NAME": "gcc:12",
|
||||
"DEBIAN_SNAPSHOT": "none"
|
||||
},
|
||||
"context": "../context"
|
||||
}
|
||||
|
||||
@ -5,7 +5,8 @@
|
||||
"build": {
|
||||
"dockerfile": "../Dockerfile",
|
||||
"args": {
|
||||
"BASE_IMAGE_NAME": "gcc:13"
|
||||
"BASE_IMAGE_NAME": "gcc:13",
|
||||
"DEBIAN_SNAPSHOT": "none"
|
||||
},
|
||||
"context": "../context"
|
||||
}
|
||||
|
||||
@ -5,7 +5,8 @@
|
||||
"build": {
|
||||
"dockerfile": "../Dockerfile",
|
||||
"args": {
|
||||
"BASE_IMAGE_NAME": "gcc:14"
|
||||
"BASE_IMAGE_NAME": "gcc:14",
|
||||
"DEBIAN_SNAPSHOT": "none"
|
||||
},
|
||||
"context": "../context"
|
||||
}
|
||||
|
||||
@ -5,7 +5,8 @@
|
||||
"build": {
|
||||
"dockerfile": "../Dockerfile",
|
||||
"args": {
|
||||
"BASE_IMAGE_NAME": "gcc:15"
|
||||
"BASE_IMAGE_NAME": "gcc:15",
|
||||
"DEBIAN_SNAPSHOT": "none"
|
||||
},
|
||||
"context": "../context"
|
||||
}
|
||||
|
||||
40
.devcontainer/s390x/Dockerfile
Normal file
40
.devcontainer/s390x/Dockerfile
Normal file
@ -0,0 +1,40 @@
|
||||
# s390x Big-Endian Test Environment for ETL
|
||||
# Uses QEMU user-mode emulation to run s390x binaries on x64 host
|
||||
FROM debian:trixie
|
||||
|
||||
# Avoid prompts from apt
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
# Install QEMU user-mode emulation and s390x cross-compilation tools
|
||||
RUN dpkg --add-architecture s390x && \
|
||||
apt-get update && apt-get install -y --no-install-recommends\
|
||||
qemu-user-static \
|
||||
qemu-user \
|
||||
binfmt-support \
|
||||
gcc-s390x-linux-gnu \
|
||||
g++-s390x-linux-gnu \
|
||||
cmake \
|
||||
make \
|
||||
ninja-build \
|
||||
git \
|
||||
wget \
|
||||
file \
|
||||
libc6:s390x \
|
||||
libstdc++6:s390x \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /workspaces/etl
|
||||
|
||||
# Verify QEMU and cross-compilation setup
|
||||
RUN echo "=== Host Architecture ===" && \
|
||||
uname -m && \
|
||||
echo "" && \
|
||||
echo "=== s390x Cross Compiler ===" && \
|
||||
s390x-linux-gnu-gcc --version && \
|
||||
echo "" && \
|
||||
echo "=== QEMU s390x ===" && \
|
||||
qemu-s390x-static --version | head -n1
|
||||
|
||||
# Default command
|
||||
CMD ["/bin/bash"]
|
||||
29
.devcontainer/s390x/devcontainer.json
Normal file
29
.devcontainer/s390x/devcontainer.json
Normal file
@ -0,0 +1,29 @@
|
||||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
|
||||
// README at: https://github.com/devcontainers/templates/tree/main/src/cpp
|
||||
{
|
||||
"name": "s390x Big Endian (Debian)",
|
||||
"build": {
|
||||
"dockerfile": "./Dockerfile",
|
||||
"context": "."
|
||||
},
|
||||
"customizations": {
|
||||
"vscode": {
|
||||
"extensions": [
|
||||
"ms-vscode.cpptools",
|
||||
"ms-vscode.cmake-tools"
|
||||
],
|
||||
"settings": {
|
||||
"cmake.sourceDirectory": "${workspaceFolder}/test",
|
||||
"cmake.configureArgs": [
|
||||
"-DCMAKE_TOOLCHAIN_FILE=${workspaceFolder}/.devcontainer/s390x/toolchain-s390x.cmake",
|
||||
"-DBUILD_TESTS=ON",
|
||||
"-DNO_STL=OFF",
|
||||
"-DETL_CXX_STANDARD=17"
|
||||
],
|
||||
"cmake.buildDirectory": "${workspaceFolder}/build-s390x",
|
||||
"cmake.generator": "Ninja"
|
||||
}
|
||||
}
|
||||
},
|
||||
"remoteUser": "root"
|
||||
}
|
||||
21
.devcontainer/s390x/toolchain-s390x.cmake
Normal file
21
.devcontainer/s390x/toolchain-s390x.cmake
Normal file
@ -0,0 +1,21 @@
|
||||
# CMake toolchain file for s390x cross-compilation
|
||||
set(CMAKE_SYSTEM_NAME Linux)
|
||||
set(CMAKE_SYSTEM_PROCESSOR s390x)
|
||||
|
||||
# Specify the cross compiler
|
||||
set(CMAKE_C_COMPILER s390x-linux-gnu-gcc)
|
||||
set(CMAKE_CXX_COMPILER s390x-linux-gnu-g++)
|
||||
set(CMAKE_AR s390x-linux-gnu-ar)
|
||||
set(CMAKE_RANLIB s390x-linux-gnu-ranlib)
|
||||
set(CMAKE_STRIP s390x-linux-gnu-strip)
|
||||
|
||||
# Search for programs in the build host directories
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
|
||||
# For libraries and headers in the target directories
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
|
||||
|
||||
# Set QEMU for running tests
|
||||
set(CMAKE_CROSSCOMPILING_EMULATOR /usr/bin/qemu-s390x-static CACHE FILEPATH "Path to the emulator for cross-compiled binaries")
|
||||
4
.github/workflows/clang-c++11.yml
vendored
4
.github/workflows/clang-c++11.yml
vendored
@ -28,7 +28,7 @@ jobs:
|
||||
make -j $(getconf _NPROCESSORS_ONLN)
|
||||
|
||||
- name: Run tests
|
||||
run: ./test/etl_tests
|
||||
run: ./test/etl_tests -v
|
||||
|
||||
build-clang-cpp11-linux-no-stl:
|
||||
name: Clang C++11 Linux - No STL
|
||||
@ -50,4 +50,4 @@ jobs:
|
||||
make -j $(getconf _NPROCESSORS_ONLN)
|
||||
|
||||
- name: Run tests
|
||||
run: ./test/etl_tests
|
||||
run: ./test/etl_tests -v
|
||||
4
.github/workflows/clang-c++14.yml
vendored
4
.github/workflows/clang-c++14.yml
vendored
@ -28,7 +28,7 @@ jobs:
|
||||
make -j $(getconf _NPROCESSORS_ONLN)
|
||||
|
||||
- name: Run tests
|
||||
run: ./test/etl_tests
|
||||
run: ./test/etl_tests -v
|
||||
|
||||
build-clang-cpp14-linux-no-stl:
|
||||
name: Clang C++14 Linux - No STL
|
||||
@ -50,4 +50,4 @@ jobs:
|
||||
make -j $(getconf _NPROCESSORS_ONLN)
|
||||
|
||||
- name: Run tests
|
||||
run: ./test/etl_tests
|
||||
run: ./test/etl_tests -v
|
||||
4
.github/workflows/clang-c++17.yml
vendored
4
.github/workflows/clang-c++17.yml
vendored
@ -28,7 +28,7 @@ jobs:
|
||||
make -j $(getconf _NPROCESSORS_ONLN)
|
||||
|
||||
- name: Run tests
|
||||
run: ./test/etl_tests
|
||||
run: ./test/etl_tests -v
|
||||
|
||||
build-clang-cpp17-linux-no-stl:
|
||||
name: Clang C++17 Linux - No STL
|
||||
@ -50,4 +50,4 @@ jobs:
|
||||
make -j $(getconf _NPROCESSORS_ONLN)
|
||||
|
||||
- name: Run tests
|
||||
run: ./test/etl_tests
|
||||
run: ./test/etl_tests -v
|
||||
14
.github/workflows/clang-c++20.yml
vendored
14
.github/workflows/clang-c++20.yml
vendored
@ -35,7 +35,7 @@ jobs:
|
||||
make -j $(getconf _NPROCESSORS_ONLN)
|
||||
|
||||
- name: Run tests
|
||||
run: ./test/etl_tests
|
||||
run: ./test/etl_tests -v
|
||||
|
||||
build-clang-cpp20-linux-stl-force-cpp03:
|
||||
name: Clang C++20 Linux - STL - Force C++03
|
||||
@ -64,7 +64,7 @@ jobs:
|
||||
make -j $(getconf _NPROCESSORS_ONLN)
|
||||
|
||||
- name: Run tests
|
||||
run: ./test/etl_tests
|
||||
run: ./test/etl_tests -v
|
||||
|
||||
build-clang-cpp20-linux-no-stl-force-cpp03:
|
||||
name: Clang C++20 Linux - No STL - Force C++03
|
||||
@ -93,7 +93,7 @@ jobs:
|
||||
make -j $(getconf _NPROCESSORS_ONLN)
|
||||
|
||||
- name: Run tests
|
||||
run: ./test/etl_tests
|
||||
run: ./test/etl_tests -v
|
||||
|
||||
build-clang-cpp20-osx-stl:
|
||||
name: Clang C++20 OSX - STL
|
||||
@ -115,7 +115,7 @@ jobs:
|
||||
make -j $(getconf _NPROCESSORS_ONLN)
|
||||
|
||||
- name: Run tests
|
||||
run: ./test/etl_tests
|
||||
run: ./test/etl_tests -v
|
||||
|
||||
build-clang-cpp20-osx-no-stl:
|
||||
name: Clang C++20 OSX - No STL
|
||||
@ -137,7 +137,7 @@ jobs:
|
||||
make -j $(getconf _NPROCESSORS_ONLN)
|
||||
|
||||
- name: Run tests
|
||||
run: ./test/etl_tests
|
||||
run: ./test/etl_tests -v
|
||||
|
||||
build-clang-cpp20-osx-stl-force-cpp03:
|
||||
name: Clang C++20 OSX - STL - Force C++03
|
||||
@ -159,7 +159,7 @@ jobs:
|
||||
make -j $(getconf _NPROCESSORS_ONLN)
|
||||
|
||||
- name: Run tests
|
||||
run: ./test/etl_tests
|
||||
run: ./test/etl_tests -v
|
||||
|
||||
build-clang-cpp20-osx-no-stl-force-cpp03:
|
||||
name: Clang C++20 OSX - No STL - Force C++03
|
||||
@ -181,5 +181,5 @@ jobs:
|
||||
make -j $(getconf _NPROCESSORS_ONLN)
|
||||
|
||||
- name: Run tests
|
||||
run: ./test/etl_tests
|
||||
run: ./test/etl_tests -v
|
||||
|
||||
|
||||
14
.github/workflows/clang-c++23.yml
vendored
14
.github/workflows/clang-c++23.yml
vendored
@ -35,7 +35,7 @@ jobs:
|
||||
make -j $(getconf _NPROCESSORS_ONLN)
|
||||
|
||||
- name: Run tests
|
||||
run: ./test/etl_tests
|
||||
run: ./test/etl_tests -v
|
||||
|
||||
build-clang-cpp23-linux-stl-force-cpp03:
|
||||
name: Clang C++23 Linux - STL - Force C++03
|
||||
@ -64,7 +64,7 @@ jobs:
|
||||
make -j $(getconf _NPROCESSORS_ONLN)
|
||||
|
||||
- name: Run tests
|
||||
run: ./test/etl_tests
|
||||
run: ./test/etl_tests -v
|
||||
|
||||
build-clang-cpp2-linux-no-stl-force-cpp03:
|
||||
name: Clang C++23 Linux - No STL - Force C++03
|
||||
@ -93,7 +93,7 @@ jobs:
|
||||
make -j $(getconf _NPROCESSORS_ONLN)
|
||||
|
||||
- name: Run tests
|
||||
run: ./test/etl_tests
|
||||
run: ./test/etl_tests -v
|
||||
|
||||
build-clang-cpp23-osx-stl:
|
||||
name: Clang C++23 OSX - STL
|
||||
@ -115,7 +115,7 @@ jobs:
|
||||
make -j $(getconf _NPROCESSORS_ONLN)
|
||||
|
||||
- name: Run tests
|
||||
run: ./test/etl_tests
|
||||
run: ./test/etl_tests -v
|
||||
|
||||
build-clang-cpp23-osx-no-stl:
|
||||
name: Clang C++23 OSX - No STL
|
||||
@ -137,7 +137,7 @@ jobs:
|
||||
make -j $(getconf _NPROCESSORS_ONLN)
|
||||
|
||||
- name: Run tests
|
||||
run: ./test/etl_tests
|
||||
run: ./test/etl_tests -v
|
||||
|
||||
build-clang-cpp23-osx-stl-force-cpp03:
|
||||
name: Clang C++23 OSX - STL - Force C++03
|
||||
@ -159,7 +159,7 @@ jobs:
|
||||
make -j $(getconf _NPROCESSORS_ONLN)
|
||||
|
||||
- name: Run tests
|
||||
run: ./test/etl_tests
|
||||
run: ./test/etl_tests -v
|
||||
|
||||
build-clang-cpp23-osx-no-stl-force-cpp03:
|
||||
name: Clang C++23 OSX - No STL - Force C++03
|
||||
@ -181,5 +181,5 @@ jobs:
|
||||
make -j $(getconf _NPROCESSORS_ONLN)
|
||||
|
||||
- name: Run tests
|
||||
run: ./test/etl_tests
|
||||
run: ./test/etl_tests -v
|
||||
|
||||
|
||||
43
.github/workflows/clang-format.yaml
vendored
Normal file
43
.github/workflows/clang-format.yaml
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
name: clang-format
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master, development, pull-request/* ]
|
||||
pull_request:
|
||||
branches: [ master, development, pull-request/* ]
|
||||
types: [opened, synchronize, reopened]
|
||||
|
||||
jobs:
|
||||
clang-format:
|
||||
name: clang-format
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Install clang-format and git
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y --no-install-recommends git clang-format
|
||||
clang-format --version
|
||||
|
||||
- name: Run clang-format on added/changed files
|
||||
run: |
|
||||
if [ "${{ github.event_name }}" = "pull_request" ]; then
|
||||
BEFORE="origin/${{ github.base_ref }}"
|
||||
elif [ "${{ github.event_name }}" = "push" ]; then
|
||||
BEFORE="${{ github.event.before }}"
|
||||
else
|
||||
echo "Unsupported event: ${{ github.event_name }}"
|
||||
echo "This is likely a bug in the workflow configuration. Please report it to the maintainers."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
git diff --name-only -z --diff-filter=AMCR "$BEFORE"..HEAD -- \
|
||||
'*.c' '*.cc' '*.cxx' '*.cpp' \
|
||||
'*.h' '*.hh' '*.hpp' '*.hxx' \
|
||||
'*.ipp' '*.inl' \
|
||||
':(exclude)include/etl/generators/*' \
|
||||
':(exclude)include/etl/private/*_cpp03.h' \
|
||||
| xargs -0 --no-run-if-empty clang-format --Werror -n --style=file
|
||||
21
.github/workflows/clang-format_update.yaml
vendored
Normal file
21
.github/workflows/clang-format_update.yaml
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
name: clang-format-update
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
clang-format:
|
||||
runs-on: ubuntu-24.04
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install clang-format
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y --no-install-recommends clang-format
|
||||
clang-format --version
|
||||
|
||||
- name: Run clang-format
|
||||
run: |
|
||||
find . \( -name '*.cpp' -o -name '*.h' -o -name '*.c' \) | xargs clang-format --dry-run --Werror
|
||||
72
.github/workflows/coverage.yml
vendored
Normal file
72
.github/workflows/coverage.yml
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
name: coverage
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master, pull-request/* ]
|
||||
pull_request:
|
||||
branches: [ master, pull-request/* ]
|
||||
types: [opened, synchronize, reopened]
|
||||
|
||||
# Allow only one concurrent deployment to GitHub Pages
|
||||
concurrency:
|
||||
group: coverage-${{ github.ref }}
|
||||
cancel-in-progress: true
|
||||
|
||||
# Grant GITHUB_TOKEN the minimum permissions needed at the workflow level
|
||||
permissions:
|
||||
contents: read
|
||||
|
||||
jobs:
|
||||
|
||||
coverage:
|
||||
name: Generate Coverage Report
|
||||
runs-on: ubuntu-24.04
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y lcov llvm gcc g++ clang cmake
|
||||
|
||||
- name: Build, test, and collect coverage
|
||||
run: |
|
||||
cd test
|
||||
./run-coverage.sh
|
||||
|
||||
- name: Upload coverage report artifact
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: coverage-report
|
||||
path: test/build-coverage/coverage/
|
||||
retention-days: 30
|
||||
|
||||
- name: Upload Pages artifact
|
||||
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
|
||||
uses: actions/upload-pages-artifact@v3
|
||||
with:
|
||||
path: test/build-coverage/coverage/
|
||||
|
||||
deploy-pages:
|
||||
name: Deploy to GitHub Pages
|
||||
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
|
||||
needs: coverage
|
||||
runs-on: ubuntu-22.04
|
||||
|
||||
permissions:
|
||||
pages: write
|
||||
id-token: write
|
||||
|
||||
environment:
|
||||
name: github-pages
|
||||
url: ${{ steps.deployment.outputs.page_url }}
|
||||
|
||||
steps:
|
||||
- name: Deploy to GitHub Pages
|
||||
id: deployment
|
||||
uses: actions/deploy-pages@v4
|
||||
|
||||
# GitHub Repository settings
|
||||
# -> Settings -> Pages
|
||||
# -> Source: gh actions
|
||||
4
.github/workflows/gcc-c++11.yml
vendored
4
.github/workflows/gcc-c++11.yml
vendored
@ -29,7 +29,7 @@ jobs:
|
||||
make -j $(getconf _NPROCESSORS_ONLN)
|
||||
|
||||
- name: Run tests
|
||||
run: ./test/etl_tests
|
||||
run: ./test/etl_tests -v
|
||||
|
||||
build-gcc-cpp11-linux-no-stl:
|
||||
name: GCC C++11 Linux - No STL
|
||||
@ -52,4 +52,4 @@ jobs:
|
||||
make -j $(getconf _NPROCESSORS_ONLN)
|
||||
|
||||
- name: Run tests
|
||||
run: ./test/etl_tests
|
||||
run: ./test/etl_tests -v
|
||||
|
||||
4
.github/workflows/gcc-c++14.yml
vendored
4
.github/workflows/gcc-c++14.yml
vendored
@ -28,7 +28,7 @@ jobs:
|
||||
make -j $(getconf _NPROCESSORS_ONLN)
|
||||
|
||||
- name: Run tests
|
||||
run: ./test/etl_tests
|
||||
run: ./test/etl_tests -v
|
||||
|
||||
build-gcc-cpp14-linux-no-stl:
|
||||
name: GCC C++14 Linux - No STL
|
||||
@ -50,4 +50,4 @@ jobs:
|
||||
make -j $(getconf _NPROCESSORS_ONLN)
|
||||
|
||||
- name: Run tests
|
||||
run: ./test/etl_tests
|
||||
run: ./test/etl_tests -v
|
||||
4
.github/workflows/gcc-c++17.yml
vendored
4
.github/workflows/gcc-c++17.yml
vendored
@ -28,7 +28,7 @@ jobs:
|
||||
make -j $(getconf _NPROCESSORS_ONLN)
|
||||
|
||||
- name: Run tests
|
||||
run: ./test/etl_tests
|
||||
run: ./test/etl_tests -v
|
||||
|
||||
build-gcc-cpp17-linux-no-stl:
|
||||
name: GCC C++17 Linux - No STL
|
||||
@ -50,4 +50,4 @@ jobs:
|
||||
make -j $(getconf _NPROCESSORS_ONLN)
|
||||
|
||||
- name: Run tests
|
||||
run: ./test/etl_tests
|
||||
run: ./test/etl_tests -v
|
||||
|
||||
8
.github/workflows/gcc-c++20.yml
vendored
8
.github/workflows/gcc-c++20.yml
vendored
@ -28,7 +28,7 @@ jobs:
|
||||
make -j $(getconf _NPROCESSORS_ONLN)
|
||||
|
||||
- name: Run tests
|
||||
run: ./test/etl_tests
|
||||
run: ./test/etl_tests -v
|
||||
|
||||
build-gcc-cpp20-linux-no-stl:
|
||||
name: GCC C++20 Linux - No STL
|
||||
@ -50,7 +50,7 @@ jobs:
|
||||
make -j $(getconf _NPROCESSORS_ONLN)
|
||||
|
||||
- name: Run tests
|
||||
run: ./test/etl_tests
|
||||
run: ./test/etl_tests -v
|
||||
|
||||
build-gcc-cpp20-linux-stl-force-cpp03:
|
||||
name: GCC C++20 Linux - STL - Force C++03
|
||||
@ -72,7 +72,7 @@ jobs:
|
||||
make -j $(getconf _NPROCESSORS_ONLN)
|
||||
|
||||
- name: Run tests
|
||||
run: ./test/etl_tests
|
||||
run: ./test/etl_tests -v
|
||||
|
||||
build-gcc-cpp20-linux-no-stl-force-cpp03:
|
||||
name: GCC C++20 Linux - No STL - Force C++03
|
||||
@ -94,4 +94,4 @@ jobs:
|
||||
make -j $(getconf _NPROCESSORS_ONLN)
|
||||
|
||||
- name: Run tests
|
||||
run: ./test/etl_tests
|
||||
run: ./test/etl_tests -v
|
||||
8
.github/workflows/gcc-c++23.yml
vendored
8
.github/workflows/gcc-c++23.yml
vendored
@ -28,7 +28,7 @@ jobs:
|
||||
make -j $(getconf _NPROCESSORS_ONLN)
|
||||
|
||||
- name: Run tests
|
||||
run: ./test/etl_tests
|
||||
run: ./test/etl_tests -v
|
||||
|
||||
build-gcc-cpp23-linux-no-stl:
|
||||
name: GCC C++23 Linux - No STL
|
||||
@ -50,7 +50,7 @@ jobs:
|
||||
make -j $(getconf _NPROCESSORS_ONLN)
|
||||
|
||||
- name: Run tests
|
||||
run: ./test/etl_tests
|
||||
run: ./test/etl_tests -v
|
||||
|
||||
build-gcc-cpp23-linux-stl-force-cpp03:
|
||||
name: GCC C++23 Linux - STL - Force C++03
|
||||
@ -72,7 +72,7 @@ jobs:
|
||||
make -j $(getconf _NPROCESSORS_ONLN)
|
||||
|
||||
- name: Run tests
|
||||
run: ./test/etl_tests
|
||||
run: ./test/etl_tests -v
|
||||
|
||||
build-gcc-cpp23-linux-no-stl-force-cpp03:
|
||||
name: GCC C++23 Linux - No STL - Force C++03
|
||||
@ -94,4 +94,4 @@ jobs:
|
||||
make -j $(getconf _NPROCESSORS_ONLN)
|
||||
|
||||
- name: Run tests
|
||||
run: ./test/etl_tests
|
||||
run: ./test/etl_tests -v
|
||||
8
.github/workflows/msvc.yml
vendored
8
.github/workflows/msvc.yml
vendored
@ -27,7 +27,7 @@ jobs:
|
||||
MSBuild.exe .\etl.sln
|
||||
|
||||
- name: Run tests
|
||||
run: test/Debug/etl_tests.exe
|
||||
run: test/Debug/etl_tests.exe -v
|
||||
|
||||
build-windows-msvc-no-stl:
|
||||
name: Windows - No STL
|
||||
@ -48,7 +48,7 @@ jobs:
|
||||
MSBuild.exe .\etl.sln
|
||||
|
||||
- name: Run tests
|
||||
run: test/Debug/etl_tests.exe
|
||||
run: test/Debug/etl_tests.exe -v
|
||||
|
||||
build-windows-msvc-stl-force-cpp03:
|
||||
name: Windows - STL - Force C++03
|
||||
@ -70,7 +70,7 @@ jobs:
|
||||
MSBuild.exe .\etl.sln
|
||||
|
||||
- name: Run tests
|
||||
run: test/Debug/etl_tests.exe
|
||||
run: test/Debug/etl_tests.exe -v
|
||||
|
||||
build-windows-msvc-no-stl-force-cpp03:
|
||||
name: Windows - No STL - Force C++03
|
||||
@ -92,5 +92,5 @@ jobs:
|
||||
MSBuild.exe .\etl.sln
|
||||
|
||||
- name: Run tests
|
||||
run: test/Debug/etl_tests.exe
|
||||
run: test/Debug/etl_tests.exe -v
|
||||
|
||||
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@ -3,6 +3,8 @@
|
||||
## Personal
|
||||
#################
|
||||
docs/html
|
||||
hugo/public
|
||||
hugo/.hugo_build.lock
|
||||
include/etl/html/
|
||||
include/etl/latex/
|
||||
test/vs2013/Debug
|
||||
|
||||
45
.treefmt.toml
Normal file
45
.treefmt.toml
Normal file
@ -0,0 +1,45 @@
|
||||
[global]
|
||||
excludes = [
|
||||
"**/Doxyfile",
|
||||
"**/Makefile",
|
||||
"*.*-format",
|
||||
"*.S",
|
||||
"*.cmm",
|
||||
"*.css",
|
||||
"*.dld",
|
||||
"*.gdb",
|
||||
"*.gif",
|
||||
"*.gitignore",
|
||||
"*.html",
|
||||
"*.ini",
|
||||
"*.josh",
|
||||
"*.json",
|
||||
"*.md",
|
||||
"*.png",
|
||||
"*.puml",
|
||||
"*.py",
|
||||
"*.rb",
|
||||
"*.rst",
|
||||
"*.s",
|
||||
"*.sh",
|
||||
"*.spec",
|
||||
"*.toml",
|
||||
"*.txt",
|
||||
"*.yaml",
|
||||
"*.yml",
|
||||
"docker/**",
|
||||
"temp/**",
|
||||
"scripts/clang-format-wrapper",
|
||||
"include/etl/generators/**",
|
||||
"include/etl/private/*_cpp03.h",
|
||||
"subprojects/**",
|
||||
"test/UnitTest++/**",
|
||||
"test/Deprecated/**",
|
||||
"test/Performance/**",
|
||||
"test/temp/**"
|
||||
]
|
||||
|
||||
[formatter.cpp]
|
||||
command = "scripts/clang-format-wrapper"
|
||||
options = [ "-i", "--style=file" ]
|
||||
includes = [ "*.c", "*.cc", "*.cpp", "*.h", "*.hh", "*.hpp" ]
|
||||
@ -1,13 +1,17 @@
|
||||
# How to contribute
|
||||
|
||||
If your are considering creating a pull request, please observe the following:
|
||||
Thanks for considering a contribution! Here’s what you need to know before opening a pull request:
|
||||
|
||||
- If you are adding or modifying a feature, add *new* unit tests that test that feature.
|
||||
- If you are fixing a bug, add a unit test that *fails* before the bug fix is implemented.
|
||||
- Do not initiate a pull request until all of the units tests pass.
|
||||
- Branches should be based on the branch `master`.
|
||||
- Do not initiate a pull request until all of the units tests pass. See below for information on project files and test scripts.
|
||||
- Branches should be based on the branch `master`. If `development` has pending updates, I’ll rebase the PR against it before pulling..
|
||||
- For formatting help, you can use clang-format, or the convenience wrapper treefmt. See also [docs/source-formatting.md](docs/source-formatting.md)
|
||||
|
||||
There is a project file for VS2022 for C++14, 17, 20, and bash scripts that run the tests for C++11, 14, 17, 20 under Linux with GCC and Clang.
|
||||
There is a project file for VS2022 for C++14, 17, 20, 23, and bash scripts that run the tests for C++11, 14, 17, 20, 23 under Linux with GCC and Clang.
|
||||
There are syntax-only check bash scripts that cover C++03, 11, 14, 17, 20, 23 under Linux with GCC and Clang.
|
||||
|
||||
If you are thinking of adding a new feature then raise this on the GitHub Issues page for discussion as the maintainers and user of the ETL may have questions or suggestions.
|
||||
It is possible that the maintainer of the ETL or another contributor is already working on the same or a related feature.
|
||||
It is possible that the maintainer of the ETL or another contributor is already working on the same or a related feature.
|
||||
|
||||
Take a look through our current issues and see if anything sparks your interest!
|
||||
|
||||
84
README.md
84
README.md
@ -1,5 +1,4 @@
|
||||
Embedded Template Library (ETL)
|
||||
-------------------------
|
||||
#  Embedded Template Library (ETL)
|
||||
|
||||

|
||||
[](https://img.shields.io/github/release-date/jwellbelove/etl?color=%231182c3)
|
||||
@ -10,7 +9,6 @@ Embedded Template Library (ETL)
|
||||

|
||||
|
||||

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

|
||||

|
||||
@ -50,7 +48,7 @@ Its design goals include:
|
||||
|
||||
- Offering APIs that closely resemble those of the STL, enabling familiar and consistent usage.
|
||||
|
||||
- Maintaining compatibility with C++98 while implementing many features introduced in later standards
|
||||
- Maintaining compatibility with C++98 while implementing many features introduced in later standards
|
||||
(C++11/14/17/20/23) where possible.
|
||||
|
||||
- Ensuring deterministic behavior, which is critical in real-time and resource-constrained environments.
|
||||
@ -184,6 +182,84 @@ add_executable(foo main.cpp)
|
||||
target_link_libraries(foo PRIVATE etl::etl)
|
||||
```
|
||||
|
||||
## Profile definition
|
||||
|
||||
When using ETL in a project, there is typically an `etl_profile.h` defined to
|
||||
adjust ETL to the project needs. ETL will automatically find `etl_profile.h`
|
||||
if it is available in the include path(s). If it's not available, ETL will
|
||||
work with default values.
|
||||
|
||||
### Example
|
||||
|
||||
```
|
||||
#ifndef __ETL_PROFILE_H__
|
||||
#define __ETL_PROFILE_H__
|
||||
|
||||
#define ETL_TARGET_DEVICE_GENERIC
|
||||
#define ETL_TARGET_OS_NONE
|
||||
|
||||
#define ETL_NO_STL
|
||||
|
||||
#endif
|
||||
```
|
||||
|
||||
## Platform specific implementation
|
||||
|
||||
Although ETL is generally a self-contained header-only library, some interfaces need to be
|
||||
implemented in every project or platform, at least if those interfaces are actually being
|
||||
used, due to project specifics:
|
||||
|
||||
| ETL header | Platform specific API to be implemented | Needed when using |
|
||||
|------------|-----------------------------------------|-------------------------------------|
|
||||
| `chrono.h` | `etl_get_high_resolution_clock()` | `etl::high_resolution_clock::now()` |
|
||||
| | `etl_get_system_clock()` | `etl::system_clock::now()` |
|
||||
| | `etl_get_steady_clock()` | `etl::steady_clock::now()` |
|
||||
| `print.h` | `etl_putchar()` | `etl::print()` |
|
||||
| | | `etl::println()` |
|
||||
|
||||
### Example
|
||||
|
||||
```
|
||||
#include <etl/chrono.h>
|
||||
#include <etl/print.h>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
||||
etl::chrono::high_resolution_clock::rep etl_get_high_resolution_clock()
|
||||
{
|
||||
return etl::chrono::high_resolution_clock::rep(static_cast<int64_t>(getSystemTimeNs()));
|
||||
}
|
||||
|
||||
etl::chrono::system_clock::rep etl_get_system_clock()
|
||||
{
|
||||
return etl::chrono::system_clock::rep(static_cast<int64_t>(getSystemTimeNs()));
|
||||
}
|
||||
|
||||
etl::chrono::system_clock::rep etl_get_steady_clock()
|
||||
{
|
||||
return etl::chrono::system_clock::rep(static_cast<int64_t>(getSystemTimeNs()));
|
||||
}
|
||||
|
||||
void etl_putchar(int c)
|
||||
{
|
||||
putByteToStdout(static_cast<uint8_t>(c));
|
||||
}
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
The following default values apply if the respective macros are not defined
|
||||
(e.g. in `etl_profile.h`):
|
||||
|
||||
| Macro | Default |
|
||||
|-----------------------------------------------|----------------------------|
|
||||
| `ETL_CHRONO_SYSTEM_CLOCK_DURATION` | `etl::chrono::nanoseconds` |
|
||||
| `ETL_CHRONO_SYSTEM_CLOCK_IS_STEADY` | `true` |
|
||||
| `ETL_CHRONO_HIGH_RESOLUTION_CLOCK_DURATION` | `etl::chrono::nanoseconds` |
|
||||
| `ETL_CHRONO_HIGH_RESOLUTION_CLOCK_IS_STEADY` | `true` |
|
||||
| `ETL_CHRONO_STEADY_CLOCK_DURATION` | `etl::chrono::nanoseconds` |
|
||||
|
||||
## 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.
|
||||
|
||||
@ -2,79 +2,79 @@
|
||||
#ifndef ETL_EMBEDDED_TEMPLATE_LIBRARY_INCLUDED
|
||||
#define ETL_EMBEDDED_TEMPLATE_LIBRARY_INCLUDED
|
||||
|
||||
#if defined(TEENSYDUINO)
|
||||
#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
|
||||
#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
|
||||
#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
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "Embedded Template Library ETL",
|
||||
"version": "20.45.0",
|
||||
"version": "20.46.2",
|
||||
"authors": {
|
||||
"name": "John Wellbelove",
|
||||
"email": "john.wellbelove@etlcpp.com"
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
name=Embedded Template Library ETL
|
||||
version=20.45.0
|
||||
version=20.46.2
|
||||
author= John Wellbelove <john.wellbelove@etlcpp.com>
|
||||
maintainer=John Wellbelove <john.wellbelove@etlcpp.com>
|
||||
license=MIT
|
||||
|
||||
6
docs/_config.yml
Normal file
6
docs/_config.yml
Normal file
@ -0,0 +1,6 @@
|
||||
plugins:
|
||||
- jekyll-relative-links
|
||||
relative_links:
|
||||
enabled: true
|
||||
include:
|
||||
- manchester.md
|
||||
7
docs/index.md
Normal file
7
docs/index.md
Normal file
@ -0,0 +1,7 @@
|
||||
---
|
||||
title: ETL documentation
|
||||
---
|
||||
|
||||
## Pages
|
||||
|
||||
* [Manchester](manchester.md)
|
||||
259
docs/manchester.md
Normal file
259
docs/manchester.md
Normal file
@ -0,0 +1,259 @@
|
||||
---
|
||||
title: Manchester encoding and decoding
|
||||
---
|
||||
|
||||
Efficient Manchester encoding and decoding of data. The Manchester code represents a data bit as a sequence of a 'high' and a 'low' value. In software this translates to a conversion from one to two bits, or in a practical situation, from `n` bytes to `n*2` bytes.
|
||||
|
||||
## See also
|
||||
|
||||
[Manchester code](https://en.wikipedia.org/wiki/Manchester_code)
|
||||
|
||||
## Features
|
||||
|
||||
- Normal and inverted Manchester encoding
|
||||
- Support for multiple encoding chunk sizes: 8-bit, 16-bit and 32-bit
|
||||
- Span-based operations or chunk-based operations
|
||||
- Constexpr functions for compile-time encoding/decoding
|
||||
- Validation of encoded data
|
||||
- Chunked span I/O uses little-endian byte order for multi-byte chunks, independent of host platform endianness
|
||||
|
||||
## Algorithm background
|
||||
|
||||
To encode the value `0b11001100` we must first duplicate all bits to create the value `0b1111000011110000`. We then perform an XOR of this value with the constant `0b1010101010101010` (`0xAAAA`) to obtain the Manchester coded value of `0b1010010110100101`. We have now replaced each `1` bit with the sequence `10` and each `0` bit with the sequence `01`.
|
||||
|
||||
### 2. Bit duplication
|
||||
|
||||
Bit duplication is achieved with the following steps. This is also called binary interleaving. The example shows encoding of an 8-bit value.
|
||||
|
||||
| Step | High Byte | Low Byte | Operation |
|
||||
|------|--------------------|--------------------|----------------------------|
|
||||
| 0 | `_ _ _ _ _ _ _ _` | `A B C D E F G H` | input value (i) |
|
||||
| 1 | `_ _ _ _ A B C D` | `_ _ _ _ E F G H` | `(i \| (i << 4)) & 0x0F0F` |
|
||||
| 2 | `_ _ A B _ _ C D` | `_ _ E F _ _ G H` | `(i \| (i << 2)) & 0x3333` |
|
||||
| 3 | `_ A _ B _ C _ D` | `_ E _ F _ G _ H` | `(i \| (i << 1)) & 0x5555` |
|
||||
| 4 | `A A B B C C D D` | `E E F F G G H H` | `(i \| (i << 1))` |
|
||||
|
||||
This process can be easily extended to 16-bit or 32-bit values by adding additional steps to the bit duplication.
|
||||
|
||||
### 3. Manchester Decoding
|
||||
|
||||
Manchester decoding is done in a similar, but reversed way.
|
||||
|
||||
### 4. Error Detection
|
||||
|
||||
Error detection in Manchester coded data is done by comparing 2 neighboring bits. If they are
|
||||
equal, then there is an error in the encoded input data.
|
||||
|
||||
Comparing all 8 bit pairs in a 16-bit word is done as follows.
|
||||
|
||||
| Step | Binary Value | Operation | Description |
|
||||
|------|--------------|-------------------|-----------------------------------------------------------------------------------------------|
|
||||
| 1 | `11011000` | Original | First bit pair (lsb, 00) is invalid. Last bit pair is also invalid. Other bit pairs are valid |
|
||||
| 2 | `01101100` | Shift right by 1 | Shift the original value right by one bit |
|
||||
| 3 | `10110100` | XOR | XOR the original with the shifted value |
|
||||
| 4 | `01010101` | Mask with 0x55 | Apply mask to isolate bit pairs |
|
||||
| 5 | `00010100` | Result | If result is not equal to 0x55, there was an error in the input |
|
||||
|
||||
## Analysis
|
||||
|
||||
Most traditional ways to Manchester encode data consist of a loop over all bits and a nested if-statement to check the value of the current bit. This approach does not scale well to increasing number of bits. The algorithm implemented here contains no conditional code and scales well. Doubling the number of processed bits per step (the chunk size) adds a single row to the bit duplication table. Because of the lack of loops and conditional code, this algorithm is likely to perform better than traditional ones on simple processors or when compiler optimization is disabled. On modern, powerful processors with caches and advanced optimization possibilities this algorithm may not show much benefit. In any case, the performance of the algorithm depends heavily on the processor type, compiler and compiler (optimization) settings.
|
||||
|
||||
## API Reference
|
||||
|
||||
### Classes
|
||||
|
||||
Classes `etl::manchester` and `etl::manchester_inverted` contain static functions for encoding, decoding and validity checking. It is not necessary to instantiate objects of these classes.
|
||||
|
||||
#### etl::manchester
|
||||
|
||||
```cpp
|
||||
typedef manchester_base<private_manchester::manchester_type_normal> manchester;
|
||||
```
|
||||
|
||||
Manchester encoder using normal encoding (no inversion).
|
||||
|
||||
#### etl::manchester_inverted
|
||||
|
||||
```cpp
|
||||
typedef manchester_base<private_manchester::manchester_type_inverted> manchester_inverted;
|
||||
```
|
||||
|
||||
Manchester encoder using inverted encoding.
|
||||
|
||||
### Encoding Functions
|
||||
|
||||
#### Encode single value
|
||||
|
||||
```cpp
|
||||
template <typename TDecoded>
|
||||
static ETL_CONSTEXPR14 typename encoded<TDecoded>::type encode(TDecoded decoded)
|
||||
```
|
||||
|
||||
Encodes a single value using Manchester encoding.
|
||||
|
||||
**Parameters:**
|
||||
|
||||
- `decoded`: The value to encode (`uint8_t`, `uint16_t`, or `uint32_t`)
|
||||
|
||||
**Returns:**
|
||||
|
||||
- The Manchester encoded value (twice the bit width of input)
|
||||
|
||||
**Example:**
|
||||
|
||||
```cpp
|
||||
uint16_t encoded = etl::manchester::encode(0x55);
|
||||
```
|
||||
|
||||
#### Encode range
|
||||
|
||||
```cpp
|
||||
template <typename TChunk = uint_least8_t>
|
||||
static ETL_CONSTEXPR14 void encode(etl::span<const uint_least8_t> decoded,
|
||||
etl::span<uint_least8_t> encoded)
|
||||
```
|
||||
|
||||
Encodes a span of data using the specified chunk size.
|
||||
|
||||
**Parameters:**
|
||||
|
||||
- `decoded`: Source data to encode
|
||||
- `encoded`: Destination for encoded data (must be twice the size of `decoded`)
|
||||
|
||||
**Template Parameters:**
|
||||
|
||||
- `TChunk`: Chunk size for encoding (`uint8_t`, `uint16_t` or `uint32_t`)
|
||||
|
||||
**Example:**
|
||||
|
||||
```cpp
|
||||
std::array<uint8_t, 4> data = {0x12, 0x34, 0x56, 0x78};
|
||||
std::array<uint8_t, 8> encoded_data1{};
|
||||
std::array<uint8_t, 8> encoded_data2{};
|
||||
|
||||
// Encode with TChunk == uint8_t
|
||||
etl::manchester::encode(data, encoded_data1);
|
||||
|
||||
// Encode with TChunk == uint32_t
|
||||
etl::manchester::encode<uint32_t>(data, encoded_data2);
|
||||
```
|
||||
|
||||
### Decoding Functions
|
||||
|
||||
#### Decode single value
|
||||
|
||||
```cpp
|
||||
template <typename TEncoded>
|
||||
static ETL_CONSTEXPR14 typename decoded<TEncoded>::type decode(TEncoded encoded)
|
||||
```
|
||||
|
||||
Decodes a single Manchester encoded value.
|
||||
|
||||
**Parameters:**
|
||||
|
||||
- `encoded`: The encoded value to decode (`uint16_t`, `uint32_t`, or `uint64_t`)
|
||||
|
||||
**Returns:**
|
||||
|
||||
- The Manchester decoded value (half the bit width of input)
|
||||
|
||||
**Example:**
|
||||
|
||||
```cpp
|
||||
uint8_t decoded = etl::manchester::decode(0x5A5A);
|
||||
```
|
||||
|
||||
#### Decode range
|
||||
|
||||
```cpp
|
||||
template <typename TChunk = typename private_manchester::encoded<uint_least8_t>::type>
|
||||
static ETL_CONSTEXPR14 void decode(etl::span<const uint_least8_t> encoded,
|
||||
etl::span<uint_least8_t> decoded)
|
||||
```
|
||||
|
||||
Decodes a span of Manchester encoded data.
|
||||
|
||||
**Parameters:**
|
||||
|
||||
- `encoded`: Source data to decode
|
||||
- `decoded`: Destination for decoded data (must be half the size of `encoded`)
|
||||
|
||||
**Template Parameters:**
|
||||
|
||||
- `TChunk`: Chunk type for decoding (`uint16_t`, `uint32_t`, or `uint64_t`)
|
||||
|
||||
**Example:**
|
||||
|
||||
```cpp
|
||||
std::array<uint8_t, 8> encoded = {/* ... */};
|
||||
std::array<uint8_t, 4> decoded1 {};
|
||||
std::array<uint8_t, 4> decoded2 {};
|
||||
|
||||
// Decode with TChunk == uint16_t
|
||||
etl::manchester::decode(encoded, decoded1);
|
||||
|
||||
// Decode with TChunk == uint64_t
|
||||
etl::manchester::decode<uint64_t>(encoded, decoded2);
|
||||
```
|
||||
|
||||
### Validation Functions
|
||||
|
||||
#### Single value
|
||||
|
||||
```cpp
|
||||
template <typename TChunk>
|
||||
static ETL_CONSTEXPR14 bool is_valid(TChunk encoded)
|
||||
```
|
||||
|
||||
Validates that a single value contains valid Manchester encoded data.
|
||||
|
||||
**Parameters:**
|
||||
|
||||
- `encoded`: The encoded value to validate
|
||||
|
||||
**Returns:**
|
||||
|
||||
- `true` if the value contains valid Manchester encoded data, `false` otherwise
|
||||
|
||||
**Example:**
|
||||
|
||||
```cpp
|
||||
bool valid = etl::manchester::is_valid(0x5A5A);
|
||||
```
|
||||
|
||||
#### Range
|
||||
|
||||
```cpp
|
||||
static ETL_CONSTEXPR14 bool is_valid(etl::span<const uint_least8_t> encoded)
|
||||
```
|
||||
|
||||
Validates that a range contains valid Manchester encoded data.
|
||||
|
||||
**Parameters:**
|
||||
|
||||
- `encoded`: The range of encoded data to validate
|
||||
|
||||
**Returns:**
|
||||
|
||||
- `true` if all data is valid Manchester encoding, `false` otherwise
|
||||
|
||||
**Example:**
|
||||
|
||||
```cpp
|
||||
std::array<uint8_t, 8> encoded_data = {/* ... */};
|
||||
bool valid = etl::manchester::is_valid(encoded_data);
|
||||
```
|
||||
|
||||
## Supported Types
|
||||
|
||||
### Input/chunk types for encoding
|
||||
|
||||
- `uint8_t` → `uint16_t` (if 8-bit types are supported)
|
||||
- `uint16_t` → `uint32_t`
|
||||
- `uint32_t` → `uint64_t` (if 64-bit types are supported)
|
||||
|
||||
### Input/chunk types for decoding
|
||||
|
||||
- `uint16_t` → `uint8_t` (if 8-bit types are supported)
|
||||
- `uint32_t` → `uint16_t`
|
||||
- `uint64_t` → `uint32_t` (if 64-bit types are supported)
|
||||
328
docs/ranges.md
Normal file
328
docs/ranges.md
Normal file
@ -0,0 +1,328 @@
|
||||
# ETL C++17 Ranges Implementation
|
||||
|
||||
## Overview
|
||||
|
||||
The Embedded Template Library provides a C++17-compatible implementation of ranges, inspired by the C++20 ranges library. This implementation enables range-based algorithms and views for embedded and resource-constrained environments where full C++20 support may not be available.
|
||||
|
||||
## Features
|
||||
|
||||
- **Ranges**: Provides range types and iterator wrappers for composing operations over sequences.
|
||||
- **Views**: Includes lightweight, composable views such as `filter_view`, `transform_view`, and `subrange`.
|
||||
- **Algorithms**: Supports range-based algorithms compatible with ETL containers and standard containers.
|
||||
- **Compatibility**: Designed for C++17, with minimal dependencies and no reliance on C++20 features.
|
||||
|
||||
## Getting Started
|
||||
|
||||
Include the main header in your project:
|
||||
|
||||
```cpp
|
||||
#include <etl/ranges.h>
|
||||
```
|
||||
|
||||
### Example Usage
|
||||
|
||||
#### Using Ranges
|
||||
|
||||
```cpp
|
||||
#include <etl/print.h>
|
||||
#include <etl/ranges.h>
|
||||
#include <etl/vector.h>
|
||||
|
||||
...
|
||||
|
||||
etl::vector<int, 10> data = {6, 1, 3, 3, 2};
|
||||
etl::ranges::sort(data);
|
||||
etl::ranges::for_each(data, [](const int& i){etl::print(" {}", i);});
|
||||
```
|
||||
|
||||
Output:
|
||||
```text
|
||||
1 2 3 3 6
|
||||
```
|
||||
|
||||
#### Using Views
|
||||
|
||||
```cpp
|
||||
#include <etl/print.h>
|
||||
#include <etl/ranges.h>
|
||||
#include <etl/vector.h>
|
||||
|
||||
...
|
||||
|
||||
etl::vector<int, 10> data = {1, 2, 3, 4, 5};
|
||||
auto even = [](int v) { return v % 2 == 0; };
|
||||
auto filtered = etl::ranges::filter_view(data, even);
|
||||
etl::ranges::for_each(filtered, [](const int& i){etl::print(" {}", i);});
|
||||
```
|
||||
|
||||
Output:
|
||||
```text
|
||||
2 4
|
||||
```
|
||||
|
||||
#### Transforming Elements
|
||||
|
||||
```cpp
|
||||
#include <etl/print.h>
|
||||
#include <etl/ranges.h>
|
||||
#include <etl/vector.h>
|
||||
|
||||
...
|
||||
|
||||
etl::vector<int, 10> data = {1, 2, 3, 4, 5};
|
||||
auto squared = etl::ranges::transform_view(data, [](int v) { return v * v; });
|
||||
etl::ranges::for_each(squared, [](const int& i){etl::print(" {}", i);});
|
||||
```
|
||||
|
||||
Output:
|
||||
```text
|
||||
1 4 9 16 25
|
||||
```
|
||||
|
||||
#### Composition
|
||||
|
||||
Views can be composed using the pipe (`|`) operator, allowing you to chain multiple transformations in a readable, left-to-right style:
|
||||
|
||||
```cpp
|
||||
#include <etl/print.h>
|
||||
#include <etl/ranges.h>
|
||||
#include <etl/vector.h>
|
||||
|
||||
namespace views = etl::ranges::views;
|
||||
|
||||
...
|
||||
|
||||
etl::vector<int, 10> data = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
|
||||
|
||||
auto result = data
|
||||
| views::filter([](const int& v) { return v % 2 == 0; })
|
||||
| views::transform([](const int& v) { return v * v; });
|
||||
|
||||
etl::ranges::for_each(result, [](const int& i){ etl::print(" {}", i); });
|
||||
```
|
||||
|
||||
Output:
|
||||
```text
|
||||
4 16 36 64 100
|
||||
```
|
||||
|
||||
This first filters the even numbers and then squares them. Each `|` passes the result of the previous stage as input to the next view adaptor.
|
||||
|
||||
## Supported Views
|
||||
|
||||
All views are in the `etl::ranges` namespace. Corresponding range adaptor objects are available in `etl::ranges::views`.
|
||||
|
||||
### Range Factories
|
||||
|
||||
| View | `views::` adaptor | Description |
|
||||
|---|---|---|
|
||||
| `empty_view<T>` | `views::empty<T>` | A view with no elements. |
|
||||
| `single_view` | `views::single` | A view containing exactly one element. |
|
||||
| `iota_view` | `views::iota` | A view of sequentially increasing values. |
|
||||
| `repeat_view` | `views::repeat` | A view that repeats a value a given number of times. |
|
||||
|
||||
### Range Adaptors
|
||||
|
||||
| View | `views::` adaptor | Description |
|
||||
|---|---|---|
|
||||
| `ref_view` | `views::ref` | A non-owning view that wraps a reference to a range. |
|
||||
| `owning_view` | `views::owning` | A view that takes ownership of a range via move. |
|
||||
| — | `views::all` | Returns the range itself (if already a view), a `ref_view`, or an `owning_view`. |
|
||||
| `filter_view` | `views::filter` | Filters elements based on a predicate. |
|
||||
| `transform_view` | `views::transform` | Applies a transformation to each element. |
|
||||
| `as_rvalue_view` | `views::as_rvalue` | Casts each element to an rvalue reference. |
|
||||
| `as_const_view` | `views::as_const` | Provides a const view of the elements. |
|
||||
| `cache_latest_view` | `views::cache_latest` | Caches the most recently accessed element (avoids recomputation). |
|
||||
| `reverse_view` | `views::reverse` | Reverses the order of elements. |
|
||||
| `drop_view` | `views::drop` | Skips the first *n* elements. |
|
||||
| `drop_while_view` | `views::drop_while` | Skips leading elements while a predicate is true. |
|
||||
| `take_view` | `views::take` | Takes the first *n* elements. |
|
||||
| `take_while_view` | `views::take_while` | Takes leading elements while a predicate is true. |
|
||||
| `join_view` | `views::join` | Flattens a range of ranges into a single range. |
|
||||
| `join_with_view` | `views::join_with` | Flattens a range of ranges, inserting a delimiter between each. |
|
||||
| `split_view` | `views::split` | Splits a range into subranges around a delimiter pattern. |
|
||||
| `lazy_split_view` | `views::lazy_split` | Lazily splits a range by a pattern (inner ranges discovered on iteration). |
|
||||
| — | `views::counted` | Creates a view of *n* elements starting from an iterator. |
|
||||
| `concat_view` | `views::concat` | Concatenates multiple ranges into a single view. |
|
||||
| `zip_view` | `views::zip` | Zips multiple ranges into a view of tuples (length of shortest range). |
|
||||
| `zip_transform_view` | `views::zip_transform` | Zips multiple ranges and applies a function to each tuple of elements. |
|
||||
| `common_view` | `views::common` | Adapts a view so that its iterator and sentinel types are the same. |
|
||||
| `enumerate_view` | `views::enumerate` | Pairs each element with its index, producing tuples of (index, value). |
|
||||
| `elements_view` | `views::elements` | Extracts the *N*-th element from each tuple-like value. |
|
||||
| `keys_view` | `views::keys` | Alias for `elements_view` with *N*=0 (extracts first element of pairs/tuples). |
|
||||
| `values_view` | `views::values` | Alias for `elements_view` with *N*=1 (extracts second element of pairs/tuples). |
|
||||
| `adjacent_view` | `views::adjacent` | Produces a view of tuples of *N* adjacent elements (sliding window of tuples). |
|
||||
| — | `views::pairwise` | Alias for `views::adjacent<2>`. |
|
||||
| `adjacent_transform_view` | `views::adjacent_transform` | Applies a function to each group of *N* adjacent elements. |
|
||||
| — | `views::pairwise_transform` | Alias for `views::adjacent_transform<2>`. |
|
||||
| `chunk_view` | `views::chunk` | Splits a range into non-overlapping chunks of a given size. |
|
||||
| `slide_view` | `views::slide` | Produces overlapping subranges (sliding windows) of a given size. |
|
||||
| `chunk_by_view` | `views::chunk_by` | Splits a range into subranges between adjacent elements where a predicate is false. |
|
||||
| `stride_view` | `views::stride` | Yields every *N*-th element from the underlying range. |
|
||||
| `cartesian_product_view` | `views::cartesian_product` | Produces the Cartesian product of multiple ranges as a view of tuples. |
|
||||
| `to_input_view` | `views::to_input` | Downgrades iterator category to input iterator while preserving elements and order. |
|
||||
| `subrange` | — | Represents a sub-range defined by an iterator–sentinel pair. |
|
||||
|
||||
All views support range-based for-loop iteration and can be composed with the pipe (`|`) operator.
|
||||
|
||||
## Supported Algorithms
|
||||
|
||||
All algorithms are callable objects in the `etl::ranges` namespace. Each supports both an iterator-pair overload and a range overload (where applicable), and most accept optional projection and comparator arguments.
|
||||
|
||||
### Non-modifying Sequence Operations
|
||||
|
||||
| Algorithm | Description |
|
||||
|---|---|
|
||||
| `for_each` | Applies a function to each element in a range. |
|
||||
| `for_each_n` | Applies a function to the first *n* elements. |
|
||||
| `find` | Finds the first element equal to a value. |
|
||||
| `find_if` | Finds the first element satisfying a predicate. |
|
||||
| `find_if_not` | Finds the first element not satisfying a predicate. |
|
||||
| `find_end` | Finds the last occurrence of a subsequence. |
|
||||
| `find_first_of` | Finds the first element matching any in a second range. |
|
||||
| `adjacent_find` | Finds the first pair of adjacent equal elements. |
|
||||
| `count` | Counts elements equal to a value. |
|
||||
| `count_if` | Counts elements satisfying a predicate. |
|
||||
| `all_of` | Checks if all elements satisfy a predicate. |
|
||||
| `any_of` | Checks if any element satisfies a predicate. |
|
||||
| `none_of` | Checks if no elements satisfy a predicate. |
|
||||
| `mismatch` | Finds the first position where two ranges differ. |
|
||||
| `equal` | Checks if two ranges are equal. |
|
||||
| `is_permutation` | Checks if one range is a permutation of another. |
|
||||
| `search` | Searches for the first occurrence of a subsequence. |
|
||||
| `search_n` | Searches for *n* consecutive copies of a value. |
|
||||
| `starts_with` | Checks if a range starts with another range. |
|
||||
| `ends_with` | Checks if a range ends with another range. |
|
||||
| `lexicographical_compare` | Compares two ranges lexicographically. |
|
||||
|
||||
### Fold Operations
|
||||
|
||||
| Algorithm | Description |
|
||||
|---|---|
|
||||
| `fold_left` | Left-folds elements with a binary operation. |
|
||||
| `fold_left_with_iter` | Left-folds, returning both the result and an iterator. |
|
||||
| `fold_left_first` | Left-folds using the first element as the initial value. |
|
||||
| `fold_left_first_with_iter` | Like `fold_left_first`, also returning an iterator. |
|
||||
| `fold_right` | Right-folds elements with a binary operation. |
|
||||
| `fold_right_last` | Right-folds using the last element as the initial value. |
|
||||
|
||||
### Modifying Sequence Operations
|
||||
|
||||
| Algorithm | Description |
|
||||
|---|---|
|
||||
| `copy` | Copies elements to a destination range. |
|
||||
| `copy_n` | Copies *n* elements to a destination range. |
|
||||
| `copy_if` | Copies elements satisfying a predicate. |
|
||||
| `copy_backward` | Copies elements backwards to a destination range. |
|
||||
| `move` | Moves elements to a destination range. |
|
||||
| `move_backward` | Moves elements backwards to a destination range. |
|
||||
| `swap_ranges` | Swaps elements between two ranges. |
|
||||
| `replace` | Replaces elements equal to a value. |
|
||||
| `replace_if` | Replaces elements satisfying a predicate. |
|
||||
| `replace_copy` | Copies, replacing elements equal to a value. |
|
||||
| `replace_copy_if` | Copies, replacing elements satisfying a predicate. |
|
||||
| `remove` | Removes elements equal to a value. |
|
||||
| `remove_if` | Removes elements satisfying a predicate. |
|
||||
| `remove_copy` | Copies, omitting elements equal to a value. |
|
||||
| `fill` | Fills a range with a value. |
|
||||
| `fill_n` | Fills *n* elements with a value. |
|
||||
| `generate` | Assigns each element the result of a generator function. |
|
||||
| `generate_n` | Assigns *n* elements the result of a generator function. |
|
||||
| `iota` | Fills a range with sequentially increasing values. |
|
||||
| `unique` | Removes consecutive duplicate elements. |
|
||||
| `unique_copy` | Copies, removing consecutive duplicates. |
|
||||
| `transform` | Applies a transformation to each element. |
|
||||
| `reverse` | Reverses the order of elements. |
|
||||
| `reverse_copy` | Copies elements in reverse order. |
|
||||
| `rotate` | Rotates elements in a range. |
|
||||
| `rotate_copy` | Copies elements with rotation. |
|
||||
| `shift_left` | Shifts elements to the left. |
|
||||
| `shift_right` | Shifts elements to the right. |
|
||||
| `shuffle` | Randomly reorders elements. |
|
||||
| `sample` | Selects *n* random elements from a range. |
|
||||
|
||||
### Sorting Operations
|
||||
|
||||
| Algorithm | Description |
|
||||
|---|---|
|
||||
| `sort` | Sorts elements in a range. |
|
||||
| `stable_sort` | Sorts elements preserving relative order of equivalent elements. |
|
||||
| `partial_sort` | Partially sorts a range so that the first *n* elements are sorted. |
|
||||
| `partial_sort_copy` | Copies and partially sorts elements. |
|
||||
| `nth_element` | Partially sorts so that the *n*-th element is in its sorted position. |
|
||||
| `is_sorted` | Checks if a range is sorted. |
|
||||
| `is_sorted_until` | Finds the first unsorted element. |
|
||||
|
||||
### Partitioning Operations
|
||||
|
||||
| Algorithm | Description |
|
||||
|---|---|
|
||||
| `partition` | Partitions elements by a predicate. |
|
||||
| `stable_partition` | Partitions elements, preserving relative order. |
|
||||
| `is_partitioned` | Checks if a range is partitioned. |
|
||||
| `partition_copy` | Copies elements into two ranges based on a predicate. |
|
||||
| `partition_point` | Finds the partition point. |
|
||||
|
||||
### Binary Search (on sorted ranges)
|
||||
|
||||
| Algorithm | Description |
|
||||
|---|---|
|
||||
| `lower_bound` | Finds the first element not less than a value. |
|
||||
| `upper_bound` | Finds the first element greater than a value. |
|
||||
| `equal_range` | Returns the range of elements equal to a value. |
|
||||
| `binary_search` | Checks if a sorted range contains a value. |
|
||||
|
||||
### Set Operations (on sorted ranges)
|
||||
|
||||
| Algorithm | Description |
|
||||
|---|---|
|
||||
| `includes` | Checks if one sorted range includes another. |
|
||||
| `merge` | Merges two sorted ranges. |
|
||||
| `inplace_merge` | Merges two consecutive sorted sub-ranges in place. |
|
||||
| `set_union` | Computes the union of two sorted ranges. |
|
||||
| `set_intersection` | Computes the intersection of two sorted ranges. |
|
||||
| `set_difference` | Computes the difference of two sorted ranges. |
|
||||
| `set_symmetric_difference` | Computes the symmetric difference of two sorted ranges. |
|
||||
|
||||
### Heap Operations
|
||||
|
||||
| Algorithm | Description |
|
||||
|---|---|
|
||||
| `make_heap` | Creates a heap from a range. |
|
||||
| `push_heap` | Pushes an element onto a heap. |
|
||||
| `pop_heap` | Pops the top element from a heap. |
|
||||
| `sort_heap` | Sorts a heap into a sorted range. |
|
||||
| `is_heap` | Checks if a range is a heap. |
|
||||
| `is_heap_until` | Finds the first element that breaks the heap property. |
|
||||
|
||||
### Min/Max Operations
|
||||
|
||||
| Algorithm | Description |
|
||||
|---|---|
|
||||
| `min` | Returns the smaller of two values or the smallest in an initializer list. |
|
||||
| `min_element` | Finds the smallest element in a range. |
|
||||
| `max` | Returns the larger of two values or the largest in an initializer list. |
|
||||
| `max_element` | Finds the largest element in a range. |
|
||||
| `minmax` | Returns the smaller and larger of two values. |
|
||||
| `minmax_element` | Finds both the smallest and largest elements in a range. |
|
||||
| `clamp` | Clamps a value between a minimum and maximum. |
|
||||
|
||||
### Permutation Operations
|
||||
|
||||
| Algorithm | Description |
|
||||
|---|---|
|
||||
| `next_permutation` | Generates the next lexicographic permutation. |
|
||||
| `prev_permutation` | Generates the previous lexicographic permutation. |
|
||||
|
||||
|
||||
## Reference
|
||||
|
||||
For reference to the STD implementation, see also:
|
||||
|
||||
- Algorithms: https://en.cppreference.com/w/cpp/algorithm.html
|
||||
- Ranges/Views: https://en.cppreference.com/w/cpp/ranges.html
|
||||
|
||||
## Limitations
|
||||
|
||||
- Not all C++20 range features are available due to limitation to C++17. Especially C++20 concepts are not used.
|
||||
- Designed for ETL containers but can work with standard containers if compatible with ETL's iterator requirements.
|
||||
100
docs/source-formatting.md
Normal file
100
docs/source-formatting.md
Normal file
@ -0,0 +1,100 @@
|
||||
# Source Formatting
|
||||
|
||||
This project uses **clang-format** (version 18) to enforce a consistent coding style
|
||||
for C and C++ source files. For convenience, **treefmt** is also configured as a
|
||||
single-command wrapper that discovers and formats every file in the tree.
|
||||
|
||||
---
|
||||
|
||||
## clang-format
|
||||
|
||||
### Configuration file
|
||||
|
||||
The formatting rules live in [`.clang-format`](../.clang-format) at the repository
|
||||
root. The style is based on **LLVM**.
|
||||
|
||||
See the `.clang-format` file itself for the complete list.
|
||||
|
||||
### Version requirement
|
||||
|
||||
clang-format **18** is required.
|
||||
The helper script [`scripts/clang-format-wrapper`](../scripts/clang-format-wrapper)
|
||||
automatically resolves the correct binary: it first looks for `clang-format-18` on
|
||||
`PATH`, then falls back to `clang-format` and verifies that its major version is 18.
|
||||
All other tooling in the repo calls this wrapper instead of `clang-format` directly.
|
||||
|
||||
### Running clang-format manually
|
||||
|
||||
Format every tracked source file in the repository:
|
||||
|
||||
```bash
|
||||
git ls-files -z \
|
||||
'*.c' '*.cc' '*.cpp' \
|
||||
'*.h' '*.hh' '*.hpp' \
|
||||
':(exclude)include/etl/generators/*' \
|
||||
':(exclude)include/etl/private/*_cpp03.h' | xargs -0 scripts/clang-format-wrapper -i --verbose --style=file
|
||||
```
|
||||
|
||||
You can also format individual files directly:
|
||||
|
||||
```bash
|
||||
scripts/clang-format-wrapper -i --style=file path/to/file.cpp
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## treefmt
|
||||
|
||||
[treefmt](https://treefmt.com) is a language-agnostic source-tree formatter.
|
||||
It reads a single configuration file and dispatches each file to the appropriate
|
||||
formatter. In this project, it delegates all C/C++ formatting to the same
|
||||
`clang-format-wrapper` described above.
|
||||
|
||||
In comparison to calling clang-format directly, it brings a significant speedup.
|
||||
|
||||
### Configuration file
|
||||
|
||||
The configuration lives in [`.treefmt.toml`](../.treefmt.toml) at the repository root.
|
||||
|
||||
### Installing treefmt
|
||||
|
||||
treefmt is a standalone Go binary. Install it with any of:
|
||||
|
||||
```bash
|
||||
# Using the official install script
|
||||
curl -fsSL https://raw.githubusercontent.com/numtide/treefmt/main/install.sh | bash
|
||||
|
||||
# Or via Homebrew
|
||||
brew install treefmt
|
||||
|
||||
# Or via Nix
|
||||
nix profile install nixpkgs#treefmt2
|
||||
```
|
||||
|
||||
See the [treefmt documentation](https://treefmt.com) for more options.
|
||||
|
||||
### Running treefmt
|
||||
|
||||
From the repository root:
|
||||
|
||||
```bash
|
||||
# Format everything
|
||||
treefmt
|
||||
|
||||
# Check formatting without modifying files (useful in CI)
|
||||
treefmt --fail-on-change
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Excluded paths
|
||||
|
||||
`.treefmt.toml` excludes generated files under
|
||||
`include/etl/generators/`. Do **not** format those files manually via clang-format or treefmt.
|
||||
|
||||
## Pre-commit
|
||||
|
||||
Before submitting a PR / contribution, run `treefmt --fail-on-change` to catch
|
||||
unformatted code before merge.
|
||||
|
||||
Alternatively, a plain `treefmt` automatically fixes any issues.
|
||||
File diff suppressed because it is too large
Load Diff
@ -10,6 +10,6 @@
|
||||
#define ETL_CALLBACK_TIMER_USE_ATOMIC_LOCK
|
||||
#define ETL_NO_STL
|
||||
|
||||
//#include "etl/profiles/auto.h"
|
||||
// #include "etl/profiles/auto.h"
|
||||
|
||||
#endif
|
||||
|
||||
@ -1,23 +1,23 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
//#if (__cplusplus < 201103L)
|
||||
// #if (__cplusplus < 201103L)
|
||||
extern "C"
|
||||
{
|
||||
//#endif
|
||||
#include "Board_LED.h" // ::Board Support:LED
|
||||
// #endif
|
||||
#include "Board_Buttons.h" // ::Board Support:Buttons
|
||||
//#if (__cplusplus < 201103L)
|
||||
#include "Board_LED.h" // ::Board Support:LED
|
||||
// #if (__cplusplus < 201103L)
|
||||
}
|
||||
//#endif
|
||||
// #endif
|
||||
|
||||
#include "stm32f4xx.h" // Device header
|
||||
#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"
|
||||
#include "etl/callback_timer.h"
|
||||
#include "etl/function.h"
|
||||
#include "etl/iterator.h"
|
||||
#include "etl/vector.h"
|
||||
|
||||
struct FP
|
||||
{
|
||||
@ -28,7 +28,7 @@ static etl::vector<FP, 10> power_callbacks;
|
||||
|
||||
void register_poweroff_callback(void (*function)())
|
||||
{
|
||||
FP fp = { function };
|
||||
FP fp = {function};
|
||||
power_callbacks.push_back(fp);
|
||||
}
|
||||
|
||||
@ -45,38 +45,38 @@ etl::timer::id::type swap_timers;
|
||||
* SystemCoreClockConfigure: configure SystemCoreClock using HSI
|
||||
(HSE is not populated on Nucleo board)
|
||||
*----------------------------------------------------------------------------*/
|
||||
void SystemCoreClockConfigure(void) {
|
||||
void SystemCoreClockConfigure(void)
|
||||
{
|
||||
RCC->CR |= ((uint32_t)RCC_CR_HSION); // Enable HSI
|
||||
while ((RCC->CR & RCC_CR_HSIRDY) == 0); // Wait for HSI Ready
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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->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
|
||||
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->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->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
|
||||
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()
|
||||
@ -123,7 +123,7 @@ void LedToggle()
|
||||
|
||||
int main()
|
||||
{
|
||||
SystemCoreClockConfigure(); // configure HSI as System Clock
|
||||
SystemCoreClockConfigure(); // configure HSI as System Clock
|
||||
SystemCoreClockUpdate();
|
||||
|
||||
LED_Initialize();
|
||||
@ -131,10 +131,10 @@ int main()
|
||||
|
||||
// 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);
|
||||
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);
|
||||
swap_timers = callback_timer.register_timer(SwapTimers, 1500, etl::timer::mode::SINGLE_SHOT);
|
||||
|
||||
SysTick_Config(SystemCoreClock / 1000);
|
||||
|
||||
@ -152,7 +152,7 @@ extern "C"
|
||||
{
|
||||
void SysTick_Handler()
|
||||
{
|
||||
const uint32_t TICK = 1U;
|
||||
const uint32_t TICK = 1U;
|
||||
static uint32_t nticks = TICK;
|
||||
|
||||
if (callback_timer.tick(nticks))
|
||||
|
||||
@ -11,8 +11,8 @@ enum VectorId
|
||||
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
|
||||
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;
|
||||
@ -91,8 +91,8 @@ public:
|
||||
|
||||
// Constructor.
|
||||
Uart(int port_id, size_t interruptId)
|
||||
: port_id(port_id),
|
||||
callback(etl::delegate<void(size_t)>::create<Uart, &Uart::InterruptHandler>(*this))
|
||||
: port_id(port_id)
|
||||
, callback(etl::delegate<void(size_t)>::create<Uart, &Uart::InterruptHandler>(*this))
|
||||
{
|
||||
GetInterruptVectorsInstance().register_delegate(interruptId, callback);
|
||||
}
|
||||
@ -119,7 +119,8 @@ 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.
|
||||
// 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.
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "etl/function.h"
|
||||
#include "etl/callback_service.h"
|
||||
#include "etl/function.h"
|
||||
|
||||
enum VectorId
|
||||
{
|
||||
@ -11,8 +11,8 @@ enum VectorId
|
||||
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
|
||||
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;
|
||||
@ -91,8 +91,8 @@ public:
|
||||
|
||||
// Constructor.
|
||||
Uart(int port_id, int interruptId)
|
||||
: port_id(port_id),
|
||||
callback(*this)
|
||||
: port_id(port_id)
|
||||
, callback(*this)
|
||||
{
|
||||
GetInterruptVectorsInstance().register_callback(interruptId, callback);
|
||||
}
|
||||
@ -119,7 +119,8 @@ 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.
|
||||
// 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.
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include <atomic>
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
|
||||
#include "etl/mutex.h"
|
||||
#include "etl/message.h"
|
||||
#include "etl/message_router.h"
|
||||
#include "etl/mutex.h"
|
||||
|
||||
//*************************************
|
||||
struct Message1 : public etl::message<1>
|
||||
@ -48,9 +48,7 @@ public:
|
||||
}
|
||||
|
||||
//*****************
|
||||
void on_receive_unknown(const etl::imessage&)
|
||||
{
|
||||
}
|
||||
void on_receive_unknown(const etl::imessage&) {}
|
||||
|
||||
std::string result;
|
||||
|
||||
@ -61,7 +59,7 @@ private:
|
||||
|
||||
//*************************************
|
||||
etl::atomic<bool> start = false;
|
||||
Router router;
|
||||
Router router;
|
||||
|
||||
//*************************************
|
||||
void thread1()
|
||||
@ -106,5 +104,3 @@ int main()
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -31,9 +31,9 @@ SOFTWARE.
|
||||
// derived class.
|
||||
//*****************************************************************************
|
||||
|
||||
#include "etl/queue.h"
|
||||
#include "etl/fsm.h"
|
||||
#include "etl/message_packet.h"
|
||||
#include "etl/queue.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
@ -122,7 +122,7 @@ public:
|
||||
while (!queue.empty())
|
||||
{
|
||||
message_packet& packet = queue.front();
|
||||
etl::imessage& msg = packet.get();
|
||||
etl::imessage& msg = packet.get();
|
||||
std::cout << "Processing message " << int(msg.get_message_id()) << std::endl;
|
||||
|
||||
// Call the base class's receive function.
|
||||
@ -258,7 +258,7 @@ int main()
|
||||
State2 state2;
|
||||
|
||||
// The list of states.
|
||||
etl::ifsm_state* state_list[] = { &state1, &state2 };
|
||||
etl::ifsm_state* state_list[] = {&state1, &state2};
|
||||
|
||||
// Define some messages.
|
||||
Message1 m1(1);
|
||||
@ -285,4 +285,3 @@ int main()
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
|
||||
#include "etl/queue.h"
|
||||
#include "etl/message_router.h"
|
||||
#include "etl/queue.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
@ -81,7 +81,7 @@ public:
|
||||
while (!queue.empty())
|
||||
{
|
||||
message_packet& packet = queue.front();
|
||||
etl::imessage& msg = packet.get();
|
||||
etl::imessage& msg = packet.get();
|
||||
std::cout << "Processing message " << int(msg.get_message_id()) << std::endl;
|
||||
|
||||
// Call the base class's receive function.
|
||||
@ -146,4 +146,3 @@ int main()
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -31,9 +31,9 @@ SOFTWARE.
|
||||
// Experiment with the different scheduling policies.
|
||||
//*****************************************************************************
|
||||
|
||||
#include "etl/function.h"
|
||||
#include "etl/scheduler.h"
|
||||
#include "etl/task.h"
|
||||
#include "etl/function.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
@ -50,13 +50,13 @@ public:
|
||||
: 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.
|
||||
return work; // How much work do we still have to do? This could be a
|
||||
// message queue length.
|
||||
}
|
||||
|
||||
//*************************************
|
||||
@ -83,13 +83,13 @@ public:
|
||||
: 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.
|
||||
return work; // How much work do we still have to do? This could be a
|
||||
// message queue length.
|
||||
}
|
||||
|
||||
//*************************************
|
||||
@ -115,7 +115,6 @@ public:
|
||||
Idle(etl::ischeduler& scheduler_)
|
||||
: scheduler(scheduler_)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//*************************************
|
||||
@ -181,4 +180,3 @@ int main()
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -2,18 +2,18 @@
|
||||
// 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/message.h"
|
||||
#include "etl/message_bus.h"
|
||||
#include "etl/message_router.h"
|
||||
#include "etl/queue.h"
|
||||
#include "etl/reference_counted_message_pool.h"
|
||||
#include "etl/shared_message.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <atomic>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
|
||||
constexpr etl::message_router_id_t RouterId1 = 1U;
|
||||
constexpr etl::message_router_id_t RouterId2 = 2U;
|
||||
@ -26,9 +26,8 @@ struct Message1 : public etl::message<1>
|
||||
Message1(std::string s_)
|
||||
: s(s_)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
std::string s;
|
||||
};
|
||||
|
||||
@ -40,10 +39,10 @@ struct Message2 : public etl::message<2>
|
||||
Message2(std::string s_)
|
||||
: s(s_)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
std::string s;
|
||||
|
||||
char data[100];
|
||||
};
|
||||
|
||||
@ -55,7 +54,6 @@ struct Message3 : public etl::message<3>
|
||||
Message3(std::string s_)
|
||||
: s(s_)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::string s;
|
||||
@ -199,7 +197,7 @@ struct Bus : public etl::message_bus<2U>
|
||||
//*****************************************************************************
|
||||
MessageRouter1 router1;
|
||||
MessageRouter2 router2;
|
||||
Bus bus;
|
||||
Bus bus;
|
||||
|
||||
//*****************************************************************************
|
||||
// The thread safe message pool. Uses atomic uint32_t for counting.
|
||||
@ -230,8 +228,8 @@ private:
|
||||
};
|
||||
|
||||
//*****************************************************************************
|
||||
// The memory block allocator that supplies the pool with memory
|
||||
// to store reference counted messages in.
|
||||
// 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>;
|
||||
@ -243,10 +241,12 @@ 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.
|
||||
// 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.
|
||||
// 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;
|
||||
|
||||
//*****************************************************************************
|
||||
@ -256,8 +256,8 @@ etl::fixed_sized_memory_block_allocator<max_size_large, max_alignment_large, 4U>
|
||||
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").
|
||||
// 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"));
|
||||
|
||||
@ -269,10 +269,15 @@ int main()
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
@ -6,7 +6,8 @@
|
||||
struct S
|
||||
{
|
||||
S(int a_, double b_)
|
||||
: a(a_), b(b_)
|
||||
: a(a_)
|
||||
, b(b_)
|
||||
{
|
||||
}
|
||||
|
||||
@ -17,11 +18,11 @@ struct S
|
||||
int main()
|
||||
{
|
||||
etl::pool<S, 10> pool;
|
||||
auto pool_deleter = [&pool](auto ptr)
|
||||
{
|
||||
std::cout << "Releasing S(" << ptr->a << ", " << ptr->b << ") back to pool." << std::endl;
|
||||
pool.destroy(ptr);
|
||||
};
|
||||
auto pool_deleter = [&pool](auto ptr)
|
||||
{
|
||||
std::cout << "Releasing S(" << ptr->a << ", " << ptr->b << ") back to pool." << std::endl;
|
||||
pool.destroy(ptr);
|
||||
};
|
||||
using Unique = etl::unique_ptr<S, decltype(pool_deleter)>;
|
||||
|
||||
Unique us1(pool.create(1, 2), pool_deleter);
|
||||
|
||||
@ -88,35 +88,35 @@ public:
|
||||
// Notify observers about a position event.
|
||||
void Position_Event()
|
||||
{
|
||||
Position position = { 100, 200 };
|
||||
Position position = {100, 200};
|
||||
notify_observers(position);
|
||||
}
|
||||
|
||||
// Notify observers about a button up event.
|
||||
void Button_Event_Up()
|
||||
{
|
||||
Button button = { Button::Up };
|
||||
Button button = {Button::Up};
|
||||
notify_observers(button);
|
||||
}
|
||||
|
||||
// Notify observers about a button down event.
|
||||
void Button_Event_Down()
|
||||
{
|
||||
Button button = { Button::Down };
|
||||
Button button = {Button::Down};
|
||||
notify_observers(button);
|
||||
}
|
||||
|
||||
// Notify observers about a wheel up event.
|
||||
void Wheel_Event_Up()
|
||||
{
|
||||
Wheel wheel = { 50 };
|
||||
Wheel wheel = {50};
|
||||
notify_observers(wheel);
|
||||
}
|
||||
|
||||
// Notify observers about a wheel down event.
|
||||
void Wheel_Event_Down()
|
||||
{
|
||||
Wheel wheel = { -25 };
|
||||
Wheel wheel = {-25};
|
||||
notify_observers(wheel);
|
||||
}
|
||||
};
|
||||
@ -137,6 +137,6 @@ int main()
|
||||
mouse_driver.Position_Event();
|
||||
mouse_driver.Wheel_Event_Down();
|
||||
mouse_driver.Wheel_Event_Up();
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIN
images/QR Github.png
Normal file
BIN
images/QR Github.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
@ -32,19 +32,40 @@ SOFTWARE.
|
||||
#define ETL_ABSOLUTE_INCLUDED
|
||||
|
||||
#include "platform.h"
|
||||
#include "type_traits.h"
|
||||
#include "error_handler.h"
|
||||
#include "integral_limits.h"
|
||||
#include "type_traits.h"
|
||||
|
||||
namespace etl
|
||||
{
|
||||
namespace private_absolute
|
||||
{
|
||||
//*************************************************************************
|
||||
// Non-constexpr function that is never called for valid inputs.
|
||||
// If reached during constant evaluation, the compiler emits an error
|
||||
// because it's not constexpr.
|
||||
// At runtime, triggers the ETL assert handler.
|
||||
//*************************************************************************
|
||||
template <typename T>
|
||||
inline T signed_min_error()
|
||||
{
|
||||
ETL_ASSERT_FAIL(ETL_ERROR_GENERIC("absolute value of minimum signed integer is undefined"));
|
||||
return T(0);
|
||||
}
|
||||
} // namespace private_absolute
|
||||
|
||||
//***************************************************************************
|
||||
// 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
|
||||
ETL_NODISCARD ETL_CONSTEXPR typename etl::enable_if< etl::is_signed<T>::value && etl::is_integral<T>::value, T>::type absolute(T value)
|
||||
{
|
||||
return (value == etl::integral_limits<T>::min) ? etl::private_absolute::signed_min_error<T>() : static_cast<T>((value < T(0)) ? -value : value);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
ETL_NODISCARD ETL_CONSTEXPR typename etl::enable_if< etl::is_signed<T>::value && !etl::is_integral<T>::value, T>::type absolute(T value)
|
||||
ETL_NOEXCEPT
|
||||
{
|
||||
return (value < T(0)) ? -value : value;
|
||||
}
|
||||
@ -53,10 +74,7 @@ namespace etl
|
||||
// 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
|
||||
ETL_NODISCARD ETL_CONSTEXPR typename etl::enable_if<etl::is_unsigned<T>::value, T>::type absolute(T value) ETL_NOEXCEPT
|
||||
{
|
||||
return value;
|
||||
}
|
||||
@ -66,15 +84,14 @@ namespace etl
|
||||
// Returns the result as the unsigned type.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR
|
||||
typename etl::enable_if<etl::is_signed<T>::value, typename etl::make_unsigned<T>::type>::type
|
||||
absolute_unsigned(T value) ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR typename etl::enable_if<etl::is_signed<T>::value, typename etl::make_unsigned<T>::type>::type absolute_unsigned(T value)
|
||||
ETL_NOEXCEPT
|
||||
{
|
||||
typedef typename etl::make_unsigned<T>::type TReturn;
|
||||
|
||||
return (value == etl::integral_limits<T>::min) ? (etl::integral_limits<TReturn>::max / 2U) + 1U
|
||||
: (value < T(0)) ? TReturn(-value) : TReturn(value);
|
||||
: (value < T(0)) ? TReturn(-value)
|
||||
: TReturn(value);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
@ -82,14 +99,10 @@ namespace etl
|
||||
// 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
|
||||
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);
|
||||
}
|
||||
}
|
||||
} // namespace etl
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -32,12 +32,11 @@ SOFTWARE.
|
||||
#define ETL_ALIGNMENT_INCLUDED
|
||||
|
||||
#include "platform.h"
|
||||
#include "type_traits.h"
|
||||
#include "static_assert.h"
|
||||
#include "error_handler.h"
|
||||
#include "exception.h"
|
||||
#include "static_assert.h"
|
||||
#include "type_traits.h"
|
||||
#include "utility.h"
|
||||
#include "algorithm.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
@ -125,28 +124,28 @@ namespace etl
|
||||
|
||||
// Matching alignment.
|
||||
template <size_t Alignment, typename T1, typename... TRest>
|
||||
class type_with_alignment_matcher<true, Alignment, T1, 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...>
|
||||
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;
|
||||
|
||||
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>
|
||||
class type_with_alignment_matcher<false, Alignment, T1>
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
typedef char type;
|
||||
};
|
||||
|
||||
@ -154,23 +153,23 @@ namespace etl
|
||||
// Helper.
|
||||
//***************************************************************************
|
||||
template <size_t Alignment, typename T1, typename... T>
|
||||
class type_with_alignment_helper
|
||||
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>
|
||||
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>
|
||||
class type_with_alignment_matcher<true, Alignment, T1, T2, T3, T4, T5, T6, T7, T8>
|
||||
{
|
||||
public:
|
||||
|
||||
@ -179,16 +178,17 @@ namespace etl
|
||||
|
||||
// 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>
|
||||
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;
|
||||
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>
|
||||
class type_with_alignment_matcher<false, Alignment, void, void, void, void, void, void, void, void>
|
||||
{
|
||||
public:
|
||||
|
||||
@ -198,16 +198,16 @@ namespace etl
|
||||
//***************************************************************************
|
||||
// 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>
|
||||
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;
|
||||
typedef typename type_with_alignment_matcher< Alignment <= etl::alignment_of<T1>::value, Alignment, T1, T2, T3, T4, T5, T6, T7, T8>::type type;
|
||||
};
|
||||
#endif
|
||||
}
|
||||
} // namespace private_alignment
|
||||
|
||||
//***************************************************************************
|
||||
/// Gets a type that has the same as the specified alignment.
|
||||
@ -219,12 +219,17 @@ namespace etl
|
||||
public:
|
||||
|
||||
#if ETL_USING_CPP11
|
||||
typedef struct { alignas(Alignment) char dummy; } type;
|
||||
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;
|
||||
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;
|
||||
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
|
||||
|
||||
@ -248,35 +253,35 @@ namespace etl
|
||||
{
|
||||
/// Convert to T reference.
|
||||
template <typename T>
|
||||
operator T& ()
|
||||
operator T&()
|
||||
{
|
||||
ETL_STATIC_ASSERT((etl::is_same<T*, void*>:: value || ((Alignment % etl::alignment_of<T>::value) == 0)), "Incompatible alignment");
|
||||
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
|
||||
operator const T&() const
|
||||
{
|
||||
ETL_STATIC_ASSERT((etl::is_same<T*, void*>:: value || ((Alignment % etl::alignment_of<T>::value) == 0)), "Incompatible alignment");
|
||||
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* ()
|
||||
operator T*()
|
||||
{
|
||||
ETL_STATIC_ASSERT((etl::is_same<T*, void*>:: value || ((Alignment % etl::alignment_of<T>::value) == 0)), "Incompatible alignment");
|
||||
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
|
||||
operator const T*() const
|
||||
{
|
||||
ETL_STATIC_ASSERT((etl::is_same<T*, void*>:: value || ((Alignment % etl::alignment_of<T>::value) == 0)), "Incompatible alignment");
|
||||
ETL_STATIC_ASSERT((etl::is_same<T*, void*>::value || ((Alignment % etl::alignment_of<T>::value) == 0)), "Incompatible alignment");
|
||||
return reinterpret_cast<const T*>(data);
|
||||
}
|
||||
|
||||
@ -284,7 +289,7 @@ namespace etl
|
||||
template <typename T>
|
||||
T& get_reference()
|
||||
{
|
||||
ETL_STATIC_ASSERT((etl::is_same<T*, void*>:: value || ((Alignment % etl::alignment_of<T>::value) == 0)), "Incompatible alignment");
|
||||
ETL_STATIC_ASSERT((etl::is_same<T*, void*>::value || ((Alignment % etl::alignment_of<T>::value) == 0)), "Incompatible alignment");
|
||||
T* t = *this;
|
||||
return *t;
|
||||
}
|
||||
@ -293,7 +298,7 @@ namespace etl
|
||||
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");
|
||||
ETL_STATIC_ASSERT((etl::is_same<T*, void*>::value || ((Alignment % etl::alignment_of<T>::value) == 0)), "Incompatible alignment");
|
||||
const T* t = *this;
|
||||
return *t;
|
||||
}
|
||||
@ -302,7 +307,7 @@ namespace etl
|
||||
template <typename T>
|
||||
T* get_address()
|
||||
{
|
||||
ETL_STATIC_ASSERT((etl::is_same<T*, void*>:: value || ((Alignment % etl::alignment_of<T>::value) == 0)), "Incompatible alignment");
|
||||
ETL_STATIC_ASSERT((etl::is_same<T*, void*>::value || ((Alignment % etl::alignment_of<T>::value) == 0)), "Incompatible alignment");
|
||||
return reinterpret_cast<T*>(data);
|
||||
}
|
||||
|
||||
@ -310,7 +315,7 @@ namespace etl
|
||||
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");
|
||||
ETL_STATIC_ASSERT((etl::is_same<T*, void*>::value || ((Alignment % etl::alignment_of<T>::value) == 0)), "Incompatible alignment");
|
||||
return reinterpret_cast<const T*>(data);
|
||||
}
|
||||
|
||||
@ -319,8 +324,9 @@ namespace etl
|
||||
#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.
|
||||
char data[Length];
|
||||
typename etl::type_with_alignment<Alignment>::type etl_alignment_type; // A POD type that has the same alignment
|
||||
// as Alignment.
|
||||
};
|
||||
#endif
|
||||
};
|
||||
@ -367,14 +373,15 @@ namespace etl
|
||||
//***************************************************************************
|
||||
// Default constructor
|
||||
//***************************************************************************
|
||||
typed_storage() ETL_NOEXCEPT
|
||||
ETL_CONSTEXPR typed_storage() ETL_NOEXCEPT
|
||||
: valid(false)
|
||||
{
|
||||
}
|
||||
|
||||
#if ETL_USING_CPP11
|
||||
//***************************************************************************
|
||||
/// Constructs the instance of T forwarding the given \p args to its constructor.
|
||||
/// Constructs the instance of T forwarding the given \p args to its
|
||||
/// constructor.
|
||||
//***************************************************************************
|
||||
template <typename... TArgs>
|
||||
typed_storage(TArgs&&... args) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
|
||||
@ -425,8 +432,8 @@ namespace etl
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// Default destructor which will NOT call the destructor of the object which
|
||||
/// was created by calling create().
|
||||
/// Default destructor which will NOT call the destructor of the object
|
||||
/// which was created by calling create().
|
||||
//***************************************************************************
|
||||
~typed_storage() ETL_NOEXCEPT
|
||||
{
|
||||
@ -444,67 +451,72 @@ namespace etl
|
||||
|
||||
#if ETL_USING_CPP11
|
||||
//***************************************************************************
|
||||
/// Constructs the instance of T forwarding the given \p args to its constructor.
|
||||
/// \returns the instance of T which has been constructed in the internal byte array.
|
||||
/// Constructs the instance of T forwarding the given \p args to its
|
||||
/// constructor. \returns the instance of T which has been constructed in
|
||||
/// the internal byte array.
|
||||
//***************************************************************************
|
||||
template <typename... TArgs>
|
||||
reference create(TArgs&&... args) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
|
||||
{
|
||||
ETL_ASSERT(!has_value(), ETL_ERROR(etl::typed_storage_error));
|
||||
pointer p = ::new (&storage.value) value_type(etl::forward<TArgs>(args)...);
|
||||
valid = true;
|
||||
valid = true;
|
||||
return *p;
|
||||
}
|
||||
#else
|
||||
//***************************************************************************
|
||||
/// Constructs the instance of T with type T1
|
||||
/// \returns the instance of T which has been constructed in the internal byte array.
|
||||
/// \returns the instance of T which has been constructed in the internal
|
||||
/// byte array.
|
||||
//***************************************************************************
|
||||
template <typename T1>
|
||||
reference create(const T1& t1)
|
||||
{
|
||||
ETL_ASSERT(!has_value(), ETL_ERROR(etl::typed_storage_error));
|
||||
pointer p = ::new (&storage.value) value_type(t1);
|
||||
valid = true;
|
||||
valid = true;
|
||||
return *p;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Constructs the instance of T with types T1, T2
|
||||
/// \returns the instance of T which has been constructed in the internal byte array.
|
||||
/// \returns the instance of T which has been constructed in the internal
|
||||
/// byte array.
|
||||
//***************************************************************************
|
||||
template <typename T1, typename T2>
|
||||
reference create(const T1& t1, const T2& t2)
|
||||
{
|
||||
ETL_ASSERT(!has_value(), ETL_ERROR(etl::typed_storage_error));
|
||||
pointer p = ::new (&storage.value) value_type(t1, t2);
|
||||
valid = true;
|
||||
valid = true;
|
||||
return *p;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Constructs the instance of T with types T1, T2, T3
|
||||
/// \returns the instance of T which has been constructed in the internal byte array.
|
||||
/// \returns the instance of T which has been constructed in the internal
|
||||
/// byte array.
|
||||
//***************************************************************************
|
||||
template <typename T1, typename T2, typename T3>
|
||||
reference create(const T1& t1, const T2& t2, const T3& t3)
|
||||
{
|
||||
ETL_ASSERT(!has_value(), ETL_ERROR(etl::typed_storage_error));
|
||||
pointer p = ::new (&storage.value) value_type(t1, t2, t3);
|
||||
valid = true;
|
||||
valid = true;
|
||||
return *p;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Constructs the instance of T with types T1, T2, T3, T4
|
||||
/// \returns the instance of T which has been constructed in the internal byte array.
|
||||
/// \returns the instance of T which has been constructed in the internal
|
||||
/// byte array.
|
||||
//***************************************************************************
|
||||
template <typename T1, typename T2, typename T3, typename T4>
|
||||
reference create(const T1& t1, const T2& t2, const T3& t3, const T4& t4)
|
||||
{
|
||||
ETL_ASSERT(!has_value(), ETL_ERROR(etl::typed_storage_error));
|
||||
pointer p = ::new (&storage.value) value_type(t1, t2, t3, t4);
|
||||
valid = true;
|
||||
valid = true;
|
||||
return *p;
|
||||
}
|
||||
#endif
|
||||
@ -537,7 +549,7 @@ namespace etl
|
||||
const_pointer operator->() const ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
|
||||
{
|
||||
ETL_ASSERT(has_value(), ETL_ERROR(etl::typed_storage_error));
|
||||
|
||||
|
||||
return &storage.value;
|
||||
}
|
||||
|
||||
@ -560,21 +572,21 @@ namespace etl
|
||||
private:
|
||||
|
||||
typed_storage(etl::typed_storage<T>&) ETL_DELETE;
|
||||
typed_storage& operator =(etl::typed_storage<T>&) ETL_DELETE;
|
||||
typed_storage& operator=(etl::typed_storage<T>&) ETL_DELETE;
|
||||
|
||||
struct dummy_t {};
|
||||
struct dummy_t
|
||||
{
|
||||
};
|
||||
|
||||
//*******************************
|
||||
//*******************************
|
||||
union union_type
|
||||
{
|
||||
union_type() ETL_NOEXCEPT
|
||||
ETL_CONSTEXPR union_type() ETL_NOEXCEPT
|
||||
: dummy()
|
||||
{
|
||||
}
|
||||
|
||||
~union_type() ETL_NOEXCEPT
|
||||
{
|
||||
}
|
||||
~union_type() ETL_NOEXCEPT {}
|
||||
|
||||
dummy_t dummy;
|
||||
value_type value;
|
||||
@ -601,7 +613,7 @@ namespace etl
|
||||
typedef const T& const_reference;
|
||||
typedef T* pointer;
|
||||
typedef const T* const_pointer;
|
||||
|
||||
|
||||
template <typename U>
|
||||
friend ETL_CONSTEXPR14 void swap(typed_storage_ext<U>& lhs, typed_storage_ext<U>& rhs) ETL_NOEXCEPT;
|
||||
|
||||
@ -609,15 +621,16 @@ namespace etl
|
||||
/// Constructor.
|
||||
//***************************************************************************
|
||||
typed_storage_ext(void* pbuffer_) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
|
||||
: pbuffer(reinterpret_cast<T*>(pbuffer_)),
|
||||
valid(false)
|
||||
: pbuffer(reinterpret_cast<T*>(pbuffer_))
|
||||
, valid(false)
|
||||
{
|
||||
ETL_ASSERT(etl::is_aligned(pbuffer_, etl::alignment_of<T>::value), ETL_ERROR(etl::alignment_error));
|
||||
}
|
||||
|
||||
#if ETL_USING_CPP11
|
||||
//***************************************************************************
|
||||
/// Constructs the instance of T forwarding the given \p args to its constructor.
|
||||
/// Constructs the instance of T forwarding the given \p args to its
|
||||
/// constructor.
|
||||
//***************************************************************************
|
||||
template <typename... TArgs>
|
||||
typed_storage_ext(void* pbuffer_, TArgs&&... args) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
|
||||
@ -690,8 +703,8 @@ namespace etl
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// Default destructor which will NOT call the destructor of the object which
|
||||
/// was created by calling create().
|
||||
/// Default destructor which will NOT call the destructor of the object
|
||||
/// which was created by calling create().
|
||||
//***************************************************************************
|
||||
~typed_storage_ext() ETL_NOEXCEPT
|
||||
{
|
||||
@ -709,67 +722,72 @@ namespace etl
|
||||
|
||||
#if ETL_USING_CPP11
|
||||
//***************************************************************************
|
||||
/// Constructs the instance of T forwarding the given \p args to its constructor.
|
||||
/// \returns the instance of T which has been constructed in the external buffer.
|
||||
/// Constructs the instance of T forwarding the given \p args to its
|
||||
/// constructor. \returns the instance of T which has been constructed in
|
||||
/// the external buffer.
|
||||
//***************************************************************************
|
||||
template <typename... TArgs>
|
||||
reference create(TArgs&&... args) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
|
||||
{
|
||||
ETL_ASSERT(!has_value(), ETL_ERROR(etl::typed_storage_error));
|
||||
pointer p = ::new (pbuffer) value_type(etl::forward<TArgs>(args)...);
|
||||
valid = true;
|
||||
valid = true;
|
||||
return *p;
|
||||
}
|
||||
#else
|
||||
//***************************************************************************
|
||||
/// Constructs the instance of T with type T1
|
||||
/// \returns the instance of T which has been constructed in the external buffer.
|
||||
/// \returns the instance of T which has been constructed in the external
|
||||
/// buffer.
|
||||
//***************************************************************************
|
||||
template <typename T1>
|
||||
reference create(const T1& t1)
|
||||
{
|
||||
ETL_ASSERT(!has_value(), ETL_ERROR(etl::typed_storage_error));
|
||||
pointer p = ::new (pbuffer) value_type(t1);
|
||||
valid = true;
|
||||
valid = true;
|
||||
return *p;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Constructs the instance of T with types T1, T2
|
||||
/// \returns the instance of T which has been constructed in the external buffer.
|
||||
/// \returns the instance of T which has been constructed in the external
|
||||
/// buffer.
|
||||
//***************************************************************************
|
||||
template <typename T1, typename T2>
|
||||
reference create(const T1& t1, const T2& t2)
|
||||
{
|
||||
ETL_ASSERT(!has_value(), ETL_ERROR(etl::typed_storage_error));
|
||||
pointer p = ::new (pbuffer) value_type(t1, t2);
|
||||
valid = true;
|
||||
valid = true;
|
||||
return *p;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Constructs the instance of T with types T1, T2, T3
|
||||
/// \returns the instance of T which has been constructed in the external buffer.
|
||||
/// \returns the instance of T which has been constructed in the external
|
||||
/// buffer.
|
||||
//***************************************************************************
|
||||
template <typename T1, typename T2, typename T3>
|
||||
reference create(const T1& t1, const T2& t2, const T3& t3)
|
||||
{
|
||||
ETL_ASSERT(!has_value(), ETL_ERROR(etl::typed_storage_error));
|
||||
pointer p = ::new (pbuffer) value_type(t1, t2, t3);
|
||||
valid = true;
|
||||
valid = true;
|
||||
return *p;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Constructs the instance of T with types T1, T2, T3, T4
|
||||
/// \returns the instance of T which has been constructed in the external buffer.
|
||||
/// \returns the instance of T which has been constructed in the external
|
||||
/// buffer.
|
||||
//***************************************************************************
|
||||
template <typename T1, typename T2, typename T3, typename T4>
|
||||
reference create(const T1& t1, const T2& t2, const T3& t3, const T4& t4)
|
||||
{
|
||||
ETL_ASSERT(!has_value(), ETL_ERROR(etl::typed_storage_error));
|
||||
pointer p = ::new (pbuffer) value_type(t1, t2, t3, t4);
|
||||
valid = true;
|
||||
valid = true;
|
||||
return *p;
|
||||
}
|
||||
#endif
|
||||
@ -825,10 +843,10 @@ namespace etl
|
||||
private:
|
||||
|
||||
typed_storage_ext(etl::typed_storage_ext<T>&) ETL_DELETE;
|
||||
typed_storage_ext& operator =(etl::typed_storage_ext<T>&) ETL_DELETE;
|
||||
typed_storage_ext& operator=(etl::typed_storage_ext<T>&) ETL_DELETE;
|
||||
|
||||
pointer pbuffer;
|
||||
bool valid;
|
||||
bool valid;
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
@ -840,8 +858,8 @@ namespace etl
|
||||
using ETL_OR_STD::swap;
|
||||
|
||||
swap(lhs.pbuffer, rhs.pbuffer);
|
||||
swap(lhs.valid, rhs.valid);
|
||||
swap(lhs.valid, rhs.valid);
|
||||
}
|
||||
}
|
||||
} // namespace etl
|
||||
|
||||
#endif
|
||||
|
||||
@ -33,20 +33,20 @@ SOFTWARE.
|
||||
|
||||
#include "platform.h"
|
||||
#include "algorithm.h"
|
||||
#include "iterator.h"
|
||||
#include "functional.h"
|
||||
#include "error_handler.h"
|
||||
#include "exception.h"
|
||||
#include "type_traits.h"
|
||||
#include "functional.h"
|
||||
#include "initializer_list.h"
|
||||
#include "iterator.h"
|
||||
#include "nth_type.h"
|
||||
#include "parameter_type.h"
|
||||
#include "static_assert.h"
|
||||
#include "error_handler.h"
|
||||
#include "nth_type.h"
|
||||
#include "initializer_list.h"
|
||||
#include "type_traits.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
///\defgroup array array
|
||||
/// A replacement for std::array if you haven't got C++0x11.
|
||||
/// A replacement for std::array if you haven't got C++11.
|
||||
///\ingroup containers
|
||||
|
||||
namespace etl
|
||||
@ -81,7 +81,7 @@ namespace etl
|
||||
|
||||
//***************************************************************************
|
||||
///\ingroup array
|
||||
/// A replacement for std::array if you haven't got C++0x11.
|
||||
/// A replacement for std::array if you haven't got C++11.
|
||||
//***************************************************************************
|
||||
template <typename T, size_t SIZE_>
|
||||
class array
|
||||
@ -94,15 +94,15 @@ namespace etl
|
||||
|
||||
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 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;
|
||||
|
||||
@ -114,9 +114,7 @@ namespace etl
|
||||
/// 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_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 reference at(size_t i) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
|
||||
{
|
||||
ETL_ASSERT(i < SIZE, ETL_ERROR(array_out_of_range));
|
||||
|
||||
@ -127,9 +125,7 @@ namespace etl
|
||||
/// 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_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 const_reference at(size_t i) const ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
|
||||
{
|
||||
ETL_ASSERT(i < SIZE, ETL_ERROR(array_out_of_range));
|
||||
|
||||
@ -141,9 +137,7 @@ namespace etl
|
||||
/// 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) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS || ETL_NOT_CHECKING_INDEX_OPERATOR)
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 reference operator[](size_t i) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS || ETL_NOT_CHECKING_INDEX_OPERATOR)
|
||||
{
|
||||
ETL_ASSERT_CHECK_INDEX_OPERATOR(i < SIZE, ETL_ERROR(array_out_of_range));
|
||||
|
||||
@ -155,8 +149,7 @@ namespace etl
|
||||
/// 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 ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS || ETL_NOT_CHECKING_INDEX_OPERATOR)
|
||||
ETL_NODISCARD ETL_CONSTEXPR const_reference operator[](size_t i) const ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS || ETL_NOT_CHECKING_INDEX_OPERATOR)
|
||||
{
|
||||
// Throwing from c++11 constexpr requires special syntax
|
||||
#if ETL_USING_CPP11 && ETL_NOT_USING_CPP14 && ETL_USING_EXCEPTIONS && ETL_CHECKING_INDEX_OPERATOR
|
||||
@ -171,9 +164,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns a reference to the first element.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
reference front() ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 reference front() ETL_NOEXCEPT
|
||||
{
|
||||
ETL_STATIC_ASSERT(SIZE > 0, "Array is empty.");
|
||||
|
||||
@ -183,8 +174,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns a const reference to the first element.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR const_reference front() const ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR const_reference front() const ETL_NOEXCEPT
|
||||
{
|
||||
ETL_STATIC_ASSERT(SIZE > 0, "Array is empty.");
|
||||
|
||||
@ -194,9 +184,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns a reference to the last element.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
reference back() ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 reference back() ETL_NOEXCEPT
|
||||
{
|
||||
ETL_STATIC_ASSERT(SIZE > 0, "Array is empty.");
|
||||
|
||||
@ -206,8 +194,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns a const reference to the last element.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR const_reference back() const ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR const_reference back() const ETL_NOEXCEPT
|
||||
{
|
||||
ETL_STATIC_ASSERT(SIZE > 0, "Array is empty.");
|
||||
|
||||
@ -217,9 +204,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns a pointer to the first element of the internal buffer.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
pointer data() ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 pointer data() ETL_NOEXCEPT
|
||||
{
|
||||
return _buffer;
|
||||
}
|
||||
@ -227,8 +212,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns a const pointer to the first element of the internal buffer.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR const_pointer data() const ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR const_pointer data() const ETL_NOEXCEPT
|
||||
{
|
||||
return _buffer;
|
||||
}
|
||||
@ -240,9 +224,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns an iterator to the beginning of the array.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
iterator begin() ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 iterator begin() ETL_NOEXCEPT
|
||||
{
|
||||
return _buffer;
|
||||
}
|
||||
@ -250,8 +232,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns a const iterator to the beginning of the array.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR const_iterator begin() const ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR const_iterator begin() const ETL_NOEXCEPT
|
||||
{
|
||||
return _buffer;
|
||||
}
|
||||
@ -259,8 +240,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns a const iterator to the beginning of the array.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR const_iterator cbegin() const ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR const_iterator cbegin() const ETL_NOEXCEPT
|
||||
{
|
||||
return begin();
|
||||
}
|
||||
@ -268,9 +248,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns an iterator to the end of the array.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
iterator end() ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 iterator end() ETL_NOEXCEPT
|
||||
{
|
||||
return _buffer + SIZE;
|
||||
}
|
||||
@ -278,8 +256,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns a const iterator to the end of the array.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR const_iterator end() const ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR const_iterator end() const ETL_NOEXCEPT
|
||||
{
|
||||
return _buffer + SIZE;
|
||||
}
|
||||
@ -287,8 +264,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
// Returns a const iterator to the end of the array.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR const_iterator cend() const ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR const_iterator cend() const ETL_NOEXCEPT
|
||||
{
|
||||
return _buffer + SIZE;
|
||||
}
|
||||
@ -296,9 +272,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
// Returns an reverse iterator to the reverse beginning of the array.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
reverse_iterator rbegin() ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 reverse_iterator rbegin() ETL_NOEXCEPT
|
||||
{
|
||||
return reverse_iterator(end());
|
||||
}
|
||||
@ -306,8 +280,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns a const reverse iterator to the reverse beginning of the array.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR const_reverse_iterator rbegin() const ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR const_reverse_iterator rbegin() const ETL_NOEXCEPT
|
||||
{
|
||||
return const_reverse_iterator(end());
|
||||
}
|
||||
@ -315,8 +288,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns a const reverse iterator to the reverse beginning of the array.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR const_reverse_iterator crbegin() const ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR const_reverse_iterator crbegin() const ETL_NOEXCEPT
|
||||
{
|
||||
return const_reverse_iterator(end());
|
||||
}
|
||||
@ -324,9 +296,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns a reverse iterator to the end of the array.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
reverse_iterator rend() ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 reverse_iterator rend() ETL_NOEXCEPT
|
||||
{
|
||||
return reverse_iterator(begin());
|
||||
}
|
||||
@ -334,8 +304,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns a const reverse iterator to the end of the array.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR const_reverse_iterator rend() const ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR const_reverse_iterator rend() const ETL_NOEXCEPT
|
||||
{
|
||||
return const_reverse_iterator(begin());
|
||||
}
|
||||
@ -343,8 +312,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns a const reverse iterator to the end of the array.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR const_reverse_iterator crend() const ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR const_reverse_iterator crend() const ETL_NOEXCEPT
|
||||
{
|
||||
return const_reverse_iterator(begin());
|
||||
}
|
||||
@ -356,8 +324,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns <b>true</b> if the array size is zero.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR bool empty() const ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR bool empty() const ETL_NOEXCEPT
|
||||
{
|
||||
return (SIZE == 0);
|
||||
}
|
||||
@ -365,8 +332,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns the size of the array.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR size_t size() const ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR size_t size() const ETL_NOEXCEPT
|
||||
{
|
||||
return SIZE;
|
||||
}
|
||||
@ -374,8 +340,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns the maximum possible size of the array.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR size_t max_size() const ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR size_t max_size() const ETL_NOEXCEPT
|
||||
{
|
||||
return SIZE;
|
||||
}
|
||||
@ -409,7 +374,8 @@ namespace etl
|
||||
|
||||
//*************************************************************************
|
||||
/// Fills the array from the range.
|
||||
/// If the range is smaller than the array then the unused array elements are left unmodified.
|
||||
/// 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().
|
||||
@ -422,7 +388,8 @@ namespace etl
|
||||
|
||||
//*************************************************************************
|
||||
/// 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.
|
||||
/// 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().
|
||||
@ -496,13 +463,13 @@ namespace etl
|
||||
iterator p = to_iterator(position);
|
||||
iterator result(p);
|
||||
|
||||
size_t source_size = etl::distance(first, last);
|
||||
size_t destination_space = etl::distance(position, cend());
|
||||
size_t source_size = static_cast<size_t>(etl::distance(first, last));
|
||||
size_t destination_space = static_cast<size_t>(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);
|
||||
size_t length = SIZE - (static_cast<size_t>(etl::distance(begin(), p)) + source_size);
|
||||
etl::move_backward(p, p + length, end());
|
||||
}
|
||||
|
||||
@ -570,7 +537,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// 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.
|
||||
///\param value The value to use to overwrite the last element in the
|
||||
/// array.
|
||||
//*************************************************************************
|
||||
inline iterator erase_at(size_t position, parameter_t value)
|
||||
{
|
||||
@ -582,7 +550,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// 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.
|
||||
///\param value The value to use to overwrite the last element in the
|
||||
/// array.
|
||||
//*************************************************************************
|
||||
iterator erase(const_iterator position, parameter_t value)
|
||||
{
|
||||
@ -600,7 +569,8 @@ namespace etl
|
||||
/// 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.
|
||||
///\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)
|
||||
{
|
||||
@ -613,7 +583,8 @@ namespace etl
|
||||
/// 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.
|
||||
///\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)
|
||||
{
|
||||
@ -646,7 +617,7 @@ namespace etl
|
||||
|
||||
//***************************************************************************
|
||||
///\ingroup array
|
||||
/// A replacement for std::array if you haven't got C++0x11.
|
||||
/// A replacement for std::array if you haven't got C++11.
|
||||
/// Specialisation for zero sized array.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
@ -660,15 +631,15 @@ namespace etl
|
||||
|
||||
static ETL_CONSTANT size_t SIZE = 0;
|
||||
|
||||
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 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;
|
||||
|
||||
@ -680,9 +651,7 @@ namespace etl
|
||||
/// 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) ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 reference at(size_t) ETL_NOEXCEPT
|
||||
{
|
||||
return *data();
|
||||
}
|
||||
@ -691,9 +660,7 @@ namespace etl
|
||||
/// 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) const ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 const_reference at(size_t) const ETL_NOEXCEPT
|
||||
{
|
||||
return *data();
|
||||
}
|
||||
@ -703,9 +670,7 @@ namespace etl
|
||||
/// 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) ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 reference operator[](size_t) ETL_NOEXCEPT
|
||||
{
|
||||
return *data();
|
||||
}
|
||||
@ -715,8 +680,7 @@ namespace etl
|
||||
/// 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) const ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR const_reference operator[](size_t) const ETL_NOEXCEPT
|
||||
{
|
||||
return *data();
|
||||
}
|
||||
@ -724,9 +688,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns a reference to the first element.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
reference front() ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 reference front() ETL_NOEXCEPT
|
||||
{
|
||||
return *data();
|
||||
}
|
||||
@ -734,8 +696,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns a const reference to the first element.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR const_reference front() const ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR const_reference front() const ETL_NOEXCEPT
|
||||
{
|
||||
return *data();
|
||||
}
|
||||
@ -743,9 +704,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns a reference to the last element.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
reference back() ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 reference back() ETL_NOEXCEPT
|
||||
{
|
||||
return *data();
|
||||
}
|
||||
@ -753,8 +712,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns a const reference to the last element.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR const_reference back() const
|
||||
ETL_NODISCARD ETL_CONSTEXPR const_reference back() const
|
||||
{
|
||||
return *data();
|
||||
}
|
||||
@ -762,9 +720,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns a pointer to the first element of the internal buffer.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
pointer data() ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 pointer data() ETL_NOEXCEPT
|
||||
{
|
||||
return (T*)0;
|
||||
}
|
||||
@ -772,8 +728,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns a const pointer to the first element of the internal buffer.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR const_pointer data() const ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR const_pointer data() const ETL_NOEXCEPT
|
||||
{
|
||||
return (const T*)0;
|
||||
}
|
||||
@ -785,9 +740,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns an iterator to the beginning of the array.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
iterator begin() ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 iterator begin() ETL_NOEXCEPT
|
||||
{
|
||||
return iterator();
|
||||
}
|
||||
@ -795,8 +748,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns a const iterator to the beginning of the array.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR const_iterator begin() const ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR const_iterator begin() const ETL_NOEXCEPT
|
||||
{
|
||||
return const_iterator();
|
||||
}
|
||||
@ -804,8 +756,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns a const iterator to the beginning of the array.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR const_iterator cbegin() const ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR const_iterator cbegin() const ETL_NOEXCEPT
|
||||
{
|
||||
return const_iterator();
|
||||
}
|
||||
@ -813,9 +764,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns an iterator to the end of the array.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
iterator end() ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 iterator end() ETL_NOEXCEPT
|
||||
{
|
||||
return iterator();
|
||||
}
|
||||
@ -823,8 +772,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns a const iterator to the end of the array.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR const_iterator end() const ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR const_iterator end() const ETL_NOEXCEPT
|
||||
{
|
||||
return const_iterator();
|
||||
}
|
||||
@ -832,8 +780,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
// Returns a const iterator to the end of the array.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR const_iterator cend() const ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR const_iterator cend() const ETL_NOEXCEPT
|
||||
{
|
||||
return const_iterator();
|
||||
}
|
||||
@ -841,9 +788,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
// Returns an reverse iterator to the reverse beginning of the array.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
reverse_iterator rbegin() ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 reverse_iterator rbegin() ETL_NOEXCEPT
|
||||
{
|
||||
return reverse_iterator(end());
|
||||
}
|
||||
@ -851,8 +796,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns a const reverse iterator to the reverse beginning of the array.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR const_reverse_iterator rbegin() const ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR const_reverse_iterator rbegin() const ETL_NOEXCEPT
|
||||
{
|
||||
return const_reverse_iterator(end());
|
||||
}
|
||||
@ -860,8 +804,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns a const reverse iterator to the reverse beginning of the array.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR const_reverse_iterator crbegin() const ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR const_reverse_iterator crbegin() const ETL_NOEXCEPT
|
||||
{
|
||||
return const_reverse_iterator(end());
|
||||
}
|
||||
@ -869,9 +812,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns a reverse iterator to the end of the array.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
reverse_iterator rend() ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 reverse_iterator rend() ETL_NOEXCEPT
|
||||
{
|
||||
return reverse_iterator(begin());
|
||||
}
|
||||
@ -879,8 +820,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns a const reverse iterator to the end of the array.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR const_reverse_iterator rend() const ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR const_reverse_iterator rend() const ETL_NOEXCEPT
|
||||
{
|
||||
return const_reverse_iterator(begin());
|
||||
}
|
||||
@ -888,8 +828,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns a const reverse iterator to the end of the array.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR const_reverse_iterator crend() const ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR const_reverse_iterator crend() const ETL_NOEXCEPT
|
||||
{
|
||||
return const_reverse_iterator(begin());
|
||||
}
|
||||
@ -901,8 +840,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns <b>true</b> if the array size is zero.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR bool empty() const ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR bool empty() const ETL_NOEXCEPT
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -910,8 +848,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns the size of the array.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR size_t size() const ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR size_t size() const ETL_NOEXCEPT
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@ -919,8 +856,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns the maximum possible size of the array.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR size_t max_size() const ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR size_t max_size() const ETL_NOEXCEPT
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@ -947,7 +883,8 @@ namespace etl
|
||||
|
||||
//*************************************************************************
|
||||
/// Fills the array from the range.
|
||||
/// If the range is smaller than the array then the unused array elements are left unmodified.
|
||||
/// 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().
|
||||
@ -960,7 +897,8 @@ namespace etl
|
||||
|
||||
//*************************************************************************
|
||||
/// 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.
|
||||
/// 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().
|
||||
@ -1060,7 +998,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// 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.
|
||||
///\param value The value to use to overwrite the last element in the
|
||||
/// array.
|
||||
//*************************************************************************
|
||||
inline iterator erase_at(size_t, parameter_t) ETL_NOEXCEPT
|
||||
{
|
||||
@ -1070,7 +1009,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// 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.
|
||||
///\param value The value to use to overwrite the last element in the
|
||||
/// array.
|
||||
//*************************************************************************
|
||||
iterator erase(const_iterator, parameter_t) ETL_NOEXCEPT
|
||||
{
|
||||
@ -1081,7 +1021,8 @@ namespace etl
|
||||
/// 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.
|
||||
///\param value The value to use to overwrite the last elements in the
|
||||
/// array.
|
||||
//*************************************************************************
|
||||
iterator erase_range(size_t, size_t, parameter_t) ETL_NOEXCEPT
|
||||
{
|
||||
@ -1091,7 +1032,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// 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.
|
||||
///\param value The value to use to overwrite the last elements in the
|
||||
/// array.
|
||||
//*************************************************************************
|
||||
iterator erase(const_iterator, const_iterator, parameter_t) ETL_NOEXCEPT
|
||||
{
|
||||
@ -1105,7 +1047,7 @@ namespace etl
|
||||
#if ETL_USING_CPP17
|
||||
template <typename... T>
|
||||
array(T...) -> array<typename etl::common_type<T...>::type, sizeof...(T)>;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
/// Make
|
||||
@ -1114,7 +1056,7 @@ namespace etl
|
||||
template <typename T, typename... TValues>
|
||||
constexpr auto make_array(TValues&&... values) ETL_NOEXCEPT -> etl::array<T, sizeof...(TValues)>
|
||||
{
|
||||
return { etl::forward<T>(values)... };
|
||||
return {etl::forward<T>(values)...};
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -1124,7 +1066,7 @@ namespace etl
|
||||
///\param rhs The second array.
|
||||
//*************************************************************************
|
||||
template <typename T, const size_t SIZE>
|
||||
void swap(etl::array<T, SIZE> &lhs, etl::array<T, SIZE> &rhs)
|
||||
void swap(etl::array<T, SIZE>& lhs, etl::array<T, SIZE>& rhs)
|
||||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
@ -1136,7 +1078,7 @@ namespace etl
|
||||
///\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)
|
||||
ETL_CONSTEXPR14 bool operator==(const etl::array<T, SIZE>& lhs, const etl::array<T, SIZE>& rhs)
|
||||
{
|
||||
return etl::equal(lhs.cbegin(), lhs.cend(), rhs.cbegin());
|
||||
}
|
||||
@ -1148,7 +1090,7 @@ namespace etl
|
||||
///\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)
|
||||
ETL_CONSTEXPR14 bool operator!=(const etl::array<T, SIZE>& lhs, const etl::array<T, SIZE>& rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
@ -1157,25 +1099,25 @@ namespace etl
|
||||
/// 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>
|
||||
///\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)
|
||||
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());
|
||||
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>
|
||||
///\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)
|
||||
bool operator<=(const etl::array<T, SIZE>& lhs, const etl::array<T, SIZE>& rhs)
|
||||
{
|
||||
return !(lhs > rhs);
|
||||
}
|
||||
@ -1184,10 +1126,11 @@ namespace etl
|
||||
/// 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>
|
||||
///\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)
|
||||
bool operator>(const etl::array<T, SIZE>& lhs, const etl::array<T, SIZE>& rhs)
|
||||
{
|
||||
return (rhs < lhs);
|
||||
}
|
||||
@ -1196,10 +1139,12 @@ namespace etl
|
||||
/// 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>
|
||||
///\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)
|
||||
bool operator>=(const etl::array<T, SIZE>& lhs, const etl::array<T, SIZE>& rhs)
|
||||
{
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
@ -1233,6 +1178,6 @@ namespace etl
|
||||
ETL_STATIC_ASSERT(Index < Size, "Index out of bounds");
|
||||
return a[Index];
|
||||
}
|
||||
}
|
||||
} // namespace etl
|
||||
|
||||
#endif
|
||||
|
||||
@ -32,18 +32,18 @@ SOFTWARE.
|
||||
#define ETL_ARRAY_VIEW_INCLUDED
|
||||
|
||||
#include "platform.h"
|
||||
#include "memory.h"
|
||||
#include "algorithm.h"
|
||||
#include "array.h"
|
||||
#include "iterator.h"
|
||||
#include "error_handler.h"
|
||||
#include "exception.h"
|
||||
#include "nullptr.h"
|
||||
#include "hash.h"
|
||||
#include "algorithm.h"
|
||||
#include "iterator.h"
|
||||
#include "memory.h"
|
||||
#include "nullptr.h"
|
||||
#include "type_traits.h"
|
||||
|
||||
#if ETL_USING_STL && ETL_USING_CPP11
|
||||
#include <array>
|
||||
#include <array>
|
||||
#endif
|
||||
|
||||
///\defgroup array array
|
||||
@ -93,6 +93,19 @@ namespace etl
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
/// The exception thrown when the view is empty.
|
||||
//***************************************************************************
|
||||
class array_view_empty : public array_view_exception
|
||||
{
|
||||
public:
|
||||
|
||||
array_view_empty(string_type file_name_, numeric_type line_number_)
|
||||
: array_view_exception(ETL_ERROR_TEXT("array_view:empty", ETL_ARRAY_VIEW_FILE_ID"C"), file_name_, line_number_)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
/// Array view.
|
||||
//***************************************************************************
|
||||
@ -101,22 +114,22 @@ namespace etl
|
||||
{
|
||||
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 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 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_pointer pointer;
|
||||
typedef const_reference reference;
|
||||
typedef const_pointer iterator;
|
||||
typedef const_reverse_iterator reverse_iterator;
|
||||
#endif
|
||||
|
||||
@ -124,8 +137,8 @@ namespace etl
|
||||
/// Default constructor.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR array_view() ETL_NOEXCEPT
|
||||
: mbegin(ETL_NULLPTR),
|
||||
mend(ETL_NULLPTR)
|
||||
: mbegin(ETL_NULLPTR)
|
||||
, mend(ETL_NULLPTR)
|
||||
{
|
||||
}
|
||||
|
||||
@ -133,7 +146,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Construct from etl::array.
|
||||
//*************************************************************************
|
||||
template <typename U, size_t Size, typename = typename etl::enable_if<etl::is_same<etl::remove_cv_t<T>, etl::remove_cv_t<U>>::value, void>::type>
|
||||
template < typename U, size_t Size,
|
||||
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, Size>& a) ETL_NOEXCEPT
|
||||
: mbegin(a.data())
|
||||
, mend(a.data() + a.size())
|
||||
@ -143,7 +157,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Construct from etl::array.
|
||||
//*************************************************************************
|
||||
template <typename U, size_t Size, typename = typename etl::enable_if<etl::is_same<etl::remove_cv_t<T>, etl::remove_cv_t<U>>::value, void>::type>
|
||||
template < typename U, size_t Size,
|
||||
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, Size>& a) ETL_NOEXCEPT
|
||||
: mbegin(a.data())
|
||||
, mend(a.data() + a.size())
|
||||
@ -154,7 +169,9 @@ namespace etl
|
||||
/// Construct from etl::array.
|
||||
//*************************************************************************
|
||||
template <typename U, size_t Size>
|
||||
ETL_CONSTEXPR array_view(etl::array<U, Size>& 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
|
||||
ETL_CONSTEXPR array_view(
|
||||
etl::array<U, Size>& 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())
|
||||
{
|
||||
@ -164,7 +181,9 @@ namespace etl
|
||||
/// Construct from etl::array.
|
||||
//*************************************************************************
|
||||
template <typename U, size_t Size>
|
||||
ETL_CONSTEXPR array_view(const etl::array<U, Size>& 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
|
||||
ETL_CONSTEXPR array_view(
|
||||
const etl::array<U, Size>& 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())
|
||||
{
|
||||
@ -175,7 +194,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Construct from std::array.
|
||||
//*************************************************************************
|
||||
template <typename U, size_t Size, typename = typename etl::enable_if<etl::is_same<etl::remove_cv_t<T>, etl::remove_cv_t<U>>::value, void>::type>
|
||||
template < typename U, size_t Size,
|
||||
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, Size>& a) ETL_NOEXCEPT
|
||||
: mbegin(a.data())
|
||||
, mend(a.data() + a.size())
|
||||
@ -185,7 +205,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Construct from std::array.
|
||||
//*************************************************************************
|
||||
template <typename U, size_t Size, typename = typename etl::enable_if<etl::is_same<etl::remove_cv_t<T>, etl::remove_cv_t<U>>::value, void>::type>
|
||||
template < typename U, size_t Size,
|
||||
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, Size>& a) ETL_NOEXCEPT
|
||||
: mbegin(a.data())
|
||||
, mend(a.data() + a.size())
|
||||
@ -198,10 +219,12 @@ namespace etl
|
||||
/// 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
|
||||
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())
|
||||
{
|
||||
@ -212,9 +235,12 @@ namespace etl
|
||||
/// 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
|
||||
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())
|
||||
{
|
||||
@ -225,9 +251,12 @@ namespace etl
|
||||
/// 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
|
||||
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())
|
||||
{
|
||||
@ -239,29 +268,28 @@ namespace etl
|
||||
//*************************************************************************
|
||||
template <typename TIterator>
|
||||
ETL_CONSTEXPR array_view(const TIterator begin_, const TIterator end_) ETL_NOEXCEPT
|
||||
: mbegin(etl::to_address(begin_)),
|
||||
mend(etl::to_address(begin_) + etl::distance(begin_, end_))
|
||||
: mbegin(etl::to_address(begin_))
|
||||
, mend(etl::to_address(begin_) + etl::distance(begin_, end_))
|
||||
{
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Construct from iterator and size
|
||||
//*************************************************************************
|
||||
template <typename TIterator,
|
||||
typename TSize>
|
||||
template <typename TIterator, typename TSize>
|
||||
ETL_CONSTEXPR array_view(const TIterator begin_, const TSize size_) ETL_NOEXCEPT
|
||||
: mbegin(etl::to_address(begin_)),
|
||||
mend(etl::to_address(begin_) + size_)
|
||||
: mbegin(etl::to_address(begin_))
|
||||
, mend(etl::to_address(begin_) + size_)
|
||||
{
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Construct from C array
|
||||
//*************************************************************************
|
||||
template<size_t Array_Size>
|
||||
ETL_CONSTEXPR array_view(T(&begin_)[Array_Size]) ETL_NOEXCEPT
|
||||
: mbegin(begin_),
|
||||
mend(begin_ + Array_Size)
|
||||
template <size_t Array_Size>
|
||||
ETL_CONSTEXPR array_view(T (&begin_)[Array_Size]) ETL_NOEXCEPT
|
||||
: mbegin(begin_)
|
||||
, mend(begin_ + Array_Size)
|
||||
{
|
||||
}
|
||||
|
||||
@ -269,40 +297,52 @@ namespace etl
|
||||
/// Copy constructor
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR array_view(const array_view& other) ETL_NOEXCEPT
|
||||
: mbegin(other.mbegin),
|
||||
mend(other.mend)
|
||||
: mbegin(other.mbegin)
|
||||
, mend(other.mend)
|
||||
{
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a reference to the first element.
|
||||
/// If asserts or exceptions are enabled, throws an etl::array_view_empty if
|
||||
/// the view is empty.
|
||||
//*************************************************************************
|
||||
reference front()
|
||||
{
|
||||
ETL_ASSERT_CHECK_EXTRA(!empty(), ETL_ERROR(array_view_empty));
|
||||
return *mbegin;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a const reference to the first element.
|
||||
/// If asserts or exceptions are enabled, throws an etl::array_view_empty if
|
||||
/// the view is empty.
|
||||
//*************************************************************************
|
||||
const_reference front() const
|
||||
{
|
||||
ETL_ASSERT_CHECK_EXTRA(!empty(), ETL_ERROR(array_view_empty));
|
||||
return *mbegin;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a reference to the last element.
|
||||
/// If asserts or exceptions are enabled, throws an etl::array_view_empty if
|
||||
/// the view is empty.
|
||||
//*************************************************************************
|
||||
reference back()
|
||||
{
|
||||
ETL_ASSERT_CHECK_EXTRA(!empty(), ETL_ERROR(array_view_empty));
|
||||
return *(mend - 1);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a const reference to the last element.
|
||||
/// If asserts or exceptions are enabled, throws an etl::array_view_empty if
|
||||
/// the view is empty.
|
||||
//*************************************************************************
|
||||
const_reference back() const
|
||||
{
|
||||
ETL_ASSERT_CHECK_EXTRA(!empty(), ETL_ERROR(array_view_empty));
|
||||
return *(mend - 1);
|
||||
}
|
||||
|
||||
@ -465,8 +505,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Assign from iterator and size.
|
||||
//*************************************************************************
|
||||
template <typename TIterator,
|
||||
typename TSize>
|
||||
template <typename TIterator, typename TSize>
|
||||
void assign(const TIterator begin_, const TSize size_)
|
||||
{
|
||||
mbegin = etl::to_address(begin_);
|
||||
@ -476,18 +515,26 @@ namespace etl
|
||||
#if defined(ETL_ARRAY_VIEW_IS_MUTABLE)
|
||||
//*************************************************************************
|
||||
/// Returns a reference to the indexed value.
|
||||
/// If asserts or exceptions are enabled, throws an etl::array_view_bounds
|
||||
/// if the index is out of bounds.
|
||||
//*************************************************************************
|
||||
reference operator[](const size_t i) ETL_NOEXCEPT
|
||||
reference operator[](const size_t i) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS || ETL_NOT_CHECKING_INDEX_OPERATOR)
|
||||
{
|
||||
ETL_ASSERT_CHECK_INDEX_OPERATOR(i < size(), ETL_ERROR(array_view_bounds));
|
||||
|
||||
return mbegin[i];
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a const reference to the indexed value.
|
||||
/// If asserts or exceptions are enabled, throws an etl::array_view_bounds
|
||||
/// if the index is out of bounds.
|
||||
//*************************************************************************
|
||||
const_reference operator[](const size_t i) const ETL_NOEXCEPT
|
||||
const_reference operator[](const size_t i) const ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS || ETL_NOT_CHECKING_INDEX_OPERATOR)
|
||||
{
|
||||
ETL_ASSERT_CHECK_INDEX_OPERATOR(i < size(), ETL_ERROR(array_view_bounds));
|
||||
|
||||
return mbegin[i];
|
||||
}
|
||||
|
||||
@ -529,10 +576,10 @@ namespace etl
|
||||
//*************************************************************************
|
||||
void remove_prefix(const size_type n) ETL_NOEXCEPT
|
||||
{
|
||||
if (n < size())
|
||||
mbegin += n;
|
||||
else
|
||||
mbegin = mend;
|
||||
if (n < size())
|
||||
mbegin += n;
|
||||
else
|
||||
mbegin = mend;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -540,10 +587,10 @@ namespace etl
|
||||
//*************************************************************************
|
||||
void remove_suffix(const size_type n) ETL_NOEXCEPT
|
||||
{
|
||||
if (n < size())
|
||||
mend -= n;
|
||||
else
|
||||
mend = mbegin;
|
||||
if (n < size())
|
||||
mend -= n;
|
||||
else
|
||||
mend = mbegin;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -557,16 +604,15 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Equality for array views.
|
||||
//*************************************************************************
|
||||
friend bool operator == (const array_view<T>& lhs, const array_view<T>& rhs)
|
||||
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());
|
||||
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)
|
||||
friend bool operator!=(const array_view<T>& lhs, const array_view<T>& rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
@ -574,7 +620,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Less-than for array views.
|
||||
//*************************************************************************
|
||||
friend bool operator < (const array_view<T>& lhs, const array_view<T>& rhs)
|
||||
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());
|
||||
}
|
||||
@ -582,7 +628,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Greater-than for array views.
|
||||
//*************************************************************************
|
||||
friend bool operator > (const array_view<T>& lhs, const array_view<T>& rhs)
|
||||
friend bool operator>(const array_view<T>& lhs, const array_view<T>& rhs)
|
||||
{
|
||||
return rhs < lhs;
|
||||
}
|
||||
@ -590,7 +636,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Less-than-equal for array views.
|
||||
//*************************************************************************
|
||||
friend bool operator <= (const array_view<T>& lhs, const array_view<T>& rhs)
|
||||
friend bool operator<=(const array_view<T>& lhs, const array_view<T>& rhs)
|
||||
{
|
||||
return !(lhs > rhs);
|
||||
}
|
||||
@ -598,7 +644,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Greater-than-equal for array views.
|
||||
//*************************************************************************
|
||||
friend bool operator >= (const array_view<T>& lhs, const array_view<T>& rhs)
|
||||
friend bool operator>=(const array_view<T>& lhs, const array_view<T>& rhs)
|
||||
{
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
@ -614,18 +660,14 @@ namespace etl
|
||||
//*************************************************************************
|
||||
#if ETL_USING_CPP17
|
||||
template <typename TArray>
|
||||
array_view(TArray& a)
|
||||
-> array_view<typename TArray::value_type>;
|
||||
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>>;
|
||||
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
|
||||
template <typename TIterator, typename TSize>
|
||||
array_view(const TIterator begin_, const TSize size_) -> array_view<etl::remove_pointer_t<TIterator>>;
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
/// Hash function.
|
||||
@ -641,7 +683,7 @@ namespace etl
|
||||
}
|
||||
};
|
||||
#endif
|
||||
}
|
||||
} // namespace etl
|
||||
|
||||
//*************************************************************************
|
||||
/// Swaps the values.
|
||||
|
||||
@ -32,12 +32,12 @@ SOFTWARE.
|
||||
#define ETL_ARRAY_WRAPPER_INCLUDED
|
||||
|
||||
#include "platform.h"
|
||||
#include "iterator.h"
|
||||
#include "algorithm.h"
|
||||
#include "error_handler.h"
|
||||
#include "exception.h"
|
||||
#include "hash.h"
|
||||
#include "iterator.h"
|
||||
#include "parameter_type.h"
|
||||
#include "algorithm.h"
|
||||
|
||||
///\defgroup array array
|
||||
/// A wrapper for arrays
|
||||
@ -75,19 +75,19 @@ namespace etl
|
||||
//***************************************************************************
|
||||
/// Array wrapper.
|
||||
//***************************************************************************
|
||||
template <typename T, size_t SIZE_, T(&ARRAY_)[SIZE_]>
|
||||
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 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;
|
||||
|
||||
@ -268,18 +268,29 @@ namespace etl
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a reference to the indexed value.
|
||||
/// If asserts or exceptions are enabled, throws an
|
||||
/// etl::array_wrapper_bounds if the index is out of bounds.
|
||||
//*************************************************************************
|
||||
reference operator[](size_t i) ETL_NOEXCEPT
|
||||
reference operator[](size_t i) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS || ETL_NOT_CHECKING_INDEX_OPERATOR)
|
||||
{
|
||||
ETL_ASSERT_CHECK_INDEX_OPERATOR(i < SIZE, ETL_ERROR(etl::array_wrapper_bounds));
|
||||
return ARRAY_[i];
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns a const reference to the indexed value.
|
||||
/// If asserts or exceptions are enabled, throws an
|
||||
/// etl::array_wrapper_bounds if the index is out of bounds.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR const_reference operator[](size_t i) const ETL_NOEXCEPT
|
||||
ETL_CONSTEXPR const_reference operator[](size_t i) const ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS || ETL_NOT_CHECKING_INDEX_OPERATOR)
|
||||
{
|
||||
// Throwing from c++11 constexpr requires special syntax
|
||||
#if ETL_USING_CPP11 && ETL_NOT_USING_CPP14 && ETL_USING_EXCEPTIONS && ETL_CHECKING_INDEX_OPERATOR
|
||||
return i < SIZE ? ARRAY_[i] : throw(ETL_ERROR(etl::array_wrapper_bounds));
|
||||
#else
|
||||
ETL_ASSERT_CHECK_INDEX_OPERATOR(i < SIZE, ETL_ERROR(etl::array_wrapper_bounds));
|
||||
return ARRAY_[i];
|
||||
#endif
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -311,9 +322,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// 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)
|
||||
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
|
||||
|
||||
@ -327,9 +337,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// 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)
|
||||
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());
|
||||
}
|
||||
@ -337,9 +346,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// 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)
|
||||
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);
|
||||
}
|
||||
@ -347,9 +355,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// 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)
|
||||
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());
|
||||
}
|
||||
@ -357,9 +364,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// 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)
|
||||
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;
|
||||
}
|
||||
@ -367,9 +373,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// 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)
|
||||
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);
|
||||
}
|
||||
@ -377,9 +382,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// 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)
|
||||
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);
|
||||
}
|
||||
@ -388,7 +392,7 @@ namespace etl
|
||||
/// Hash function.
|
||||
//*************************************************************************
|
||||
#if ETL_USING_8BIT_TYPES
|
||||
template <typename T, size_t SIZE, T(&ARRAY)[SIZE]>
|
||||
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
|
||||
@ -400,19 +404,17 @@ namespace etl
|
||||
}
|
||||
};
|
||||
#endif
|
||||
}
|
||||
} // namespace etl
|
||||
|
||||
//*************************************************************************
|
||||
/// 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)
|
||||
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>
|
||||
#define ETL_ARRAY_WRAPPER(arraytype, arrayobject) etl::array_wrapper<arraytype, ETL_ARRAY_SIZE(arrayobject), arrayobject>
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@ -32,7 +32,7 @@ SOFTWARE.
|
||||
#include "platform.h"
|
||||
|
||||
#if ETL_HAS_ATOMIC
|
||||
#if (ETL_USING_CPP11 && (ETL_USING_STL || defined(ETL_IN_UNIT_TEST)))
|
||||
#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"
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -30,8 +30,8 @@ SOFTWARE.
|
||||
#define ETL_ATOMIC_STD_INCLUDED
|
||||
|
||||
#include "../platform.h"
|
||||
#include "../nullptr.h"
|
||||
#include "../char_traits.h"
|
||||
#include "../nullptr.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <stdint.h>
|
||||
@ -55,39 +55,39 @@ namespace etl
|
||||
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>;
|
||||
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>;
|
||||
using atomic_char16_t = std::atomic<char16_t>;
|
||||
#endif
|
||||
#if ETL_HAS_NATIVE_CHAR32_T
|
||||
using atomic_char32_t = std::atomic<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>;
|
||||
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>;
|
||||
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>;
|
||||
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>;
|
||||
@ -99,22 +99,22 @@ namespace etl
|
||||
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>;
|
||||
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>;
|
||||
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>;
|
||||
}
|
||||
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>;
|
||||
} // namespace etl
|
||||
|
||||
#endif
|
||||
|
||||
@ -27,27 +27,29 @@ SOFTWARE.
|
||||
#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 "error_handler.h"
|
||||
#include "exception.h"
|
||||
#include "integral_limits.h"
|
||||
#include "static_assert.h"
|
||||
#include "type_traits.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
|
||||
**************************************************************************************************************************************************************************/
|
||||
* 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
|
||||
{
|
||||
@ -114,8 +116,8 @@ namespace etl
|
||||
{
|
||||
enum enum_type
|
||||
{
|
||||
//RFC_1421, // Not implemented
|
||||
//RFC_2045, // Not implemented
|
||||
// RFC_1421, // Not implemented
|
||||
// RFC_2045, // Not implemented
|
||||
RFC_2152,
|
||||
RFC_3501,
|
||||
RFC_4648,
|
||||
@ -125,8 +127,8 @@ namespace etl
|
||||
};
|
||||
|
||||
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_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")
|
||||
@ -166,16 +168,14 @@ namespace etl
|
||||
|
||||
enum
|
||||
{
|
||||
Invalid_Data = etl::integral_limits<int>::max,
|
||||
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_)
|
||||
ETL_CONSTEXPR14 base64(const char* encoder_table_, bool use_padding_)
|
||||
: encoder_table(encoder_table_)
|
||||
, use_padding(use_padding_)
|
||||
{
|
||||
@ -184,9 +184,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
// Character set for RFC-1421, RFC-2045, RFC-2152 and RFC-4648
|
||||
//*************************************************************************
|
||||
static
|
||||
ETL_CONSTEXPR14
|
||||
const char* character_set_1()
|
||||
static ETL_CONSTEXPR14 const char* character_set_1()
|
||||
{
|
||||
return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||
}
|
||||
@ -194,9 +192,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
// Character set for RFC-4648-URL
|
||||
//*************************************************************************
|
||||
static
|
||||
ETL_CONSTEXPR14
|
||||
const char* character_set_2()
|
||||
static ETL_CONSTEXPR14 const char* character_set_2()
|
||||
{
|
||||
return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
||||
}
|
||||
@ -204,9 +200,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
// Character set for RFC-3501-URL
|
||||
//*************************************************************************
|
||||
static
|
||||
ETL_CONSTEXPR14
|
||||
const char* character_set_3()
|
||||
static ETL_CONSTEXPR14 const char* character_set_3()
|
||||
{
|
||||
return "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+,";
|
||||
}
|
||||
@ -214,5 +208,5 @@ namespace etl
|
||||
const char* encoder_table;
|
||||
const bool use_padding;
|
||||
};
|
||||
}
|
||||
} // namespace etl
|
||||
#endif
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
//*************************************************************************
|
||||
///Decode from Base64 from and to pointer/length
|
||||
/// Decode from Base64 from and to pointer/length
|
||||
//*************************************************************************///\file
|
||||
|
||||
/******************************************************************************
|
||||
@ -29,16 +29,16 @@ SOFTWARE.
|
||||
#define ETL_BASE64_DECODER_INCLUDED
|
||||
|
||||
#include "platform.h"
|
||||
#include "static_assert.h"
|
||||
#include "error_handler.h"
|
||||
#include "type_traits.h"
|
||||
#include "binary.h"
|
||||
#include "algorithm.h"
|
||||
#include "binary.h"
|
||||
#include "delegate.h"
|
||||
#include "enum_type.h"
|
||||
#include "error_handler.h"
|
||||
#include "integral_limits.h"
|
||||
#include "iterator.h"
|
||||
#include "enum_type.h"
|
||||
#include "delegate.h"
|
||||
#include "span.h"
|
||||
#include "static_assert.h"
|
||||
#include "type_traits.h"
|
||||
|
||||
#include "base64.h"
|
||||
|
||||
@ -48,11 +48,12 @@ SOFTWARE.
|
||||
#include <iterator>
|
||||
#endif
|
||||
|
||||
#define ETL_IS_8_BIT_INTEGRAL(Type) (etl::is_integral<typename etl::remove_cv<Type>::type>::value && \
|
||||
(etl::integral_limits<typename etl::remove_cv<Type>::type>::bits == 8U))
|
||||
#define ETL_IS_8_BIT_INTEGRAL(Type) \
|
||||
(etl::is_integral<typename etl::remove_cv<Type>::type>::value && (etl::integral_limits<typename etl::remove_cv<Type>::type>::bits == 8U))
|
||||
|
||||
#define ETL_IS_ITERATOR_TYPE_8_BIT_INTEGRAL(Type) (etl::is_integral<typename etl::iterator_traits<typename etl::remove_cv<Type>::type>::value_type>::value && \
|
||||
(etl::integral_limits<typename etl::iterator_traits<typename etl::remove_cv<Type>::type>::value_type>::bits == 8U))
|
||||
#define ETL_IS_ITERATOR_TYPE_8_BIT_INTEGRAL(Type) \
|
||||
(etl::is_integral< typename etl::iterator_traits< typename etl::remove_cv<Type>::type>::value_type>::value \
|
||||
&& (etl::integral_limits< typename etl::iterator_traits< typename etl::remove_cv<Type>::type>::value_type>::bits == 8U))
|
||||
|
||||
namespace etl
|
||||
{
|
||||
@ -70,8 +71,7 @@ namespace etl
|
||||
/// Decode to Base64
|
||||
//*************************************************************************
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR14
|
||||
bool decode(T value)
|
||||
ETL_CONSTEXPR14 bool decode(T value)
|
||||
{
|
||||
ETL_STATIC_ASSERT(ETL_IS_8_BIT_INTEGRAL(T), "Input type must be an 8 bit integral");
|
||||
|
||||
@ -101,8 +101,7 @@ namespace etl
|
||||
/// Decode from Base64
|
||||
//*************************************************************************
|
||||
template <typename TInputIterator>
|
||||
ETL_CONSTEXPR14
|
||||
bool decode(TInputIterator input_begin, TInputIterator input_end)
|
||||
ETL_CONSTEXPR14 bool decode(TInputIterator input_begin, TInputIterator input_end)
|
||||
{
|
||||
ETL_STATIC_ASSERT(ETL_IS_ITERATOR_TYPE_8_BIT_INTEGRAL(TInputIterator), "Input type must be an 8 bit integral");
|
||||
|
||||
@ -121,8 +120,7 @@ namespace etl
|
||||
/// Decode from Base64
|
||||
//*************************************************************************
|
||||
template <typename TInputIterator>
|
||||
ETL_CONSTEXPR14
|
||||
bool decode(TInputIterator input_begin, size_t input_length)
|
||||
ETL_CONSTEXPR14 bool decode(TInputIterator input_begin, size_t input_length)
|
||||
{
|
||||
ETL_STATIC_ASSERT(ETL_IS_ITERATOR_TYPE_8_BIT_INTEGRAL(TInputIterator), "Input type must be an 8 bit integral");
|
||||
|
||||
@ -141,8 +139,7 @@ namespace etl
|
||||
/// Decode from Base64
|
||||
//*************************************************************************
|
||||
template <typename TInputIterator>
|
||||
ETL_CONSTEXPR14
|
||||
bool decode_final(TInputIterator input_begin, TInputIterator input_end)
|
||||
ETL_CONSTEXPR14 bool decode_final(TInputIterator input_begin, TInputIterator input_end)
|
||||
{
|
||||
return decode(input_begin, input_end) && flush();
|
||||
}
|
||||
@ -151,8 +148,7 @@ namespace etl
|
||||
/// Decode from Base64
|
||||
//*************************************************************************
|
||||
template <typename TInputIterator>
|
||||
ETL_CONSTEXPR14
|
||||
bool decode_final(TInputIterator input_begin, size_t input_length)
|
||||
ETL_CONSTEXPR14 bool decode_final(TInputIterator input_begin, size_t input_length)
|
||||
{
|
||||
return decode(input_begin, input_length) && flush();
|
||||
}
|
||||
@ -160,8 +156,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Flush any remaining data to the output.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14
|
||||
bool flush()
|
||||
ETL_CONSTEXPR14 bool flush()
|
||||
{
|
||||
// Encode any remaining input data.
|
||||
bool success = decode_block();
|
||||
@ -193,32 +188,28 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Reset the encoder.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14
|
||||
void restart()
|
||||
ETL_CONSTEXPR14 void restart()
|
||||
{
|
||||
reset_input_buffer();
|
||||
reset_output_buffer();
|
||||
overflow_detected = false;
|
||||
overflow_detected = false;
|
||||
invalid_data_detected = false;
|
||||
padding_received = false;
|
||||
padding_received = false;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns the beginning of the output buffer.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
const unsigned char* begin() const
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 const unsigned char* begin() const
|
||||
{
|
||||
return p_output_buffer;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// This only returns a useful value if a callback has not been set or called.
|
||||
/// This only returns a useful value if a callback has not been set or
|
||||
/// called.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
const unsigned char* end() const
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 const unsigned char* end() const
|
||||
{
|
||||
return p_output_buffer + output_buffer_length;
|
||||
}
|
||||
@ -226,30 +217,26 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns the beginning of the output buffer.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
const unsigned char* cbegin() const
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 const unsigned char* cbegin() const
|
||||
{
|
||||
return p_output_buffer;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// This only returns a useful value if a callback has not been set or called.
|
||||
/// This only returns a useful value if a callback has not been set or
|
||||
/// called.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
const unsigned char* cend() const
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 const unsigned char* cend() const
|
||||
{
|
||||
return p_output_buffer + output_buffer_length;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns the size of the output buffer.
|
||||
/// This only returns a useful value if a callback has not been set or called.
|
||||
/// This only returns a useful value if a callback has not been set or
|
||||
/// called.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
size_t size() const
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 size_t size() const
|
||||
{
|
||||
return output_buffer_length;
|
||||
}
|
||||
@ -257,20 +244,17 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns the maximum size of the output buffer.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
size_t buffer_size() const
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 size_t buffer_size() const
|
||||
{
|
||||
return output_buffer_max_size;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Get a span of the output data.
|
||||
/// This only returns a useful span if a callback has not been set or called.
|
||||
/// This only returns a useful span if a callback has not been set or
|
||||
/// called.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
span_type span() const
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 span_type span() const
|
||||
{
|
||||
return span_type(begin(), end());
|
||||
}
|
||||
@ -278,9 +262,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns true if the output buffer has overflowed
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
bool overflow() const
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 bool overflow() const
|
||||
{
|
||||
return overflow_detected;
|
||||
}
|
||||
@ -288,9 +270,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns true if an invalid character was detected.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
bool invalid_data() const
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 bool invalid_data() const
|
||||
{
|
||||
return invalid_data_detected;
|
||||
}
|
||||
@ -298,9 +278,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns true if an error was detected.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
bool error() const
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 bool error() const
|
||||
{
|
||||
return overflow() || invalid_data();
|
||||
}
|
||||
@ -310,12 +288,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Constructor
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14
|
||||
ibase64_decoder(const char* encoder_table_,
|
||||
bool use_padding_,
|
||||
unsigned char* p_output_buffer_,
|
||||
size_t ouput_buffer_max_size_,
|
||||
callback_type callback_)
|
||||
ETL_CONSTEXPR14 ibase64_decoder(const char* encoder_table_, bool use_padding_, unsigned char* p_output_buffer_, size_t ouput_buffer_max_size_,
|
||||
callback_type callback_)
|
||||
: base64(encoder_table_, use_padding_)
|
||||
, input_buffer()
|
||||
, input_buffer_length(0)
|
||||
@ -333,9 +307,7 @@ namespace etl
|
||||
/// Calculates the minimum buffer size required to decode from Base64
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
static
|
||||
ETL_CONSTEXPR14
|
||||
size_t decoded_size_from_valid_input_length(size_t input_length)
|
||||
static ETL_CONSTEXPR14 size_t decoded_size_from_valid_input_length(size_t input_length)
|
||||
{
|
||||
return input_length - (input_length / 4U);
|
||||
}
|
||||
@ -343,14 +315,13 @@ namespace etl
|
||||
private:
|
||||
|
||||
//*************************************************************************
|
||||
// Translates a sextet into an index
|
||||
// Translates a sextet into an index
|
||||
//*************************************************************************
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR14
|
||||
uint32_t get_index_from_sextet(T sextet)
|
||||
ETL_CONSTEXPR14 uint32_t get_index_from_sextet(T sextet)
|
||||
{
|
||||
const char* encoder_table_end = encoder_table + 64;
|
||||
const char* p_sextet = etl::find(encoder_table, encoder_table_end, static_cast<char>(sextet));
|
||||
const char* p_sextet = etl::find(encoder_table, encoder_table_end, static_cast<char>(sextet));
|
||||
|
||||
if (p_sextet != encoder_table_end)
|
||||
{
|
||||
@ -369,8 +340,7 @@ namespace etl
|
||||
template <typename T>
|
||||
ETL_NODISCARD
|
||||
static
|
||||
ETL_CONSTEXPR14
|
||||
T padding()
|
||||
ETL_CONSTEXPR14 T padding()
|
||||
{
|
||||
return static_cast<T>('=');
|
||||
}
|
||||
@ -378,51 +348,50 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Decode one block of data.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14
|
||||
bool decode_block()
|
||||
ETL_CONSTEXPR14 bool decode_block()
|
||||
{
|
||||
switch (input_buffer_length)
|
||||
{
|
||||
// Only triggered on call to flush().
|
||||
case 2:
|
||||
{
|
||||
uint32_t sextets = (get_index_from_sextet(input_buffer[0]) << 6);
|
||||
sextets = sextets | (get_index_from_sextet(input_buffer[1]));
|
||||
push_to_output_buffer((sextets >> 4) & 0xFF);
|
||||
break;
|
||||
}
|
||||
{
|
||||
uint32_t sextets = (get_index_from_sextet(input_buffer[0]) << 6);
|
||||
sextets = sextets | (get_index_from_sextet(input_buffer[1]));
|
||||
push_to_output_buffer((sextets >> 4) & 0xFF);
|
||||
break;
|
||||
}
|
||||
|
||||
// Only triggered on call to flush().
|
||||
case 3:
|
||||
{
|
||||
uint32_t sextets = (get_index_from_sextet(input_buffer[0]) << 12);
|
||||
sextets = sextets | (get_index_from_sextet(input_buffer[1]) << 6);
|
||||
sextets = sextets | (get_index_from_sextet(input_buffer[2]));
|
||||
push_to_output_buffer((sextets >> 10) & 0xFF);
|
||||
push_to_output_buffer((sextets >> 2) & 0xFF);
|
||||
break;
|
||||
}
|
||||
{
|
||||
uint32_t sextets = (get_index_from_sextet(input_buffer[0]) << 12);
|
||||
sextets = sextets | (get_index_from_sextet(input_buffer[1]) << 6);
|
||||
sextets = sextets | (get_index_from_sextet(input_buffer[2]));
|
||||
push_to_output_buffer((sextets >> 10) & 0xFF);
|
||||
push_to_output_buffer((sextets >> 2) & 0xFF);
|
||||
break;
|
||||
}
|
||||
|
||||
// Only triggered on call to decode().
|
||||
case 4:
|
||||
{
|
||||
// Read in four sextets
|
||||
uint32_t sextets = (get_index_from_sextet(input_buffer[0]) << 18);
|
||||
sextets = sextets | (get_index_from_sextet(input_buffer[1]) << 12);
|
||||
sextets = sextets | (get_index_from_sextet(input_buffer[2]) << 6);
|
||||
sextets = sextets | (get_index_from_sextet(input_buffer[3]));
|
||||
{
|
||||
// Read in four sextets
|
||||
uint32_t sextets = (get_index_from_sextet(input_buffer[0]) << 18);
|
||||
sextets = sextets | (get_index_from_sextet(input_buffer[1]) << 12);
|
||||
sextets = sextets | (get_index_from_sextet(input_buffer[2]) << 6);
|
||||
sextets = sextets | (get_index_from_sextet(input_buffer[3]));
|
||||
|
||||
// Write out three octets
|
||||
push_to_output_buffer((sextets >> 16) & 0xFF);
|
||||
push_to_output_buffer((sextets >> 8) & 0xFF);
|
||||
push_to_output_buffer((sextets >> 0) & 0xFF);
|
||||
break;
|
||||
}
|
||||
// Write out three octets
|
||||
push_to_output_buffer((sextets >> 16) & 0xFF);
|
||||
push_to_output_buffer((sextets >> 8) & 0xFF);
|
||||
push_to_output_buffer((sextets >> 0) & 0xFF);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ETL_ASSERT(!invalid_data_detected, ETL_ERROR(etl::base64_invalid_data));
|
||||
@ -434,8 +403,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
// Push to the output buffer.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14
|
||||
void push_to_output_buffer(unsigned char c)
|
||||
ETL_CONSTEXPR14 void push_to_output_buffer(unsigned char c)
|
||||
{
|
||||
if (output_buffer_length < output_buffer_max_size)
|
||||
{
|
||||
@ -448,28 +416,25 @@ namespace etl
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
//
|
||||
//
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14
|
||||
bool output_buffer_is_full() const
|
||||
ETL_CONSTEXPR14 bool output_buffer_is_full() const
|
||||
{
|
||||
return output_buffer_length == output_buffer_max_size;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
//
|
||||
//
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14
|
||||
bool output_buffer_is_empty() const
|
||||
ETL_CONSTEXPR14 bool output_buffer_is_empty() const
|
||||
{
|
||||
return output_buffer_length == 0;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
//
|
||||
//
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14
|
||||
void reset_output_buffer()
|
||||
ETL_CONSTEXPR14 void reset_output_buffer()
|
||||
{
|
||||
output_buffer_length = 0;
|
||||
}
|
||||
@ -478,8 +443,7 @@ namespace etl
|
||||
// Push to the input buffer.
|
||||
//*************************************************************************
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR14
|
||||
void push_to_input_buffer(T value)
|
||||
ETL_CONSTEXPR14 void push_to_input_buffer(T value)
|
||||
{
|
||||
if (value == padding<T>())
|
||||
{
|
||||
@ -494,25 +458,23 @@ namespace etl
|
||||
}
|
||||
else
|
||||
{
|
||||
input_buffer[input_buffer_length++] = static_cast<uint8_t>(value);
|
||||
input_buffer[input_buffer_length++] = static_cast<char>(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
//
|
||||
//
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14
|
||||
bool input_buffer_is_full() const
|
||||
ETL_CONSTEXPR14 bool input_buffer_is_full() const
|
||||
{
|
||||
return input_buffer_length == 4U;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
//
|
||||
//
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14
|
||||
void reset_input_buffer()
|
||||
ETL_CONSTEXPR14 void reset_input_buffer()
|
||||
{
|
||||
input_buffer_length = 0;
|
||||
}
|
||||
@ -544,13 +506,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Base64 RFC-2152 constructor.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14
|
||||
base64_rfc2152_decoder()
|
||||
: ibase64_decoder(etl::base64::character_set_1(),
|
||||
etl::base64::Padding::No_Padding,
|
||||
output_buffer,
|
||||
Buffer_Size,
|
||||
callback_type())
|
||||
ETL_CONSTEXPR14 base64_rfc2152_decoder()
|
||||
: ibase64_decoder(etl::base64::character_set_1(), etl::base64::Padding::No_Padding, output_buffer, Buffer_Size, callback_type())
|
||||
, output_buffer()
|
||||
{
|
||||
}
|
||||
@ -558,13 +515,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Base64 RFC-2152 constructor.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14
|
||||
base64_rfc2152_decoder(callback_type callback_)
|
||||
: ibase64_decoder(etl::base64::character_set_1(),
|
||||
etl::base64::Padding::No_Padding,
|
||||
output_buffer,
|
||||
Buffer_Size,
|
||||
callback_)
|
||||
ETL_CONSTEXPR14 base64_rfc2152_decoder(callback_type callback_)
|
||||
: ibase64_decoder(etl::base64::character_set_1(), etl::base64::Padding::No_Padding, output_buffer, Buffer_Size, callback_)
|
||||
, output_buffer()
|
||||
{
|
||||
}
|
||||
@ -574,8 +526,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
static
|
||||
ETL_CONSTEXPR14
|
||||
size_t safe_output_buffer_size(size_t input_length)
|
||||
ETL_CONSTEXPR14 size_t safe_output_buffer_size(size_t input_length)
|
||||
{
|
||||
return ibase64_decoder::decoded_size_from_valid_input_length(input_length);
|
||||
}
|
||||
@ -599,13 +550,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Base64 RFC-3501 constructor.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14
|
||||
base64_rfc3501_decoder()
|
||||
: ibase64_decoder(etl::base64::character_set_3(),
|
||||
etl::base64::Padding::No_Padding,
|
||||
output_buffer,
|
||||
Buffer_Size,
|
||||
callback_type())
|
||||
ETL_CONSTEXPR14 base64_rfc3501_decoder()
|
||||
: ibase64_decoder(etl::base64::character_set_3(), etl::base64::Padding::No_Padding, output_buffer, Buffer_Size, callback_type())
|
||||
, output_buffer()
|
||||
{
|
||||
}
|
||||
@ -613,13 +559,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Base64 RFC-3501 constructor.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14
|
||||
base64_rfc3501_decoder(callback_type callback_)
|
||||
: ibase64_decoder(etl::base64::character_set_3(),
|
||||
etl::base64::Padding::No_Padding,
|
||||
output_buffer,
|
||||
Buffer_Size,
|
||||
callback_)
|
||||
ETL_CONSTEXPR14 base64_rfc3501_decoder(callback_type callback_)
|
||||
: ibase64_decoder(etl::base64::character_set_3(), etl::base64::Padding::No_Padding, output_buffer, Buffer_Size, callback_)
|
||||
, output_buffer()
|
||||
{
|
||||
}
|
||||
@ -629,8 +570,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
static
|
||||
ETL_CONSTEXPR14
|
||||
size_t safe_output_buffer_size(size_t input_length)
|
||||
ETL_CONSTEXPR14 size_t safe_output_buffer_size(size_t input_length)
|
||||
{
|
||||
return ibase64_decoder::decoded_size_from_valid_input_length(input_length);
|
||||
}
|
||||
@ -654,13 +594,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Base64 RFC-4648 constructor.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14
|
||||
base64_rfc4648_decoder()
|
||||
: ibase64_decoder(etl::base64::character_set_1(),
|
||||
etl::base64::Padding::No_Padding,
|
||||
output_buffer,
|
||||
Buffer_Size,
|
||||
callback_type())
|
||||
ETL_CONSTEXPR14 base64_rfc4648_decoder()
|
||||
: ibase64_decoder(etl::base64::character_set_1(), etl::base64::Padding::No_Padding, output_buffer, Buffer_Size, callback_type())
|
||||
, output_buffer()
|
||||
{
|
||||
}
|
||||
@ -668,13 +603,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Base64 RFC-4648 constructor.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14
|
||||
base64_rfc4648_decoder(callback_type callback_)
|
||||
: ibase64_decoder(etl::base64::character_set_1(),
|
||||
etl::base64::Padding::No_Padding,
|
||||
output_buffer,
|
||||
Buffer_Size,
|
||||
callback_)
|
||||
ETL_CONSTEXPR14 base64_rfc4648_decoder(callback_type callback_)
|
||||
: ibase64_decoder(etl::base64::character_set_1(), etl::base64::Padding::No_Padding, output_buffer, Buffer_Size, callback_)
|
||||
, output_buffer()
|
||||
{
|
||||
}
|
||||
@ -683,9 +613,8 @@ namespace etl
|
||||
/// Calculate the required output encode buffer size.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
static
|
||||
ETL_CONSTEXPR14
|
||||
size_t safe_output_buffer_size(size_t input_length)
|
||||
static
|
||||
ETL_CONSTEXPR14 size_t safe_output_buffer_size(size_t input_length)
|
||||
{
|
||||
return ibase64_decoder::decoded_size_from_valid_input_length(input_length);
|
||||
}
|
||||
@ -709,13 +638,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Base64 RFC-4648-Padding constructor.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14
|
||||
base64_rfc4648_padding_decoder()
|
||||
: ibase64_decoder(etl::base64::character_set_1(),
|
||||
etl::base64::Padding::Use_Padding,
|
||||
output_buffer,
|
||||
Buffer_Size,
|
||||
callback_type())
|
||||
ETL_CONSTEXPR14 base64_rfc4648_padding_decoder()
|
||||
: ibase64_decoder(etl::base64::character_set_1(), etl::base64::Padding::Use_Padding, output_buffer, Buffer_Size, callback_type())
|
||||
, output_buffer()
|
||||
{
|
||||
}
|
||||
@ -723,13 +647,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Base64 RFC-4648-Padding constructor.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14
|
||||
base64_rfc4648_padding_decoder(callback_type callback_)
|
||||
: ibase64_decoder(etl::base64::character_set_1(),
|
||||
etl::base64::Padding::Use_Padding,
|
||||
output_buffer,
|
||||
Buffer_Size,
|
||||
callback_)
|
||||
ETL_CONSTEXPR14 base64_rfc4648_padding_decoder(callback_type callback_)
|
||||
: ibase64_decoder(etl::base64::character_set_1(), etl::base64::Padding::Use_Padding, output_buffer, Buffer_Size, callback_)
|
||||
, output_buffer()
|
||||
{
|
||||
}
|
||||
@ -739,8 +658,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
static
|
||||
ETL_CONSTEXPR14
|
||||
size_t safe_output_buffer_size(size_t input_length)
|
||||
ETL_CONSTEXPR14 size_t safe_output_buffer_size(size_t input_length)
|
||||
{
|
||||
return ibase64_decoder::decoded_size_from_valid_input_length(input_length);
|
||||
}
|
||||
@ -764,13 +682,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Base64 RFC-4648-Padding constructor.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14
|
||||
base64_rfc4648_url_decoder()
|
||||
: ibase64_decoder(etl::base64::character_set_2(),
|
||||
etl::base64::Padding::No_Padding,
|
||||
output_buffer,
|
||||
Buffer_Size,
|
||||
callback_type())
|
||||
ETL_CONSTEXPR14 base64_rfc4648_url_decoder()
|
||||
: ibase64_decoder(etl::base64::character_set_2(), etl::base64::Padding::No_Padding, output_buffer, Buffer_Size, callback_type())
|
||||
, output_buffer()
|
||||
{
|
||||
}
|
||||
@ -778,13 +691,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Base64 RFC-4648-Padding constructor.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14
|
||||
base64_rfc4648_url_decoder(callback_type callback_)
|
||||
: ibase64_decoder(etl::base64::character_set_2(),
|
||||
etl::base64::Padding::No_Padding,
|
||||
output_buffer,
|
||||
Buffer_Size,
|
||||
callback_)
|
||||
ETL_CONSTEXPR14 base64_rfc4648_url_decoder(callback_type callback_)
|
||||
: ibase64_decoder(etl::base64::character_set_2(), etl::base64::Padding::No_Padding, output_buffer, Buffer_Size, callback_)
|
||||
, output_buffer()
|
||||
{
|
||||
}
|
||||
@ -794,8 +702,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
static
|
||||
ETL_CONSTEXPR14
|
||||
size_t safe_output_buffer_size(size_t input_length)
|
||||
ETL_CONSTEXPR14 size_t safe_output_buffer_size(size_t input_length)
|
||||
{
|
||||
return ibase64_decoder::decoded_size_from_valid_input_length(input_length);
|
||||
}
|
||||
@ -819,13 +726,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Base64 RFC-4648-Padding constructor.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14
|
||||
base64_rfc4648_url_padding_decoder()
|
||||
: ibase64_decoder(etl::base64::character_set_2(),
|
||||
etl::base64::Padding::Use_Padding,
|
||||
output_buffer,
|
||||
Buffer_Size,
|
||||
callback_type())
|
||||
ETL_CONSTEXPR14 base64_rfc4648_url_padding_decoder()
|
||||
: ibase64_decoder(etl::base64::character_set_2(), etl::base64::Padding::Use_Padding, output_buffer, Buffer_Size, callback_type())
|
||||
, output_buffer()
|
||||
{
|
||||
}
|
||||
@ -833,13 +735,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Base64 RFC-4648-Padding constructor.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14
|
||||
base64_rfc4648_url_padding_decoder(callback_type callback_)
|
||||
: ibase64_decoder(etl::base64::character_set_2(),
|
||||
etl::base64::Padding::Use_Padding,
|
||||
output_buffer,
|
||||
Buffer_Size,
|
||||
callback_)
|
||||
ETL_CONSTEXPR14 base64_rfc4648_url_padding_decoder(callback_type callback_)
|
||||
: ibase64_decoder(etl::base64::character_set_2(), etl::base64::Padding::Use_Padding, output_buffer, Buffer_Size, callback_)
|
||||
, output_buffer()
|
||||
{
|
||||
}
|
||||
@ -849,8 +746,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
static
|
||||
ETL_CONSTEXPR14
|
||||
size_t safe_output_buffer_size(size_t input_length)
|
||||
ETL_CONSTEXPR14 size_t safe_output_buffer_size(size_t input_length)
|
||||
{
|
||||
return ibase64_decoder::decoded_size_from_valid_input_length(input_length);
|
||||
}
|
||||
@ -860,7 +756,7 @@ namespace etl
|
||||
/// The internal output buffer.
|
||||
unsigned char output_buffer[Buffer_Size];
|
||||
};
|
||||
}
|
||||
} // namespace etl
|
||||
|
||||
#undef ETL_IS_TYPE_8_BIT_INTEGRAL
|
||||
#undef ETL_IS_ITERATOR_TYPE_8_BIT_INTEGRAL
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
//*************************************************************************
|
||||
///Decode from Base64 from and to pointer/length
|
||||
/// Decode from Base64 from and to pointer/length
|
||||
//*************************************************************************///\file
|
||||
|
||||
/******************************************************************************
|
||||
@ -29,16 +29,16 @@ SOFTWARE.
|
||||
#define ETL_BASE64_ENCODER_INCLUDED
|
||||
|
||||
#include "platform.h"
|
||||
#include "static_assert.h"
|
||||
#include "error_handler.h"
|
||||
#include "type_traits.h"
|
||||
#include "binary.h"
|
||||
#include "algorithm.h"
|
||||
#include "binary.h"
|
||||
#include "delegate.h"
|
||||
#include "enum_type.h"
|
||||
#include "error_handler.h"
|
||||
#include "integral_limits.h"
|
||||
#include "iterator.h"
|
||||
#include "enum_type.h"
|
||||
#include "delegate.h"
|
||||
#include "span.h"
|
||||
#include "static_assert.h"
|
||||
#include "type_traits.h"
|
||||
|
||||
#include "base64.h"
|
||||
|
||||
@ -48,11 +48,12 @@ SOFTWARE.
|
||||
#include <iterator>
|
||||
#endif
|
||||
|
||||
#define ETL_IS_8_BIT_INTEGRAL(Type) (etl::is_integral<typename etl::remove_cv<Type>::type>::value && \
|
||||
(etl::integral_limits<typename etl::remove_cv<Type>::type>::bits == 8U))
|
||||
#define ETL_IS_8_BIT_INTEGRAL(Type) \
|
||||
(etl::is_integral<typename etl::remove_cv<Type>::type>::value && (etl::integral_limits<typename etl::remove_cv<Type>::type>::bits == 8U))
|
||||
|
||||
#define ETL_IS_ITERATOR_TYPE_8_BIT_INTEGRAL(Type) (etl::is_integral<typename etl::iterator_traits<typename etl::remove_cv<Type>::type>::value_type>::value && \
|
||||
(etl::integral_limits<typename etl::iterator_traits<typename etl::remove_cv<Type>::type>::value_type>::bits == 8U))
|
||||
#define ETL_IS_ITERATOR_TYPE_8_BIT_INTEGRAL(Type) \
|
||||
(etl::is_integral< typename etl::iterator_traits< typename etl::remove_cv<Type>::type>::value_type>::value \
|
||||
&& (etl::integral_limits< typename etl::iterator_traits< typename etl::remove_cv<Type>::type>::value_type>::bits == 8U))
|
||||
|
||||
namespace etl
|
||||
{
|
||||
@ -70,8 +71,7 @@ namespace etl
|
||||
/// Encode to Base64
|
||||
//*************************************************************************
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR14
|
||||
bool encode(T value)
|
||||
ETL_CONSTEXPR14 bool encode(T value)
|
||||
{
|
||||
ETL_STATIC_ASSERT(ETL_IS_8_BIT_INTEGRAL(T), "Input type must be an 8 bit integral");
|
||||
|
||||
@ -99,8 +99,7 @@ namespace etl
|
||||
/// Encode to Base64
|
||||
//*************************************************************************
|
||||
template <typename TInputIterator>
|
||||
ETL_CONSTEXPR14
|
||||
bool encode(TInputIterator input_begin, size_t input_length)
|
||||
ETL_CONSTEXPR14 bool encode(TInputIterator input_begin, size_t input_length)
|
||||
{
|
||||
ETL_STATIC_ASSERT(ETL_IS_ITERATOR_TYPE_8_BIT_INTEGRAL(TInputIterator), "Input type must be an 8 bit integral");
|
||||
|
||||
@ -119,8 +118,7 @@ namespace etl
|
||||
/// Encode to Base64
|
||||
//*************************************************************************
|
||||
template <typename TInputIterator>
|
||||
ETL_CONSTEXPR14
|
||||
bool encode(TInputIterator input_begin, TInputIterator input_end)
|
||||
ETL_CONSTEXPR14 bool encode(TInputIterator input_begin, TInputIterator input_end)
|
||||
{
|
||||
ETL_STATIC_ASSERT(ETL_IS_ITERATOR_TYPE_8_BIT_INTEGRAL(TInputIterator), "Input type must be an 8 bit integral");
|
||||
|
||||
@ -139,8 +137,7 @@ namespace etl
|
||||
/// Encode to Base64
|
||||
//*************************************************************************
|
||||
template <typename TInputIterator>
|
||||
ETL_CONSTEXPR14
|
||||
bool encode_final(TInputIterator input_begin, size_t input_length)
|
||||
ETL_CONSTEXPR14 bool encode_final(TInputIterator input_begin, size_t input_length)
|
||||
{
|
||||
return encode(input_begin, input_length) && flush();
|
||||
}
|
||||
@ -149,8 +146,7 @@ namespace etl
|
||||
/// Encode to Base64
|
||||
//*************************************************************************
|
||||
template <typename TInputIterator>
|
||||
ETL_CONSTEXPR14
|
||||
bool encode_final(TInputIterator input_begin, TInputIterator input_end)
|
||||
ETL_CONSTEXPR14 bool encode_final(TInputIterator input_begin, TInputIterator input_end)
|
||||
{
|
||||
return encode(input_begin, input_end) && flush();
|
||||
}
|
||||
@ -158,8 +154,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Flush any remaining data to the output.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14
|
||||
bool flush()
|
||||
ETL_CONSTEXPR14 bool flush()
|
||||
{
|
||||
// Encode any remaining input data.
|
||||
bool success = encode_block();
|
||||
@ -189,8 +184,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Reset the encoder.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14
|
||||
void restart()
|
||||
ETL_CONSTEXPR14 void restart()
|
||||
{
|
||||
reset_input_buffer();
|
||||
reset_output_buffer();
|
||||
@ -199,19 +193,16 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns the beginning of the output buffer.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
const char* begin() const
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 const char* begin() const
|
||||
{
|
||||
return p_output_buffer;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// This only returns a useful value if a callback has not been set or called.
|
||||
/// This only returns a useful value if a callback has not been set or
|
||||
/// called.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
const char* end() const
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 const char* end() const
|
||||
{
|
||||
return p_output_buffer + output_buffer_length;
|
||||
}
|
||||
@ -219,30 +210,26 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns the beginning of the output buffer.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
const char* cbegin() const
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 const char* cbegin() const
|
||||
{
|
||||
return p_output_buffer;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// This only returns a useful value if a callback has not been set or called.
|
||||
/// This only returns a useful value if a callback has not been set or
|
||||
/// called.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
const char* cend() const
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 const char* cend() const
|
||||
{
|
||||
return p_output_buffer + output_buffer_length;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Returns the size of the output buffer.
|
||||
/// This only returns a useful value if a callback has not been set or called.
|
||||
/// This only returns a useful value if a callback has not been set or
|
||||
/// called.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
size_t size() const
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 size_t size() const
|
||||
{
|
||||
return output_buffer_length;
|
||||
}
|
||||
@ -250,20 +237,17 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns the maximum size of the output buffer.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
size_t max_size() const
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 size_t max_size() const
|
||||
{
|
||||
return output_buffer_max_size;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Get a span of the output data.
|
||||
/// This only returns a useful span if a callback has not been set or called.
|
||||
/// This only returns a useful span if a callback has not been set or
|
||||
/// called.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
span_type span() const
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 span_type span() const
|
||||
{
|
||||
return span_type(begin(), end());
|
||||
}
|
||||
@ -271,9 +255,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns true if the output buffer has overflowed
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
bool overflow() const
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 bool overflow() const
|
||||
{
|
||||
return overflowed;
|
||||
}
|
||||
@ -281,9 +263,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Returns true if an error was detected.
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
bool error() const
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 bool error() const
|
||||
{
|
||||
return overflow();
|
||||
}
|
||||
@ -293,12 +273,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Constructor
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14
|
||||
ibase64_encoder(const char* encoder_table_,
|
||||
bool use_padding_,
|
||||
char* p_output_buffer_,
|
||||
size_t ouput_buffer_max_size_,
|
||||
callback_type callback_)
|
||||
ETL_CONSTEXPR14 ibase64_encoder(const char* encoder_table_, bool use_padding_, char* p_output_buffer_, size_t ouput_buffer_max_size_,
|
||||
callback_type callback_)
|
||||
: base64(encoder_table_, use_padding_)
|
||||
, input_buffer()
|
||||
, input_buffer_length(0)
|
||||
@ -313,64 +289,65 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Encode one block of data.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14
|
||||
bool encode_block()
|
||||
ETL_CONSTEXPR14 bool encode_block()
|
||||
{
|
||||
switch (input_buffer_length)
|
||||
{
|
||||
// Only triggered on call to flush().
|
||||
case 1:
|
||||
{
|
||||
uint32_t octets = input_buffer[0];
|
||||
octets = octets << 4; // Adjust one octet (8 bits) for two sextets worth of data (12 bits)
|
||||
|
||||
// Write out two sextets + optional padding.
|
||||
push_to_output_buffer(encoder_table[(octets >> 6) & 0x3F]);
|
||||
push_to_output_buffer(encoder_table[(octets >> 0) & 0x3F]);
|
||||
|
||||
if (use_padding)
|
||||
{
|
||||
push_to_output_buffer('=');
|
||||
push_to_output_buffer('=');
|
||||
}
|
||||
break;
|
||||
}
|
||||
uint32_t octets = input_buffer[0];
|
||||
octets = octets << 4; // Adjust one octet (8 bits) for two sextets
|
||||
// worth of data (12 bits)
|
||||
|
||||
// Write out two sextets + optional padding.
|
||||
push_to_output_buffer(encoder_table[(octets >> 6) & 0x3F]);
|
||||
push_to_output_buffer(encoder_table[(octets >> 0) & 0x3F]);
|
||||
|
||||
if (use_padding)
|
||||
{
|
||||
push_to_output_buffer('=');
|
||||
push_to_output_buffer('=');
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Only triggered on call to flush().
|
||||
case 2:
|
||||
{
|
||||
uint32_t octets = (input_buffer[0] << 8) | input_buffer[1];
|
||||
octets <<= 2; // Adjust two octets (16 bits) for three sextets worth of data (18 bits)
|
||||
|
||||
// Write out three sextets + optional padding.
|
||||
push_to_output_buffer(encoder_table[(octets >> 12) & 0x3F]);
|
||||
push_to_output_buffer(encoder_table[(octets >> 6) & 0x3F]);
|
||||
push_to_output_buffer(encoder_table[(octets >> 0) & 0x3F]);
|
||||
|
||||
if (use_padding)
|
||||
{
|
||||
push_to_output_buffer('=');
|
||||
uint32_t octets = (static_cast<uint32_t>(input_buffer[0]) << 8) | input_buffer[1];
|
||||
octets <<= 2; // Adjust two octets (16 bits) for three sextets worth
|
||||
// of data (18 bits)
|
||||
|
||||
// Write out three sextets + optional padding.
|
||||
push_to_output_buffer(encoder_table[(octets >> 12) & 0x3F]);
|
||||
push_to_output_buffer(encoder_table[(octets >> 6) & 0x3F]);
|
||||
push_to_output_buffer(encoder_table[(octets >> 0) & 0x3F]);
|
||||
|
||||
if (use_padding)
|
||||
{
|
||||
push_to_output_buffer('=');
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Only triggered on call to encode().
|
||||
case 3:
|
||||
{
|
||||
uint32_t octets = (input_buffer[0] << 16) | (input_buffer[1] << 8) | input_buffer[2];
|
||||
{
|
||||
uint32_t octets = (static_cast<uint32_t>(input_buffer[0]) << 16) | (static_cast<uint32_t>(input_buffer[1]) << 8) | input_buffer[2];
|
||||
|
||||
// Write out four sextets
|
||||
push_to_output_buffer(encoder_table[(octets >> 18) & 0x3F]);
|
||||
push_to_output_buffer(encoder_table[(octets >> 12) & 0x3F]);
|
||||
push_to_output_buffer(encoder_table[(octets >> 6) & 0x3F]);
|
||||
push_to_output_buffer(encoder_table[(octets >> 0) & 0x3F]);
|
||||
break;
|
||||
}
|
||||
// Write out four sextets
|
||||
push_to_output_buffer(encoder_table[(octets >> 18) & 0x3F]);
|
||||
push_to_output_buffer(encoder_table[(octets >> 12) & 0x3F]);
|
||||
push_to_output_buffer(encoder_table[(octets >> 6) & 0x3F]);
|
||||
push_to_output_buffer(encoder_table[(octets >> 0) & 0x3F]);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ETL_ASSERT(!overflowed, ETL_ERROR(etl::base64_overflow));
|
||||
@ -383,8 +360,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
static
|
||||
ETL_CONSTEXPR14
|
||||
size_t encoded_size(size_t input_length, bool use_padding)
|
||||
ETL_CONSTEXPR14 size_t encoded_size(size_t input_length, bool use_padding)
|
||||
{
|
||||
size_t required_output_length = 0;
|
||||
|
||||
@ -420,8 +396,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
// Push to the output buffer.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14
|
||||
void push_to_output_buffer(char c)
|
||||
ETL_CONSTEXPR14 void push_to_output_buffer(char c)
|
||||
{
|
||||
if (output_buffer_length < output_buffer_max_size)
|
||||
{
|
||||
@ -434,28 +409,25 @@ namespace etl
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
//
|
||||
//
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14
|
||||
bool output_buffer_is_full() const
|
||||
ETL_CONSTEXPR14 bool output_buffer_is_full() const
|
||||
{
|
||||
return output_buffer_length == output_buffer_max_size;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
//
|
||||
//
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14
|
||||
bool output_buffer_is_empty() const
|
||||
ETL_CONSTEXPR14 bool output_buffer_is_empty() const
|
||||
{
|
||||
return output_buffer_length == 0;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
//
|
||||
//
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14
|
||||
void reset_output_buffer()
|
||||
ETL_CONSTEXPR14 void reset_output_buffer()
|
||||
{
|
||||
output_buffer_length = 0;
|
||||
}
|
||||
@ -464,26 +436,23 @@ namespace etl
|
||||
// Push to the input buffer.
|
||||
//*************************************************************************
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR14
|
||||
void push_to_input_buffer(T value)
|
||||
ETL_CONSTEXPR14 void push_to_input_buffer(T value)
|
||||
{
|
||||
input_buffer[input_buffer_length++] = static_cast<uint8_t>(value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
//
|
||||
//
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14
|
||||
bool input_buffer_is_full() const
|
||||
ETL_CONSTEXPR14 bool input_buffer_is_full() const
|
||||
{
|
||||
return input_buffer_length == 3U;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
//
|
||||
//
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14
|
||||
void reset_input_buffer()
|
||||
ETL_CONSTEXPR14 void reset_input_buffer()
|
||||
{
|
||||
input_buffer_length = 0;
|
||||
}
|
||||
@ -496,7 +465,7 @@ namespace etl
|
||||
const size_t output_buffer_max_size;
|
||||
|
||||
callback_type callback;
|
||||
|
||||
|
||||
bool overflowed;
|
||||
};
|
||||
|
||||
@ -508,19 +477,15 @@ namespace etl
|
||||
{
|
||||
public:
|
||||
|
||||
ETL_STATIC_ASSERT((Buffer_Size >= etl::base64::Min_Encode_Buffer_Size), "Buffer size must be greater than etl::base64::Min_Encode_Buffer_Size");
|
||||
ETL_STATIC_ASSERT(((Buffer_Size % etl::base64::Min_Encode_Buffer_Size) == 0), "Buffer size must be a multiple of etl::base64::Min_Encode_Buffer_Size");
|
||||
ETL_STATIC_ASSERT((Buffer_Size >= etl::base64::Min_Encode_Buffer_Size), "Buffer size must be greater than etl::base64::Min_Encode_Buffer_Size");
|
||||
ETL_STATIC_ASSERT(((Buffer_Size % etl::base64::Min_Encode_Buffer_Size) == 0),
|
||||
"Buffer size must be a multiple of etl::base64::Min_Encode_Buffer_Size");
|
||||
|
||||
//*************************************************************************
|
||||
/// Base64 RFC-2152 constructor.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14
|
||||
base64_rfc2152_encoder()
|
||||
: ibase64_encoder(etl::base64::character_set_1(),
|
||||
etl::base64::Padding::No_Padding,
|
||||
output_buffer,
|
||||
Buffer_Size,
|
||||
callback_type())
|
||||
ETL_CONSTEXPR14 base64_rfc2152_encoder()
|
||||
: ibase64_encoder(etl::base64::character_set_1(), etl::base64::Padding::No_Padding, output_buffer, Buffer_Size, callback_type())
|
||||
, output_buffer()
|
||||
{
|
||||
}
|
||||
@ -528,13 +493,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Base64 RFC-2152 constructor.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14
|
||||
base64_rfc2152_encoder(callback_type callback_)
|
||||
: ibase64_encoder(etl::base64::character_set_1(),
|
||||
etl::base64::Padding::No_Padding,
|
||||
output_buffer,
|
||||
Buffer_Size,
|
||||
callback_)
|
||||
ETL_CONSTEXPR14 base64_rfc2152_encoder(callback_type callback_)
|
||||
: ibase64_encoder(etl::base64::character_set_1(), etl::base64::Padding::No_Padding, output_buffer, Buffer_Size, callback_)
|
||||
, output_buffer()
|
||||
{
|
||||
}
|
||||
@ -544,8 +504,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
static
|
||||
ETL_CONSTEXPR14
|
||||
size_t safe_output_buffer_size(size_t input_length)
|
||||
ETL_CONSTEXPR14 size_t safe_output_buffer_size(size_t input_length)
|
||||
{
|
||||
return ibase64_encoder::encoded_size(input_length, etl::base64::Padding::No_Padding);
|
||||
}
|
||||
@ -564,19 +523,15 @@ namespace etl
|
||||
{
|
||||
public:
|
||||
|
||||
ETL_STATIC_ASSERT((Buffer_Size >= etl::base64::Min_Encode_Buffer_Size), "Buffer size must be greater than etl::base64::Min_Encode_Buffer_Size");
|
||||
ETL_STATIC_ASSERT(((Buffer_Size% etl::base64::Min_Encode_Buffer_Size) == 0), "Buffer size must be a multiple of etl::base64::Min_Encode_Buffer_Size");
|
||||
ETL_STATIC_ASSERT((Buffer_Size >= etl::base64::Min_Encode_Buffer_Size), "Buffer size must be greater than etl::base64::Min_Encode_Buffer_Size");
|
||||
ETL_STATIC_ASSERT(((Buffer_Size % etl::base64::Min_Encode_Buffer_Size) == 0),
|
||||
"Buffer size must be a multiple of etl::base64::Min_Encode_Buffer_Size");
|
||||
|
||||
//*************************************************************************
|
||||
/// Base64 RFC-3501 constructor.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14
|
||||
base64_rfc3501_encoder()
|
||||
: ibase64_encoder(etl::base64::character_set_3(),
|
||||
etl::base64::Padding::No_Padding,
|
||||
output_buffer,
|
||||
Buffer_Size,
|
||||
callback_type())
|
||||
ETL_CONSTEXPR14 base64_rfc3501_encoder()
|
||||
: ibase64_encoder(etl::base64::character_set_3(), etl::base64::Padding::No_Padding, output_buffer, Buffer_Size, callback_type())
|
||||
, output_buffer()
|
||||
{
|
||||
}
|
||||
@ -584,13 +539,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Base64 RFC-3501 constructor.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14
|
||||
base64_rfc3501_encoder(callback_type callback_)
|
||||
: ibase64_encoder(etl::base64::character_set_3(),
|
||||
etl::base64::Padding::No_Padding,
|
||||
output_buffer,
|
||||
Buffer_Size,
|
||||
callback_)
|
||||
ETL_CONSTEXPR14 base64_rfc3501_encoder(callback_type callback_)
|
||||
: ibase64_encoder(etl::base64::character_set_3(), etl::base64::Padding::No_Padding, output_buffer, Buffer_Size, callback_)
|
||||
, output_buffer()
|
||||
{
|
||||
}
|
||||
@ -600,8 +550,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
static
|
||||
ETL_CONSTEXPR14
|
||||
size_t safe_output_buffer_size(size_t input_length)
|
||||
ETL_CONSTEXPR14 size_t safe_output_buffer_size(size_t input_length)
|
||||
{
|
||||
return ibase64_encoder::encoded_size(input_length, etl::base64::Padding::No_Padding);
|
||||
}
|
||||
@ -620,19 +569,15 @@ namespace etl
|
||||
{
|
||||
public:
|
||||
|
||||
ETL_STATIC_ASSERT((Buffer_Size >= etl::base64::Min_Encode_Buffer_Size), "Buffer size must be greater than etl::base64::Min_Encode_Buffer_Size");
|
||||
ETL_STATIC_ASSERT(((Buffer_Size % etl::base64::Min_Encode_Buffer_Size) == 0), "Buffer size must be a multiple of etl::base64::Min_Encode_Buffer_Size");
|
||||
ETL_STATIC_ASSERT((Buffer_Size >= etl::base64::Min_Encode_Buffer_Size), "Buffer size must be greater than etl::base64::Min_Encode_Buffer_Size");
|
||||
ETL_STATIC_ASSERT(((Buffer_Size % etl::base64::Min_Encode_Buffer_Size) == 0),
|
||||
"Buffer size must be a multiple of etl::base64::Min_Encode_Buffer_Size");
|
||||
|
||||
//*************************************************************************
|
||||
/// Base64 RFC-4648 constructor.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14
|
||||
base64_rfc4648_encoder()
|
||||
: ibase64_encoder(etl::base64::character_set_1(),
|
||||
etl::base64::Padding::No_Padding,
|
||||
output_buffer,
|
||||
Buffer_Size,
|
||||
callback_type())
|
||||
ETL_CONSTEXPR14 base64_rfc4648_encoder()
|
||||
: ibase64_encoder(etl::base64::character_set_1(), etl::base64::Padding::No_Padding, output_buffer, Buffer_Size, callback_type())
|
||||
, output_buffer()
|
||||
{
|
||||
}
|
||||
@ -640,13 +585,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Base64 RFC-4648 constructor.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14
|
||||
base64_rfc4648_encoder(callback_type callback_)
|
||||
: ibase64_encoder(etl::base64::character_set_1(),
|
||||
etl::base64::Padding::No_Padding,
|
||||
output_buffer,
|
||||
Buffer_Size,
|
||||
callback_)
|
||||
ETL_CONSTEXPR14 base64_rfc4648_encoder(callback_type callback_)
|
||||
: ibase64_encoder(etl::base64::character_set_1(), etl::base64::Padding::No_Padding, output_buffer, Buffer_Size, callback_)
|
||||
, output_buffer()
|
||||
{
|
||||
}
|
||||
@ -656,8 +596,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
static
|
||||
ETL_CONSTEXPR14
|
||||
size_t safe_output_buffer_size(size_t input_length)
|
||||
ETL_CONSTEXPR14 size_t safe_output_buffer_size(size_t input_length)
|
||||
{
|
||||
return ibase64_encoder::encoded_size(input_length, etl::base64::Padding::No_Padding);
|
||||
}
|
||||
@ -676,19 +615,15 @@ namespace etl
|
||||
{
|
||||
public:
|
||||
|
||||
ETL_STATIC_ASSERT((Buffer_Size >= etl::base64::Min_Encode_Buffer_Size), "Buffer size must be greater than etl::base64::Min_Encode_Buffer_Size");
|
||||
ETL_STATIC_ASSERT(((Buffer_Size% etl::base64::Min_Encode_Buffer_Size) == 0), "Buffer size must be a multiple of etl::base64::Min_Encode_Buffer_Size");
|
||||
ETL_STATIC_ASSERT((Buffer_Size >= etl::base64::Min_Encode_Buffer_Size), "Buffer size must be greater than etl::base64::Min_Encode_Buffer_Size");
|
||||
ETL_STATIC_ASSERT(((Buffer_Size % etl::base64::Min_Encode_Buffer_Size) == 0),
|
||||
"Buffer size must be a multiple of etl::base64::Min_Encode_Buffer_Size");
|
||||
|
||||
//*************************************************************************
|
||||
/// Base64 RFC-4648-Padding constructor.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14
|
||||
base64_rfc4648_padding_encoder()
|
||||
: ibase64_encoder(etl::base64::character_set_1(),
|
||||
etl::base64::Padding::Use_Padding,
|
||||
output_buffer,
|
||||
Buffer_Size,
|
||||
callback_type())
|
||||
ETL_CONSTEXPR14 base64_rfc4648_padding_encoder()
|
||||
: ibase64_encoder(etl::base64::character_set_1(), etl::base64::Padding::Use_Padding, output_buffer, Buffer_Size, callback_type())
|
||||
, output_buffer()
|
||||
{
|
||||
}
|
||||
@ -696,13 +631,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Base64 RFC-4648-Padding constructor.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14
|
||||
base64_rfc4648_padding_encoder(callback_type callback_)
|
||||
: ibase64_encoder(etl::base64::character_set_1(),
|
||||
etl::base64::Padding::Use_Padding,
|
||||
output_buffer,
|
||||
Buffer_Size,
|
||||
callback_)
|
||||
ETL_CONSTEXPR14 base64_rfc4648_padding_encoder(callback_type callback_)
|
||||
: ibase64_encoder(etl::base64::character_set_1(), etl::base64::Padding::Use_Padding, output_buffer, Buffer_Size, callback_)
|
||||
, output_buffer()
|
||||
{
|
||||
}
|
||||
@ -712,8 +642,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
static
|
||||
ETL_CONSTEXPR14
|
||||
size_t safe_output_buffer_size(size_t input_length)
|
||||
ETL_CONSTEXPR14 size_t safe_output_buffer_size(size_t input_length)
|
||||
{
|
||||
return ibase64_encoder::encoded_size(input_length, etl::base64::Padding::Use_Padding);
|
||||
}
|
||||
@ -732,19 +661,15 @@ namespace etl
|
||||
{
|
||||
public:
|
||||
|
||||
ETL_STATIC_ASSERT((Buffer_Size >= etl::base64::Min_Encode_Buffer_Size), "Buffer size must be greater than etl::base64::Min_Encode_Buffer_Size");
|
||||
ETL_STATIC_ASSERT(((Buffer_Size % etl::base64::Min_Encode_Buffer_Size) == 0), "Buffer size must be a multiple of etl::base64::Min_Encode_Buffer_Size");
|
||||
ETL_STATIC_ASSERT((Buffer_Size >= etl::base64::Min_Encode_Buffer_Size), "Buffer size must be greater than etl::base64::Min_Encode_Buffer_Size");
|
||||
ETL_STATIC_ASSERT(((Buffer_Size % etl::base64::Min_Encode_Buffer_Size) == 0),
|
||||
"Buffer size must be a multiple of etl::base64::Min_Encode_Buffer_Size");
|
||||
|
||||
//*************************************************************************
|
||||
/// Base64 RFC-4648-URL constructor.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14
|
||||
base64_rfc4648_url_encoder()
|
||||
: ibase64_encoder(etl::base64::character_set_2(),
|
||||
etl::base64::Padding::No_Padding,
|
||||
output_buffer,
|
||||
Buffer_Size,
|
||||
callback_type())
|
||||
ETL_CONSTEXPR14 base64_rfc4648_url_encoder()
|
||||
: ibase64_encoder(etl::base64::character_set_2(), etl::base64::Padding::No_Padding, output_buffer, Buffer_Size, callback_type())
|
||||
, output_buffer()
|
||||
{
|
||||
}
|
||||
@ -752,13 +677,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Base64 RFC-4648-URL constructor.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14
|
||||
base64_rfc4648_url_encoder(callback_type callback_)
|
||||
: ibase64_encoder(etl::base64::character_set_2(),
|
||||
etl::base64::Padding::No_Padding,
|
||||
output_buffer,
|
||||
Buffer_Size,
|
||||
callback_)
|
||||
ETL_CONSTEXPR14 base64_rfc4648_url_encoder(callback_type callback_)
|
||||
: ibase64_encoder(etl::base64::character_set_2(), etl::base64::Padding::No_Padding, output_buffer, Buffer_Size, callback_)
|
||||
, output_buffer()
|
||||
{
|
||||
}
|
||||
@ -768,8 +688,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
static
|
||||
ETL_CONSTEXPR14
|
||||
size_t safe_output_buffer_size(size_t input_length)
|
||||
ETL_CONSTEXPR14 size_t safe_output_buffer_size(size_t input_length)
|
||||
{
|
||||
return ibase64_encoder::encoded_size(input_length, etl::base64::Padding::No_Padding);
|
||||
}
|
||||
@ -788,19 +707,15 @@ namespace etl
|
||||
{
|
||||
public:
|
||||
|
||||
ETL_STATIC_ASSERT((Buffer_Size >= etl::base64::Min_Encode_Buffer_Size), "Buffer size must be greater than etl::base64::Min_Encode_Buffer_Size");
|
||||
ETL_STATIC_ASSERT(((Buffer_Size% etl::base64::Min_Encode_Buffer_Size) == 0), "Buffer size must be a multiple of etl::base64::Min_Encode_Buffer_Size");
|
||||
ETL_STATIC_ASSERT((Buffer_Size >= etl::base64::Min_Encode_Buffer_Size), "Buffer size must be greater than etl::base64::Min_Encode_Buffer_Size");
|
||||
ETL_STATIC_ASSERT(((Buffer_Size % etl::base64::Min_Encode_Buffer_Size) == 0),
|
||||
"Buffer size must be a multiple of etl::base64::Min_Encode_Buffer_Size");
|
||||
|
||||
//*************************************************************************
|
||||
/// Base64 RFC-4648-URL constructor.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14
|
||||
base64_rfc4648_url_padding_encoder()
|
||||
: ibase64_encoder(etl::base64::character_set_2(),
|
||||
etl::base64::Padding::Use_Padding,
|
||||
output_buffer,
|
||||
Buffer_Size,
|
||||
callback_type())
|
||||
ETL_CONSTEXPR14 base64_rfc4648_url_padding_encoder()
|
||||
: ibase64_encoder(etl::base64::character_set_2(), etl::base64::Padding::Use_Padding, output_buffer, Buffer_Size, callback_type())
|
||||
, output_buffer()
|
||||
{
|
||||
}
|
||||
@ -808,13 +723,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Base64 RFC-4648-URL constructor.
|
||||
//*************************************************************************
|
||||
ETL_CONSTEXPR14
|
||||
base64_rfc4648_url_padding_encoder(callback_type callback_)
|
||||
: ibase64_encoder(etl::base64::character_set_2(),
|
||||
etl::base64::Padding::Use_Padding,
|
||||
output_buffer,
|
||||
Buffer_Size,
|
||||
callback_)
|
||||
ETL_CONSTEXPR14 base64_rfc4648_url_padding_encoder(callback_type callback_)
|
||||
: ibase64_encoder(etl::base64::character_set_2(), etl::base64::Padding::Use_Padding, output_buffer, Buffer_Size, callback_)
|
||||
, output_buffer()
|
||||
{
|
||||
}
|
||||
@ -824,8 +734,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
ETL_NODISCARD
|
||||
static
|
||||
ETL_CONSTEXPR14
|
||||
size_t safe_output_buffer_size(size_t input_length)
|
||||
ETL_CONSTEXPR14 size_t safe_output_buffer_size(size_t input_length)
|
||||
{
|
||||
return ibase64_encoder::encoded_size(input_length, etl::base64::Padding::Use_Padding);
|
||||
}
|
||||
@ -835,7 +744,7 @@ namespace etl
|
||||
/// The internal output buffer.
|
||||
char output_buffer[Buffer_Size];
|
||||
};
|
||||
}
|
||||
} // namespace etl
|
||||
|
||||
#undef ETL_IS_TYPE_8_BIT_INTEGRAL
|
||||
#undef ETL_IS_ITERATOR_TYPE_8_BIT_INTEGRAL
|
||||
|
||||
@ -34,8 +34,9 @@ SOFTWARE.
|
||||
///\ingroup string
|
||||
|
||||
#include "platform.h"
|
||||
#include "type_traits.h"
|
||||
#include "static_assert.h"
|
||||
#include "type_traits.h"
|
||||
#include "utility.h"
|
||||
|
||||
namespace etl
|
||||
{
|
||||
@ -130,7 +131,7 @@ namespace etl
|
||||
struct right_spec
|
||||
{
|
||||
};
|
||||
}
|
||||
} // namespace private_basic_format_spec
|
||||
|
||||
//***************************************************************************
|
||||
// Stream formatting manipulators.
|
||||
@ -206,7 +207,7 @@ namespace etl
|
||||
//***************************************************************************
|
||||
/// Default constructor.
|
||||
//***************************************************************************
|
||||
ETL_CONSTEXPR basic_format_spec()
|
||||
ETL_CONSTEXPR basic_format_spec() ETL_NOEXCEPT
|
||||
: base_(10U)
|
||||
, width_(0U)
|
||||
, precision_(0U)
|
||||
@ -221,14 +222,8 @@ namespace etl
|
||||
//***************************************************************************
|
||||
/// Constructor.
|
||||
//***************************************************************************
|
||||
ETL_CONSTEXPR basic_format_spec(uint_least8_t base__,
|
||||
uint_least8_t width__,
|
||||
uint_least8_t precision__,
|
||||
bool upper_case__,
|
||||
bool left_justified__,
|
||||
bool boolalpha__,
|
||||
bool show_base__,
|
||||
typename TString::value_type fill__)
|
||||
ETL_CONSTEXPR basic_format_spec(uint_least8_t base__, uint_least8_t width__, uint_least8_t precision__, bool upper_case__, bool left_justified__,
|
||||
bool boolalpha__, bool show_base__, typename TString::value_type fill__) ETL_NOEXCEPT
|
||||
: base_(base__)
|
||||
, width_(width__)
|
||||
, precision_(precision__)
|
||||
@ -243,7 +238,7 @@ namespace etl
|
||||
//***************************************************************************
|
||||
/// Clears the format spec back to default.
|
||||
//***************************************************************************
|
||||
ETL_CONSTEXPR14 void clear()
|
||||
ETL_CONSTEXPR14 void clear() ETL_NOEXCEPT
|
||||
{
|
||||
base_ = 10U;
|
||||
width_ = 0U;
|
||||
@ -259,56 +254,93 @@ namespace etl
|
||||
/// Sets the base.
|
||||
/// \return A reference to the basic_format_spec.
|
||||
//***************************************************************************
|
||||
ETL_CONSTEXPR14 basic_format_spec& base(uint32_t b)
|
||||
ETL_CONSTEXPR14 basic_format_spec& base(uint32_t b) ETL_LVALUE_REF_QUALIFIER ETL_NOEXCEPT
|
||||
{
|
||||
base_ = static_cast<uint_least8_t>(b);
|
||||
return *this;
|
||||
}
|
||||
|
||||
#if ETL_USING_CPP11
|
||||
/// @overload
|
||||
ETL_CONSTEXPR14 basic_format_spec&& base(uint32_t b) ETL_RVALUE_REF_QUALIFIER ETL_NOEXCEPT
|
||||
{
|
||||
base_ = static_cast<uint_least8_t>(b);
|
||||
return etl::move(*this);
|
||||
}
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// Sets the base to binary.
|
||||
/// \return A reference to the basic_format_spec.
|
||||
//***************************************************************************
|
||||
ETL_CONSTEXPR14 basic_format_spec& binary()
|
||||
ETL_CONSTEXPR14 basic_format_spec& binary() ETL_LVALUE_REF_QUALIFIER ETL_NOEXCEPT
|
||||
{
|
||||
base(2);
|
||||
return *this;
|
||||
return base(2);
|
||||
}
|
||||
|
||||
#if ETL_USING_CPP11
|
||||
/// @overload
|
||||
ETL_CONSTEXPR14 basic_format_spec&& binary() ETL_RVALUE_REF_QUALIFIER ETL_NOEXCEPT
|
||||
{
|
||||
return etl::move(base(2));
|
||||
}
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// Sets the base to octal.
|
||||
/// \return A reference to the basic_format_spec.
|
||||
//***************************************************************************
|
||||
ETL_CONSTEXPR14 basic_format_spec& octal()
|
||||
ETL_CONSTEXPR14 basic_format_spec& octal() ETL_LVALUE_REF_QUALIFIER ETL_NOEXCEPT
|
||||
{
|
||||
base(8);
|
||||
return *this;
|
||||
return base(8);
|
||||
}
|
||||
|
||||
#if ETL_USING_CPP11
|
||||
/// @overload
|
||||
ETL_CONSTEXPR14 basic_format_spec&& octal() ETL_RVALUE_REF_QUALIFIER ETL_NOEXCEPT
|
||||
{
|
||||
return etl::move(base(8));
|
||||
}
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// Sets the base to decimal.
|
||||
/// \return A reference to the basic_format_spec.
|
||||
//***************************************************************************
|
||||
ETL_CONSTEXPR14 basic_format_spec& decimal()
|
||||
ETL_CONSTEXPR14 basic_format_spec& decimal() ETL_LVALUE_REF_QUALIFIER ETL_NOEXCEPT
|
||||
{
|
||||
base(10);
|
||||
return *this;
|
||||
return base(10);
|
||||
}
|
||||
|
||||
#if ETL_USING_CPP11
|
||||
/// @overload
|
||||
ETL_CONSTEXPR14 basic_format_spec&& decimal() ETL_RVALUE_REF_QUALIFIER ETL_NOEXCEPT
|
||||
{
|
||||
return etl::move(base(10));
|
||||
}
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// Sets the base to hex.
|
||||
/// \return A reference to the basic_format_spec.
|
||||
//***************************************************************************
|
||||
ETL_CONSTEXPR14 basic_format_spec& hex()
|
||||
ETL_CONSTEXPR14 basic_format_spec& hex() ETL_LVALUE_REF_QUALIFIER ETL_NOEXCEPT
|
||||
{
|
||||
base(16);
|
||||
return *this;
|
||||
return base(16);
|
||||
}
|
||||
|
||||
#if ETL_USING_CPP11
|
||||
/// @overload
|
||||
ETL_CONSTEXPR14 basic_format_spec&& hex() ETL_RVALUE_REF_QUALIFIER ETL_NOEXCEPT
|
||||
{
|
||||
return etl::move(base(16));
|
||||
}
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// Gets the base.
|
||||
//***************************************************************************
|
||||
ETL_CONSTEXPR uint32_t get_base() const
|
||||
ETL_CONSTEXPR uint32_t get_base() const ETL_NOEXCEPT
|
||||
{
|
||||
return base_;
|
||||
}
|
||||
@ -317,16 +349,25 @@ namespace etl
|
||||
/// Sets the show base flag.
|
||||
/// \return A reference to the basic_format_spec.
|
||||
//***************************************************************************
|
||||
ETL_CONSTEXPR14 basic_format_spec& show_base(bool b)
|
||||
ETL_CONSTEXPR14 basic_format_spec& show_base(bool b) ETL_LVALUE_REF_QUALIFIER ETL_NOEXCEPT
|
||||
{
|
||||
show_base_ = b;
|
||||
return *this;
|
||||
}
|
||||
|
||||
#if ETL_USING_CPP11
|
||||
/// @overload
|
||||
ETL_CONSTEXPR14 basic_format_spec&& show_base(bool b) ETL_RVALUE_REF_QUALIFIER ETL_NOEXCEPT
|
||||
{
|
||||
show_base_ = b;
|
||||
return etl::move(*this);
|
||||
}
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// Gets the show base flag.
|
||||
//***************************************************************************
|
||||
ETL_CONSTEXPR bool is_show_base() const
|
||||
ETL_CONSTEXPR bool is_show_base() const ETL_NOEXCEPT
|
||||
{
|
||||
return show_base_;
|
||||
}
|
||||
@ -335,16 +376,25 @@ namespace etl
|
||||
/// Sets the width.
|
||||
/// \return A reference to the basic_format_spec.
|
||||
//***************************************************************************
|
||||
ETL_CONSTEXPR14 basic_format_spec& width(uint32_t w)
|
||||
ETL_CONSTEXPR14 basic_format_spec& width(uint32_t w) ETL_LVALUE_REF_QUALIFIER ETL_NOEXCEPT
|
||||
{
|
||||
width_ = static_cast<uint_least8_t>(w);
|
||||
return *this;
|
||||
}
|
||||
|
||||
#if ETL_USING_CPP11
|
||||
/// @overload
|
||||
ETL_CONSTEXPR14 basic_format_spec&& width(uint32_t w) ETL_RVALUE_REF_QUALIFIER ETL_NOEXCEPT
|
||||
{
|
||||
width_ = static_cast<uint_least8_t>(w);
|
||||
return etl::move(*this);
|
||||
}
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// Gets the width.
|
||||
//***************************************************************************
|
||||
ETL_CONSTEXPR uint32_t get_width() const
|
||||
ETL_CONSTEXPR uint32_t get_width() const ETL_NOEXCEPT
|
||||
{
|
||||
return width_;
|
||||
}
|
||||
@ -353,16 +403,25 @@ namespace etl
|
||||
/// Sets the precision.
|
||||
/// \return A reference to the basic_format_spec.
|
||||
//***************************************************************************
|
||||
ETL_CONSTEXPR14 basic_format_spec& precision(uint32_t p)
|
||||
ETL_CONSTEXPR14 basic_format_spec& precision(uint32_t p) ETL_LVALUE_REF_QUALIFIER ETL_NOEXCEPT
|
||||
{
|
||||
precision_ = static_cast<uint_least8_t>(p);
|
||||
return *this;
|
||||
}
|
||||
|
||||
#if ETL_USING_CPP11
|
||||
/// @overload
|
||||
ETL_CONSTEXPR14 basic_format_spec&& precision(uint32_t p) ETL_RVALUE_REF_QUALIFIER ETL_NOEXCEPT
|
||||
{
|
||||
precision_ = static_cast<uint_least8_t>(p);
|
||||
return etl::move(*this);
|
||||
}
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// Gets the precision.
|
||||
//***************************************************************************
|
||||
ETL_CONSTEXPR uint32_t get_precision() const
|
||||
ETL_CONSTEXPR uint32_t get_precision() const ETL_NOEXCEPT
|
||||
{
|
||||
return precision_;
|
||||
}
|
||||
@ -371,16 +430,25 @@ namespace etl
|
||||
/// Sets the upper case flag.
|
||||
/// \return A reference to the basic_format_spec.
|
||||
//***************************************************************************
|
||||
ETL_CONSTEXPR14 basic_format_spec& upper_case(bool u)
|
||||
ETL_CONSTEXPR14 basic_format_spec& upper_case(bool u) ETL_LVALUE_REF_QUALIFIER ETL_NOEXCEPT
|
||||
{
|
||||
upper_case_ = u;
|
||||
return *this;
|
||||
}
|
||||
|
||||
#if ETL_USING_CPP11
|
||||
/// @overload
|
||||
ETL_CONSTEXPR14 basic_format_spec&& upper_case(bool u) ETL_RVALUE_REF_QUALIFIER ETL_NOEXCEPT
|
||||
{
|
||||
upper_case_ = u;
|
||||
return etl::move(*this);
|
||||
}
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// Gets the upper case flag.
|
||||
//***************************************************************************
|
||||
ETL_CONSTEXPR bool is_upper_case() const
|
||||
ETL_CONSTEXPR bool is_upper_case() const ETL_NOEXCEPT
|
||||
{
|
||||
return upper_case_;
|
||||
}
|
||||
@ -389,16 +457,25 @@ namespace etl
|
||||
/// Sets the fill character.
|
||||
/// \return A reference to the basic_format_spec.
|
||||
//***************************************************************************
|
||||
ETL_CONSTEXPR14 basic_format_spec& fill(typename TString::value_type c)
|
||||
ETL_CONSTEXPR14 basic_format_spec& fill(typename TString::value_type c) ETL_LVALUE_REF_QUALIFIER ETL_NOEXCEPT
|
||||
{
|
||||
fill_ = c;
|
||||
return *this;
|
||||
}
|
||||
|
||||
#if ETL_USING_CPP11
|
||||
/// @overload
|
||||
ETL_CONSTEXPR14 basic_format_spec&& fill(typename TString::value_type c) ETL_RVALUE_REF_QUALIFIER ETL_NOEXCEPT
|
||||
{
|
||||
fill_ = c;
|
||||
return etl::move(*this);
|
||||
}
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// Gets the fill character.
|
||||
//***************************************************************************
|
||||
ETL_CONSTEXPR typename TString::value_type get_fill() const
|
||||
ETL_CONSTEXPR typename TString::value_type get_fill() const ETL_NOEXCEPT
|
||||
{
|
||||
return fill_;
|
||||
}
|
||||
@ -407,16 +484,25 @@ namespace etl
|
||||
/// Sets the left justify flag.
|
||||
/// \return A reference to the basic_format_spec.
|
||||
//***************************************************************************
|
||||
ETL_CONSTEXPR14 basic_format_spec& left()
|
||||
ETL_CONSTEXPR14 basic_format_spec& left() ETL_LVALUE_REF_QUALIFIER ETL_NOEXCEPT
|
||||
{
|
||||
left_justified_ = true;
|
||||
return *this;
|
||||
}
|
||||
|
||||
#if ETL_USING_CPP11
|
||||
/// @overload
|
||||
ETL_CONSTEXPR14 basic_format_spec&& left() ETL_RVALUE_REF_QUALIFIER ETL_NOEXCEPT
|
||||
{
|
||||
left_justified_ = true;
|
||||
return etl::move(*this);
|
||||
}
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// Gets the left justify flag.
|
||||
//***************************************************************************
|
||||
ETL_CONSTEXPR bool is_left() const
|
||||
ETL_CONSTEXPR bool is_left() const ETL_NOEXCEPT
|
||||
{
|
||||
return left_justified_;
|
||||
}
|
||||
@ -425,16 +511,25 @@ namespace etl
|
||||
/// Sets the right justify flag.
|
||||
/// \return A reference to the basic_format_spec.
|
||||
//***************************************************************************
|
||||
ETL_CONSTEXPR14 basic_format_spec& right()
|
||||
ETL_CONSTEXPR14 basic_format_spec& right() ETL_LVALUE_REF_QUALIFIER ETL_NOEXCEPT
|
||||
{
|
||||
left_justified_ = false;
|
||||
return *this;
|
||||
}
|
||||
|
||||
#if ETL_USING_CPP11
|
||||
/// @overload
|
||||
ETL_CONSTEXPR14 basic_format_spec&& right() ETL_RVALUE_REF_QUALIFIER ETL_NOEXCEPT
|
||||
{
|
||||
left_justified_ = false;
|
||||
return etl::move(*this);
|
||||
}
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// Gets the right justify flag.
|
||||
//***************************************************************************
|
||||
ETL_CONSTEXPR bool is_right() const
|
||||
ETL_CONSTEXPR bool is_right() const ETL_NOEXCEPT
|
||||
{
|
||||
return !left_justified_;
|
||||
}
|
||||
@ -443,16 +538,25 @@ namespace etl
|
||||
/// Sets the bool alpha flag.
|
||||
/// \return A reference to the basic_format_spec.
|
||||
//***************************************************************************
|
||||
ETL_CONSTEXPR14 basic_format_spec& boolalpha(bool b)
|
||||
ETL_CONSTEXPR14 basic_format_spec& boolalpha(bool b) ETL_LVALUE_REF_QUALIFIER ETL_NOEXCEPT
|
||||
{
|
||||
boolalpha_ = b;
|
||||
return *this;
|
||||
}
|
||||
|
||||
#if ETL_USING_CPP11
|
||||
/// @overload
|
||||
ETL_CONSTEXPR14 basic_format_spec&& boolalpha(bool b) ETL_RVALUE_REF_QUALIFIER ETL_NOEXCEPT
|
||||
{
|
||||
boolalpha_ = b;
|
||||
return etl::move(*this);
|
||||
}
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// Gets the boolalpha flag.
|
||||
//***************************************************************************
|
||||
ETL_CONSTEXPR bool is_boolalpha() const
|
||||
ETL_CONSTEXPR bool is_boolalpha() const ETL_NOEXCEPT
|
||||
{
|
||||
return boolalpha_;
|
||||
}
|
||||
@ -460,37 +564,32 @@ namespace etl
|
||||
//***************************************************************************
|
||||
/// Equality operator.
|
||||
//***************************************************************************
|
||||
ETL_CONSTEXPR friend bool operator ==(const basic_format_spec& lhs, const basic_format_spec& rhs)
|
||||
ETL_CONSTEXPR friend bool operator==(const basic_format_spec& lhs, const basic_format_spec& rhs)
|
||||
{
|
||||
return (lhs.base_ == rhs.base_) &&
|
||||
(lhs.width_ == rhs.width_) &&
|
||||
(lhs.precision_ == rhs.precision_) &&
|
||||
(lhs.upper_case_ == rhs.upper_case_) &&
|
||||
(lhs.left_justified_ == rhs.left_justified_) &&
|
||||
(lhs.boolalpha_ == rhs.boolalpha_) &&
|
||||
(lhs.show_base_ == rhs.show_base_) &&
|
||||
(lhs.fill_ == rhs.fill_);
|
||||
return (lhs.base_ == rhs.base_) && (lhs.width_ == rhs.width_) && (lhs.precision_ == rhs.precision_) && (lhs.upper_case_ == rhs.upper_case_)
|
||||
&& (lhs.left_justified_ == rhs.left_justified_) && (lhs.boolalpha_ == rhs.boolalpha_) && (lhs.show_base_ == rhs.show_base_)
|
||||
&& (lhs.fill_ == rhs.fill_);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Inequality operator.
|
||||
//***************************************************************************
|
||||
ETL_CONSTEXPR friend bool operator !=(const basic_format_spec& lhs, const basic_format_spec& rhs)
|
||||
ETL_CONSTEXPR friend bool operator!=(const basic_format_spec& lhs, const basic_format_spec& rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
uint_least8_t base_;
|
||||
uint_least8_t width_;
|
||||
uint_least8_t precision_;
|
||||
bool upper_case_;
|
||||
bool left_justified_;
|
||||
bool boolalpha_;
|
||||
bool show_base_;
|
||||
uint_least8_t base_;
|
||||
uint_least8_t width_;
|
||||
uint_least8_t precision_;
|
||||
bool upper_case_;
|
||||
bool left_justified_;
|
||||
bool boolalpha_;
|
||||
bool show_base_;
|
||||
typename TString::value_type fill_;
|
||||
};
|
||||
}
|
||||
} // namespace etl
|
||||
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -35,6 +35,10 @@ SOFTWARE.
|
||||
|
||||
#include "platform.h"
|
||||
#include "to_string.h"
|
||||
#include "to_u16string.h"
|
||||
#include "to_u32string.h"
|
||||
#include "to_u8string.h"
|
||||
#include "to_wstring.h"
|
||||
|
||||
namespace etl
|
||||
{
|
||||
@ -121,16 +125,17 @@ namespace etl
|
||||
//*********************************
|
||||
/// TFormat
|
||||
//*********************************
|
||||
friend basic_string_stream& operator <<(basic_string_stream& ss, const TFormat& fmt)
|
||||
friend basic_string_stream& operator<<(basic_string_stream& ss, const TFormat& fmt)
|
||||
{
|
||||
ss.format = fmt;
|
||||
return ss;
|
||||
}
|
||||
|
||||
//*********************************
|
||||
/// etl::base_spec from etl::setbase, etl::bin, etl::oct, etl::dec & etl::hex stream manipulators
|
||||
/// etl::base_spec from etl::setbase, etl::bin, etl::oct, etl::dec &
|
||||
/// etl::hex stream manipulators
|
||||
//*********************************
|
||||
friend basic_string_stream& operator <<(basic_string_stream& ss, etl::private_basic_format_spec::base_spec fmt)
|
||||
friend basic_string_stream& operator<<(basic_string_stream& ss, etl::private_basic_format_spec::base_spec fmt)
|
||||
{
|
||||
ss.format.base(fmt.base);
|
||||
return ss;
|
||||
@ -139,7 +144,7 @@ namespace etl
|
||||
//*********************************
|
||||
/// etl::width_spec from etl::setw stream manipulator
|
||||
//*********************************
|
||||
friend basic_string_stream& operator <<(basic_string_stream& ss, etl::private_basic_format_spec::width_spec fmt)
|
||||
friend basic_string_stream& operator<<(basic_string_stream& ss, etl::private_basic_format_spec::width_spec fmt)
|
||||
{
|
||||
ss.format.width(fmt.width);
|
||||
return ss;
|
||||
@ -149,7 +154,7 @@ namespace etl
|
||||
/// etl::fill_spec from etl::setfill stream manipulator
|
||||
//*********************************
|
||||
template <typename TChar>
|
||||
friend basic_string_stream& operator <<(basic_string_stream& ss, etl::private_basic_format_spec::fill_spec<TChar> fmt)
|
||||
friend basic_string_stream& operator<<(basic_string_stream& ss, etl::private_basic_format_spec::fill_spec<TChar> fmt)
|
||||
{
|
||||
ss.format.fill(fmt.fill);
|
||||
return ss;
|
||||
@ -158,34 +163,37 @@ namespace etl
|
||||
//*********************************
|
||||
/// etl::precision_spec from etl::setprecision stream manipulator
|
||||
//*********************************
|
||||
friend basic_string_stream& operator <<(basic_string_stream& ss, etl::private_basic_format_spec::precision_spec fmt)
|
||||
friend basic_string_stream& operator<<(basic_string_stream& ss, etl::private_basic_format_spec::precision_spec fmt)
|
||||
{
|
||||
ss.format.precision(fmt.precision);
|
||||
return ss;
|
||||
}
|
||||
|
||||
//*********************************
|
||||
/// etl::boolalpha_spec from etl::boolalpha & etl::noboolalpha stream manipulators
|
||||
/// etl::boolalpha_spec from etl::boolalpha & etl::noboolalpha stream
|
||||
/// manipulators
|
||||
//*********************************
|
||||
friend basic_string_stream& operator <<(basic_string_stream& ss, etl::private_basic_format_spec::boolalpha_spec fmt)
|
||||
friend basic_string_stream& operator<<(basic_string_stream& ss, etl::private_basic_format_spec::boolalpha_spec fmt)
|
||||
{
|
||||
ss.format.boolalpha(fmt.boolalpha);
|
||||
return ss;
|
||||
}
|
||||
|
||||
//*********************************
|
||||
/// etl::uppercase_spec from etl::uppercase & etl::nouppercase stream manipulators
|
||||
/// etl::uppercase_spec from etl::uppercase & etl::nouppercase stream
|
||||
/// manipulators
|
||||
//*********************************
|
||||
friend basic_string_stream& operator <<(basic_string_stream& ss, etl::private_basic_format_spec::uppercase_spec fmt)
|
||||
friend basic_string_stream& operator<<(basic_string_stream& ss, etl::private_basic_format_spec::uppercase_spec fmt)
|
||||
{
|
||||
ss.format.upper_case(fmt.upper_case);
|
||||
return ss;
|
||||
}
|
||||
|
||||
//*********************************
|
||||
/// etl::showbase_spec from etl::showbase & etl::noshowbase stream manipulators
|
||||
/// etl::showbase_spec from etl::showbase & etl::noshowbase stream
|
||||
/// manipulators
|
||||
//*********************************
|
||||
friend basic_string_stream& operator <<(basic_string_stream& ss, etl::private_basic_format_spec::showbase_spec fmt)
|
||||
friend basic_string_stream& operator<<(basic_string_stream& ss, etl::private_basic_format_spec::showbase_spec fmt)
|
||||
{
|
||||
ss.format.show_base(fmt.show_base);
|
||||
return ss;
|
||||
@ -194,7 +202,7 @@ namespace etl
|
||||
//*********************************
|
||||
/// etl::left_spec from etl::left stream manipulator
|
||||
//*********************************
|
||||
friend basic_string_stream& operator <<(basic_string_stream& ss, etl::private_basic_format_spec::left_spec /*fmt*/)
|
||||
friend basic_string_stream& operator<<(basic_string_stream& ss, etl::private_basic_format_spec::left_spec /*fmt*/)
|
||||
{
|
||||
ss.format.left();
|
||||
return ss;
|
||||
@ -203,7 +211,7 @@ namespace etl
|
||||
//*********************************
|
||||
/// etl::right_spec from etl::left stream manipulator
|
||||
//*********************************
|
||||
friend basic_string_stream& operator <<(basic_string_stream& ss, etl::private_basic_format_spec::right_spec /*fmt*/)
|
||||
friend basic_string_stream& operator<<(basic_string_stream& ss, etl::private_basic_format_spec::right_spec /*fmt*/)
|
||||
{
|
||||
ss.format.right();
|
||||
return ss;
|
||||
@ -212,7 +220,7 @@ namespace etl
|
||||
//*********************************
|
||||
/// From a string view
|
||||
//*********************************
|
||||
friend basic_string_stream& operator <<(basic_string_stream& ss, TStringView view)
|
||||
friend basic_string_stream& operator<<(basic_string_stream& ss, TStringView view)
|
||||
{
|
||||
etl::to_string(view, ss.text, ss.format, true);
|
||||
return ss;
|
||||
@ -221,7 +229,7 @@ namespace etl
|
||||
//*********************************
|
||||
/// From a character pointer to a string
|
||||
//*********************************
|
||||
friend basic_string_stream& operator <<(basic_string_stream& ss, pointer p)
|
||||
friend basic_string_stream& operator<<(basic_string_stream& ss, pointer p)
|
||||
{
|
||||
TStringView view(p);
|
||||
ss << view;
|
||||
@ -231,7 +239,7 @@ namespace etl
|
||||
//*********************************
|
||||
/// From a const character pointer to a string
|
||||
//*********************************
|
||||
friend basic_string_stream& operator <<(basic_string_stream& ss, const_pointer p)
|
||||
friend basic_string_stream& operator<<(basic_string_stream& ss, const_pointer p)
|
||||
{
|
||||
TStringView view(p);
|
||||
ss << view;
|
||||
@ -241,7 +249,7 @@ namespace etl
|
||||
//*********************************
|
||||
/// From a string interface
|
||||
//*********************************
|
||||
friend basic_string_stream& operator <<(basic_string_stream& ss, const TIString& t)
|
||||
friend basic_string_stream& operator<<(basic_string_stream& ss, const TIString& t)
|
||||
{
|
||||
etl::to_string(t, ss.text, ss.format, true);
|
||||
return ss;
|
||||
@ -251,7 +259,7 @@ namespace etl
|
||||
/// From a string
|
||||
//*********************************
|
||||
template <template <size_t> class TString, size_t SIZE>
|
||||
friend basic_string_stream& operator <<(basic_string_stream& ss, const TString<SIZE>& t)
|
||||
friend basic_string_stream& operator<<(basic_string_stream& ss, const TString<SIZE>& t)
|
||||
{
|
||||
const TIString& itext = t;
|
||||
etl::to_string(itext, ss.str(), ss.get_format(), true);
|
||||
@ -262,7 +270,7 @@ namespace etl
|
||||
/// From anything else
|
||||
//*********************************
|
||||
template <typename T>
|
||||
friend basic_string_stream& operator <<(basic_string_stream& ss, const T& value)
|
||||
friend basic_string_stream& operator<<(basic_string_stream& ss, const T& value)
|
||||
{
|
||||
etl::to_string(value, ss.text, ss.format, true);
|
||||
return ss;
|
||||
@ -274,8 +282,8 @@ namespace etl
|
||||
TFormat format;
|
||||
|
||||
basic_string_stream(const basic_string_stream&) ETL_DELETE;
|
||||
basic_string_stream& operator =(const basic_string_stream&) ETL_DELETE;
|
||||
basic_string_stream& operator=(const basic_string_stream&) ETL_DELETE;
|
||||
};
|
||||
}
|
||||
} // namespace etl
|
||||
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -40,15 +40,15 @@ SOFTWARE.
|
||||
|
||||
#include "platform.h"
|
||||
#include "alignment.h"
|
||||
#include "parameter_type.h"
|
||||
#include "atomic.h"
|
||||
#include "error_handler.h"
|
||||
#include "file_error_numbers.h"
|
||||
#include "integral_limits.h"
|
||||
#include "memory.h"
|
||||
#include "memory_model.h"
|
||||
#include "integral_limits.h"
|
||||
#include "utility.h"
|
||||
#include "error_handler.h"
|
||||
#include "parameter_type.h"
|
||||
#include "span.h"
|
||||
#include "file_error_numbers.h"
|
||||
#include "utility.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
@ -60,12 +60,12 @@ namespace etl
|
||||
//***************************************************************************
|
||||
/// Base exception for a bip buffer.
|
||||
//***************************************************************************
|
||||
class bip_buffer_exception: public exception
|
||||
class bip_buffer_exception : public exception
|
||||
{
|
||||
public:
|
||||
|
||||
bip_buffer_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
|
||||
: exception(reason_, file_name_, line_number_)
|
||||
: exception(reason_, file_name_, line_number_)
|
||||
{
|
||||
}
|
||||
};
|
||||
@ -73,7 +73,7 @@ namespace etl
|
||||
//***************************************************************************
|
||||
/// Exception for an invalid reserve.
|
||||
//***************************************************************************
|
||||
class bip_buffer_reserve_invalid: public bip_buffer_exception
|
||||
class bip_buffer_reserve_invalid : public bip_buffer_exception
|
||||
{
|
||||
public:
|
||||
|
||||
@ -117,7 +117,7 @@ namespace etl
|
||||
size_type size() const
|
||||
{
|
||||
size_type write_index = write.load(etl::memory_order_acquire);
|
||||
size_type read_index = read.load(etl::memory_order_acquire);
|
||||
size_type read_index = read.load(etl::memory_order_acquire);
|
||||
|
||||
// no wraparound
|
||||
if (write_index >= read_index)
|
||||
@ -140,7 +140,7 @@ namespace etl
|
||||
size_type available() const
|
||||
{
|
||||
size_type write_index = write.load(etl::memory_order_acquire);
|
||||
size_type read_index = read.load(etl::memory_order_acquire);
|
||||
size_type read_index = read.load(etl::memory_order_acquire);
|
||||
|
||||
// no wraparound
|
||||
if (write_index >= read_index)
|
||||
@ -185,10 +185,10 @@ namespace etl
|
||||
/// Constructs the buffer.
|
||||
//*************************************************************************
|
||||
bip_buffer_spsc_atomic_base(size_type reserved_)
|
||||
: read(0)
|
||||
, write(0)
|
||||
, last(0)
|
||||
, Reserved(reserved_)
|
||||
: read(0)
|
||||
, write(0)
|
||||
, last(0)
|
||||
, Reserved(reserved_)
|
||||
{
|
||||
}
|
||||
|
||||
@ -204,7 +204,7 @@ namespace etl
|
||||
size_type get_write_reserve(size_type* psize, size_type fallback_size = numeric_limits<size_type>::max())
|
||||
{
|
||||
size_type write_index = write.load(etl::memory_order_relaxed);
|
||||
size_type read_index = read.load(etl::memory_order_acquire);
|
||||
size_type read_index = read.load(etl::memory_order_acquire);
|
||||
|
||||
// No wraparound
|
||||
if (write_index >= read_index)
|
||||
@ -262,7 +262,7 @@ namespace etl
|
||||
if (wsize > 0)
|
||||
{
|
||||
size_type write_index = write.load(etl::memory_order_relaxed);
|
||||
size_type read_index = read.load(etl::memory_order_acquire);
|
||||
size_type read_index = read.load(etl::memory_order_acquire);
|
||||
|
||||
// Wrapped around already
|
||||
if (write_index < read_index)
|
||||
@ -281,8 +281,11 @@ namespace etl
|
||||
else
|
||||
{
|
||||
ETL_ASSERT_OR_RETURN((windex == 0) && ((wsize + 1) <= read_index), ETL_ERROR(bip_buffer_reserve_invalid));
|
||||
|
||||
// Correct wrapping point
|
||||
last.store(write_index, etl::memory_order_release);
|
||||
}
|
||||
|
||||
|
||||
// Always update write index
|
||||
write.store(windex + wsize, etl::memory_order_release);
|
||||
}
|
||||
@ -291,7 +294,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
size_type get_read_reserve(size_type* psize)
|
||||
{
|
||||
size_type read_index = read.load(etl::memory_order_relaxed);
|
||||
size_type read_index = read.load(etl::memory_order_relaxed);
|
||||
size_type write_index = write.load(etl::memory_order_acquire);
|
||||
|
||||
if (read_index > write_index)
|
||||
@ -341,21 +344,19 @@ namespace etl
|
||||
etl::atomic<size_type> read;
|
||||
etl::atomic<size_type> write;
|
||||
etl::atomic<size_type> last;
|
||||
const size_type Reserved;
|
||||
const size_type Reserved;
|
||||
|
||||
#if defined(ETL_POLYMORPHIC_SPSC_BIP_BUFFER_ATOMIC) || defined(ETL_POLYMORPHIC_CONTAINERS)
|
||||
|
||||
#if defined(ETL_POLYMORPHIC_SPSC_BIP_BUFFER_ATOMIC) || defined(ETL_POLYMORPHIC_CONTAINERS)
|
||||
public:
|
||||
|
||||
virtual ~bip_buffer_spsc_atomic_base()
|
||||
{
|
||||
}
|
||||
#else
|
||||
virtual ~bip_buffer_spsc_atomic_base() {}
|
||||
#else
|
||||
|
||||
protected:
|
||||
|
||||
~bip_buffer_spsc_atomic_base()
|
||||
{
|
||||
}
|
||||
#endif
|
||||
~bip_buffer_spsc_atomic_base() {}
|
||||
#endif
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
@ -367,21 +368,21 @@ namespace etl
|
||||
private:
|
||||
|
||||
typedef typename etl::bip_buffer_spsc_atomic_base<Memory_Model> base_t;
|
||||
using base_t::reset;
|
||||
using base_t::get_read_reserve;
|
||||
using base_t::apply_read_reserve;
|
||||
using base_t::get_write_reserve;
|
||||
using base_t::apply_write_reserve;
|
||||
using base_t::get_read_reserve;
|
||||
using base_t::get_write_reserve;
|
||||
using base_t::reset;
|
||||
|
||||
public:
|
||||
|
||||
typedef T value_type; ///< The type stored in the buffer.
|
||||
typedef T& reference; ///< A reference to the type used in the buffer.
|
||||
typedef const T& const_reference; ///< A const reference to the type used in the buffer.
|
||||
#if ETL_USING_CPP11
|
||||
typedef T&& rvalue_reference;///< An rvalue_reference to the type used in the buffer.
|
||||
#endif
|
||||
typedef typename base_t::size_type size_type; ///< The type used for determining the size of the buffer.
|
||||
typedef T value_type; ///< The type stored in the buffer.
|
||||
typedef T& reference; ///< A reference to the type used in the buffer.
|
||||
typedef const T& const_reference; ///< A const reference to the type used in the buffer.
|
||||
#if ETL_USING_CPP11
|
||||
typedef T&& rvalue_reference; ///< An rvalue_reference to the type used in the buffer.
|
||||
#endif
|
||||
typedef typename base_t::size_type size_type; ///< The type used for determining the size of the buffer.
|
||||
|
||||
using base_t::max_size;
|
||||
|
||||
@ -391,8 +392,8 @@ namespace etl
|
||||
span<T> read_reserve(size_type max_reserve_size = numeric_limits<size_type>::max())
|
||||
{
|
||||
size_type reserve_size = max_reserve_size;
|
||||
size_type rindex = get_read_reserve(&reserve_size);
|
||||
|
||||
size_type rindex = get_read_reserve(&reserve_size);
|
||||
|
||||
return span<T>(p_buffer + rindex, reserve_size);
|
||||
}
|
||||
|
||||
@ -401,7 +402,7 @@ namespace etl
|
||||
// the reserve can be trimmed at the end before committing.
|
||||
// Throws bip_buffer_reserve_invalid
|
||||
//*************************************************************************
|
||||
void read_commit(const span<T> &reserve)
|
||||
void read_commit(const span<T>& reserve)
|
||||
{
|
||||
size_type rindex = etl::distance(p_buffer, reserve.data());
|
||||
apply_read_reserve(rindex, reserve.size());
|
||||
@ -413,8 +414,8 @@ namespace etl
|
||||
span<T> write_reserve(size_type max_reserve_size)
|
||||
{
|
||||
size_type reserve_size = max_reserve_size;
|
||||
size_type windex = get_write_reserve(&reserve_size);
|
||||
|
||||
size_type windex = get_write_reserve(&reserve_size);
|
||||
|
||||
return span<T>(p_buffer + windex, reserve_size);
|
||||
}
|
||||
|
||||
@ -424,10 +425,10 @@ namespace etl
|
||||
//*************************************************************************
|
||||
span<T> write_reserve_optimal(size_type min_reserve_size = 1U)
|
||||
{
|
||||
size_type reserve_size = numeric_limits<size_type>::max();
|
||||
size_type windex = get_write_reserve(&reserve_size, min_reserve_size);
|
||||
size_type reserve_size = numeric_limits<size_type>::max();
|
||||
size_type windex = get_write_reserve(&reserve_size, min_reserve_size);
|
||||
|
||||
return span<T>(p_buffer + windex, reserve_size);
|
||||
return span<T>(p_buffer + windex, reserve_size);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -435,7 +436,7 @@ namespace etl
|
||||
// the reserve can be trimmed at the end before committing.
|
||||
// Throws bip_buffer_reserve_invalid
|
||||
//*************************************************************************
|
||||
void write_commit(const span<T> &reserve)
|
||||
void write_commit(const span<T>& reserve)
|
||||
{
|
||||
size_type windex = etl::distance(p_buffer, reserve.data());
|
||||
apply_write_reserve(windex, reserve.size());
|
||||
@ -472,12 +473,12 @@ namespace etl
|
||||
|
||||
// Disable copy construction and assignment.
|
||||
ibip_buffer_spsc_atomic(const ibip_buffer_spsc_atomic&) ETL_DELETE;
|
||||
ibip_buffer_spsc_atomic& operator =(const ibip_buffer_spsc_atomic&) ETL_DELETE;
|
||||
ibip_buffer_spsc_atomic& operator=(const ibip_buffer_spsc_atomic&) ETL_DELETE;
|
||||
|
||||
#if ETL_USING_CPP11
|
||||
ibip_buffer_spsc_atomic(ibip_buffer_spsc_atomic&&) = delete;
|
||||
ibip_buffer_spsc_atomic& operator =(ibip_buffer_spsc_atomic&&) = delete;
|
||||
#endif
|
||||
#if ETL_USING_CPP11
|
||||
ibip_buffer_spsc_atomic(ibip_buffer_spsc_atomic&&) = delete;
|
||||
ibip_buffer_spsc_atomic& operator=(ibip_buffer_spsc_atomic&&) = delete;
|
||||
#endif
|
||||
|
||||
T* const p_buffer;
|
||||
};
|
||||
@ -487,7 +488,8 @@ namespace etl
|
||||
/// This buffer supports concurrent access by one producer and one consumer.
|
||||
/// \tparam T The type this buffer should support.
|
||||
/// \tparam Size The maximum capacity of the buffer.
|
||||
/// \tparam Memory_Model The memory model for the buffer. Determines the type of the internal counter variables.
|
||||
/// \tparam Memory_Model The memory model for the buffer. Determines the type
|
||||
/// of the internal counter variables.
|
||||
//***************************************************************************
|
||||
template <typename T, const size_t Size, const size_t Memory_Model = etl::memory_model::MEMORY_MODEL_LARGE>
|
||||
class bip_buffer_spsc_atomic : public ibip_buffer_spsc_atomic<T, Memory_Model>
|
||||
@ -526,15 +528,15 @@ namespace etl
|
||||
base_t::clear();
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
|
||||
/// The uninitialised buffer of T used in the bip_buffer_spsc.
|
||||
etl::uninitialized_buffer_of<T, Reserved_Size> buffer;
|
||||
};
|
||||
|
||||
template <typename T, const size_t Size, const size_t Memory_Model>
|
||||
template <typename T, const size_t Size, const size_t Memory_Model>
|
||||
ETL_CONSTANT typename bip_buffer_spsc_atomic<T, Size, Memory_Model>::size_type bip_buffer_spsc_atomic<T, Size, Memory_Model>::Reserved_Size;
|
||||
}
|
||||
} // namespace etl
|
||||
|
||||
#endif /* ETL_HAS_ATOMIC && ETL_USING_CPP11 */
|
||||
|
||||
|
||||
@ -32,10 +32,9 @@ SOFTWARE.
|
||||
#define ETL_BIT_INCLUDED
|
||||
|
||||
#include "platform.h"
|
||||
#include "type_traits.h"
|
||||
#include "binary.h"
|
||||
#include "integral_limits.h"
|
||||
#include "endianness.h"
|
||||
#include "integral_limits.h"
|
||||
#include "type_traits.h"
|
||||
|
||||
#include <string.h>
|
||||
@ -51,11 +50,9 @@ namespace etl
|
||||
//***************************************************************************
|
||||
template <typename TDestination, typename TSource>
|
||||
ETL_NODISCARD
|
||||
typename etl::enable_if<!(etl::is_integral<TDestination>::value&& etl::is_integral<TSource>::value) &&
|
||||
(sizeof(TDestination) == sizeof(TSource)) &&
|
||||
etl::is_trivially_copyable<TSource>::value &&
|
||||
etl::is_trivially_copyable<TDestination>::value, TDestination>::type
|
||||
bit_cast(const TSource& source) ETL_NOEXCEPT
|
||||
typename etl::enable_if< !(etl::is_integral<TDestination>::value && etl::is_integral<TSource>::value) && (sizeof(TDestination) == sizeof(TSource))
|
||||
&& etl::is_trivially_copyable<TSource>::value && etl::is_trivially_copyable<TDestination>::value,
|
||||
TDestination>::type bit_cast(const TSource& source) ETL_NOEXCEPT
|
||||
{
|
||||
TDestination destination;
|
||||
|
||||
@ -68,11 +65,9 @@ namespace etl
|
||||
/// bit_cast - Integral to integral
|
||||
//***************************************************************************
|
||||
template <typename TDestination, typename TSource>
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR14
|
||||
typename etl::enable_if<(etl::is_integral<TDestination>::value && etl::is_integral<TSource>::value) &&
|
||||
(sizeof(TDestination) == sizeof(TSource)), TDestination>::type
|
||||
bit_cast(const TSource& source) ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR14
|
||||
typename etl::enable_if< (etl::is_integral<TDestination>::value && etl::is_integral<TSource>::value) && (sizeof(TDestination) == sizeof(TSource)),
|
||||
TDestination>::type bit_cast(const TSource& source) ETL_NOEXCEPT
|
||||
{
|
||||
return static_cast<TDestination>(source);
|
||||
}
|
||||
@ -81,9 +76,7 @@ namespace etl
|
||||
/// byteswap
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR14
|
||||
typename etl::enable_if<etl::is_integral<T>::value, T>::type
|
||||
byteswap(T value) ETL_NOEXCEPT
|
||||
ETL_CONSTEXPR14 typename etl::enable_if<etl::is_integral<T>::value, T>::type byteswap(T value) ETL_NOEXCEPT
|
||||
{
|
||||
return etl::reverse_bytes(value);
|
||||
}
|
||||
@ -92,8 +85,7 @@ namespace etl
|
||||
/// has_single_bit
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
ETL_NODISCARD ETL_CONSTEXPR14
|
||||
typename etl::enable_if<etl::is_unsigned<T>::value, bool>::type has_single_bit(T value) ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 typename etl::enable_if<etl::is_unsigned<T>::value, bool>::type has_single_bit(T value) ETL_NOEXCEPT
|
||||
{
|
||||
return (value & (value - 1)) == 0;
|
||||
}
|
||||
@ -101,9 +93,7 @@ namespace etl
|
||||
/// countl_zero
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
ETL_NODISCARD ETL_CONSTEXPR14
|
||||
typename etl::enable_if<etl::is_unsigned<T>::value, int>::type
|
||||
countl_zero(T value) ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 typename etl::enable_if<etl::is_unsigned<T>::value, int>::type countl_zero(T value) ETL_NOEXCEPT
|
||||
{
|
||||
return etl::count_leading_zeros(value);
|
||||
}
|
||||
@ -112,9 +102,7 @@ namespace etl
|
||||
/// countl_one
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
ETL_NODISCARD ETL_CONSTEXPR14
|
||||
typename etl::enable_if<etl::is_unsigned<T>::value, int>::type
|
||||
countl_one(T value) ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 typename etl::enable_if<etl::is_unsigned<T>::value, int>::type countl_one(T value) ETL_NOEXCEPT
|
||||
{
|
||||
return etl::count_leading_ones(value);
|
||||
}
|
||||
@ -123,9 +111,7 @@ namespace etl
|
||||
/// countr_zero
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
ETL_NODISCARD ETL_CONSTEXPR14
|
||||
typename etl::enable_if<etl::is_unsigned<T>::value, int>::type
|
||||
countr_zero(T value) ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 typename etl::enable_if<etl::is_unsigned<T>::value, int>::type countr_zero(T value) ETL_NOEXCEPT
|
||||
{
|
||||
return etl::count_trailing_zeros(value);
|
||||
}
|
||||
@ -134,26 +120,21 @@ namespace etl
|
||||
/// countr_one
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
ETL_NODISCARD ETL_CONSTEXPR14
|
||||
typename etl::enable_if<etl::is_unsigned<T>::value, int>::type
|
||||
countr_one(T value) ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 typename etl::enable_if<etl::is_unsigned<T>::value, int>::type countr_one(T value) ETL_NOEXCEPT
|
||||
{
|
||||
return etl::count_trailing_ones(value);
|
||||
}
|
||||
|
||||
|
||||
//***************************************************************************
|
||||
/// bit_width
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
ETL_CONSTEXPR14
|
||||
typename etl::enable_if<etl::is_unsigned<T>::value, T>::type
|
||||
bit_width(T value) ETL_NOEXCEPT
|
||||
ETL_CONSTEXPR14 typename etl::enable_if<etl::is_unsigned<T>::value, T>::type bit_width(T value) ETL_NOEXCEPT
|
||||
{
|
||||
#if ETL_USING_CPP20 && ETL_USING_STL
|
||||
return std::bit_width(value);
|
||||
return static_cast<T>(std::bit_width(value));
|
||||
#else
|
||||
return etl::integral_limits<T>::bits - etl::countl_zero(value);
|
||||
return static_cast<T>(etl::integral_limits<T>::bits - etl::countl_zero(value));
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -161,9 +142,7 @@ namespace etl
|
||||
/// bit_ceil
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
ETL_NODISCARD ETL_CONSTEXPR14
|
||||
typename etl::enable_if<etl::is_unsigned<T>::value, T>::type
|
||||
bit_ceil(T value)
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 typename etl::enable_if<etl::is_unsigned<T>::value, T>::type bit_ceil(T value)
|
||||
{
|
||||
#if ETL_USING_CPP20 && ETL_USING_STL
|
||||
return std::bit_ceil(value);
|
||||
@ -183,9 +162,7 @@ namespace etl
|
||||
/// bit_floor
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
ETL_NODISCARD ETL_CONSTEXPR14
|
||||
typename etl::enable_if<etl::is_unsigned<T>::value, T>::type
|
||||
bit_floor(T value) ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 typename etl::enable_if<etl::is_unsigned<T>::value, T>::type bit_floor(T value) ETL_NOEXCEPT
|
||||
{
|
||||
#if ETL_USING_CPP20 && ETL_USING_STL
|
||||
return std::bit_floor(value);
|
||||
@ -205,17 +182,15 @@ namespace etl
|
||||
/// rotl
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
ETL_NODISCARD ETL_CONSTEXPR14
|
||||
typename etl::enable_if<etl::is_unsigned<T>::value, T>::type
|
||||
rotl(T value, int n) ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 typename etl::enable_if<etl::is_unsigned<T>::value, T>::type rotl(T value, int n) ETL_NOEXCEPT
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
return etl::rotate_right(value, -n);
|
||||
return etl::rotate_right(value, static_cast<size_t>(-n));
|
||||
}
|
||||
else
|
||||
{
|
||||
return etl::rotate_left(value, n);
|
||||
return etl::rotate_left(value, static_cast<size_t>(n));
|
||||
}
|
||||
}
|
||||
|
||||
@ -223,30 +198,26 @@ namespace etl
|
||||
/// rotr
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
ETL_NODISCARD ETL_CONSTEXPR14
|
||||
typename etl::enable_if<etl::is_unsigned<T>::value, T>::type
|
||||
rotr(T value, int n) ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 typename etl::enable_if<etl::is_unsigned<T>::value, T>::type rotr(T value, int n) ETL_NOEXCEPT
|
||||
{
|
||||
if (n < 0)
|
||||
{
|
||||
return etl::rotate_left(value, -n);
|
||||
return etl::rotate_left(value, static_cast<size_t>(-n));
|
||||
}
|
||||
else
|
||||
{
|
||||
return etl::rotate_right(value, n);
|
||||
return etl::rotate_right(value, static_cast<size_t>(n));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//***************************************************************************
|
||||
/// popcount
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
ETL_NODISCARD ETL_CONSTEXPR14
|
||||
typename etl::enable_if<etl::is_unsigned<T>::value, int>::type
|
||||
popcount(T value) ETL_NOEXCEPT
|
||||
ETL_NODISCARD ETL_CONSTEXPR14 typename etl::enable_if<etl::is_unsigned<T>::value, int>::type popcount(T value) ETL_NOEXCEPT
|
||||
{
|
||||
return etl::count_bits(value);
|
||||
}
|
||||
}
|
||||
} // namespace etl
|
||||
|
||||
#endif
|
||||
|
||||
@ -27,22 +27,22 @@ SOFTWARE.
|
||||
#define ETL_BIT_STREAM_INCLUDED
|
||||
|
||||
#include "platform.h"
|
||||
#include "type_traits.h"
|
||||
#include "nullptr.h"
|
||||
#include "endianness.h"
|
||||
#include "integral_limits.h"
|
||||
#include "binary.h"
|
||||
#include "algorithm.h"
|
||||
#include "binary.h"
|
||||
#include "delegate.h"
|
||||
#include "endianness.h"
|
||||
#include "error_handler.h"
|
||||
#include "exception.h"
|
||||
#include "integral_limits.h"
|
||||
#include "iterator.h"
|
||||
#include "memory.h"
|
||||
#include "delegate.h"
|
||||
#include "span.h"
|
||||
#include "nullptr.h"
|
||||
#include "optional.h"
|
||||
#include "exception.h"
|
||||
#include "error_handler.h"
|
||||
#include "span.h"
|
||||
#include "type_traits.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "private/minmax_push.h"
|
||||
|
||||
@ -73,7 +73,7 @@ namespace etl
|
||||
//***************************************************************************
|
||||
bit_stream(void* begin_, void* end_)
|
||||
: pdata(reinterpret_cast<unsigned char*>(begin_))
|
||||
, length_chars(etl::distance(reinterpret_cast<unsigned char*>(begin_), reinterpret_cast<unsigned char*>(end_)))
|
||||
, length_chars(static_cast<size_t>(etl::distance(reinterpret_cast<unsigned char*>(begin_), reinterpret_cast<unsigned char*>(end_))))
|
||||
{
|
||||
restart();
|
||||
}
|
||||
@ -93,7 +93,7 @@ namespace etl
|
||||
//***************************************************************************
|
||||
void set_stream(void* begin_, size_t length_)
|
||||
{
|
||||
pdata = reinterpret_cast<unsigned char*>(begin_);
|
||||
pdata = reinterpret_cast<unsigned char*>(begin_);
|
||||
length_chars = length_;
|
||||
restart();
|
||||
}
|
||||
@ -103,7 +103,7 @@ namespace etl
|
||||
//***************************************************************************
|
||||
void set_stream(void* begin_, void* end_)
|
||||
{
|
||||
set_stream(begin_, etl::distance(reinterpret_cast<unsigned char*>(begin_), reinterpret_cast<unsigned char*>(end_)));
|
||||
set_stream(begin_, static_cast<size_t>(etl::distance(reinterpret_cast<unsigned char*>(begin_), reinterpret_cast<unsigned char*>(end_))));
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
@ -112,8 +112,8 @@ namespace etl
|
||||
void restart()
|
||||
{
|
||||
bits_available_in_char = CHAR_BIT;
|
||||
char_index = 0U;
|
||||
bits_available = CHAR_BIT * length_chars;
|
||||
char_index = 0U;
|
||||
bits_available = CHAR_BIT * length_chars;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
@ -148,8 +148,7 @@ namespace etl
|
||||
/// For integral types
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value, bool>::type
|
||||
put(T value, uint_least8_t nbits = CHAR_BIT * sizeof(T))
|
||||
typename etl::enable_if<etl::is_integral<T>::value, bool>::type put(T value, uint_least8_t nbits = CHAR_BIT * sizeof(T))
|
||||
{
|
||||
return put_integral(static_cast<uint32_t>(value), nbits);
|
||||
}
|
||||
@ -176,8 +175,7 @@ namespace etl
|
||||
/// For floating point types
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_floating_point<T>::value, bool>::type
|
||||
put(T value)
|
||||
typename etl::enable_if<etl::is_floating_point<T>::value, bool>::type put(T value)
|
||||
{
|
||||
bool success = true;
|
||||
|
||||
@ -207,7 +205,7 @@ namespace etl
|
||||
// Do we have enough bits?
|
||||
if (bits_available > 0U)
|
||||
{
|
||||
value = get_bit();
|
||||
value = get_bit();
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
@ -219,11 +217,10 @@ namespace etl
|
||||
/// For integral types
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value, bool>::type
|
||||
get(T& value, uint_least8_t nbits = CHAR_BIT * sizeof(T))
|
||||
typename etl::enable_if<etl::is_integral<T>::value, bool>::type get(T& value, uint_least8_t nbits = CHAR_BIT * sizeof(T))
|
||||
{
|
||||
bool success = false;
|
||||
uint_least8_t bits = nbits;
|
||||
bool success = false;
|
||||
uint_least8_t bits = nbits;
|
||||
|
||||
if (pdata != ETL_NULLPTR)
|
||||
{
|
||||
@ -238,7 +235,7 @@ namespace etl
|
||||
unsigned char mask_width = static_cast<unsigned char>(etl::min(nbits, bits_available_in_char));
|
||||
|
||||
typedef typename etl::make_unsigned<T>::type chunk_t;
|
||||
chunk_t chunk = get_chunk(mask_width);
|
||||
chunk_t chunk = get_chunk(mask_width);
|
||||
|
||||
nbits -= mask_width;
|
||||
value |= static_cast<T>(chunk << nbits);
|
||||
@ -252,7 +249,7 @@ namespace etl
|
||||
if (etl::is_signed<T>::value && (bits != (CHAR_BIT * sizeof(T))))
|
||||
{
|
||||
typedef typename etl::make_signed<T>::type ST;
|
||||
value = etl::sign_extend<ST, ST>(value, bits);
|
||||
value = static_cast<T>(etl::sign_extend<ST, ST>(static_cast<ST>(value), bits));
|
||||
}
|
||||
|
||||
return success;
|
||||
@ -262,8 +259,7 @@ namespace etl
|
||||
/// For floating point types
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_floating_point<T>::value, bool>::type
|
||||
get(T& value)
|
||||
typename etl::enable_if<etl::is_floating_point<T>::value, bool>::type get(T& value)
|
||||
{
|
||||
bool success = false;
|
||||
|
||||
@ -279,7 +275,7 @@ namespace etl
|
||||
|
||||
for (size_t i = 0UL; i < sizeof(T); ++i)
|
||||
{
|
||||
get(data.raw[i], CHAR_BIT);
|
||||
get(data.raw[i], CHAR_BIT);
|
||||
}
|
||||
|
||||
from_bytes(reinterpret_cast<const unsigned char*>(data.raw), value);
|
||||
@ -351,7 +347,7 @@ namespace etl
|
||||
unsigned char mask_width = static_cast<unsigned char>(etl::min(nbits, bits_available_in_char));
|
||||
nbits -= mask_width;
|
||||
uint32_t mask = ((1U << mask_width) - 1U) << nbits;
|
||||
//uint32_t mask = ((uint32_t(1U) << mask_width) - 1U) << nbits;
|
||||
// uint32_t mask = ((uint32_t(1U) << mask_width) - 1U) << nbits;
|
||||
|
||||
// Move chunk to lowest char bits.
|
||||
// Chunks are never larger than one char.
|
||||
@ -422,7 +418,7 @@ namespace etl
|
||||
//***************************************************************************
|
||||
unsigned char get_chunk(unsigned char nbits)
|
||||
{
|
||||
unsigned char value = pdata[char_index];
|
||||
unsigned char value = static_cast<unsigned char>(pdata[char_index]);
|
||||
|
||||
value >>= (bits_available_in_char - nbits);
|
||||
|
||||
@ -434,7 +430,7 @@ namespace etl
|
||||
}
|
||||
else
|
||||
{
|
||||
mask = (1U << nbits) - 1;
|
||||
mask = static_cast<unsigned char>((1U << nbits) - 1);
|
||||
}
|
||||
|
||||
value &= mask;
|
||||
@ -449,7 +445,7 @@ namespace etl
|
||||
//***************************************************************************
|
||||
bool get_bit()
|
||||
{
|
||||
bool result = (pdata[char_index] & (1U << (bits_available_in_char - 1U))) != 0U;
|
||||
bool result = (static_cast<unsigned char>(pdata[char_index]) & (1U << (bits_available_in_char - 1U))) != 0U;
|
||||
|
||||
step(1U);
|
||||
|
||||
@ -467,11 +463,11 @@ namespace etl
|
||||
// Network to host.
|
||||
if (etl::endianness::value() == etl::endian::little)
|
||||
{
|
||||
etl::reverse_copy(data, data + sizeof(T), temp.raw);
|
||||
etl::reverse_copy(data, data + sizeof(T), reinterpret_cast<unsigned char*>(temp.raw));
|
||||
}
|
||||
else
|
||||
{
|
||||
etl::copy(data, data + sizeof(T), temp.raw);
|
||||
etl::copy(data, data + sizeof(T), reinterpret_cast<unsigned char*>(temp.raw));
|
||||
}
|
||||
|
||||
value = *reinterpret_cast<T*>(temp.raw);
|
||||
@ -513,11 +509,13 @@ namespace etl
|
||||
bits_available -= nbits;
|
||||
}
|
||||
|
||||
unsigned char *pdata; ///< The start of the bitstream buffer.
|
||||
size_t length_chars; ///< The length, in char, of the bitstream buffer.
|
||||
unsigned char bits_available_in_char; ///< The number of available bits in the current char.
|
||||
size_t char_index; ///< The index of the char in the bitstream buffer.
|
||||
size_t bits_available; ///< The number of bits still available in the bitstream buffer.
|
||||
unsigned char* pdata; ///< The start of the bitstream buffer.
|
||||
size_t length_chars; ///< The length, in char, of the bitstream buffer.
|
||||
unsigned char bits_available_in_char; ///< The number of available bits in
|
||||
///< the current char.
|
||||
size_t char_index; ///< The index of the char in the bitstream buffer.
|
||||
size_t bits_available; ///< The number of bits still available in the
|
||||
///< bitstream buffer.
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
@ -527,10 +525,10 @@ namespace etl
|
||||
{
|
||||
public:
|
||||
|
||||
typedef char value_type;
|
||||
typedef value_type* iterator;
|
||||
typedef const value_type* const_iterator;
|
||||
typedef etl::span<value_type> callback_parameter_type;
|
||||
typedef char value_type;
|
||||
typedef value_type* iterator;
|
||||
typedef const value_type* const_iterator;
|
||||
typedef etl::span<value_type> callback_parameter_type;
|
||||
typedef etl::delegate<void(callback_parameter_type)> callback_type;
|
||||
|
||||
//***************************************************************************
|
||||
@ -564,7 +562,7 @@ namespace etl
|
||||
//***************************************************************************
|
||||
bit_stream_writer(void* begin_, void* end_, etl::endian stream_endianness_, callback_type callback_ = callback_type())
|
||||
: pdata(reinterpret_cast<char*>(begin_))
|
||||
, length_chars(etl::distance(reinterpret_cast<unsigned char*>(begin_), reinterpret_cast<unsigned char*>(end_)))
|
||||
, length_chars(static_cast<size_t>(etl::distance(reinterpret_cast<unsigned char*>(begin_), reinterpret_cast<unsigned char*>(end_))))
|
||||
, stream_endianness(stream_endianness_)
|
||||
, callback(callback_)
|
||||
{
|
||||
@ -589,8 +587,8 @@ namespace etl
|
||||
void restart()
|
||||
{
|
||||
bits_available_in_char = CHAR_BIT;
|
||||
char_index = 0U;
|
||||
bits_available = capacity_bits();
|
||||
char_index = 0U;
|
||||
bits_available = capacity_bits();
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
@ -653,8 +651,7 @@ namespace etl
|
||||
/// For integral types
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value, void>::type
|
||||
write_unchecked(T value, uint_least8_t nbits = CHAR_BIT * sizeof(T))
|
||||
typename etl::enable_if<etl::is_integral<T>::value, void>::type write_unchecked(T value, uint_least8_t nbits = CHAR_BIT * sizeof(T))
|
||||
{
|
||||
typedef typename etl::unsigned_type<T>::type unsigned_t;
|
||||
|
||||
@ -665,8 +662,7 @@ namespace etl
|
||||
/// For integral types
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value, bool>::type
|
||||
write(T value, uint_least8_t nbits = CHAR_BIT * sizeof(T))
|
||||
typename etl::enable_if<etl::is_integral<T>::value, bool>::type write(T value, uint_least8_t nbits = CHAR_BIT * sizeof(T))
|
||||
{
|
||||
bool success = (available(nbits) > 0U);
|
||||
|
||||
@ -975,10 +971,12 @@ namespace etl
|
||||
char* const pdata; ///< The start of the bitstream buffer.
|
||||
const size_t length_chars; ///< The length of the bitstream buffer.
|
||||
const etl::endian stream_endianness; ///< The endianness of the stream data.
|
||||
unsigned char bits_available_in_char; ///< The number of available bits in the current char.
|
||||
size_t char_index; ///< The index of the current char in the bitstream buffer.
|
||||
size_t bits_available; ///< The number of bits still available in the bitstream buffer.
|
||||
callback_type callback; ///< An optional callback on every filled byte in buffer.
|
||||
unsigned char bits_available_in_char; ///< The number of available bits in
|
||||
///< the current char.
|
||||
size_t char_index; ///< The index of the current char in the bitstream buffer.
|
||||
size_t bits_available; ///< The number of bits still available in the
|
||||
///< bitstream buffer.
|
||||
callback_type callback; ///< An optional callback on every filled byte in buffer.
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
@ -1005,8 +1003,8 @@ namespace etl
|
||||
/// Overload this to support custom types.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value, void>::type
|
||||
write_unchecked(etl::bit_stream_writer& stream, const T& value, uint_least8_t nbits = CHAR_BIT * sizeof(T))
|
||||
typename etl::enable_if<etl::is_integral<T>::value, void>::type write_unchecked(etl::bit_stream_writer& stream, const T& value,
|
||||
uint_least8_t nbits = CHAR_BIT * sizeof(T))
|
||||
{
|
||||
stream.write_unchecked(value, nbits);
|
||||
}
|
||||
@ -1017,8 +1015,8 @@ namespace etl
|
||||
/// Overload this to support custom types.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value, bool>::type
|
||||
write(etl::bit_stream_writer& stream, const T& value, uint_least8_t nbits = CHAR_BIT * sizeof(T))
|
||||
typename etl::enable_if<etl::is_integral<T>::value, bool>::type write(etl::bit_stream_writer& stream, const T& value,
|
||||
uint_least8_t nbits = CHAR_BIT * sizeof(T))
|
||||
{
|
||||
return stream.write(value, nbits);
|
||||
}
|
||||
@ -1030,7 +1028,7 @@ namespace etl
|
||||
{
|
||||
public:
|
||||
|
||||
typedef char value_type;
|
||||
typedef char value_type;
|
||||
typedef const char* const_iterator;
|
||||
|
||||
//***************************************************************************
|
||||
@ -1086,7 +1084,7 @@ namespace etl
|
||||
//***************************************************************************
|
||||
bit_stream_reader(const void* begin_, const void* end_, etl::endian stream_endianness_)
|
||||
: pdata(reinterpret_cast<const char*>(begin_))
|
||||
, length_chars(etl::distance(reinterpret_cast<const char*>(begin_), reinterpret_cast<const char*>(end_)))
|
||||
, length_chars(static_cast<size_t>(etl::distance(reinterpret_cast<const char*>(begin_), reinterpret_cast<const char*>(end_))))
|
||||
, stream_endianness(stream_endianness_)
|
||||
{
|
||||
restart();
|
||||
@ -1109,16 +1107,15 @@ namespace etl
|
||||
void restart()
|
||||
{
|
||||
bits_available_in_char = CHAR_BIT;
|
||||
char_index = 0U;
|
||||
bits_available = CHAR_BIT * length_chars;
|
||||
char_index = 0U;
|
||||
bits_available = CHAR_BIT * length_chars;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// For bool types
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_same<bool, T>::value, bool>::type
|
||||
read_unchecked()
|
||||
typename etl::enable_if<etl::is_same<bool, T>::value, bool>::type read_unchecked()
|
||||
{
|
||||
return get_bit();
|
||||
}
|
||||
@ -1127,8 +1124,7 @@ namespace etl
|
||||
/// For bool types
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_same<bool, T>::value, etl::optional<bool> >::type
|
||||
read()
|
||||
typename etl::enable_if<etl::is_same<bool, T>::value, etl::optional<bool> >::type read()
|
||||
{
|
||||
etl::optional<bool> result;
|
||||
|
||||
@ -1144,12 +1140,12 @@ namespace etl
|
||||
/// For integral types
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value && !etl::is_same<bool, T>::value, T>::type
|
||||
read_unchecked(uint_least8_t nbits = CHAR_BIT * sizeof(T))
|
||||
typename etl::enable_if< etl::is_integral<T>::value && !etl::is_same<bool, T>::value, T>::type read_unchecked(uint_least8_t nbits = CHAR_BIT
|
||||
* sizeof(T))
|
||||
{
|
||||
typedef typename etl::unsigned_type<T>::type unsigned_t;
|
||||
|
||||
T value = read_value<unsigned_t>(nbits, etl::is_signed<T>::value);
|
||||
T value = static_cast<T>(read_value<unsigned_t>(nbits, etl::is_signed<T>::value));
|
||||
|
||||
return static_cast<T>(value);
|
||||
}
|
||||
@ -1166,7 +1162,7 @@ namespace etl
|
||||
// Do we have enough bits?
|
||||
if (bits_available >= nbits)
|
||||
{
|
||||
result = read_unchecked<T>(nbits);
|
||||
result = read_unchecked<T>(nbits);
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -1266,8 +1262,8 @@ namespace etl
|
||||
// Make sure that we are not reading more bits than should be available.
|
||||
nbits = (nbits > (CHAR_BIT * sizeof(T))) ? (CHAR_BIT * sizeof(T)) : nbits;
|
||||
|
||||
T value = 0;
|
||||
uint_least8_t bits = nbits;
|
||||
T value = 0;
|
||||
uint_least8_t bits = nbits;
|
||||
|
||||
// Get the bits from the stream.
|
||||
while (nbits != 0)
|
||||
@ -1299,7 +1295,7 @@ namespace etl
|
||||
//***************************************************************************
|
||||
unsigned char get_chunk(unsigned char nbits)
|
||||
{
|
||||
unsigned char value = pdata[char_index];
|
||||
unsigned char value = static_cast<unsigned char>(pdata[char_index]);
|
||||
value >>= (bits_available_in_char - nbits);
|
||||
|
||||
unsigned char mask;
|
||||
@ -1310,7 +1306,7 @@ namespace etl
|
||||
}
|
||||
else
|
||||
{
|
||||
mask = (1U << nbits) - 1;
|
||||
mask = static_cast<unsigned char>((1U << nbits) - 1);
|
||||
}
|
||||
|
||||
value &= mask;
|
||||
@ -1325,7 +1321,7 @@ namespace etl
|
||||
//***************************************************************************
|
||||
bool get_bit()
|
||||
{
|
||||
bool result = (pdata[char_index] & (1U << (bits_available_in_char - 1U))) != 0U;
|
||||
bool result = (static_cast<unsigned char>(pdata[char_index]) & (1U << (bits_available_in_char - 1U))) != 0U;
|
||||
|
||||
step(1U);
|
||||
|
||||
@ -1352,9 +1348,11 @@ namespace etl
|
||||
const char* pdata; ///< The start of the bitstream buffer.
|
||||
size_t length_chars; ///< The length, in char, of the bitstream buffer.
|
||||
const etl::endian stream_endianness; ///< The endianness of the stream data.
|
||||
unsigned char bits_available_in_char; ///< The number of available bits in the current char.
|
||||
size_t char_index; ///< The index of the char in the bitstream buffer.
|
||||
size_t bits_available; ///< The number of bits still available in the bitstream buffer.
|
||||
unsigned char bits_available_in_char; ///< The number of available bits in
|
||||
///< the current char.
|
||||
size_t char_index; ///< The index of the char in the bitstream buffer.
|
||||
size_t bits_available; ///< The number of bits still available in the
|
||||
///< bitstream buffer.
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
@ -1404,7 +1402,7 @@ namespace etl
|
||||
{
|
||||
return stream.read<bool>();
|
||||
}
|
||||
}
|
||||
} // namespace etl
|
||||
|
||||
#include "private/minmax_pop.h"
|
||||
|
||||
|
||||
@ -32,12 +32,12 @@ SOFTWARE.
|
||||
#define ETL_BLOOM_FILTER_INCLUDED
|
||||
|
||||
#include "platform.h"
|
||||
#include "parameter_type.h"
|
||||
#include "bitset.h"
|
||||
#include "type_traits.h"
|
||||
#include "binary.h"
|
||||
#include "bitset.h"
|
||||
#include "log.h"
|
||||
#include "parameter_type.h"
|
||||
#include "power.h"
|
||||
#include "type_traits.h"
|
||||
|
||||
///\defgroup bloom_filter bloom_filter
|
||||
/// A Bloom filter
|
||||
@ -51,34 +51,33 @@ namespace etl
|
||||
struct null_hash
|
||||
{
|
||||
template <typename T>
|
||||
size_t operator ()(T)
|
||||
size_t operator()(T)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace private_bloom_filter
|
||||
|
||||
//***************************************************************************
|
||||
/// An implementation of a bloom filter.
|
||||
/// Allows up to three hashes to be defined.
|
||||
/// Hashes must support the () operator and define 'argument_type'.
|
||||
///\tparam Desired_Width The desired number of hash results that can be stored. Rounded up to best fit the underlying bitset.
|
||||
///\tparam THash1 The first hash generator class.
|
||||
///\tparam THash2 The second hash generator class. If omitted, uses the null hash.
|
||||
///\tparam THash3 The third hash generator class. If omitted, uses the null hash.
|
||||
/// The hash classes must define <b>argument_type</b>.
|
||||
///\tparam Desired_Width The desired number of hash results that can be
|
||||
/// stored. Rounded up to best fit the underlying
|
||||
/// bitset. \tparam THash1 The first hash generator class. \tparam
|
||||
/// THash2 The second hash generator class. If omitted, uses the null
|
||||
/// hash. \tparam THash3 The third hash generator class. If omitted,
|
||||
/// uses the null hash. The hash classes must define <b>argument_type</b>.
|
||||
///\ingroup bloom_filter
|
||||
//***************************************************************************
|
||||
template <size_t Desired_Width,
|
||||
typename THash1,
|
||||
typename THash2 = private_bloom_filter::null_hash,
|
||||
template <size_t Desired_Width, typename THash1, typename THash2 = private_bloom_filter::null_hash,
|
||||
typename THash3 = private_bloom_filter::null_hash>
|
||||
class bloom_filter
|
||||
{
|
||||
private:
|
||||
|
||||
typedef typename etl::parameter_type<typename THash1::argument_type>::type parameter_t;
|
||||
typedef private_bloom_filter::null_hash null_hash;
|
||||
typedef private_bloom_filter::null_hash null_hash;
|
||||
|
||||
public:
|
||||
|
||||
@ -90,11 +89,11 @@ namespace etl
|
||||
|
||||
//***************************************************************************
|
||||
/// Clears the bloom filter of all entries.
|
||||
//***************************************************************************
|
||||
void clear()
|
||||
{
|
||||
flags.reset();
|
||||
}
|
||||
//***************************************************************************
|
||||
void clear()
|
||||
{
|
||||
flags.reset();
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Adds a key to the filter.
|
||||
@ -184,7 +183,6 @@ namespace etl
|
||||
/// The Bloom filter flags.
|
||||
etl::bitset<WIDTH> flags;
|
||||
};
|
||||
}
|
||||
} // namespace etl
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@ -91,7 +91,7 @@ namespace etl
|
||||
//***************************************************
|
||||
/// Assignment operator
|
||||
//***************************************************
|
||||
const_iterator& operator =(const const_iterator& rhs)
|
||||
const_iterator& operator=(const const_iterator& rhs)
|
||||
{
|
||||
p_bresenham_line = rhs.p_bresenham_line;
|
||||
|
||||
@ -101,7 +101,7 @@ namespace etl
|
||||
//***************************************************
|
||||
/// Pre-increment operator
|
||||
//***************************************************
|
||||
const_iterator& operator ++()
|
||||
const_iterator& operator++()
|
||||
{
|
||||
// Has the end of the series has been reached?
|
||||
if (p_bresenham_line->get_coordinate() == p_bresenham_line->back())
|
||||
@ -120,7 +120,7 @@ namespace etl
|
||||
//***************************************************
|
||||
/// De-reference operator
|
||||
//***************************************************
|
||||
value_type operator *() const
|
||||
value_type operator*() const
|
||||
{
|
||||
return p_bresenham_line->get_coordinate();
|
||||
}
|
||||
@ -128,7 +128,7 @@ namespace etl
|
||||
//***************************************************
|
||||
/// Equality operator
|
||||
//***************************************************
|
||||
friend bool operator ==(const const_iterator& lhs, const const_iterator& rhs)
|
||||
friend bool operator==(const const_iterator& lhs, const const_iterator& rhs)
|
||||
{
|
||||
return lhs.p_bresenham_line == rhs.p_bresenham_line;
|
||||
}
|
||||
@ -136,7 +136,7 @@ namespace etl
|
||||
//***************************************************
|
||||
/// Inequality operator
|
||||
//***************************************************
|
||||
friend bool operator !=(const const_iterator& lhs, const const_iterator& rhs)
|
||||
friend bool operator!=(const const_iterator& lhs, const const_iterator& rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
@ -240,18 +240,18 @@ namespace etl
|
||||
{
|
||||
if (y_is_major_axis())
|
||||
{
|
||||
return (dy / 2) + 1;
|
||||
return static_cast<size_t>((dy / 2) + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
return (dx / 2) + 1;
|
||||
return static_cast<size_t>((dx / 2) + 1);
|
||||
}
|
||||
}
|
||||
|
||||
//***************************************************
|
||||
/// Equality operator
|
||||
//***************************************************
|
||||
friend bool operator ==(const bresenham_line& lhs, const bresenham_line& rhs)
|
||||
friend bool operator==(const bresenham_line& lhs, const bresenham_line& rhs)
|
||||
{
|
||||
return (lhs.front() == rhs.front()) && (lhs.back() == rhs.back());
|
||||
}
|
||||
@ -259,7 +259,7 @@ namespace etl
|
||||
//***************************************************
|
||||
/// Inequality operator
|
||||
//***************************************************
|
||||
friend bool operator !=(const bresenham_line& lhs, const bresenham_line& rhs)
|
||||
friend bool operator!=(const bresenham_line& lhs, const bresenham_line& rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
@ -272,7 +272,7 @@ namespace etl
|
||||
void initialise(T first_x, T first_y, T last_x, T last_y)
|
||||
{
|
||||
first = value_type(first_x, first_y);
|
||||
last = value_type(last_x, last_y);
|
||||
last = value_type(last_x, last_y);
|
||||
coordinate = first;
|
||||
x_increment = (last_x < first_x) ? -1 : 1;
|
||||
y_increment = (last_y < first_y) ? -1 : 1;
|
||||
@ -355,7 +355,6 @@ namespace etl
|
||||
work_t balance;
|
||||
bool do_minor_increment;
|
||||
};
|
||||
}
|
||||
} // namespace etl
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@ -32,12 +32,12 @@ SOFTWARE.
|
||||
#define ETL_BUFFER_DESCRIPTORS_INCLUDED
|
||||
|
||||
#include "platform.h"
|
||||
#include "array.h"
|
||||
#include "delegate.h"
|
||||
#include "type_traits.h"
|
||||
#include "static_assert.h"
|
||||
#include "cyclic_value.h"
|
||||
#include "algorithm.h"
|
||||
#include "array.h"
|
||||
#include "cyclic_value.h"
|
||||
#include "delegate.h"
|
||||
#include "static_assert.h"
|
||||
#include "type_traits.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
@ -89,7 +89,7 @@ namespace etl
|
||||
}
|
||||
|
||||
//*********************************
|
||||
descriptor& operator =(const descriptor& other)
|
||||
descriptor& operator=(const descriptor& other)
|
||||
{
|
||||
pdesc_item = other.pdesc_item;
|
||||
return *this;
|
||||
@ -99,14 +99,13 @@ namespace etl
|
||||
pointer data() const
|
||||
{
|
||||
assert(pdesc_item != ETL_NULLPTR);
|
||||
#include "private/diagnostic_null_dereference_push.h"
|
||||
#include "private/diagnostic_null_dereference_push.h"
|
||||
return pdesc_item->pbuffer;
|
||||
#include "private/diagnostic_pop.h"
|
||||
#include "private/diagnostic_pop.h"
|
||||
}
|
||||
|
||||
//*********************************
|
||||
ETL_NODISCARD
|
||||
ETL_CONSTEXPR size_type max_size() const
|
||||
ETL_NODISCARD ETL_CONSTEXPR size_type max_size() const
|
||||
{
|
||||
return BUFFER_SIZE;
|
||||
}
|
||||
@ -284,23 +283,26 @@ namespace etl
|
||||
//*********************************
|
||||
struct descriptor_item
|
||||
{
|
||||
pointer pbuffer;
|
||||
pointer pbuffer;
|
||||
volatile flag_type in_use;
|
||||
};
|
||||
|
||||
callback_type callback;
|
||||
etl::array<descriptor_item, N_BUFFERS> descriptor_items;
|
||||
callback_type callback;
|
||||
etl::array<descriptor_item, N_BUFFERS> descriptor_items;
|
||||
etl::cyclic_value<uint_least8_t, 0U, N_BUFFERS - 1> next;
|
||||
};
|
||||
|
||||
template <typename TBuffer, size_t BUFFER_SIZE_, size_t N_BUFFERS_, typename TFlag>
|
||||
ETL_CONSTANT typename buffer_descriptors<TBuffer, BUFFER_SIZE_, N_BUFFERS_, TFlag>::size_type buffer_descriptors<TBuffer, BUFFER_SIZE_, N_BUFFERS_, TFlag>::N_BUFFERS;
|
||||
ETL_CONSTANT typename buffer_descriptors<TBuffer, BUFFER_SIZE_, N_BUFFERS_, TFlag>::size_type
|
||||
buffer_descriptors<TBuffer, BUFFER_SIZE_, N_BUFFERS_, TFlag>::N_BUFFERS;
|
||||
|
||||
template <typename TBuffer, size_t BUFFER_SIZE_, size_t N_BUFFERS_, typename TFlag>
|
||||
ETL_CONSTANT typename buffer_descriptors<TBuffer, BUFFER_SIZE_, N_BUFFERS_, TFlag>::size_type buffer_descriptors<TBuffer, BUFFER_SIZE_, N_BUFFERS_, TFlag>::BUFFER_SIZE;
|
||||
|
||||
ETL_CONSTANT typename buffer_descriptors<TBuffer, BUFFER_SIZE_, N_BUFFERS_, TFlag>::size_type
|
||||
buffer_descriptors<TBuffer, BUFFER_SIZE_, N_BUFFERS_, TFlag>::BUFFER_SIZE;
|
||||
|
||||
template <typename TBuffer, size_t BUFFER_SIZE_, size_t N_BUFFERS_, typename TFlag>
|
||||
ETL_CONSTANT typename buffer_descriptors<TBuffer, BUFFER_SIZE_, N_BUFFERS_, TFlag>::size_type buffer_descriptors<TBuffer, BUFFER_SIZE_, N_BUFFERS_, TFlag>::descriptor::MAX_SIZE;
|
||||
}
|
||||
ETL_CONSTANT typename buffer_descriptors<TBuffer, BUFFER_SIZE_, N_BUFFERS_, TFlag>::size_type
|
||||
buffer_descriptors<TBuffer, BUFFER_SIZE_, N_BUFFERS_, TFlag>::descriptor::MAX_SIZE;
|
||||
} // namespace etl
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -33,15 +33,15 @@ namespace etl
|
||||
{
|
||||
#if ETL_USING_CPP11 && !defined(ETL_BYTE_FORCE_CPP03_IMPLEMENTATION)
|
||||
|
||||
enum class byte : unsigned char {};
|
||||
enum class byte : unsigned char
|
||||
{
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
/// To integer.
|
||||
//*************************************************************************
|
||||
template <typename TInteger>
|
||||
constexpr
|
||||
typename etl::enable_if<etl::is_integral<TInteger>::value, TInteger>::type
|
||||
to_integer(etl::byte b) ETL_NOEXCEPT
|
||||
constexpr typename etl::enable_if<etl::is_integral<TInteger>::value, TInteger>::type to_integer(etl::byte b) ETL_NOEXCEPT
|
||||
{
|
||||
return TInteger(b);
|
||||
}
|
||||
@ -50,31 +50,25 @@ namespace etl
|
||||
/// Shift left.
|
||||
//*************************************************************************
|
||||
template <typename TInteger>
|
||||
constexpr
|
||||
typename etl::enable_if<etl::is_integral<TInteger>::value, etl::byte>::type
|
||||
operator <<(etl::byte b, TInteger shift) ETL_NOEXCEPT
|
||||
constexpr typename etl::enable_if<etl::is_integral<TInteger>::value, etl::byte>::type operator<<(etl::byte b, TInteger shift) ETL_NOEXCEPT
|
||||
{
|
||||
return etl::byte(static_cast<unsigned int>(b) << shift);
|
||||
return etl::byte(static_cast<unsigned int>(b) << shift);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Shift right
|
||||
//*************************************************************************
|
||||
template <typename TInteger>
|
||||
constexpr
|
||||
typename etl::enable_if<etl::is_integral<TInteger>::value, etl::byte>::type
|
||||
operator >>(etl::byte b, TInteger shift) ETL_NOEXCEPT
|
||||
constexpr typename etl::enable_if<etl::is_integral<TInteger>::value, etl::byte>::type operator>>(etl::byte b, TInteger shift) ETL_NOEXCEPT
|
||||
{
|
||||
return etl::byte(static_cast<unsigned int>(b) >> shift);
|
||||
return etl::byte(static_cast<unsigned int>(b) >> shift);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Shift left equals.
|
||||
//*************************************************************************
|
||||
template <typename TInteger>
|
||||
constexpr
|
||||
typename etl::enable_if<etl::is_integral<TInteger>::value, etl::byte&>::type
|
||||
operator <<=(etl::byte& b, TInteger shift) ETL_NOEXCEPT
|
||||
constexpr typename etl::enable_if<etl::is_integral<TInteger>::value, etl::byte&>::type operator<<=(etl::byte& b, TInteger shift) ETL_NOEXCEPT
|
||||
{
|
||||
return b = b << shift;
|
||||
}
|
||||
@ -83,9 +77,7 @@ namespace etl
|
||||
/// Shift right equals.
|
||||
//*************************************************************************
|
||||
template <typename TInteger>
|
||||
constexpr
|
||||
typename etl::enable_if<etl::is_integral<TInteger>::value, etl::byte&>::type
|
||||
operator >>=(etl::byte& b, TInteger shift) ETL_NOEXCEPT
|
||||
constexpr typename etl::enable_if<etl::is_integral<TInteger>::value, etl::byte&>::type operator>>=(etl::byte& b, TInteger shift) ETL_NOEXCEPT
|
||||
{
|
||||
return b = b >> shift;
|
||||
}
|
||||
@ -93,7 +85,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Or.
|
||||
//*************************************************************************
|
||||
inline constexpr etl::byte operator |(etl::byte lhs, etl::byte rhs) ETL_NOEXCEPT
|
||||
inline constexpr etl::byte operator|(etl::byte lhs, etl::byte rhs) ETL_NOEXCEPT
|
||||
{
|
||||
return etl::byte(static_cast<unsigned int>(lhs) | static_cast<unsigned int>(rhs));
|
||||
}
|
||||
@ -101,7 +93,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// And.
|
||||
//*************************************************************************
|
||||
inline constexpr etl::byte operator &(etl::byte lhs, etl::byte rhs) ETL_NOEXCEPT
|
||||
inline constexpr etl::byte operator&(etl::byte lhs, etl::byte rhs) ETL_NOEXCEPT
|
||||
{
|
||||
return etl::byte(static_cast<unsigned int>(lhs) & static_cast<unsigned int>(rhs));
|
||||
}
|
||||
@ -109,7 +101,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Exclusive Or.
|
||||
//*************************************************************************
|
||||
inline constexpr etl::byte operator ^(etl::byte lhs, etl::byte rhs) ETL_NOEXCEPT
|
||||
inline constexpr etl::byte operator^(etl::byte lhs, etl::byte rhs) ETL_NOEXCEPT
|
||||
{
|
||||
return etl::byte(static_cast<unsigned int>(lhs) ^ static_cast<unsigned int>(rhs));
|
||||
}
|
||||
@ -117,7 +109,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Or equals.
|
||||
//*************************************************************************
|
||||
inline ETL_CONSTEXPR14 etl::byte& operator |=(etl::byte& lhs, etl::byte rhs) ETL_NOEXCEPT
|
||||
inline ETL_CONSTEXPR14 etl::byte& operator|=(etl::byte& lhs, etl::byte rhs) ETL_NOEXCEPT
|
||||
{
|
||||
return lhs = lhs | rhs;
|
||||
}
|
||||
@ -125,7 +117,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// And equals
|
||||
//*************************************************************************
|
||||
inline ETL_CONSTEXPR14 etl::byte& operator &=(etl::byte& lhs, etl::byte rhs) ETL_NOEXCEPT
|
||||
inline ETL_CONSTEXPR14 etl::byte& operator&=(etl::byte& lhs, etl::byte rhs) ETL_NOEXCEPT
|
||||
{
|
||||
return lhs = lhs & rhs;
|
||||
}
|
||||
@ -133,7 +125,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Exclusive or equals.
|
||||
//*************************************************************************
|
||||
inline ETL_CONSTEXPR14 etl::byte& operator ^=(etl::byte& lhs, etl::byte rhs) ETL_NOEXCEPT
|
||||
inline ETL_CONSTEXPR14 etl::byte& operator^=(etl::byte& lhs, etl::byte rhs) ETL_NOEXCEPT
|
||||
{
|
||||
return lhs = lhs ^ rhs;
|
||||
}
|
||||
@ -141,7 +133,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Not.
|
||||
//*************************************************************************
|
||||
inline constexpr etl::byte operator ~(etl::byte b) ETL_NOEXCEPT
|
||||
inline constexpr etl::byte operator~(etl::byte b) ETL_NOEXCEPT
|
||||
{
|
||||
return etl::byte(~static_cast<unsigned int>(b));
|
||||
}
|
||||
@ -157,11 +149,9 @@ namespace etl
|
||||
|
||||
// Friend functions
|
||||
template <typename TInteger>
|
||||
friend
|
||||
typename etl::enable_if<etl::is_integral<TInteger>::value, TInteger>::type
|
||||
to_integer(etl::byte b);
|
||||
friend typename etl::enable_if<etl::is_integral<TInteger>::value, TInteger>::type to_integer(etl::byte b);
|
||||
|
||||
friend bool operator ==(etl::byte lhs, etl::byte rhs);
|
||||
friend bool operator==(etl::byte lhs, etl::byte rhs);
|
||||
|
||||
// Default constructor
|
||||
byte()
|
||||
@ -192,7 +182,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Equality test
|
||||
//*************************************************************************
|
||||
inline bool operator ==(etl::byte lhs, etl::byte rhs)
|
||||
inline bool operator==(etl::byte lhs, etl::byte rhs)
|
||||
{
|
||||
return (lhs.value == rhs.value);
|
||||
}
|
||||
@ -200,7 +190,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Inequality test
|
||||
//*************************************************************************
|
||||
inline bool operator !=(etl::byte lhs, etl::byte rhs)
|
||||
inline bool operator!=(etl::byte lhs, etl::byte rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
@ -208,9 +198,8 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// To integer.
|
||||
//*************************************************************************
|
||||
template <typename TInteger>
|
||||
typename etl::enable_if<etl::is_integral<TInteger>::value, TInteger>::type
|
||||
to_integer(etl::byte b)
|
||||
template <typename TInteger>
|
||||
typename etl::enable_if<etl::is_integral<TInteger>::value, TInteger>::type to_integer(etl::byte b)
|
||||
{
|
||||
return TInteger(b);
|
||||
}
|
||||
@ -219,28 +208,25 @@ namespace etl
|
||||
/// Shift left.
|
||||
//*************************************************************************
|
||||
template <typename TInteger>
|
||||
typename etl::enable_if<etl::is_integral<TInteger>::value, etl::byte>::type
|
||||
operator <<(etl::byte b, TInteger shift)
|
||||
typename etl::enable_if<etl::is_integral<TInteger>::value, etl::byte>::type operator<<(etl::byte b, TInteger shift)
|
||||
{
|
||||
return etl::byte(to_integer<unsigned int>(b) << shift);
|
||||
return etl::byte(to_integer<unsigned int>(b) << shift);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Shift right
|
||||
//*************************************************************************
|
||||
template <typename TInteger>
|
||||
typename etl::enable_if<etl::is_integral<TInteger>::value, etl::byte>::type
|
||||
operator >>(etl::byte b, TInteger shift)
|
||||
typename etl::enable_if<etl::is_integral<TInteger>::value, etl::byte>::type operator>>(etl::byte b, TInteger shift)
|
||||
{
|
||||
return etl::byte(to_integer<unsigned int>(b) >> shift);
|
||||
return etl::byte(to_integer<unsigned int>(b) >> shift);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Shift left equals.
|
||||
//*************************************************************************
|
||||
template <typename TInteger>
|
||||
typename etl::enable_if<etl::is_integral<TInteger>::value, etl::byte&>::type
|
||||
operator <<=(etl::byte& b, TInteger shift)
|
||||
template <typename TInteger>
|
||||
typename etl::enable_if<etl::is_integral<TInteger>::value, etl::byte&>::type operator<<=(etl::byte& b, TInteger shift)
|
||||
{
|
||||
b = b << shift;
|
||||
|
||||
@ -251,8 +237,7 @@ namespace etl
|
||||
/// Shift right equals.
|
||||
//*************************************************************************
|
||||
template <typename TInteger>
|
||||
typename etl::enable_if<etl::is_integral<TInteger>::value, etl::byte&>::type
|
||||
operator >>=(etl::byte& b, TInteger shift)
|
||||
typename etl::enable_if<etl::is_integral<TInteger>::value, etl::byte&>::type operator>>=(etl::byte& b, TInteger shift)
|
||||
{
|
||||
b = b >> shift;
|
||||
|
||||
@ -262,7 +247,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Or.
|
||||
//*************************************************************************
|
||||
inline etl::byte operator |(etl::byte lhs, etl::byte rhs)
|
||||
inline etl::byte operator|(etl::byte lhs, etl::byte rhs)
|
||||
{
|
||||
return etl::byte(to_integer<unsigned int>(lhs) | to_integer<unsigned int>(rhs));
|
||||
}
|
||||
@ -270,7 +255,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// And.
|
||||
//*************************************************************************
|
||||
inline etl::byte operator &(etl::byte lhs, etl::byte rhs)
|
||||
inline etl::byte operator&(etl::byte lhs, etl::byte rhs)
|
||||
{
|
||||
return etl::byte(to_integer<unsigned int>(lhs) & to_integer<unsigned int>(rhs));
|
||||
}
|
||||
@ -278,15 +263,15 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Exclusive Or.
|
||||
//*************************************************************************
|
||||
inline etl::byte operator ^(etl::byte lhs, etl::byte rhs)
|
||||
inline etl::byte operator^(etl::byte lhs, etl::byte rhs)
|
||||
{
|
||||
return etl::byte(to_integer<unsigned int>(lhs) ^ to_integer<unsigned int>(rhs));
|
||||
return etl::byte(to_integer<unsigned int>(lhs) ^ to_integer<unsigned int>(rhs));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Or equals.
|
||||
//*************************************************************************
|
||||
inline etl::byte& operator |=(etl::byte& lhs, etl::byte rhs)
|
||||
inline etl::byte& operator|=(etl::byte& lhs, etl::byte rhs)
|
||||
{
|
||||
return lhs = lhs | rhs;
|
||||
}
|
||||
@ -294,7 +279,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// And equals
|
||||
//*************************************************************************
|
||||
inline etl::byte& operator &=(etl::byte& lhs, etl::byte rhs)
|
||||
inline etl::byte& operator&=(etl::byte& lhs, etl::byte rhs)
|
||||
{
|
||||
return lhs = lhs & rhs;
|
||||
}
|
||||
@ -302,7 +287,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Exclusive or equals.
|
||||
//*************************************************************************
|
||||
inline etl::byte& operator ^=(etl::byte& lhs, etl::byte rhs)
|
||||
inline etl::byte& operator^=(etl::byte& lhs, etl::byte rhs)
|
||||
{
|
||||
return lhs = lhs ^ rhs;
|
||||
}
|
||||
@ -310,14 +295,13 @@ namespace etl
|
||||
//*************************************************************************
|
||||
/// Not.
|
||||
//*************************************************************************
|
||||
inline etl::byte operator ~(etl::byte b)
|
||||
inline etl::byte operator~(etl::byte b)
|
||||
{
|
||||
return etl::byte(~to_integer<unsigned char>(b));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
} // namespace etl
|
||||
|
||||
#endif
|
||||
|
||||
@ -32,22 +32,21 @@ SOFTWARE.
|
||||
#define ETL_BYTE_STREAM_INCLUDED
|
||||
|
||||
#include "platform.h"
|
||||
#include "type_traits.h"
|
||||
#include "nullptr.h"
|
||||
#include "endianness.h"
|
||||
#include "integral_limits.h"
|
||||
#include "algorithm.h"
|
||||
#include "delegate.h"
|
||||
#include "endianness.h"
|
||||
#include "error_handler.h"
|
||||
#include "exception.h"
|
||||
#include "integral_limits.h"
|
||||
#include "iterator.h"
|
||||
#include "memory.h"
|
||||
#include "span.h"
|
||||
#include "iterator.h"
|
||||
#include "nullptr.h"
|
||||
#include "optional.h"
|
||||
#include "delegate.h"
|
||||
#include "exception.h"
|
||||
#include "error_handler.h"
|
||||
#include "span.h"
|
||||
#include "type_traits.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <limits.h>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace etl
|
||||
{
|
||||
@ -58,9 +57,9 @@ namespace etl
|
||||
{
|
||||
public:
|
||||
|
||||
typedef char* iterator;
|
||||
typedef const char* const_iterator;
|
||||
typedef etl::span<char> callback_parameter_type;
|
||||
typedef char* iterator;
|
||||
typedef const char* const_iterator;
|
||||
typedef etl::span<char> callback_parameter_type;
|
||||
typedef etl::delegate<void(callback_parameter_type)> callback_type;
|
||||
|
||||
//***************************************************************************
|
||||
@ -93,7 +92,7 @@ namespace etl
|
||||
byte_stream_writer(void* begin_, void* end_, etl::endian stream_endianness_, callback_type callback_ = callback_type())
|
||||
: pdata(reinterpret_cast<char*>(begin_))
|
||||
, pcurrent(reinterpret_cast<char*>(begin_))
|
||||
, stream_length(etl::distance(reinterpret_cast<char*>(begin_), reinterpret_cast<char*>(end_)))
|
||||
, stream_length(static_cast<size_t>(etl::distance(reinterpret_cast<char*>(begin_), reinterpret_cast<char*>(end_))))
|
||||
, stream_endianness(stream_endianness_)
|
||||
, callback(callback_)
|
||||
{
|
||||
@ -115,7 +114,7 @@ namespace etl
|
||||
/// Construct from array.
|
||||
//***************************************************************************
|
||||
template <typename T, size_t Size>
|
||||
byte_stream_writer(T(&begin_)[Size], etl::endian stream_endianness_, callback_type callback_ = callback_type())
|
||||
byte_stream_writer(T (&begin_)[Size], etl::endian stream_endianness_, callback_type callback_ = callback_type())
|
||||
: pdata(begin_)
|
||||
, pcurrent(begin_)
|
||||
, stream_length(begin_ + (Size * sizeof(T)))
|
||||
@ -143,7 +142,7 @@ namespace etl
|
||||
{
|
||||
write_unchecked(value);
|
||||
}
|
||||
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
@ -151,8 +150,7 @@ namespace etl
|
||||
/// Write a value to the stream.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, void>::type
|
||||
write_unchecked(T value)
|
||||
typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, void>::type write_unchecked(T value)
|
||||
{
|
||||
to_bytes<T>(value);
|
||||
}
|
||||
@ -161,14 +159,13 @@ namespace etl
|
||||
/// Write a value to the stream.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, bool>::type
|
||||
write(T value)
|
||||
typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, bool>::type write(T value)
|
||||
{
|
||||
bool success = (available<T>() > 0U);
|
||||
|
||||
if (success)
|
||||
{
|
||||
write_unchecked(value);
|
||||
write_unchecked(value);
|
||||
}
|
||||
|
||||
return success;
|
||||
@ -178,8 +175,7 @@ namespace etl
|
||||
/// Write a range of T to the stream.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, void>::type
|
||||
write_unchecked(const etl::span<T>& range)
|
||||
typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, void>::type write_unchecked(const etl::span<T>& range)
|
||||
{
|
||||
typename etl::span<T>::iterator itr = range.begin();
|
||||
|
||||
@ -194,8 +190,7 @@ namespace etl
|
||||
/// Write a range of T to the stream.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, bool>::type
|
||||
write(const etl::span<T>& range)
|
||||
typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, bool>::type write(const etl::span<T>& range)
|
||||
{
|
||||
bool success = (available<T>() >= range.size());
|
||||
|
||||
@ -211,8 +206,7 @@ namespace etl
|
||||
/// Write a range of T to the stream.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, void>::type
|
||||
write_unchecked(const T* start, size_t length)
|
||||
typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, void>::type write_unchecked(const T* start, size_t length)
|
||||
{
|
||||
while (length-- != 0U)
|
||||
{
|
||||
@ -225,8 +219,7 @@ namespace etl
|
||||
/// Write a range of T to the stream.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, bool>::type
|
||||
write(const T* start, size_t length)
|
||||
typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, bool>::type write(const T* start, size_t length)
|
||||
{
|
||||
bool success = (available<T>() >= length);
|
||||
|
||||
@ -381,7 +374,7 @@ namespace etl
|
||||
//***************************************************************************
|
||||
size_t size_bytes() const
|
||||
{
|
||||
return etl::distance(pdata, pcurrent);
|
||||
return static_cast<size_t>(etl::distance(pdata, pcurrent));
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
@ -439,8 +432,7 @@ namespace etl
|
||||
/// to_bytes
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<sizeof(T) == 1U, void>::type
|
||||
to_bytes(const T value)
|
||||
typename etl::enable_if<sizeof(T) == 1U, void>::type to_bytes(const T value)
|
||||
{
|
||||
*pcurrent = static_cast<char>(value);
|
||||
step(1U);
|
||||
@ -448,8 +440,7 @@ namespace etl
|
||||
|
||||
//*********************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<sizeof(T) != 1U, void>::type
|
||||
to_bytes(const T value)
|
||||
typename etl::enable_if<sizeof(T) != 1U, void>::type to_bytes(const T value)
|
||||
{
|
||||
const char* pv = reinterpret_cast<const char*>(&value);
|
||||
copy_value(pv, pcurrent, sizeof(T));
|
||||
@ -494,7 +485,7 @@ namespace etl
|
||||
{
|
||||
public:
|
||||
|
||||
typedef char* iterator;
|
||||
typedef char* iterator;
|
||||
typedef const char* const_iterator;
|
||||
|
||||
//***************************************************************************
|
||||
@ -525,7 +516,7 @@ namespace etl
|
||||
byte_stream_reader(const void* begin_, const void* end_, etl::endian stream_endianness_)
|
||||
: pdata(reinterpret_cast<const char*>(begin_))
|
||||
, pcurrent(reinterpret_cast<const char*>(begin_))
|
||||
, stream_length(etl::distance(reinterpret_cast<const char*>(begin_), reinterpret_cast<const char*>(end_)))
|
||||
, stream_length(static_cast<size_t>(etl::distance(reinterpret_cast<const char*>(begin_), reinterpret_cast<const char*>(end_))))
|
||||
, stream_endianness(stream_endianness_)
|
||||
{
|
||||
}
|
||||
@ -545,7 +536,7 @@ namespace etl
|
||||
/// Construct from array.
|
||||
//***************************************************************************
|
||||
template <typename T, size_t Size>
|
||||
byte_stream_reader(T(&begin_)[Size], etl::endian stream_endianness_)
|
||||
byte_stream_reader(T (&begin_)[Size], etl::endian stream_endianness_)
|
||||
: pdata(begin_)
|
||||
, pcurrent(begin_)
|
||||
, stream_length(begin_ + (Size * sizeof(T)))
|
||||
@ -557,7 +548,7 @@ namespace etl
|
||||
/// Construct from const array.
|
||||
//***************************************************************************
|
||||
template <typename T, size_t Size>
|
||||
byte_stream_reader(const T(&begin_)[Size], etl::endian stream_endianness_)
|
||||
byte_stream_reader(const T (&begin_)[Size], etl::endian stream_endianness_)
|
||||
: pdata(begin_)
|
||||
, pcurrent(begin_)
|
||||
, stream_length(begin_ + (Size * sizeof(T)))
|
||||
@ -569,8 +560,7 @@ namespace etl
|
||||
/// Read a value from the stream.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, T>::type
|
||||
read_unchecked()
|
||||
typename etl::enable_if< etl::is_integral<T>::value || etl::is_floating_point<T>::value, T>::type read_unchecked()
|
||||
{
|
||||
return from_bytes<T>();
|
||||
}
|
||||
@ -579,8 +569,7 @@ namespace etl
|
||||
/// Read a value from the stream.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, etl::optional<T> >::type
|
||||
read()
|
||||
typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, etl::optional<T> >::type read()
|
||||
{
|
||||
etl::optional<T> result;
|
||||
|
||||
@ -597,14 +586,13 @@ namespace etl
|
||||
/// Read a byte range from the stream.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<sizeof(T) == 1U, etl::span<const T> >::type
|
||||
read_unchecked(size_t n)
|
||||
typename etl::enable_if<sizeof(T) == 1U, etl::span<const T> >::type read_unchecked(size_t n)
|
||||
{
|
||||
etl::span<const T> result;
|
||||
|
||||
const char* pend = pcurrent + (n * sizeof(T));
|
||||
|
||||
result = etl::span<const T>(reinterpret_cast<const T*>(pcurrent), reinterpret_cast<const T*>(pend));
|
||||
result = etl::span<const T>(reinterpret_cast<const T*>(pcurrent), reinterpret_cast<const T*>(pend));
|
||||
pcurrent = pend;
|
||||
|
||||
return result;
|
||||
@ -614,8 +602,7 @@ namespace etl
|
||||
/// Read a byte range from the stream.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<sizeof(T) == 1U, etl::optional<etl::span<const T> > >::type
|
||||
read(size_t n)
|
||||
typename etl::enable_if<sizeof(T) == 1U, etl::optional<etl::span<const T> > >::type read(size_t n)
|
||||
{
|
||||
etl::optional<etl::span<const T> > result;
|
||||
|
||||
@ -665,8 +652,8 @@ namespace etl
|
||||
/// Read a range of T from the stream.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, etl::span<const T> >::type
|
||||
read_unchecked(T* start, size_t length)
|
||||
typename etl::enable_if<etl::is_integral<T>::value || etl::is_floating_point<T>::value, etl::span<const T> >::type read_unchecked(T* start,
|
||||
size_t length)
|
||||
{
|
||||
T* destination = start;
|
||||
|
||||
@ -799,7 +786,7 @@ namespace etl
|
||||
template <typename T>
|
||||
size_t available() const
|
||||
{
|
||||
size_t used = etl::distance(pdata, pcurrent);
|
||||
size_t used = static_cast<size_t>(etl::distance(pdata, pcurrent));
|
||||
|
||||
return (stream_length - used) / sizeof(T);
|
||||
}
|
||||
@ -812,22 +799,28 @@ namespace etl
|
||||
return available<char>();
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Gets the endianness of the stream.
|
||||
//***************************************************************************
|
||||
etl::endian get_endianness() const
|
||||
{
|
||||
return stream_endianness;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
//***************************************************************************
|
||||
/// from_bytes
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<sizeof(T) == 1U, T>::type
|
||||
from_bytes()
|
||||
typename etl::enable_if<sizeof(T) == 1U, T>::type from_bytes()
|
||||
{
|
||||
return static_cast<T>(*pcurrent++);
|
||||
}
|
||||
|
||||
//*********************************
|
||||
template <typename T>
|
||||
typename etl::enable_if<sizeof(T) != 1U, T>::type
|
||||
from_bytes()
|
||||
typename etl::enable_if<sizeof(T) != 1U, T>::type from_bytes()
|
||||
{
|
||||
T value;
|
||||
|
||||
@ -885,7 +878,7 @@ namespace etl
|
||||
/// Overload this to support custom types.
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
T read_unchecked(etl::byte_stream_reader& stream)
|
||||
T read_unchecked(etl::byte_stream_reader& stream)
|
||||
{
|
||||
return stream.read_unchecked<T>();
|
||||
}
|
||||
@ -898,6 +891,6 @@ namespace etl
|
||||
{
|
||||
return stream.read<T>();
|
||||
}
|
||||
}
|
||||
} // namespace etl
|
||||
|
||||
#endif
|
||||
|
||||
@ -34,9 +34,10 @@ SOFTWARE.
|
||||
namespace etl
|
||||
{
|
||||
//***************************************************************************
|
||||
/// A callback class designed to be multiply inherited by other client classes.
|
||||
/// The class is parametrised with a callback parameter type and a unique id.
|
||||
/// The unique id allows multiple callbacks with the same parameter type.
|
||||
/// A callback class designed to be multiply inherited by other client
|
||||
/// classes. The class is parametrised with a callback parameter type and a
|
||||
/// unique id. The unique id allows multiple callbacks with the same parameter
|
||||
/// type.
|
||||
///\tparam TParameter The callback parameter type.
|
||||
///\tparam ID The unique id for this callback.
|
||||
//***************************************************************************
|
||||
@ -49,25 +50,25 @@ namespace etl
|
||||
template <typename T, const int I>
|
||||
struct parameter
|
||||
{
|
||||
parameter(T value_)
|
||||
: value(value_)
|
||||
{
|
||||
}
|
||||
parameter(T value_)
|
||||
: value(value_)
|
||||
{
|
||||
}
|
||||
|
||||
typedef T value_type;
|
||||
typedef T value_type;
|
||||
|
||||
T value;
|
||||
T value;
|
||||
|
||||
private:
|
||||
|
||||
parameter();
|
||||
parameter();
|
||||
};
|
||||
|
||||
// Specialisation for void.
|
||||
template <const int I>
|
||||
struct parameter<void, I>
|
||||
{
|
||||
typedef void value_type;
|
||||
typedef void value_type;
|
||||
};
|
||||
|
||||
public:
|
||||
@ -76,6 +77,6 @@ namespace etl
|
||||
|
||||
virtual void etl_callback(type p = type()) = 0;
|
||||
};
|
||||
}
|
||||
} // namespace etl
|
||||
|
||||
#endif
|
||||
|
||||
@ -32,10 +32,10 @@ SOFTWARE.
|
||||
#define ETL_CALLBACK_SERVICE_INCLUDED
|
||||
|
||||
#include "platform.h"
|
||||
#include "array.h"
|
||||
#include "function.h"
|
||||
#include "nullptr.h"
|
||||
#include "static_assert.h"
|
||||
#include "function.h"
|
||||
#include "array.h"
|
||||
|
||||
namespace etl
|
||||
{
|
||||
@ -55,8 +55,8 @@ namespace etl
|
||||
/// Sets all callbacks to the internal default.
|
||||
//*************************************************************************
|
||||
callback_service()
|
||||
: unhandled_callback(*this),
|
||||
p_unhandled(ETL_NULLPTR)
|
||||
: unhandled_callback(*this)
|
||||
, p_unhandled(ETL_NULLPTR)
|
||||
{
|
||||
lookup.fill(&unhandled_callback);
|
||||
}
|
||||
@ -71,7 +71,7 @@ namespace etl
|
||||
void register_callback(etl::ifunction<size_t>& callback)
|
||||
{
|
||||
ETL_STATIC_ASSERT(Id < (Offset + Range), "Callback Id out of range");
|
||||
ETL_STATIC_ASSERT(Id >= Offset, "Callback Id out of range");
|
||||
ETL_STATIC_ASSERT(Id >= Offset, "Callback Id out of range");
|
||||
|
||||
lookup[Id - Offset] = &callback;
|
||||
}
|
||||
@ -108,7 +108,7 @@ namespace etl
|
||||
void callback()
|
||||
{
|
||||
ETL_STATIC_ASSERT(Id < (Offset + Range), "Callback Id out of range");
|
||||
ETL_STATIC_ASSERT(Id >= Offset, "Callback Id out of range");
|
||||
ETL_STATIC_ASSERT(Id >= Offset, "Callback Id out of range");
|
||||
|
||||
(*lookup[Id - Offset])(Id);
|
||||
}
|
||||
@ -144,9 +144,7 @@ namespace etl
|
||||
}
|
||||
|
||||
/// The default callback for unhandled ids.
|
||||
etl::function_mp<callback_service<Range, Offset>,
|
||||
size_t,
|
||||
&callback_service<Range, Offset>::unhandled> unhandled_callback;
|
||||
etl::function_mp<callback_service<Range, Offset>, size_t, &callback_service<Range, Offset>::unhandled> unhandled_callback;
|
||||
|
||||
/// Pointer to the user defined 'unhandled' callback.
|
||||
etl::ifunction<size_t>* p_unhandled;
|
||||
@ -154,6 +152,6 @@ namespace etl
|
||||
/// Lookup table of callbacks.
|
||||
etl::array<etl::ifunction<size_t>*, Range> lookup;
|
||||
};
|
||||
}
|
||||
} // namespace etl
|
||||
|
||||
#endif
|
||||
|
||||
@ -31,14 +31,14 @@ SOFTWARE.
|
||||
|
||||
#include "platform.h"
|
||||
#include "algorithm.h"
|
||||
#include "nullptr.h"
|
||||
#include "atomic.h"
|
||||
#include "delegate.h"
|
||||
#include "error_handler.h"
|
||||
#include "function.h"
|
||||
#include "nullptr.h"
|
||||
#include "placement_new.h"
|
||||
#include "static_assert.h"
|
||||
#include "timer.h"
|
||||
#include "atomic.h"
|
||||
#include "error_handler.h"
|
||||
#include "placement_new.h"
|
||||
#include "delegate.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
@ -91,9 +91,7 @@ namespace etl
|
||||
//*******************************************
|
||||
/// Register a timer.
|
||||
//*******************************************
|
||||
etl::timer::id::type register_timer(void (*p_callback_)(),
|
||||
uint32_t period_,
|
||||
bool repeating_)
|
||||
etl::timer::id::type register_timer(void (*p_callback_)(), uint32_t period_, bool repeating_)
|
||||
{
|
||||
etl::timer::id::type id = etl::timer::id::NO_TIMER;
|
||||
|
||||
@ -123,9 +121,7 @@ namespace etl
|
||||
//*******************************************
|
||||
/// Register a timer.
|
||||
//*******************************************
|
||||
etl::timer::id::type register_timer(etl::ifunction<void>& callback_,
|
||||
uint32_t period_,
|
||||
bool repeating_)
|
||||
etl::timer::id::type register_timer(etl::ifunction<void>& callback_, uint32_t period_, bool repeating_)
|
||||
{
|
||||
etl::timer::id::type id = etl::timer::id::NO_TIMER;
|
||||
|
||||
@ -152,38 +148,36 @@ namespace etl
|
||||
return id;
|
||||
}
|
||||
|
||||
//*******************************************
|
||||
/// Register a timer.
|
||||
//*******************************************
|
||||
//*******************************************
|
||||
/// Register a timer.
|
||||
//*******************************************
|
||||
#if ETL_USING_CPP11
|
||||
etl::timer::id::type register_timer(callback_type& callback_,
|
||||
uint32_t period_,
|
||||
bool repeating_)
|
||||
etl::timer::id::type register_timer(callback_type& callback_, uint32_t period_, bool repeating_)
|
||||
{
|
||||
etl::timer::id::type id = etl::timer::id::NO_TIMER;
|
||||
|
||||
bool is_space = (registered_timers < MAX_TIMERS);
|
||||
|
||||
if (is_space)
|
||||
{
|
||||
etl::timer::id::type id = etl::timer::id::NO_TIMER;
|
||||
// Search for the free space.
|
||||
for (uint_least8_t i = 0U; i < MAX_TIMERS; ++i)
|
||||
{
|
||||
timer_data& timer = timer_array[i];
|
||||
|
||||
bool is_space = (registered_timers < MAX_TIMERS);
|
||||
|
||||
if (is_space)
|
||||
if (timer.id == etl::timer::id::NO_TIMER)
|
||||
{
|
||||
// Search for the free space.
|
||||
for (uint_least8_t i = 0U; i < MAX_TIMERS; ++i)
|
||||
{
|
||||
timer_data& timer = timer_array[i];
|
||||
|
||||
if (timer.id == etl::timer::id::NO_TIMER)
|
||||
{
|
||||
// Create in-place.
|
||||
new (&timer) timer_data(i, callback_, period_, repeating_);
|
||||
++registered_timers;
|
||||
id = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Create in-place.
|
||||
new (&timer) timer_data(i, callback_, period_, repeating_);
|
||||
++registered_timers;
|
||||
id = i;
|
||||
break;
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
#endif
|
||||
|
||||
//*******************************************
|
||||
@ -290,17 +284,17 @@ namespace etl
|
||||
if (timer.cbk_type == timer_data::C_CALLBACK)
|
||||
{
|
||||
// Call the C callback.
|
||||
reinterpret_cast<void(*)()>(timer.p_callback)();
|
||||
reinterpret_cast<void (*)()>(timer.p_callback)();
|
||||
}
|
||||
else if(timer.cbk_type == timer_data::IFUNCTION)
|
||||
else if (timer.cbk_type == timer_data::IFUNCTION)
|
||||
{
|
||||
// Call the function wrapper callback.
|
||||
(*reinterpret_cast<etl::ifunction<void>*>(timer.p_callback))();
|
||||
}
|
||||
else if(timer.cbk_type == timer_data::DELEGATE)
|
||||
else if (timer.cbk_type == timer_data::DELEGATE)
|
||||
{
|
||||
// Call the delegate callback.
|
||||
(*reinterpret_cast<callback_type*>(timer.p_callback))();
|
||||
// Call the delegate callback.
|
||||
(*reinterpret_cast<callback_type*>(timer.p_callback))();
|
||||
}
|
||||
}
|
||||
|
||||
@ -427,7 +421,8 @@ namespace etl
|
||||
|
||||
//*******************************************
|
||||
/// Get the time to the next timer event.
|
||||
/// Returns etl::timer::interval::No_Active_Interval if there is no active timer.
|
||||
/// Returns etl::timer::interval::No_Active_Interval if there is no active
|
||||
/// timer.
|
||||
//*******************************************
|
||||
uint32_t time_to_next() const
|
||||
{
|
||||
@ -524,10 +519,7 @@ namespace etl
|
||||
//*******************************************
|
||||
/// C function callback
|
||||
//*******************************************
|
||||
timer_data(etl::timer::id::type id_,
|
||||
void (*p_callback_)(),
|
||||
uint32_t period_,
|
||||
bool repeating_)
|
||||
timer_data(etl::timer::id::type id_, void (*p_callback_)(), uint32_t period_, bool repeating_)
|
||||
: p_callback(reinterpret_cast<void*>(p_callback_))
|
||||
, period(period_)
|
||||
, delta(etl::timer::state::Inactive)
|
||||
@ -542,10 +534,7 @@ namespace etl
|
||||
//*******************************************
|
||||
/// ETL function callback
|
||||
//*******************************************
|
||||
timer_data(etl::timer::id::type id_,
|
||||
etl::ifunction<void>& callback_,
|
||||
uint32_t period_,
|
||||
bool repeating_)
|
||||
timer_data(etl::timer::id::type id_, etl::ifunction<void>& callback_, uint32_t period_, bool repeating_)
|
||||
: p_callback(reinterpret_cast<void*>(&callback_))
|
||||
, period(period_)
|
||||
, delta(etl::timer::state::Inactive)
|
||||
@ -560,18 +549,15 @@ namespace etl
|
||||
//*******************************************
|
||||
/// ETL delegate callback
|
||||
//*******************************************
|
||||
timer_data(etl::timer::id::type id_,
|
||||
callback_type& callback_,
|
||||
uint32_t period_,
|
||||
bool repeating_)
|
||||
: p_callback(reinterpret_cast<void*>(&callback_)),
|
||||
period(period_),
|
||||
delta(etl::timer::state::Inactive),
|
||||
id(id_),
|
||||
previous(etl::timer::id::NO_TIMER),
|
||||
next(etl::timer::id::NO_TIMER),
|
||||
repeating(repeating_),
|
||||
cbk_type(DELEGATE)
|
||||
timer_data(etl::timer::id::type id_, callback_type& callback_, uint32_t period_, bool repeating_)
|
||||
: p_callback(reinterpret_cast<void*>(&callback_))
|
||||
, period(period_)
|
||||
, delta(etl::timer::state::Inactive)
|
||||
, id(id_)
|
||||
, previous(etl::timer::id::NO_TIMER)
|
||||
, next(etl::timer::id::NO_TIMER)
|
||||
, repeating(repeating_)
|
||||
, cbk_type(DELEGATE)
|
||||
{
|
||||
}
|
||||
|
||||
@ -591,34 +577,36 @@ namespace etl
|
||||
delta = etl::timer::state::Inactive;
|
||||
}
|
||||
|
||||
void* p_callback;
|
||||
uint32_t period;
|
||||
uint32_t delta;
|
||||
etl::timer::id::type id;
|
||||
uint_least8_t previous;
|
||||
uint_least8_t next;
|
||||
bool repeating;
|
||||
callback_type_id cbk_type;
|
||||
void* p_callback;
|
||||
uint32_t period;
|
||||
uint32_t delta;
|
||||
etl::timer::id::type id;
|
||||
uint_least8_t previous;
|
||||
uint_least8_t next;
|
||||
bool repeating;
|
||||
callback_type_id cbk_type;
|
||||
|
||||
private:
|
||||
|
||||
// Disabled.
|
||||
timer_data(const timer_data& other);
|
||||
timer_data& operator =(const timer_data& other);
|
||||
timer_data& operator=(const timer_data& other);
|
||||
};
|
||||
|
||||
//*******************************************
|
||||
/// Constructor.
|
||||
//*******************************************
|
||||
icallback_timer(timer_data* const timer_array_, const uint_least8_t Max_Timers_)
|
||||
: timer_array(timer_array_),
|
||||
active_list(timer_array_),
|
||||
enabled(false),
|
||||
icallback_timer(timer_data* const timer_array_, const uint_least8_t Max_Timers_)
|
||||
: timer_array(timer_array_)
|
||||
, active_list(timer_array_)
|
||||
, enabled(false)
|
||||
,
|
||||
#if defined(ETL_CALLBACK_TIMER_USE_ATOMIC_LOCK)
|
||||
process_semaphore(0),
|
||||
process_semaphore(0)
|
||||
,
|
||||
#endif
|
||||
registered_timers(0),
|
||||
MAX_TIMERS(Max_Timers_)
|
||||
registered_timers(0)
|
||||
, MAX_TIMERS(Max_Timers_)
|
||||
{
|
||||
}
|
||||
|
||||
@ -662,10 +650,10 @@ namespace etl
|
||||
if (head == etl::timer::id::NO_TIMER)
|
||||
{
|
||||
// No entries yet.
|
||||
head = id_;
|
||||
tail = id_;
|
||||
head = id_;
|
||||
tail = id_;
|
||||
timer.previous = etl::timer::id::NO_TIMER;
|
||||
timer.next = etl::timer::id::NO_TIMER;
|
||||
timer.next = etl::timer::id::NO_TIMER;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -686,8 +674,8 @@ namespace etl
|
||||
|
||||
// Insert before test.
|
||||
timer.previous = test.previous;
|
||||
test.previous = timer.id;
|
||||
timer.next = test.id;
|
||||
test.previous = timer.id;
|
||||
timer.next = test.id;
|
||||
|
||||
// Adjust the next delta to compensate.
|
||||
test.delta -= timer.delta;
|
||||
@ -711,9 +699,9 @@ namespace etl
|
||||
{
|
||||
// Tag on to the tail.
|
||||
ptimers[tail].next = timer.id;
|
||||
timer.previous = tail;
|
||||
timer.next = etl::timer::id::NO_TIMER;
|
||||
tail = timer.id;
|
||||
timer.previous = tail;
|
||||
timer.next = etl::timer::id::NO_TIMER;
|
||||
tail = timer.id;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -751,8 +739,8 @@ namespace etl
|
||||
}
|
||||
|
||||
timer.previous = etl::timer::id::NO_TIMER;
|
||||
timer.next = etl::timer::id::NO_TIMER;
|
||||
timer.delta = etl::timer::state::Inactive;
|
||||
timer.next = etl::timer::id::NO_TIMER;
|
||||
timer.delta = etl::timer::state::Inactive;
|
||||
}
|
||||
|
||||
//*******************************
|
||||
@ -796,12 +784,12 @@ namespace etl
|
||||
while (id != etl::timer::id::NO_TIMER)
|
||||
{
|
||||
timer_data& timer = ptimers[id];
|
||||
id = next(id);
|
||||
timer.next = etl::timer::id::NO_TIMER;
|
||||
id = next(id);
|
||||
timer.next = etl::timer::id::NO_TIMER;
|
||||
}
|
||||
|
||||
head = etl::timer::id::NO_TIMER;
|
||||
tail = etl::timer::id::NO_TIMER;
|
||||
head = etl::timer::id::NO_TIMER;
|
||||
tail = etl::timer::id::NO_TIMER;
|
||||
current = etl::timer::id::NO_TIMER;
|
||||
}
|
||||
|
||||
@ -823,15 +811,15 @@ namespace etl
|
||||
volatile bool enabled;
|
||||
#if defined(ETL_CALLBACK_TIMER_USE_ATOMIC_LOCK)
|
||||
|
||||
#if defined(ETL_TIMER_SEMAPHORE_TYPE)
|
||||
#if defined(ETL_TIMER_SEMAPHORE_TYPE)
|
||||
typedef ETL_TIMER_SEMAPHORE_TYPE timer_semaphore_t;
|
||||
#else
|
||||
#if ETL_HAS_ATOMIC
|
||||
typedef etl::atomic_uint16_t timer_semaphore_t;
|
||||
#else
|
||||
#error No atomic type available
|
||||
#if ETL_HAS_ATOMIC
|
||||
typedef etl::atomic_uint16_t timer_semaphore_t;
|
||||
#else
|
||||
#error No atomic type available
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
mutable etl::timer_semaphore_t process_semaphore;
|
||||
#endif
|
||||
@ -867,7 +855,7 @@ namespace etl
|
||||
|
||||
timer_data timer_array[Max_Timers_];
|
||||
};
|
||||
}
|
||||
} // namespace etl
|
||||
|
||||
#undef ETL_DISABLE_TIMER_UPDATES
|
||||
#undef ETL_ENABLE_TIMER_UPDATES
|
||||
|
||||
@ -31,13 +31,13 @@ SOFTWARE.
|
||||
|
||||
#include "platform.h"
|
||||
#include "algorithm.h"
|
||||
#include "nullptr.h"
|
||||
#include "delegate.h"
|
||||
#include "error_handler.h"
|
||||
#include "function.h"
|
||||
#include "nullptr.h"
|
||||
#include "placement_new.h"
|
||||
#include "static_assert.h"
|
||||
#include "timer.h"
|
||||
#include "error_handler.h"
|
||||
#include "placement_new.h"
|
||||
#include "delegate.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
@ -58,35 +58,33 @@ namespace etl
|
||||
//*******************************************
|
||||
/// Register a timer.
|
||||
//*******************************************
|
||||
etl::timer::id::type register_timer(callback_type callback_,
|
||||
uint32_t period_,
|
||||
bool repeating_)
|
||||
etl::timer::id::type register_timer(callback_type callback_, uint32_t period_, bool repeating_)
|
||||
{
|
||||
etl::timer::id::type id = etl::timer::id::NO_TIMER;
|
||||
|
||||
bool is_space = (number_of_registered_timers < Max_Timers);
|
||||
etl::timer::id::type id = etl::timer::id::NO_TIMER;
|
||||
|
||||
if (is_space)
|
||||
bool is_space = (number_of_registered_timers < Max_Timers);
|
||||
|
||||
if (is_space)
|
||||
{
|
||||
// Search for the free space.
|
||||
for (uint_least8_t i = 0U; i < Max_Timers; ++i)
|
||||
{
|
||||
// Search for the free space.
|
||||
for (uint_least8_t i = 0U; i < Max_Timers; ++i)
|
||||
{
|
||||
timer_data& timer = timer_array[i];
|
||||
|
||||
if (timer.id == etl::timer::id::NO_TIMER)
|
||||
{
|
||||
// Create in-place.
|
||||
new (&timer) timer_data(i, callback_, period_, repeating_);
|
||||
++number_of_registered_timers;
|
||||
id = i;
|
||||
break;
|
||||
}
|
||||
timer_data& timer = timer_array[i];
|
||||
|
||||
if (timer.id == etl::timer::id::NO_TIMER)
|
||||
{
|
||||
// Create in-place.
|
||||
new (&timer) timer_data(i, callback_, period_, repeating_);
|
||||
++number_of_registered_timers;
|
||||
id = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
//*******************************************
|
||||
/// Unregister a timer.
|
||||
//*******************************************
|
||||
@ -319,7 +317,8 @@ namespace etl
|
||||
|
||||
//*******************************************
|
||||
/// Get the time to the next timer event.
|
||||
/// Returns etl::timer::interval::No_Active_Interval if there is no active timer.
|
||||
/// Returns etl::timer::interval::No_Active_Interval if there is no active
|
||||
/// timer.
|
||||
//*******************************************
|
||||
uint32_t time_to_next() const
|
||||
{
|
||||
@ -412,10 +411,7 @@ namespace etl
|
||||
//*******************************************
|
||||
/// ETL delegate callback
|
||||
//*******************************************
|
||||
timer_data(etl::timer::id::type id_,
|
||||
callback_type callback_,
|
||||
uint32_t period_,
|
||||
bool repeating_)
|
||||
timer_data(etl::timer::id::type id_, callback_type callback_, uint32_t period_, bool repeating_)
|
||||
: callback(callback_)
|
||||
, period(period_)
|
||||
, delta(etl::timer::state::Inactive)
|
||||
@ -454,13 +450,13 @@ namespace etl
|
||||
|
||||
// Disabled.
|
||||
timer_data(const timer_data& other) ETL_DELETE;
|
||||
timer_data& operator =(const timer_data& other) ETL_DELETE;
|
||||
timer_data& operator=(const timer_data& other) ETL_DELETE;
|
||||
};
|
||||
|
||||
//*******************************************
|
||||
/// Constructor.
|
||||
//*******************************************
|
||||
icallback_timer_atomic(timer_data* const timer_array_, const uint_least8_t Max_Timers_)
|
||||
icallback_timer_atomic(timer_data* const timer_array_, const uint_least8_t Max_Timers_)
|
||||
: timer_array(timer_array_)
|
||||
, active_list(timer_array_)
|
||||
, enabled(false)
|
||||
@ -512,10 +508,10 @@ namespace etl
|
||||
if (head == etl::timer::id::NO_TIMER)
|
||||
{
|
||||
// No entries yet.
|
||||
head = id_;
|
||||
tail = id_;
|
||||
head = id_;
|
||||
tail = id_;
|
||||
timer.previous = etl::timer::id::NO_TIMER;
|
||||
timer.next = etl::timer::id::NO_TIMER;
|
||||
timer.next = etl::timer::id::NO_TIMER;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -536,8 +532,8 @@ namespace etl
|
||||
|
||||
// Insert before test.
|
||||
timer.previous = test.previous;
|
||||
test.previous = timer.id;
|
||||
timer.next = test.id;
|
||||
test.previous = timer.id;
|
||||
timer.next = test.id;
|
||||
|
||||
// Adjust the next delta to compensate.
|
||||
test.delta -= timer.delta;
|
||||
@ -561,9 +557,9 @@ namespace etl
|
||||
{
|
||||
// Tag on to the tail.
|
||||
ptimers[tail].next = timer.id;
|
||||
timer.previous = tail;
|
||||
timer.next = etl::timer::id::NO_TIMER;
|
||||
tail = timer.id;
|
||||
timer.previous = tail;
|
||||
timer.next = etl::timer::id::NO_TIMER;
|
||||
tail = timer.id;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -601,8 +597,8 @@ namespace etl
|
||||
}
|
||||
|
||||
timer.previous = etl::timer::id::NO_TIMER;
|
||||
timer.next = etl::timer::id::NO_TIMER;
|
||||
timer.delta = etl::timer::state::Inactive;
|
||||
timer.next = etl::timer::id::NO_TIMER;
|
||||
timer.delta = etl::timer::state::Inactive;
|
||||
}
|
||||
|
||||
//*******************************
|
||||
@ -646,12 +642,12 @@ namespace etl
|
||||
while (id != etl::timer::id::NO_TIMER)
|
||||
{
|
||||
timer_data& timer = ptimers[id];
|
||||
id = next(id);
|
||||
timer.next = etl::timer::id::NO_TIMER;
|
||||
id = next(id);
|
||||
timer.next = etl::timer::id::NO_TIMER;
|
||||
}
|
||||
|
||||
head = etl::timer::id::NO_TIMER;
|
||||
tail = etl::timer::id::NO_TIMER;
|
||||
head = etl::timer::id::NO_TIMER;
|
||||
tail = etl::timer::id::NO_TIMER;
|
||||
current = etl::timer::id::NO_TIMER;
|
||||
}
|
||||
|
||||
@ -670,9 +666,9 @@ namespace etl
|
||||
// The list of active timers.
|
||||
timer_list active_list;
|
||||
|
||||
bool enabled;
|
||||
bool enabled;
|
||||
mutable TSemaphore process_semaphore;
|
||||
uint_least8_t number_of_registered_timers;
|
||||
uint_least8_t number_of_registered_timers;
|
||||
|
||||
event_callback_type insert_callback;
|
||||
event_callback_type remove_callback;
|
||||
@ -704,6 +700,6 @@ namespace etl
|
||||
|
||||
typename etl::icallback_timer_atomic<TSemaphore>::timer_data timer_array[Max_Timers_];
|
||||
};
|
||||
}
|
||||
} // namespace etl
|
||||
|
||||
#endif
|
||||
|
||||
@ -31,10 +31,10 @@ SOFTWARE.
|
||||
|
||||
#include "platform.h"
|
||||
#include "callback_timer_locked.h"
|
||||
#include "delegate.h"
|
||||
#include "etl/nullptr.h"
|
||||
#include "etl/optional.h"
|
||||
#include "priority_queue.h"
|
||||
#include "delegate.h"
|
||||
|
||||
namespace etl
|
||||
{
|
||||
@ -103,7 +103,7 @@ namespace etl
|
||||
{
|
||||
if (!handler_queue.full())
|
||||
{
|
||||
handler_queue.push(callback_node(timer.callback, timer_priorities[timer.id]));
|
||||
handler_queue.push(callback_node(timer.callback, timer_priorities[timer.id]));
|
||||
}
|
||||
}
|
||||
|
||||
@ -143,18 +143,17 @@ namespace etl
|
||||
{
|
||||
callback_type work_todo_callback;
|
||||
|
||||
do
|
||||
{
|
||||
do {
|
||||
lock();
|
||||
|
||||
|
||||
if (handler_queue.empty())
|
||||
{
|
||||
work_todo_callback.clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
callback_node &work_todo_callback_node = handler_queue.top();
|
||||
work_todo_callback = work_todo_callback_node.callback;
|
||||
callback_node& work_todo_callback_node = handler_queue.top();
|
||||
work_todo_callback = work_todo_callback_node.callback;
|
||||
handler_queue.pop();
|
||||
}
|
||||
|
||||
@ -169,11 +168,9 @@ namespace etl
|
||||
//*******************************************
|
||||
/// Register a timer.
|
||||
//*******************************************
|
||||
etl::timer::id::type register_timer(const callback_type& callback_,
|
||||
uint32_t period_,
|
||||
bool repeating_)
|
||||
etl::timer::id::type register_timer(const callback_type& callback_, uint32_t period_, bool repeating_)
|
||||
{
|
||||
return register_timer(callback_, period_, repeating_, 0);
|
||||
return register_timer(callback_, period_, repeating_, 0);
|
||||
}
|
||||
|
||||
//*******************************************
|
||||
@ -182,27 +179,24 @@ namespace etl
|
||||
/// Suggestion: this could be used as amonth of work to do and
|
||||
/// less work will be done in first place.
|
||||
//*******************************************
|
||||
etl::timer::id::type register_timer(const callback_type& callback_,
|
||||
uint32_t period_,
|
||||
bool repeating_,
|
||||
uint_least8_t priority_)
|
||||
etl::timer::id::type register_timer(const callback_type& callback_, uint32_t period_, bool repeating_, uint_least8_t priority_)
|
||||
{
|
||||
etl::timer::id::type id = icallback_timer_locked::register_timer(callback_, period_, repeating_);
|
||||
etl::timer::id::type id = icallback_timer_locked::register_timer(callback_, period_, repeating_);
|
||||
|
||||
if (id != etl::timer::id::NO_TIMER)
|
||||
{
|
||||
timer_priorities[id] = priority_;
|
||||
}
|
||||
if (id != etl::timer::id::NO_TIMER)
|
||||
{
|
||||
timer_priorities[id] = priority_;
|
||||
}
|
||||
|
||||
return id;
|
||||
return id;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
priority_queue<callback_node, Max_Handlers_> handler_queue;
|
||||
uint_least8_t timer_priorities[Max_Timers_];
|
||||
timer_data timer_array[Max_Timers_];
|
||||
uint_least8_t timer_priorities[Max_Timers_];
|
||||
timer_data timer_array[Max_Timers_];
|
||||
};
|
||||
}
|
||||
} // namespace etl
|
||||
|
||||
#endif
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
/******************************************************************************
|
||||
/******************************************************************************
|
||||
The MIT License(MIT)
|
||||
|
||||
Embedded Template Library.
|
||||
@ -31,12 +31,12 @@ SOFTWARE.
|
||||
|
||||
#include "platform.h"
|
||||
#include "algorithm.h"
|
||||
#include "nullptr.h"
|
||||
#include "delegate.h"
|
||||
#include "error_handler.h"
|
||||
#include "nullptr.h"
|
||||
#include "placement_new.h"
|
||||
#include "static_assert.h"
|
||||
#include "timer.h"
|
||||
#include "error_handler.h"
|
||||
#include "placement_new.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
@ -57,9 +57,7 @@ namespace etl
|
||||
//*******************************************
|
||||
/// Register a timer.
|
||||
//*******************************************
|
||||
etl::timer::id::type register_timer(const callback_type& callback_,
|
||||
uint32_t period_,
|
||||
bool repeating_)
|
||||
etl::timer::id::type register_timer(const callback_type& callback_, uint32_t period_, bool repeating_)
|
||||
{
|
||||
etl::timer::id::type id = etl::timer::id::NO_TIMER;
|
||||
|
||||
@ -168,7 +166,7 @@ namespace etl
|
||||
if (enabled)
|
||||
{
|
||||
// We have something to do?
|
||||
bool has_active = !active_list.empty();
|
||||
bool has_active = !active_list.empty();
|
||||
|
||||
if (has_active)
|
||||
{
|
||||
@ -320,7 +318,8 @@ namespace etl
|
||||
|
||||
//*******************************************
|
||||
/// Get the time to the next timer event.
|
||||
/// Returns etl::timer::interval::No_Active_Interval if there is no active timer.
|
||||
/// Returns etl::timer::interval::No_Active_Interval if there is no active
|
||||
/// timer.
|
||||
//*******************************************
|
||||
uint32_t time_to_next() const
|
||||
{
|
||||
@ -349,7 +348,7 @@ namespace etl
|
||||
if (has_active_timer())
|
||||
{
|
||||
TInterruptGuard guard;
|
||||
(void)guard; // Silence 'unused variable warnings.
|
||||
(void)guard; // Silence 'unused variable warnings.
|
||||
|
||||
const timer_data& timer = timer_array[id_];
|
||||
|
||||
@ -413,10 +412,7 @@ namespace etl
|
||||
//*******************************************
|
||||
/// ETL delegate callback
|
||||
//*******************************************
|
||||
timer_data(etl::timer::id::type id_,
|
||||
callback_type callback_,
|
||||
uint32_t period_,
|
||||
bool repeating_)
|
||||
timer_data(etl::timer::id::type id_, callback_type callback_, uint32_t period_, bool repeating_)
|
||||
: callback(callback_)
|
||||
, period(period_)
|
||||
, delta(etl::timer::state::Inactive)
|
||||
@ -455,13 +451,13 @@ namespace etl
|
||||
|
||||
// Disabled.
|
||||
timer_data(const timer_data& other) ETL_DELETE;
|
||||
timer_data& operator =(const timer_data& other) ETL_DELETE;
|
||||
timer_data& operator=(const timer_data& other) ETL_DELETE;
|
||||
};
|
||||
|
||||
//*******************************************
|
||||
/// Constructor.
|
||||
//*******************************************
|
||||
icallback_timer_interrupt(timer_data* const timer_array_, const uint_least8_t Max_Timers_)
|
||||
icallback_timer_interrupt(timer_data* const timer_array_, const uint_least8_t Max_Timers_)
|
||||
: timer_array(timer_array_)
|
||||
, active_list(timer_array_)
|
||||
, enabled(false)
|
||||
@ -512,10 +508,10 @@ namespace etl
|
||||
if (head == etl::timer::id::NO_TIMER)
|
||||
{
|
||||
// No entries yet.
|
||||
head = id_;
|
||||
tail = id_;
|
||||
head = id_;
|
||||
tail = id_;
|
||||
timer.previous = etl::timer::id::NO_TIMER;
|
||||
timer.next = etl::timer::id::NO_TIMER;
|
||||
timer.next = etl::timer::id::NO_TIMER;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -536,8 +532,8 @@ namespace etl
|
||||
|
||||
// Insert before test.
|
||||
timer.previous = test.previous;
|
||||
test.previous = timer.id;
|
||||
timer.next = test.id;
|
||||
test.previous = timer.id;
|
||||
timer.next = test.id;
|
||||
|
||||
// Adjust the next delta to compensate.
|
||||
test.delta -= timer.delta;
|
||||
@ -561,9 +557,9 @@ namespace etl
|
||||
{
|
||||
// Tag on to the tail.
|
||||
ptimers[tail].next = timer.id;
|
||||
timer.previous = tail;
|
||||
timer.next = etl::timer::id::NO_TIMER;
|
||||
tail = timer.id;
|
||||
timer.previous = tail;
|
||||
timer.next = etl::timer::id::NO_TIMER;
|
||||
tail = timer.id;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -646,8 +642,8 @@ namespace etl
|
||||
while (id != etl::timer::id::NO_TIMER)
|
||||
{
|
||||
timer_data& timer = ptimers[id];
|
||||
id = next(id);
|
||||
timer.next = etl::timer::id::NO_TIMER;
|
||||
id = next(id);
|
||||
timer.next = etl::timer::id::NO_TIMER;
|
||||
}
|
||||
|
||||
head = etl::timer::id::NO_TIMER;
|
||||
@ -670,7 +666,7 @@ namespace etl
|
||||
// The list of active timers.
|
||||
timer_list active_list;
|
||||
|
||||
bool enabled;
|
||||
bool enabled;
|
||||
uint_least8_t number_of_registered_timers;
|
||||
|
||||
event_callback_type insert_callback;
|
||||
@ -705,6 +701,6 @@ namespace etl
|
||||
|
||||
typename icallback_timer_interrupt<TInterruptGuard>::timer_data timer_array[Max_Timers_];
|
||||
};
|
||||
}
|
||||
} // namespace etl
|
||||
|
||||
#endif
|
||||
|
||||
@ -31,12 +31,12 @@ SOFTWARE.
|
||||
|
||||
#include "platform.h"
|
||||
#include "algorithm.h"
|
||||
#include "nullptr.h"
|
||||
#include "delegate.h"
|
||||
#include "error_handler.h"
|
||||
#include "nullptr.h"
|
||||
#include "placement_new.h"
|
||||
#include "static_assert.h"
|
||||
#include "timer.h"
|
||||
#include "error_handler.h"
|
||||
#include "placement_new.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
@ -59,9 +59,7 @@ namespace etl
|
||||
//*******************************************
|
||||
/// Register a timer.
|
||||
//*******************************************
|
||||
etl::timer::id::type register_timer(const callback_type& callback_,
|
||||
uint32_t period_,
|
||||
bool repeating_)
|
||||
etl::timer::id::type register_timer(const callback_type& callback_, uint32_t period_, bool repeating_)
|
||||
{
|
||||
etl::timer::id::type id = etl::timer::id::NO_TIMER;
|
||||
|
||||
@ -281,7 +279,8 @@ namespace etl
|
||||
|
||||
//*******************************************
|
||||
/// Get the time to the next timer event.
|
||||
/// Returns etl::timer::interval::No_Active_Interval if there is no active timer.
|
||||
/// Returns etl::timer::interval::No_Active_Interval if there is no active
|
||||
/// timer.
|
||||
//*******************************************
|
||||
uint32_t time_to_next() const
|
||||
{
|
||||
@ -355,17 +354,20 @@ namespace etl
|
||||
|
||||
protected:
|
||||
|
||||
class callback_node
|
||||
class callback_node
|
||||
{
|
||||
public:
|
||||
|
||||
callback_node(callback_type &callback_,uint_least8_t priority_) : callback(callback_), priority(priority_)
|
||||
callback_node(callback_type& callback_, uint_least8_t priority_)
|
||||
: callback(callback_)
|
||||
, priority(priority_)
|
||||
{
|
||||
}
|
||||
|
||||
bool operator < (const callback_node& p) const
|
||||
bool operator<(const callback_node& p) const
|
||||
{
|
||||
return this->priority > p.priority; // comparison was inverted here to easy the code design
|
||||
return this->priority > p.priority; // comparison was inverted here to
|
||||
// easy the code design
|
||||
}
|
||||
|
||||
callback_type callback;
|
||||
@ -391,10 +393,7 @@ namespace etl
|
||||
//*******************************************
|
||||
/// ETL delegate callback
|
||||
//*******************************************
|
||||
timer_data(etl::timer::id::type id_,
|
||||
callback_type callback_,
|
||||
uint32_t period_,
|
||||
bool repeating_)
|
||||
timer_data(etl::timer::id::type id_, callback_type callback_, uint32_t period_, bool repeating_)
|
||||
: callback(callback_)
|
||||
, period(period_)
|
||||
, delta(etl::timer::state::Inactive)
|
||||
@ -433,18 +432,18 @@ namespace etl
|
||||
|
||||
// Disabled.
|
||||
timer_data(const timer_data& other) ETL_DELETE;
|
||||
timer_data& operator =(const timer_data& other) ETL_DELETE;
|
||||
timer_data& operator=(const timer_data& other) ETL_DELETE;
|
||||
};
|
||||
|
||||
//*******************************************
|
||||
/// Constructor.
|
||||
//*******************************************
|
||||
icallback_timer_locked(timer_data* const timer_array_, const uint_least8_t Max_Timers_)
|
||||
: timer_array(timer_array_),
|
||||
active_list(timer_array_),
|
||||
enabled(false),
|
||||
number_of_registered_timers(0U),
|
||||
Max_Timers(Max_Timers_)
|
||||
icallback_timer_locked(timer_data* const timer_array_, const uint_least8_t Max_Timers_)
|
||||
: timer_array(timer_array_)
|
||||
, active_list(timer_array_)
|
||||
, enabled(false)
|
||||
, number_of_registered_timers(0U)
|
||||
, Max_Timers(Max_Timers_)
|
||||
{
|
||||
}
|
||||
|
||||
@ -482,10 +481,10 @@ namespace etl
|
||||
if (head == etl::timer::id::NO_TIMER)
|
||||
{
|
||||
// No entries yet.
|
||||
head = id_;
|
||||
tail = id_;
|
||||
head = id_;
|
||||
tail = id_;
|
||||
timer.previous = etl::timer::id::NO_TIMER;
|
||||
timer.next = etl::timer::id::NO_TIMER;
|
||||
timer.next = etl::timer::id::NO_TIMER;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -506,8 +505,8 @@ namespace etl
|
||||
|
||||
// Insert before test.
|
||||
timer.previous = test.previous;
|
||||
test.previous = timer.id;
|
||||
timer.next = test.id;
|
||||
test.previous = timer.id;
|
||||
timer.next = test.id;
|
||||
|
||||
// Adjust the next delta to compensate.
|
||||
test.delta -= timer.delta;
|
||||
@ -531,9 +530,9 @@ namespace etl
|
||||
{
|
||||
// Tag on to the tail.
|
||||
ptimers[tail].next = timer.id;
|
||||
timer.previous = tail;
|
||||
timer.next = etl::timer::id::NO_TIMER;
|
||||
tail = timer.id;
|
||||
timer.previous = tail;
|
||||
timer.next = etl::timer::id::NO_TIMER;
|
||||
tail = timer.id;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -571,8 +570,8 @@ namespace etl
|
||||
}
|
||||
|
||||
timer.previous = etl::timer::id::NO_TIMER;
|
||||
timer.next = etl::timer::id::NO_TIMER;
|
||||
timer.delta = etl::timer::state::Inactive;
|
||||
timer.next = etl::timer::id::NO_TIMER;
|
||||
timer.delta = etl::timer::state::Inactive;
|
||||
}
|
||||
|
||||
//*******************************
|
||||
@ -616,12 +615,12 @@ namespace etl
|
||||
while (id != etl::timer::id::NO_TIMER)
|
||||
{
|
||||
timer_data& timer = ptimers[id];
|
||||
id = next(id);
|
||||
timer.next = etl::timer::id::NO_TIMER;
|
||||
id = next(id);
|
||||
timer.next = etl::timer::id::NO_TIMER;
|
||||
}
|
||||
|
||||
head = etl::timer::id::NO_TIMER;
|
||||
tail = etl::timer::id::NO_TIMER;
|
||||
head = etl::timer::id::NO_TIMER;
|
||||
tail = etl::timer::id::NO_TIMER;
|
||||
current = etl::timer::id::NO_TIMER;
|
||||
}
|
||||
|
||||
@ -648,7 +647,7 @@ namespace etl
|
||||
// The list of active timers.
|
||||
timer_list active_list;
|
||||
|
||||
bool enabled;
|
||||
bool enabled;
|
||||
uint_least8_t number_of_registered_timers;
|
||||
|
||||
try_lock_type try_lock; ///< The callback that tries to lock.
|
||||
@ -766,6 +765,6 @@ namespace etl
|
||||
|
||||
timer_data timer_array[Max_Timers_];
|
||||
};
|
||||
}
|
||||
} // namespace etl
|
||||
|
||||
#endif
|
||||
|
||||
@ -45,9 +45,11 @@ SOFTWARE.
|
||||
|
||||
namespace etl
|
||||
{
|
||||
template<typename T> struct char_traits_types;
|
||||
template <typename T>
|
||||
struct char_traits_types;
|
||||
|
||||
template<> struct char_traits_types<char>
|
||||
template <>
|
||||
struct char_traits_types<char>
|
||||
{
|
||||
typedef char char_type;
|
||||
typedef int int_type;
|
||||
@ -56,7 +58,8 @@ namespace etl
|
||||
typedef char state_type;
|
||||
};
|
||||
|
||||
template<> struct char_traits_types<signed char>
|
||||
template <>
|
||||
struct char_traits_types<signed char>
|
||||
{
|
||||
typedef signed char char_type;
|
||||
typedef int int_type;
|
||||
@ -65,7 +68,8 @@ namespace etl
|
||||
typedef signed char state_type;
|
||||
};
|
||||
|
||||
template<> struct char_traits_types<unsigned char>
|
||||
template <>
|
||||
struct char_traits_types<unsigned char>
|
||||
{
|
||||
typedef unsigned char char_type;
|
||||
typedef int int_type;
|
||||
@ -74,7 +78,8 @@ namespace etl
|
||||
typedef unsigned char state_type;
|
||||
};
|
||||
|
||||
template<> struct char_traits_types<wchar_t>
|
||||
template <>
|
||||
struct char_traits_types<wchar_t>
|
||||
{
|
||||
typedef wchar_t char_type;
|
||||
typedef uint_least16_t int_type;
|
||||
@ -84,17 +89,19 @@ namespace etl
|
||||
};
|
||||
|
||||
#if ETL_USING_CPP20
|
||||
template<> struct char_traits_types<char8_t>
|
||||
template <>
|
||||
struct char_traits_types<char8_t>
|
||||
{
|
||||
typedef char8_t char_type;
|
||||
typedef unsigned int int_type;
|
||||
typedef long long off_type;
|
||||
typedef size_t pos_type;
|
||||
typedef char state_type;
|
||||
typedef char8_t char_type;
|
||||
typedef unsigned int int_type;
|
||||
typedef long long off_type;
|
||||
typedef size_t pos_type;
|
||||
typedef char state_type;
|
||||
};
|
||||
#endif
|
||||
|
||||
template<> struct char_traits_types<char16_t>
|
||||
template <>
|
||||
struct char_traits_types<char16_t>
|
||||
{
|
||||
typedef char16_t char_type;
|
||||
typedef uint_least16_t int_type;
|
||||
@ -103,7 +110,8 @@ namespace etl
|
||||
typedef char state_type;
|
||||
};
|
||||
|
||||
template<> struct char_traits_types<char32_t>
|
||||
template <>
|
||||
struct char_traits_types<char32_t>
|
||||
{
|
||||
typedef char32_t char_type;
|
||||
typedef uint_least32_t int_type;
|
||||
@ -115,7 +123,7 @@ namespace etl
|
||||
//***************************************************************************
|
||||
/// Character traits for any character type.
|
||||
//***************************************************************************
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
struct char_traits : public char_traits_types<T>
|
||||
{
|
||||
typedef typename char_traits_types<T>::char_type char_type;
|
||||
@ -196,9 +204,7 @@ namespace etl
|
||||
}
|
||||
else
|
||||
{
|
||||
etl::copy_n(ETL_OR_STD::reverse_iterator<const char_type*>(src + count),
|
||||
count,
|
||||
ETL_OR_STD::reverse_iterator<char_type*>(dst + count));
|
||||
etl::copy_n(ETL_OR_STD::reverse_iterator<const char_type*>(src + count), count, ETL_OR_STD::reverse_iterator<char_type*>(dst + count));
|
||||
}
|
||||
|
||||
return dst;
|
||||
@ -270,7 +276,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
static ETL_CONSTEXPR int_type eof() ETL_NOEXCEPT
|
||||
{
|
||||
return -1;
|
||||
return static_cast<int_type>(-1);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -310,7 +316,7 @@ namespace etl
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
if (*t1 < *t2)
|
||||
{
|
||||
return -1;
|
||||
@ -343,7 +349,7 @@ namespace etl
|
||||
++t1;
|
||||
++t2;
|
||||
--n;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -384,6 +390,6 @@ namespace etl
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
} // namespace etl
|
||||
|
||||
#endif
|
||||
|
||||
@ -179,7 +179,7 @@ namespace etl
|
||||
/// \param begin Start of the range.
|
||||
/// \param end End of the range.
|
||||
//*************************************************************************
|
||||
template<typename TIterator>
|
||||
template <typename TIterator>
|
||||
checksum(TIterator begin, const TIterator end)
|
||||
{
|
||||
this->reset();
|
||||
@ -208,7 +208,7 @@ namespace etl
|
||||
/// \param begin Start of the range.
|
||||
/// \param end End of the range.
|
||||
//*************************************************************************
|
||||
template<typename TIterator>
|
||||
template <typename TIterator>
|
||||
bsd_checksum(TIterator begin, const TIterator end)
|
||||
{
|
||||
this->reset();
|
||||
@ -237,7 +237,7 @@ namespace etl
|
||||
/// \param begin Start of the range.
|
||||
/// \param end End of the range.
|
||||
//*************************************************************************
|
||||
template<typename TIterator>
|
||||
template <typename TIterator>
|
||||
xor_checksum(TIterator begin, const TIterator end)
|
||||
{
|
||||
this->reset();
|
||||
@ -266,7 +266,7 @@ namespace etl
|
||||
/// \param begin Start of the range.
|
||||
/// \param end End of the range.
|
||||
//*************************************************************************
|
||||
template<typename TIterator>
|
||||
template <typename TIterator>
|
||||
xor_rotate_checksum(TIterator begin, const TIterator end)
|
||||
{
|
||||
this->reset();
|
||||
@ -295,13 +295,13 @@ namespace etl
|
||||
/// \param begin Start of the range.
|
||||
/// \param end End of the range.
|
||||
//*************************************************************************
|
||||
template<typename TIterator>
|
||||
template <typename TIterator>
|
||||
parity_checksum(TIterator begin, const TIterator end)
|
||||
{
|
||||
this->reset();
|
||||
this->add(begin, end);
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace etl
|
||||
|
||||
#endif
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user