Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// ************************************************************************************************
//
// 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