Publishing 2019 R3 content
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / api / compounds.h
1 /*
2 // Copyright (c) 2016 Intel Corporation
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 #pragma once
17
18 #include <vector>
19 #include <cassert>
20 #include <iterator>
21 #include <cstring>
22 #include <string>
23 #include <stdexcept>
24
25 #include "meta_utils.hpp"
26
27 namespace cldnn {
28
29 /// @addtogroup cpp_api C++ API
30 /// @{
31
32 /// @cond CPP_HELPERS
33
34 /// @defgroup cpp_helpers Helpers
35 /// @{
36
37 template <typename T>
38 class mutable_array_ref {
39 public:
40     typedef size_t size_type;
41
42     mutable_array_ref() : _data(nullptr), _size(0) {}
43     explicit mutable_array_ref(T& val) : _data(&val), _size(1) {}
44     mutable_array_ref(T* data, size_t size) : _data(data), _size(size) {}
45
46     template <size_t N>
47     explicit mutable_array_ref(T (&arr)[N]) : _data(arr), _size(N) {}
48
49     mutable_array_ref(const mutable_array_ref& other) : _data(other._data), _size(other._size) {}
50
51     mutable_array_ref& operator=(const mutable_array_ref& other) {
52         if (this == &other)
53             return *this;
54         _data = other._data;
55         _size = other._size;
56         return *this;
57     }
58
59     T* data() const { return _data; }
60     size_t size() const { return _size; }
61     bool empty() const { return _size == 0; }
62
63 #if defined(_SECURE_SCL) && (_SECURE_SCL > 0)
64     typedef stdext::checked_array_iterator<T*> iterator;
65     typedef stdext::checked_array_iterator<const T*> const_iterator;
66     iterator begin() const { return stdext::make_checked_array_iterator(_data, _size); }
67     iterator end() const { return stdext::make_checked_array_iterator(_data, _size, _size); }
68     const_iterator cbegin() const { return stdext::make_checked_array_iterator(_data, _size); }
69     const_iterator cend() const { return stdext::make_checked_array_iterator(_data, _size, _size); }
70 #else
71     typedef T* iterator;
72     typedef T* const_iterator;
73     iterator begin() const { return _data; }
74     iterator end() const { return _data + _size; }
75     const_iterator cbegin() const { return _data; }
76     const_iterator cend() const { return _data + _size; }
77 #endif
78
79     T& operator[](size_t idx) const {
80         assert(idx < _size);
81         return _data[idx];
82     }
83
84     T& at(size_t idx) const {
85         if (idx >= _size) throw std::out_of_range("idx");
86         return _data[idx];
87     }
88
89     std::vector<T> vector() const { return std::vector<T>(_data, _data + _size); }
90
91 private:
92     T* _data;
93     size_t _size;
94 };
95
96 /// @}
97
98 /// @endcond
99
100 /// @}
101 }  // namespace cldnn