BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
ModelView::TagInfo Class Reference

Holds info about single tag for SessionItem. More...

Public Member Functions

 TagInfo ()
 
 TagInfo (std::string name, int min, int max, std::vector< std::string > modelTypes)
 
bool isSinglePropertyTag () const
 Returns true if this tag is used to store single properties. More...
 
bool isValidChild (const std::string &modelType) const
 Returns true if given modelType matches the list of possible model types. More...
 
int max () const
 
bool maximumReached () const
 
int min () const
 
std::vector< std::string > modelTypes () const
 
std::string name () const
 
bool operator!= (const TagInfo &other) const
 
bool operator== (const TagInfo &other) const
 

Static Public Member Functions

static TagInfo propertyTag (std::string name, std::string model_type)
 Constructs tag intended for single property. More...
 
static TagInfo universalTag (std::string name, std::vector< std::string > modelTypes={})
 Constructs universal tag intended for unlimited amount of various items. More...
 

Private Attributes

int m_max
 
int m_min
 
std::vector< std::string > m_modelTypes
 
std::string m_name
 

Detailed Description

Holds info about single tag for SessionItem.

The tag specifies information about children that can be added to a SessionItem. A tag has a name, min, max allowed number of children, and vector of all modelTypes that children can have.

Definition at line 28 of file taginfo.h.

Constructor & Destructor Documentation

◆ TagInfo() [1/2]

ModelView::TagInfo::TagInfo ( )

Definition at line 21 of file taginfo.cpp.

21 : m_min(0), m_max(-1) {}

◆ TagInfo() [2/2]

ModelView::TagInfo::TagInfo ( std::string  name,
int  min,
int  max,
std::vector< std::string >  modelTypes 
)

Definition at line 23 of file taginfo.cpp.

24  : m_name(std::move(name)), m_min(min), m_max(max), m_modelTypes(std::move(modelTypes))
25 {
26  if (m_min < 0 || (m_min > m_max && m_max >= 0) || m_name.empty()) {
27  std::ostringstream ostr;
28  ostr << "Invalid constructor parameters"
29  << " " << m_name << " " << m_min << " " << m_max;
30  throw std::runtime_error(ostr.str());
31  }
32 }
std::vector< std::string > m_modelTypes
Definition: taginfo.h:61
std::string name() const
Definition: taginfo.cpp:45
int max() const
Definition: taginfo.cpp:55
std::vector< std::string > modelTypes() const
Definition: taginfo.cpp:60
int min() const
Definition: taginfo.cpp:50
std::string m_name
Definition: taginfo.h:58

References m_max, m_min, and m_name.

Member Function Documentation

◆ isSinglePropertyTag()

bool ModelView::TagInfo::isSinglePropertyTag ( ) const

Returns true if this tag is used to store single properties.

Properties are children that are created in SessionItem constructor using ::addProperty method.

Definition at line 75 of file taginfo.cpp.

76 {
77  return m_min == 1 && m_max == 1;
78 }

Referenced by TEST_F().

◆ isValidChild()

bool ModelView::TagInfo::isValidChild ( const std::string &  modelType) const

Returns true if given modelType matches the list of possible model types.

Definition at line 67 of file taginfo.cpp.

68 {
69  return m_modelTypes.empty() ? true : Utils::Contains(m_modelTypes, modelType);
70 }
bool Contains(const A &container, const B &element)
Returns true if container contains a given element.

References ModelView::Utils::Contains().

Referenced by ModelView::SessionItemContainer::is_valid_item(), and TEST_F().

Here is the call graph for this function:

◆ max()

int ModelView::TagInfo::max ( ) const

Definition at line 55 of file taginfo.cpp.

56 {
57  return m_max;
58 }

Referenced by ModelView::SessionItemContainer::maximum_reached(), TEST_F(), and ModelView::JsonTagInfoConverter::to_json().

◆ maximumReached()

bool ModelView::TagInfo::maximumReached ( ) const

◆ min()

int ModelView::TagInfo::min ( ) const

Definition at line 50 of file taginfo.cpp.

51 {
52  return m_min;
53 }

Referenced by ModelView::SessionItemContainer::minimum_reached(), TEST_F(), and ModelView::JsonTagInfoConverter::to_json().

◆ modelTypes()

std::vector< std::string > ModelView::TagInfo::modelTypes ( ) const

Definition at line 60 of file taginfo.cpp.

61 {
62  return m_modelTypes;
63 }

Referenced by TEST_F(), and ModelView::JsonTagInfoConverter::to_json().

◆ name()

◆ operator!=()

bool ModelView::TagInfo::operator!= ( const TagInfo other) const

Definition at line 86 of file taginfo.cpp.

87 {
88  return !(*this == other);
89 }

◆ operator==()

bool ModelView::TagInfo::operator== ( const TagInfo other) const

Definition at line 80 of file taginfo.cpp.

81 {
82  return m_name == other.m_name && m_min == other.m_min && m_max == other.m_max
83  && m_modelTypes == other.m_modelTypes;
84 }

References m_max, m_min, m_modelTypes, and m_name.

◆ propertyTag()

ModelView::TagInfo ModelView::TagInfo::propertyTag ( std::string  name,
std::string  model_type 
)
static

Constructs tag intended for single property.

Definition at line 40 of file taginfo.cpp.

41 {
42  return TagInfo(std::move(name), 1, 1, {std::move(model_type)});
43 }
std::string model_type
Definition: types.h:23

References RealSpace::Particles::name().

Referenced by ModelView::CompoundItem::addProperty(), and TEST_F().

Here is the call graph for this function:

◆ universalTag()

ModelView::TagInfo ModelView::TagInfo::universalTag ( std::string  name,
std::vector< std::string >  modelTypes = {} 
)
static

Constructs universal tag intended for unlimited amount of various items.

Definition at line 34 of file taginfo.cpp.

36 {
37  return TagInfo(std::move(name), 0, -1, std::move(modelTypes));
38 }

References RealSpace::Particles::name().

Referenced by ModelView::ContainerItem::ContainerItem(), ModelView::GraphViewportItem::GraphViewportItem(), ModelView::GroupItem::GroupItem(), ToyItems::LayerItem::LayerItem(), gui2::MaterialContainerItem::MaterialContainerItem(), gui2::MultiLayerItem::MultiLayerItem(), ToyItems::MultiLayerItem::MultiLayerItem(), StandardChildrenStrategiesTest::TestItem::TestItem(), SessionModel::SessionModelImpl::createRootItem(), TEST(), and TEST_F().

Here is the call graph for this function:

Member Data Documentation

◆ m_max

int ModelView::TagInfo::m_max
private

Definition at line 60 of file taginfo.h.

Referenced by TagInfo(), and operator==().

◆ m_min

int ModelView::TagInfo::m_min
private

Definition at line 59 of file taginfo.h.

Referenced by TagInfo(), and operator==().

◆ m_modelTypes

std::vector<std::string> ModelView::TagInfo::m_modelTypes
private

Definition at line 61 of file taginfo.h.

Referenced by operator==().

◆ m_name

std::string ModelView::TagInfo::m_name
private

Definition at line 58 of file taginfo.h.

Referenced by TagInfo(), and operator==().


The documentation for this class was generated from the following files: