BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
compatibilityutils.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // qt-mvvm: Model-view-view-model framework for large GUI applications
4 //
5 //! @file mvvm/model/mvvm/serialization/compatibilityutils.cpp
6 //! @brief Implements class CLASS?
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2020
11 //! @authors Gennady Pospelov et al, Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
16 #include "mvvm/model/groupitem.h"
19 #include <set>
20 
21 namespace ModelView ::Compatibility {
22 
23 /*
24 Returns `true` if given TagInfo is compatible with given container.
25 Here, `container` is what exists at runtime, `taginfo` has been obtained from the serialization.
26 Container is considered to be compatible (i.e. can be updated from serialized content), if it has
27 exactly same tag, and it is empty.
28 */
29 
30 bool IsCompatibleUniversalTag(const SessionItemContainer& container, const TagInfo& taginfo)
31 {
32  auto container_taginfo = container.tagInfo();
33 
34  bool is_empty = container.empty();
35  bool both_are_universal =
36  !container_taginfo.isSinglePropertyTag() && !taginfo.isSinglePropertyTag();
37  bool same_tags = container_taginfo == taginfo;
38 
39  return both_are_universal && same_tags && is_empty;
40 }
41 
42 /*
43 Returns `true` if given TagInfo is a single property tag which is compatible with given container.
44 Here, `container` is what exists at runtime, `taginfo` has been obtained from the serialization.
45 Container is considered to be compatible (i.e. can be updated from serialized content), if it has
46 exactly same tag, and property item ready for update.
47 */
48 
49 bool IsCompatibleSinglePropertyTag(const SessionItemContainer& container, const TagInfo& taginfo)
50 {
51  auto container_taginfo = container.tagInfo();
52 
53  bool has_item = !container.empty();
54  bool both_are_properties =
55  container_taginfo.isSinglePropertyTag() && taginfo.isSinglePropertyTag();
56  bool same_tags = container_taginfo == taginfo;
57 
58  return both_are_properties && same_tags && has_item;
59 }
60 
61 /*
62 Returns `true` if given TagInfo is compatible with given container.
63 Here, `container` is what exists at runtime, `taginfo` has been obtained from the serialization.
64 Container is considered to be compatible (i.e. can be updated from serialized content),
65 if it has exactly same tag, and it's name corresponds to GroupItem.
66 */
67 
68 bool IsCompatibleGroupTag(const SessionItemContainer& container, const TagInfo& taginfo)
69 {
70  auto container_taginfo = container.tagInfo();
71  bool has_item = !container.empty();
72  bool same_tags = container_taginfo == taginfo;
73  bool both_are_universal =
74  !container_taginfo.isSinglePropertyTag() && !taginfo.isSinglePropertyTag();
75  bool valid_tag_name = taginfo.name() == GroupItem::T_GROUP_ITEMS;
76  return both_are_universal && same_tags && has_item && valid_tag_name;
77 }
78 
79 } // namespace ModelView::Compatibility
static const std::string T_GROUP_ITEMS
Definition: groupitem.h:28
Defines class CLASS?
Defines class CLASS?
bool IsCompatibleUniversalTag(const SessionItemContainer &container, const TagInfo &taginfo)
bool IsCompatibleSinglePropertyTag(const SessionItemContainer &container, const TagInfo &taginfo)
bool IsCompatibleGroupTag(const SessionItemContainer &container, const TagInfo &taginfo)
MVVM_MODEL_EXPORT bool is_empty(const std::string &path)
Returns true if the file indicated by 'path' refers to empty file or directory.
Definition: fileutils.cpp:121
materialitems.h Collection of materials to populate MaterialModel.
Defines class CLASS?
Defines class CLASS?