Skip to content

Commit dbacf7b

Browse files
authored
Remove references to boost::container::pmr (#14395)
Use fair::mq::pmr instead, so that we can then easily migrate fair::mq to std::pmr while still having backward compatibility.
1 parent ad4cc98 commit dbacf7b

File tree

6 files changed

+31
-42
lines changed

6 files changed

+31
-42
lines changed

DataFormats/Headers/include/Headers/Stack.h

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414
#include "MemoryResources/MemoryResources.h"
1515
#include "Headers/DataHeader.h"
1616

17-
namespace o2
18-
{
19-
20-
namespace header
17+
namespace o2::header
2118
{
2219
//__________________________________________________________________________________________________
2320
/// @struct Stack
@@ -45,20 +42,20 @@ struct Stack {
4542
};
4643

4744
public:
48-
using allocator_type = boost::container::pmr::polymorphic_allocator<std::byte>;
45+
using allocator_type = fair::mq::pmr::polymorphic_allocator<std::byte>;
4946
using value_type = std::byte;
50-
using BufferType = std::unique_ptr<value_type[], freeobj>; //this gives us proper default move semantics for free
47+
using BufferType = std::unique_ptr<value_type[], freeobj>; // this gives us proper default move semantics for free
5148

5249
Stack() = default;
5350
Stack(Stack&&) = default;
5451
Stack(Stack&) = delete;
5552
Stack& operator=(Stack&) = delete;
56-
Stack& operator=(Stack&&) = default;
53+
Stack& operator=(Stack&&) = delete;
5754

58-
value_type* data() const { return buffer.get(); }
59-
size_t size() const { return bufferSize; }
55+
[[nodiscard]] value_type* data() const { return buffer.get(); }
56+
[[nodiscard]] size_t size() const { return bufferSize; }
6057
allocator_type get_allocator() const { return allocator; }
61-
const BaseHeader* first() const { return reinterpret_cast<const BaseHeader*>(this->data()); }
58+
[[nodiscard]] const BaseHeader* first() const { return reinterpret_cast<const BaseHeader*>(this->data()); }
6259
static const BaseHeader* firstHeader(std::byte const* buf) { return BaseHeader::get(buf); }
6360
static const BaseHeader* lastHeader(std::byte const* buf)
6461
{
@@ -90,9 +87,9 @@ struct Stack {
9087
/// all headers must derive from BaseHeader, in addition also other stacks can be passed to ctor.
9188
template <typename FirstArgType, typename... Headers,
9289
typename std::enable_if_t<
93-
!std::is_convertible<FirstArgType, boost::container::pmr::polymorphic_allocator<std::byte>>::value, int> = 0>
90+
!std::is_convertible<FirstArgType, fair::mq::pmr::polymorphic_allocator<std::byte>>::value, int> = 0>
9491
Stack(FirstArgType&& firstHeader, Headers&&... headers)
95-
: Stack(boost::container::pmr::new_delete_resource(), std::forward<FirstArgType>(firstHeader),
92+
: Stack(fair::mq::pmr::new_delete_resource(), std::forward<FirstArgType>(firstHeader),
9693
std::forward<Headers>(headers)...)
9794
{
9895
}
@@ -122,7 +119,7 @@ struct Stack {
122119
template <typename T>
123120
constexpr static size_t calculateSize(T&& h) noexcept
124121
{
125-
//if it's a pointer (to a stack) traverse it
122+
// if it's a pointer (to a stack) traverse it
126123
if constexpr (std::is_convertible_v<T, std::byte*>) {
127124
const BaseHeader* next = BaseHeader::get(std::forward<T>(h));
128125
if (!next) {
@@ -133,17 +130,17 @@ struct Stack {
133130
size += next->size();
134131
}
135132
return size;
136-
//otherwise get the size directly
133+
// otherwise get the size directly
137134
} else {
138135
return h.size();
139136
}
140137
}
141138

142-
//recursion terminator
139+
// recursion terminator
143140
constexpr static size_t calculateSize() { return 0; }
144141

145142
private:
146-
allocator_type allocator{boost::container::pmr::new_delete_resource()};
143+
allocator_type allocator{fair::mq::pmr::new_delete_resource()};
147144
size_t bufferSize{0};
148145
BufferType buffer{nullptr, freeobj{allocator.resource()}};
149146

@@ -231,7 +228,6 @@ struct Stack {
231228
}
232229
};
233230

234-
} // namespace header
235-
} // namespace o2
231+
} // namespace o2::header
236232

237233
#endif // HEADERS_STACK_H

DataFormats/Headers/test/testDataHeader.cxx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,8 @@ BOOST_AUTO_TEST_CASE(headerStack_test)
280280
Stack s2{s1, meta};
281281
BOOST_CHECK(s2.size() == s1.size() + sizeof(decltype(meta)));
282282

283-
//check dynamic construction - where we don't have the type information and need to
284-
//work with BaseHeader pointers
283+
// check dynamic construction - where we don't have the type information and need to
284+
// work with BaseHeader pointers
285285
const test::MetaHeader thead{2};
286286
o2::header::BaseHeader const* bname = reinterpret_cast<BaseHeader const*>(&thead);
287287
Stack ds2(s1, *bname);
@@ -313,8 +313,8 @@ BOOST_AUTO_TEST_CASE(headerStack_test)
313313
BOOST_REQUIRE(h3 != nullptr);
314314
BOOST_CHECK(h3->secret == 42);
315315

316-
//test constructing from a buffer and an additional header
317-
using namespace boost::container::pmr;
316+
// test constructing from a buffer and an additional header
317+
using namespace fair::mq::pmr;
318318
Stack s5(new_delete_resource(), s1.data(), Stack{}, meta);
319319
BOOST_CHECK(s5.size() == s1.size() + sizeof(meta));
320320
// check if we can find the header even though there was an empty stack in the middle

DataFormats/MemoryResources/include/MemoryResources/MemoryResources.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class MessageResource : public FairMQMemoryResource
115115
// A spectator pmr memory resource which only watches the memory of the underlying buffer, does not
116116
// carry out real allocation. It owns the underlying buffer which is destroyed on deallocation.
117117
template <typename BufferType>
118-
class SpectatorMemoryResource : public boost::container::pmr::memory_resource
118+
class SpectatorMemoryResource : public fair::mq::pmr::memory_resource
119119
{
120120
public:
121121
using buffer_type = BufferType;
@@ -183,10 +183,10 @@ class SpectatorMemoryResource : public boost::container::pmr::memory_resource
183183
// This in general (as in STL) is a bad idea, but here it is safe to inherit from an allocator since we
184184
// have no additional data and only override some methods so we don't get into slicing and other problems.
185185
template <typename T>
186-
class SpectatorAllocator : public boost::container::pmr::polymorphic_allocator<T>
186+
class SpectatorAllocator : public fair::mq::pmr::polymorphic_allocator<T>
187187
{
188188
public:
189-
using boost::container::pmr::polymorphic_allocator<T>::polymorphic_allocator;
189+
using fair::mq::pmr::polymorphic_allocator<T>::polymorphic_allocator;
190190
using propagate_on_container_move_assignment = std::true_type;
191191

192192
// skip default construction of empty elements
@@ -243,7 +243,7 @@ class OwningMessageSpectatorAllocator
243243
return OwningMessageSpectatorAllocator();
244244
}
245245

246-
boost::container::pmr::memory_resource* resource() { return &mResource; }
246+
fair::mq::pmr::memory_resource* resource() { return &mResource; }
247247

248248
// skip default construction of empty elements
249249
// this is important for two reasons: one: it allows us to adopt an existing buffer (e.g. incoming message) and
@@ -269,14 +269,14 @@ class OwningMessageSpectatorAllocator
269269

270270
// The NoConstructAllocator behaves like the normal pmr vector but does not call constructors / destructors
271271
template <typename T>
272-
class NoConstructAllocator : public boost::container::pmr::polymorphic_allocator<T>
272+
class NoConstructAllocator : public fair::mq::pmr::polymorphic_allocator<T>
273273
{
274274
public:
275-
using boost::container::pmr::polymorphic_allocator<T>::polymorphic_allocator;
275+
using fair::mq::pmr::polymorphic_allocator<T>::polymorphic_allocator;
276276
using propagate_on_container_move_assignment = std::true_type;
277277

278278
template <typename... Args>
279-
NoConstructAllocator(Args&&... args) : boost::container::pmr::polymorphic_allocator<T>(std::forward<Args>(args)...)
279+
NoConstructAllocator(Args&&... args) : fair::mq::pmr::polymorphic_allocator<T>(std::forward<Args>(args)...)
280280
{
281281
}
282282

@@ -302,9 +302,9 @@ class NoConstructAllocator : public boost::container::pmr::polymorphic_allocator
302302
//__________________________________________________________________________________________________
303303

304304
using ByteSpectatorAllocator = SpectatorAllocator<std::byte>;
305-
using BytePmrAllocator = boost::container::pmr::polymorphic_allocator<std::byte>;
305+
using BytePmrAllocator = fair::mq::pmr::polymorphic_allocator<std::byte>;
306306
template <class T>
307-
using vector = std::vector<T, o2::pmr::polymorphic_allocator<T>>;
307+
using vector = std::vector<T, fair::mq::pmr::polymorphic_allocator<T>>;
308308

309309
//__________________________________________________________________________________________________
310310
/// Return a std::vector spanned over the contents of the message, takes ownership of the message

DataFormats/MemoryResources/test/testMemoryResources.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ BOOST_AUTO_TEST_CASE(transportallocatormap_test)
6060
BOOST_CHECK(_tmp == allocZMQ);
6161
}
6262

63-
using namespace boost::container::pmr;
63+
using namespace fair::mq::pmr;
6464

6565
BOOST_AUTO_TEST_CASE(allocator_test)
6666
{

Framework/Core/include/Framework/Output.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,13 @@ struct Output {
5959

6060
Output& operator=(const Output&) = delete;
6161

62-
Output& operator=(Output&& rhs)
63-
{
64-
origin = rhs.origin;
65-
description = rhs.description;
66-
subSpec = rhs.subSpec;
67-
metaHeader = std::move(rhs.metaHeader);
68-
return *this;
69-
}
62+
Output& operator=(Output&& rhs) = delete;
7063

7164
bool operator==(const Output& that) const
7265
{
7366
return origin == that.origin && description == that.description && subSpec == that.subSpec;
7467
}
7568
};
7669

77-
} // namespace o2
70+
} // namespace o2::framework
7871
#endif

Framework/Core/test/test_FairMQ.cxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ TEST_CASE("addDataBlockForEach_test")
174174
int i;
175175
int j;
176176
};
177-
using namespace boost::container::pmr;
177+
using namespace fair::mq::pmr;
178178
fair::mq::Parts message;
179179
std::vector<elem, polymorphic_allocator<elem>> vec(polymorphic_allocator<elem>{allocZMQ});
180180
vec.reserve(100);

0 commit comments

Comments
 (0)