src/core/messenger/Message.hpp

Base for the message implementation. More…

Namespaces

Name
allpix
Helper class to hold support layers for a detector model.

Classes

Name
class allpix::BaseMessage
Type-erased base class for all messages.
class allpix::Message
Generic class for all messages.

Detailed Description

Base for the message implementation.

Copyright: Copyright (c) 2017-2024 CERN and the Allpix Squared authors. This software is distributed under the terms of the MIT License, copied verbatim in the file “LICENSE.md”. In applying this license, CERN does not waive the privileges and immunities granted to it by virtue of its status as an Intergovernmental Organization or submit itself to any jurisdiction. SPDX-License-Identifier: MIT

Source code


#ifndef ALLPIX_MESSAGE_H
#define ALLPIX_MESSAGE_H

#include <vector>

#include "core/geometry/Detector.hpp"
#include "objects/Object.hpp"

namespace allpix {
    class BaseMessage {
    public:
        virtual ~BaseMessage();


        BaseMessage(const BaseMessage&) = default;
        BaseMessage& operator=(const BaseMessage&) = default;

        BaseMessage(BaseMessage&&) noexcept = default;
        BaseMessage& operator=(BaseMessage&&) noexcept = default;

        std::shared_ptr<const Detector> getDetector() const { return detector_; }

        virtual std::vector<std::reference_wrapper<Object>> getObjectArray();

    protected:
        BaseMessage();
        explicit BaseMessage(std::shared_ptr<const Detector> detector);

    private:
        std::shared_ptr<const Detector> detector_;
    };

    template <typename T> class Message : public BaseMessage {
    public:
        explicit Message(std::vector<T> data);
        Message(std::vector<T> data, const std::shared_ptr<const Detector>& detector);

        ~Message() override;

        const std::vector<T>& getData() const;

        std::vector<std::reference_wrapper<Object>> getObjectArray() override;

    private:
        template <typename U = T>
        std::vector<std::reference_wrapper<Object>>
        get_object_array(typename std::enable_if<std::is_base_of<Object, U>::value>::type* = nullptr);

        template <typename U = T>
        std::vector<std::reference_wrapper<Object>>
        get_object_array(typename std::enable_if<!std::is_base_of<Object, U>::value>::type* = nullptr);

        template <typename U = T>
        void skip_object_cleanup(typename std::enable_if<std::is_base_of<Object, U>::value>::type* = nullptr);

        template <typename U = T>
        void skip_object_cleanup(typename std::enable_if<!std::is_base_of<Object, U>::value>::type* = nullptr) {}

        std::vector<T> data_;
    };
} // namespace allpix

// Include template members
#include "Message.tpp"

#endif /* ALLPIX_MESSAGE_H */

Updated on 2024-12-13 at 08:31:37 +0000