Fast DDS  Version 3.0.0
Fast DDS
Loading...
Searching...
No Matches
UserAllocatedSequence.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__USERALLOCATEDSEQUENCE_HPP
20#define FASTDDS_DDS_CORE__USERALLOCATEDSEQUENCE_HPP
21
22#include <cassert>
23#include <cstdint>
24#include <stdexcept>
25
26#include <fastdds/dds/core/LoanableCollection.hpp>
27
28namespace eprosima {
29namespace fastdds {
30namespace dds {
31
41{
44
57 element_type* items,
58 size_type num_items)
59 {
60 has_ownership_ = true;
61 maximum_ = num_items;
62 length_ = 0;
63 elements_ = items;
64 }
65
67
68 // Non-copyable
70 const UserAllocatedSequence&) = delete;
72 const UserAllocatedSequence&) = delete;
73
74 // Non-moveable
76 UserAllocatedSequence&&) = delete;
78 UserAllocatedSequence&&) = delete;
79
80protected:
81
86
87 void resize(
88 size_type new_length) override
89 {
90 // This kind of collection cannot grow above its stack-allocated size
91 if (new_length > maximum_)
92 {
93 throw std::bad_alloc();
94 }
95 }
96
97};
98
99} // namespace dds
100} // namespace fastdds
101} // namespace eprosima
102
103#endif // FASTDDS_DDS_CORE__USERALLOCATEDSEQUENCE_HPP
A collection of generic opaque pointers that can receive the buffer from outside (loan).
Definition LoanableCollection.hpp:34
bool has_ownership_
Definition LoanableCollection.hpp:243
size_type maximum_
Definition LoanableCollection.hpp:240
int32_t size_type
Definition LoanableCollection.hpp:37
size_type length_
Definition LoanableCollection.hpp:241
element_type * elements_
Definition LoanableCollection.hpp:242
void * element_type
Definition LoanableCollection.hpp:38
Definition DomainParticipant.hpp:45
eProsima namespace.
A collection of generic opaque pointers allocated by the user.
Definition UserAllocatedSequence.hpp:41
UserAllocatedSequence(const UserAllocatedSequence &)=delete
UserAllocatedSequence(element_type *items, size_type num_items)
Construct a UserAllocatedSequence.
Definition UserAllocatedSequence.hpp:56
bool has_ownership_
Definition LoanableCollection.hpp:243
size_type maximum_
Definition LoanableCollection.hpp:240
void resize(size_type new_length) override
Definition UserAllocatedSequence.hpp:87
size_type length_
Definition LoanableCollection.hpp:241
UserAllocatedSequence(UserAllocatedSequence &&)=delete
LoanableCollection::element_type element_type
Definition UserAllocatedSequence.hpp:43
element_type * elements_
Definition LoanableCollection.hpp:242
LoanableCollection::size_type size_type
Definition UserAllocatedSequence.hpp:42
UserAllocatedSequence & operator=(const UserAllocatedSequence &)=delete