/src/Fast-DDS/include/fastdds/utils/collections/ResourceLimitedContainerConfig.hpp
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright 2019 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 | | |
15 | | /** |
16 | | * @file ResourceLimitedContainerConfig.hpp |
17 | | * |
18 | | */ |
19 | | |
20 | | #ifndef FASTDDS_UTILS_COLLECTIONS__RESOURCELIMITEDCONTAINERCONFIG_HPP |
21 | | #define FASTDDS_UTILS_COLLECTIONS__RESOURCELIMITEDCONTAINERCONFIG_HPP |
22 | | |
23 | | #include <cstddef> |
24 | | #include <limits> |
25 | | |
26 | | namespace eprosima { |
27 | | namespace fastdds { |
28 | | |
29 | | #define dummy_avoid_winmax |
30 | | |
31 | | /** |
32 | | * Specifies the configuration of a resource limited collection. |
33 | | * @ingroup UTILITIES_MODULE |
34 | | */ |
35 | | struct ResourceLimitedContainerConfig |
36 | | { |
37 | | |
38 | | ResourceLimitedContainerConfig( |
39 | | size_t ini = 0, |
40 | | size_t max = std::numeric_limits<size_t>::max dummy_avoid_winmax (), |
41 | | size_t inc = 1u) |
42 | 1.22M | : initial(ini) |
43 | 1.22M | , maximum(max) |
44 | 1.22M | , increment(inc) |
45 | 1.22M | { |
46 | 1.22M | } |
47 | | |
48 | | //! Number of elements to be preallocated in the collection. |
49 | | size_t initial = 0; |
50 | | //! Maximum number of elements allowed in the collection. |
51 | | size_t maximum = std::numeric_limits<size_t>::max dummy_avoid_winmax (); |
52 | | //! Number of items to add when capacity limit is reached. |
53 | | size_t increment = 1u; |
54 | | |
55 | | /** |
56 | | * Return a resource limits configuration for a fixed size collection. |
57 | | * @param size Number of elements to allocate. |
58 | | * @return Resource limits configuration. |
59 | | */ |
60 | | inline static ResourceLimitedContainerConfig fixed_size_configuration( |
61 | | size_t size) |
62 | 0 | { |
63 | 0 | return ResourceLimitedContainerConfig(size, size, 0u); |
64 | 0 | } |
65 | | |
66 | | /** |
67 | | * Return a resource limits configuration for a linearly growing, dynamically allocated collection. |
68 | | * @param increment Number of new elements to allocate when increasing the capacity of the collection. |
69 | | * @return Resource limits configuration. |
70 | | */ |
71 | | inline static ResourceLimitedContainerConfig dynamic_allocation_configuration( |
72 | | size_t increment = 1u) |
73 | 0 | { |
74 | 0 | return ResourceLimitedContainerConfig(0u, |
75 | 0 | std::numeric_limits<size_t>::max dummy_avoid_winmax (), increment ? increment : 1u); |
76 | 0 | } |
77 | | |
78 | | }; |
79 | | |
80 | | inline bool operator == ( |
81 | | const ResourceLimitedContainerConfig& lhs, |
82 | | const ResourceLimitedContainerConfig& rhs) |
83 | 0 | { |
84 | 0 | return |
85 | 0 | lhs.maximum == rhs.maximum && |
86 | 0 | lhs.initial == rhs.initial && |
87 | 0 | lhs.increment == rhs.increment; |
88 | 0 | } |
89 | | |
90 | | } // namespace fastdds |
91 | | } // namespace eprosima |
92 | | |
93 | | #endif // FASTDDS_UTILS_COLLECTIONS__RESOURCELIMITEDCONTAINERCONFIG_HPP |