diff options
author | Grant Watson <grant.watson@arm.com> | 2022-11-16 15:32:39 +0000 |
---|---|---|
committer | Eric Kunze <eric.kunze@arm.com> | 2022-12-15 16:41:27 +0000 |
commit | 64285a1f25e2c7b85ed1f00b7947403e92baea00 (patch) | |
tree | 6d29c54f6497741449339e808508c854ba6a2267 /reference_model/src/array_proxy.h | |
parent | b45db9a696f5df7b233f374248f329c16ee7ae64 (diff) | |
download | reference_model-64285a1f25e2c7b85ed1f00b7947403e92baea00.tar.gz |
Extend reference model API with eager operator execution entrypoints
- Adds a script to generate operators.h and operators.cc
- Adds jinja2 templates for generating operators.h and operators.cc
- Adds unit tests for a subset of the operators generated
- Includes the TOSA specification as a submodule
- Adds supporting C++ and header files
Signed-off-by: Grant Watson <grant.watson@arm.com>
Change-Id: I5b60db4c56113110d8e75fe1152525d258233f9c
Diffstat (limited to 'reference_model/src/array_proxy.h')
-rw-r--r-- | reference_model/src/array_proxy.h | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/reference_model/src/array_proxy.h b/reference_model/src/array_proxy.h new file mode 100644 index 0000000..f6b3105 --- /dev/null +++ b/reference_model/src/array_proxy.h @@ -0,0 +1,98 @@ + +// Copyright (c) 2022, ARM Limited. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef ARRAY_PROXY_H_ +#define ARRAY_PROXY_H_ + +#include <cstddef> +#include <type_traits> + +template <typename T> +class ArrayProxy +{ +public: + ArrayProxy(size_t n, T* ptr) noexcept + : _n(n) + , _ptr(ptr) + {} + + template <typename U = T, std::enable_if_t<std::is_const<U>::value, int> = 0> + ArrayProxy(size_t n, typename std::remove_const_t<T>* ptr) noexcept + : _n(n) + , _ptr(ptr) + {} + + template <std::size_t S> + ArrayProxy(T (&ptr)[S]) noexcept + : _n(S) + , _ptr(ptr) + {} + + template <std::size_t S, typename U = T, std::enable_if_t<std::is_const<U>::value, int> = 0> + ArrayProxy(typename std::remove_const_t<T> (&ptr)[S]) noexcept + : _n(S) + , _ptr(ptr) + {} + + template <typename O, + std::enable_if_t<std::is_convertible_v<decltype(std::declval<O>().data()), T*> && + std::is_convertible_v<decltype(std::declval<O>().size()), std::size_t>, + int> = 0> + ArrayProxy(O& obj) noexcept + : _n(obj.size()) + , _ptr(obj.data()) + {} + + size_t size() const noexcept + { + return _n; + } + + T* data() const noexcept + { + return _ptr; + } + + bool empty() const noexcept + { + return _n == 0; + } + + const T* begin() const noexcept + { + return _ptr; + } + + const T* end() const noexcept + { + return _ptr + _n; + } + + T& operator[](size_t idx) noexcept + { + return *(_ptr + idx); + } + + const T& operator[](size_t idx) const noexcept + { + return *(_ptr + idx); + } + +private: + size_t _n; + T* _ptr; +}; + +#endif // ARRAY_PROXY_H_ |