Fast DDS
Version 3.6.1.0
Fast DDS
Toggle main menu visibility
Loading...
Searching...
No Matches
StackAllocatedSequence.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
18
19
#ifndef FASTDDS_DDS_CORE__STACKALLOCATEDSEQUENCE_HPP
20
#define FASTDDS_DDS_CORE__STACKALLOCATEDSEQUENCE_HPP
21
22
#include <array>
23
#include <cassert>
24
#include <cstdint>
25
#include <stdexcept>
26
27
#include <fastdds/dds/core/LoanableArray.hpp>
28
#include <fastdds/dds/core/LoanableTypedCollection.hpp>
29
30
namespace
eprosima
{
31
namespace
fastdds
{
32
namespace
dds
{
33
37
template
<
typename
T, LoanableCollection::
size_t
ype num_items>
38
struct
StackAllocatedSequence
:
public
LoanableTypedCollection
<T>
39
{
40
using
size_type
=
LoanableCollection::size_type
;
41
using
element_type
=
LoanableCollection::element_type
;
42
43
StackAllocatedSequence
()
44
{
45
has_ownership_
=
true
;
46
maximum_
= num_items;
47
length_
= 0;
48
elements_
= data_.buffer_for_loans();
49
}
50
51
~StackAllocatedSequence
() =
default
;
52
53
// Non-copyable
54
StackAllocatedSequence
(
55
const
StackAllocatedSequence
&) =
delete
;
56
StackAllocatedSequence
&
operator =
(
57
const
StackAllocatedSequence
&) =
delete
;
58
59
// Non-moveable
60
StackAllocatedSequence
(
61
StackAllocatedSequence
&&) =
delete
;
62
StackAllocatedSequence
&
operator =
(
63
StackAllocatedSequence
&&) =
delete
;
64
65
protected
:
66
67
using
LoanableCollection::maximum_
;
68
using
LoanableCollection::length_
;
69
using
LoanableCollection::elements_
;
70
using
LoanableCollection::has_ownership_
;
71
72
void
resize
(
73
LoanableCollection::size_type
new_length)
override
74
{
75
// This kind of collection cannot grow above its stack-allocated size
76
if
(new_length > num_items)
77
{
78
throw
std::bad_alloc();
79
}
80
}
81
82
private
:
83
84
LoanableArray<T, num_items>
data_;
85
};
86
87
}
// namespace dds
88
}
// namespace fastdds
89
}
// namespace eprosima
90
91
#endif
// FASTDDS_DDS_CORE__STACKALLOCATEDSEQUENCE_HPP
eprosima::fastdds::dds::LoanableCollection::has_ownership_
bool has_ownership_
Definition
LoanableCollection.hpp:243
eprosima::fastdds::dds::LoanableCollection::maximum_
size_type maximum_
Definition
LoanableCollection.hpp:240
eprosima::fastdds::dds::LoanableCollection::size_type
int32_t size_type
Definition
LoanableCollection.hpp:37
eprosima::fastdds::dds::LoanableCollection::length_
size_type length_
Definition
LoanableCollection.hpp:241
eprosima::fastdds::dds::LoanableCollection::elements_
element_type * elements_
Definition
LoanableCollection.hpp:242
eprosima::fastdds::dds::LoanableCollection::element_type
void * element_type
Definition
LoanableCollection.hpp:38
eprosima::fastdds::dds::LoanableTypedCollection
A type-safe accessible collection of generic opaque pointers that can receive the buffer from outside...
Definition
LoanableTypedCollection.hpp:40
eprosima::fastdds::dds
Definition
BuiltinTopicKey.hpp:26
eprosima::fastdds
eprosima
eProsima namespace.
eprosima::fastdds::dds::LoanableArray
A type-safe, ordered collection of elements allocated on the stack, which can be loaned to a Loanable...
Definition
LoanableArray.hpp:35
eprosima::fastdds::dds::StackAllocatedSequence::has_ownership_
bool has_ownership_
Definition
LoanableCollection.hpp:243
eprosima::fastdds::dds::StackAllocatedSequence::operator=
StackAllocatedSequence & operator=(const StackAllocatedSequence &)=delete
eprosima::fastdds::dds::StackAllocatedSequence::maximum_
size_type maximum_
Definition
LoanableCollection.hpp:240
eprosima::fastdds::dds::StackAllocatedSequence::length_
size_type length_
Definition
LoanableCollection.hpp:241
eprosima::fastdds::dds::StackAllocatedSequence::StackAllocatedSequence
StackAllocatedSequence(const StackAllocatedSequence &)=delete
eprosima::fastdds::dds::StackAllocatedSequence::StackAllocatedSequence
StackAllocatedSequence()
Definition
StackAllocatedSequence.hpp:43
eprosima::fastdds::dds::StackAllocatedSequence::StackAllocatedSequence
StackAllocatedSequence(StackAllocatedSequence &&)=delete
eprosima::fastdds::dds::StackAllocatedSequence::element_type
LoanableCollection::element_type element_type
Definition
StackAllocatedSequence.hpp:41
eprosima::fastdds::dds::StackAllocatedSequence::elements_
element_type * elements_
Definition
LoanableCollection.hpp:242
eprosima::fastdds::dds::StackAllocatedSequence::size_type
LoanableCollection::size_type size_type
Definition
StackAllocatedSequence.hpp:40
eprosima::fastdds::dds::StackAllocatedSequence::~StackAllocatedSequence
~StackAllocatedSequence()=default
eprosima::fastdds::dds::StackAllocatedSequence::resize
void resize(LoanableCollection::size_type new_length) override
Definition
StackAllocatedSequence.hpp:72
include
fastdds
dds
core
StackAllocatedSequence.hpp
Generated on
for