FairMQParts.h
/********************************************************************************
* Copyright (C) 2014 GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
* *
* This software is distributed under the terms of the *
* GNU Lesser General Public Licence (LGPL) version 3, *
* copied verbatim in the file "LICENSE" *
********************************************************************************/
#ifndef FAIRMQPARTS_H_
#define FAIRMQPARTS_H_
#include "FairMQTransportFactory.h"
#include "FairMQMessage.h"
#include <vector>
#include <memory> // unique_ptr
class FairMQParts
{
private:
using container = std::vector<std::unique_ptr<FairMQMessage>>;
public:
FairMQParts() : fParts() {};
FairMQParts(const FairMQParts&) = delete;
FairMQParts(FairMQParts&& p) = default;
FairMQParts& operator=(const FairMQParts&) = delete;
~FairMQParts() {};
void AddPart(FairMQMessage* msg)
{
fParts.push_back(std::unique_ptr<FairMQMessage>(msg));
}
// inline void AddPart(std::unique_ptr<FairMQMessage>& msg)
// {
// fParts.push_back(std::move(msg));
// }
void AddPart(std::unique_ptr<FairMQMessage>&& msg)
{
fParts.push_back(std::move(msg));
}
FairMQMessage& operator[](const int index) { return *(fParts[index]); }
std::unique_ptr<FairMQMessage>& At(const int index) { return fParts.at(index); }
// ref version
FairMQMessage& AtRef(const int index) { return *(fParts.at(index)); }
int Size() const { return fParts.size(); }
container fParts;
// forward container iterators
using iterator = container::iterator;
using const_iterator = container::const_iterator;
auto begin() -> decltype(fParts.begin()) { return fParts.begin(); }
auto end() -> decltype(fParts.end()) { return fParts.end(); }
auto cbegin() -> decltype(fParts.cbegin()) { return fParts.cbegin(); }
auto cend() -> decltype(fParts.cend()) { return fParts.cend(); }
};
#endif /* FAIRMQPARTS_H_ */
FairMQParts::~FairMQParts
~FairMQParts()
Default destructor.
Definition: FairMQParts.h:35
FairMQParts::operator[]
FairMQMessage & operator[](const int index)
Definition: FairMQParts.h:62
FairMQParts::AddPart
void AddPart(FairMQMessage *msg)
Definition: FairMQParts.h:39
FairMQParts::operator=
FairMQParts & operator=(const FairMQParts &)=delete
Assignment operator.
FairMQParts::At
std::unique_ptr< FairMQMessage > & At(const int index)
Definition: FairMQParts.h:66
FairMQParts::AddPart
void AddPart(std::unique_ptr< FairMQMessage > &&msg)
Definition: FairMQParts.h:55
FairMQParts::Size
int Size() const
Definition: FairMQParts.h:73
FairMQParts
FairMQParts is a lightweight convenience wrapper around a vector of unique pointers to FairMQMessage...
Definition: FairMQParts.h:20
FairMQParts::FairMQParts
FairMQParts()
Default constructor.
Definition: FairMQParts.h:27
FairMQMessage
Definition: FairMQMessage.h:19