src/core/module/ModuleIdentifier.hpp

Provide an identifier for module instances. More…

Namespaces

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

Classes

Name
class allpix::ModuleIdentifier
Internal identifier for a module.

Detailed Description

Provide an identifier for module instances.

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_MODULE_IDENTIFIER_H
#define ALLPIX_MODULE_IDENTIFIER_H

#include <memory>
#include <string>
#include <vector>

namespace allpix {
    class ModuleIdentifier {
    public:
        // TODO [doc] Is this method really necessary
        ModuleIdentifier() = default;
        ModuleIdentifier(std::string module_name, std::string identifier, int prio)
            : name_(std::move(module_name)), identifier_(std::move(identifier)), prio_(prio) {}

        const std::string& getName() const { return name_; }
        const std::string& getIdentifier() const { return identifier_; }
        std::string getUniqueName() const {
            std::string unique_name = name_;
            if(!identifier_.empty()) {
                unique_name += ":" + identifier_;
            }
            return unique_name;
        }
        int getPriority() const { return prio_; }


        bool operator==(const ModuleIdentifier& other) const {
            return getUniqueName() == other.getUniqueName() && getPriority() == other.getPriority();
        }
        bool operator!=(const ModuleIdentifier& other) const {
            return getUniqueName() != other.getUniqueName() || getPriority() != other.getPriority();
        }
        bool operator<(const ModuleIdentifier& other) const {
            return getUniqueName() != other.getUniqueName() ? getUniqueName() < other.getUniqueName()
                                                            : getPriority() < other.getPriority();
        }
        bool operator<=(const ModuleIdentifier& other) const {
            return getUniqueName() != other.getUniqueName() ? getUniqueName() <= other.getUniqueName()
                                                            : getPriority() <= other.getPriority();
        }
        bool operator>(const ModuleIdentifier& other) const {
            return getUniqueName() != other.getUniqueName() ? getUniqueName() > other.getUniqueName()
                                                            : getPriority() > other.getPriority();
        }
        bool operator>=(const ModuleIdentifier& other) const {
            return getUniqueName() != other.getUniqueName() ? getUniqueName() >= other.getUniqueName()
                                                            : getPriority() >= other.getPriority();
        }

    private:
        std::string name_;
        std::string identifier_;
        int prio_{};
    };
} // namespace allpix

#endif /*ALLPIX_MODULE_IDENTIFIER_H */

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