Fast DDS  Version 3.6.1.0
Fast DDS
LoanableArray.hpp
1 // Copyright 2020 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__LOANABLEARRAY_HPP
20 #define FASTDDS_DDS_CORE__LOANABLEARRAY_HPP
21 
22 #include <cstdint>
23 #include <array>
24 
25 namespace eprosima {
26 namespace fastdds {
27 namespace dds {
28 
33 template<typename T, std::size_t num_items>
34 struct LoanableArray : public std::array<T, num_items>
35 {
37  {
38  for (std::size_t n = 0; n < num_items; ++n)
39  {
40  buffer_[n] = &((*this)[n]);
41  }
42  }
43 
44  // Non-copyable
46  const LoanableArray&) = delete;
48  const LoanableArray&) = delete;
49 
50  // Non-moveable
52  LoanableArray&&) = delete;
54  LoanableArray&&) = delete;
55 
61  void** buffer_for_loans() const
62  {
63  return (void**) buffer_;
64  }
65 
66 private:
67 
68  void* buffer_[num_items];
69 };
70 
71 } // namespace dds
72 } // namespace fastdds
73 } // namespace eprosima
74 
75 #endif // FASTDDS_DDS_CORE__LOANABLEARRAY_HPP
Definition: DomainParticipant.hpp:46
A type-safe, ordered collection of elements allocated on the stack, which can be loaned to a Loanable...
Definition: LoanableArray.hpp:35
void ** buffer_for_loans() const
Get a buffer pointer that could be used on LoanableCollection::loan.
Definition: LoanableArray.hpp:61
LoanableArray & operator=(const LoanableArray &)=delete
LoanableArray(const LoanableArray &)=delete
LoanableArray(LoanableArray &&)=delete
LoanableArray()
Definition: LoanableArray.hpp:36