FairMQ  1.2.3
C++ Message Passing 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;
36 
40  {
41  fParts.push_back(std::unique_ptr<FairMQMessage>(msg));
42  }
43 
47  // inline void AddPart(std::unique_ptr<FairMQMessage>& msg)
48  // {
49  // fParts.push_back(std::move(msg));
50  // }
51 
55  void AddPart(std::unique_ptr<FairMQMessage>&& msg)
56  {
57  fParts.push_back(std::move(msg));
58  }
59 
62  FairMQMessage& operator[](const int index) { return *(fParts[index]); }
63 
66  std::unique_ptr<FairMQMessage>& At(const int index) { return fParts.at(index); }
67 
68  // ref version
69  FairMQMessage& AtRef(const int index) { return *(fParts.at(index)); }
70 
73  int Size() const { return fParts.size(); }
74 
75  container fParts;
76 
77  // forward container iterators
78  using iterator = container::iterator;
79  using const_iterator = container::const_iterator;
80  auto begin() -> decltype(fParts.begin()) { return fParts.begin(); }
81  auto end() -> decltype(fParts.end()) { return fParts.end(); }
82  auto cbegin() -> decltype(fParts.cbegin()) { return fParts.cbegin(); }
83  auto cend() -> decltype(fParts.cend()) { return fParts.cend(); }
84 };
85 
86 #endif /* FAIRMQPARTS_H_ */
~FairMQParts()
Default destructor.
Definition: FairMQParts.h:35
FairMQMessage & operator[](const int index)
Definition: FairMQParts.h:62
void AddPart(FairMQMessage *msg)
Definition: FairMQParts.h:39
FairMQParts & operator=(const FairMQParts &)=delete
Assignment operator.
std::unique_ptr< FairMQMessage > & At(const int index)
Definition: FairMQParts.h:66
void AddPart(std::unique_ptr< FairMQMessage > &&msg)
Definition: FairMQParts.h:55
int Size() const
Definition: FairMQParts.h:73
FairMQParts is a lightweight convenience wrapper around a vector of unique pointers to FairMQMessage...
Definition: FairMQParts.h:20
FairMQParts()
Default constructor.
Definition: FairMQParts.h:27
Definition: FairMQMessage.h:19