FairMQ  1.4.33
C++ Message Queuing Library and Framework
FairMQParts.h
1 /********************************************************************************
2  * Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
3  * *
4  * This software is distributed under the terms of the *
5  * GNU Lesser General Public Licence (LGPL) version 3, *
6  * copied verbatim in the file "LICENSE" *
7  ********************************************************************************/
8 
9 #ifndef FAIRMQPARTS_H_
10 #define FAIRMQPARTS_H_
11 
12 #include "FairMQTransportFactory.h"
13 #include "FairMQMessage.h"
14 
15 #include <vector>
16 #include <memory> // unique_ptr
17 
19 
21 {
22  private:
23  using container = std::vector<std::unique_ptr<FairMQMessage>>;
24 
25  public:
27  FairMQParts() : fParts() {};
29  FairMQParts(const FairMQParts&) = delete;
31  FairMQParts(FairMQParts&& p) = default;
33  FairMQParts& operator=(const FairMQParts&) = delete;
35  template <typename... Ts>
36  FairMQParts(Ts&&... messages) : fParts() { AddPart(std::forward<Ts>(messages)...); }
38  ~FairMQParts() {};
39 
43  {
44  fParts.push_back(std::unique_ptr<FairMQMessage>(msg));
45  }
46 
50  void AddPart(std::unique_ptr<FairMQMessage>&& msg)
51  {
52  fParts.push_back(std::move(msg));
53  }
54 
56  template <typename... Ts>
57  void AddPart(std::unique_ptr<FairMQMessage>&& first, Ts&&... remaining)
58  {
59  AddPart(std::move(first));
60  AddPart(std::forward<Ts>(remaining)...);
61  }
62 
64  void AddPart(FairMQParts&& other)
65  {
66  container parts = std::move(other.fParts);
67  for (auto& part : parts) {
68  fParts.push_back(std::move(part));
69  }
70  }
71 
74  FairMQMessage& operator[](const int index) { return *(fParts[index]); }
75 
78  std::unique_ptr<FairMQMessage>& At(const int index) { return fParts.at(index); }
79 
80  // ref version
81  FairMQMessage& AtRef(const int index) { return *(fParts.at(index)); }
82 
85  int Size() const { return fParts.size(); }
86 
87  container fParts;
88 
89  // forward container iterators
90  using iterator = container::iterator;
91  using const_iterator = container::const_iterator;
92  auto begin() -> decltype(fParts.begin()) { return fParts.begin(); }
93  auto end() -> decltype(fParts.end()) { return fParts.end(); }
94  auto cbegin() -> decltype(fParts.cbegin()) { return fParts.cbegin(); }
95  auto cend() -> decltype(fParts.cend()) { return fParts.cend(); }
96 };
97 
98 #endif /* FAIRMQPARTS_H_ */
FairMQParts::~FairMQParts
~FairMQParts()
Default destructor.
Definition: FairMQParts.h:44
FairMQParts::AddPart
void AddPart(FairMQMessage *msg)
Definition: FairMQParts.h:48
FairMQParts::operator[]
FairMQMessage & operator[](const int index)
Definition: FairMQParts.h:80
FairMQParts
FairMQParts is a lightweight convenience wrapper around a vector of unique pointers to FairMQMessage,...
Definition: FairMQParts.h:21
FairMQParts::At
std::unique_ptr< FairMQMessage > & At(const int index)
Definition: FairMQParts.h:84
FairMQParts::Size
int Size() const
Definition: FairMQParts.h:91
FairMQParts::operator=
FairMQParts & operator=(const FairMQParts &)=delete
Assignment operator.
FairMQMessage
Definition: FairMQMessage.h:33
FairMQParts::FairMQParts
FairMQParts()
Default constructor.
Definition: FairMQParts.h:33

privacy