BornAgain
1.19.79
Simulate and fit neutron and x-ray scattering at grazing incidence
SampleItem.h
Go to the documentation of this file.
1
// ************************************************************************************************
2
//
3
// BornAgain: simulate and fit reflection and scattering
4
//
5
//! @file GUI/Model/Sample/SampleItem.h
6
//! @brief Defines class SampleItem
7
//!
8
//! @homepage http://www.bornagainproject.org
9
//! @license GNU General Public License v3 or higher (see COPYING)
10
//! @copyright Forschungszentrum Jülich GmbH 2021
11
//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12
//
13
// ************************************************************************************************
14
15
#ifndef BORNAGAIN_GUI_MODEL_SAMPLE_SAMPLEITEM_H
16
#define BORNAGAIN_GUI_MODEL_SAMPLE_SAMPLEITEM_H
17
18
#include <variant>
19
20
class
MultiLayerItem
;
21
class
LayerItem
;
22
class
ParticleLayoutItem
;
23
class
ItemWithParticles
;
24
class
SessionItem
;
25
26
using
VariantForSampleItems
=
27
std::variant<MultiLayerItem*, LayerItem*, ParticleLayoutItem*, ItemWithParticles*>;
28
29
//! This can hold any item which belongs to a sample.
30
//!
31
//! Removes the need to derive every xxxItem from a same base class and then try dynamic_cast'ing
32
//! it.
33
class
SampleItem
:
public
VariantForSampleItems
{
34
public
:
35
template
<
typename
T>
36
SampleItem
(T* item)
37
:
base
(item)
38
{
39
}
40
41
//! Short version to get a contained pointer (the std::get_if would return pointer-to-pointer)
42
template
<
typename
T>
43
T
get_if
()
44
{
45
if
(T* pp = std::get_if<T>(
this
))
46
return
*pp;
47
return
nullptr
;
48
}
49
50
private
:
51
using
base
=
VariantForSampleItems
;
52
};
53
54
#endif
// BORNAGAIN_GUI_MODEL_SAMPLE_SAMPLEITEM_H
VariantForSampleItems
std::variant< MultiLayerItem *, LayerItem *, ParticleLayoutItem *, ItemWithParticles * > VariantForSampleItems
Definition:
SampleItem.h:27
ItemWithParticles
Definition:
ItemWithParticles.h:27
LayerItem
Definition:
LayerItem.h:36
MultiLayerItem
Definition:
MultiLayerItem.h:31
ParticleLayoutItem
Definition:
ParticleLayoutItem.h:28
SampleItem
This can hold any item which belongs to a sample.
Definition:
SampleItem.h:33
SampleItem::base
VariantForSampleItems base
Definition:
SampleItem.h:51
SampleItem::get_if
T get_if()
Short version to get a contained pointer (the std::get_if would return pointer-to-pointer)
Definition:
SampleItem.h:43
SampleItem::SampleItem
SampleItem(T *item)
Definition:
SampleItem.h:36
SessionItem
Base class for a GUI data item.
Definition:
SessionItem.h:204
GUI
Model
Sample
SampleItem.h
Generated by
1.9.1