1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 namespace android {
20 namespace hardware {
21 namespace camera {
22 namespace provider {
23 namespace implementation {
24 
25 template <class T> struct Span {
SpanSpan26     Span() : begin_(nullptr), end_(nullptr) {}
SpanSpan27     template <size_t N> Span(T (&a)[N]) : begin_(&a[0]), end_(&a[N]) {}
SpanSpan28     template <class I> Span(I begin, I end) : begin_(&*begin), end_(&*end) {}
SpanSpan29     template <class I> Span(I begin, size_t size) : begin_(&*begin), end_(&begin[size]) {}
30 
dataSpan31     T* data() { return begin_; }
dataSpan32     const T* data() const { return begin_; }
beginSpan33     T* begin() { return begin_; }
endSpan34     T* end() { return end_; }
beginSpan35     const T* begin() const { return begin_; }
endSpan36     const T* end() const { return end_; }
sizeSpan37     size_t size() const { return end_ - begin_; }
38     T& operator[](size_t i) { return begin_[i]; }
39     const T& operator[](size_t i) const { return begin_[i]; }
40 
41 private:
42     T* begin_;
43     T* end_;
44 };
45 
46 }  // namespace implementation
47 }  // namespace provider
48 }  // namespace camera
49 }  // namespace hardware
50 }  // namespace android
51