Skip to content
Snippets Groups Projects
SampleItem.h 1.65 KiB
Newer Older
  • Learn to ignore specific revisions
  • //  ************************************************************************************************
    //
    //  BornAgain: simulate and fit reflection and scattering
    //
    //! @file      GUI/Model/Sample/SampleItem.h
    //! @brief     Defines class SampleItem
    //!
    //! @homepage  http://www.bornagainproject.org
    //! @license   GNU General Public License v3 or higher (see COPYING)
    //! @copyright Forschungszentrum Jülich GmbH 2021
    //! @authors   Scientific Computing Group at MLZ (see CITATION, AUTHORS)
    //
    //  ************************************************************************************************
    
    #ifndef BORNAGAIN_GUI_MODEL_SAMPLE_SAMPLEITEM_H
    #define BORNAGAIN_GUI_MODEL_SAMPLE_SAMPLEITEM_H
    
    #include <variant>
    
    class MultiLayerItem;
    class LayerItem;
    class ParticleLayoutItem;
    class ItemWithParticles;
    class SessionItem;
    
    using VariantForSampleItems =
        std::variant<MultiLayerItem*, LayerItem*, ParticleLayoutItem*, ItemWithParticles*>;
    
    //! This can hold any item which belongs to a sample.
    //!
    //! Removes the need to derive every xxxItem from a same base class and then try dynamic_cast'ing
    //! it.
    class SampleItem : public VariantForSampleItems {
    public:
        //! #baMigration only for migration; remove after finished SampleModel migration
        SampleItem(SessionItem* item);
    
    
        template <typename T> SampleItem(T* item) : base(item) {}
    
    
        //! Short version to get a contained pointer (the std::get_if would return pointer-to-pointer)
        template <typename T> T get_if()
        {
            if (T* pp = std::get_if<T>(this))
                return *pp;
            return nullptr;
        }
    
    private:
        using base = VariantForSampleItems;
    };
    
    #endif // BORNAGAIN_GUI_MODEL_SAMPLE_SAMPLEITEM_H