Fast DDS  Version 3.0.0
Fast DDS
Loading...
Searching...
No Matches
LoanableTypedCollection.hpp
1// Copyright 2021 Proyectos y Sistemas de Mantenimiento SL (eProsima).
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
19#ifndef FASTDDS_DDS_CORE__LOANABLETYPEDCOLLECTION_HPP
20#define FASTDDS_DDS_CORE__LOANABLETYPEDCOLLECTION_HPP
21
22#include <cassert>
23#include <cstdint>
24#include <stdexcept>
25#include <type_traits>
26
27#include <fastdds/dds/core/LoanableCollection.hpp>
28
29namespace eprosima {
30namespace fastdds {
31namespace dds {
32
38template<typename T, typename _NonConstEnabler = std::true_type>
40{
41public:
42
58 template <typename Enabler = _NonConstEnabler>
59 typename std::enable_if<Enabler::value, T>::type& operator [](
60 size_type n)
61 {
62 if (n >= length_)
63 {
64 throw std::out_of_range("");
65 }
66
67 return *static_cast<T*>(elements_[n]);
68 }
69
84 const T& operator [](
85 size_type n) const
86 {
87 if (n >= length_)
88 {
89 throw std::out_of_range("");
90 }
91
92 return *static_cast<const T*>(elements_[n]);
93 }
94
95};
96
97} // namespace dds
98} // namespace fastdds
99} // namespace eprosima
100
101#endif // FASTDDS_DDS_CORE__LOANABLETYPEDCOLLECTION_HPP
A collection of generic opaque pointers that can receive the buffer from outside (loan).
Definition LoanableCollection.hpp:34
int32_t size_type
Definition LoanableCollection.hpp:37
size_type length_
Definition LoanableCollection.hpp:241
element_type * elements_
Definition LoanableCollection.hpp:242
A type-safe accessible collection of generic opaque pointers that can receive the buffer from outside...
Definition LoanableTypedCollection.hpp:40
std::enable_if< Enabler::value, T >::type & operator[](size_type n)
Set an element of the sequence.
Definition LoanableTypedCollection.hpp:59
Definition DomainParticipant.hpp:45
eProsima namespace.