Medical Imaging Interaction Toolkit  2018.4.99-36d69b77
Medical Imaging Interaction Toolkit
mitkPropertyRelations.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include <algorithm>
14 #include <regex>
15 #include <utility>
16 
17 #include <mitkPropertyRelations.h>
18 
20 {
21 }
22 
24 {
25 }
26 
28 {
29  if (!rule)
30  {
31  return false;
32  }
33 
34  if (rule->GetRuleID().empty())
35  {
36  return false;
37  }
38 
39  auto ruleFinding = m_RuleMap.find(rule->GetRuleID());
40 
41  bool result = false;
42  if (ruleFinding == m_RuleMap.end())
43  {
44  m_RuleMap.insert(std::make_pair(rule->GetRuleID(), rule));
45  result = true;
46  }
47  else if (overwrite)
48  {
49  m_RuleMap[rule->GetRuleID()] = rule;
50  result = true;
51  }
52 
53  return result;
54 }
55 
57 {
58  RuleResultVectorType result;
59 
60  if (source)
61  {
62  for (const auto& rule : m_RuleMap)
63  {
64  if (rule.second->IsSource(source))
65  {
66  result.push_back(rule.second);
67  }
68  }
69  }
70 
71  return result;
72 };
73 
75 {
76  RuleResultVectorType result;
77 
78  for (const auto& rule : m_RuleMap)
79  {
80  if (rule.second->IsSourceCandidate(sourceCandidate))
81  {
82  result.push_back(rule.second);
83  }
84  }
85 
86  return result;
87 };
88 
90 {
91  RuleResultVectorType result;
92 
93  for (const auto& rule : m_RuleMap)
94  {
95  if (rule.second->IsDestinationCandidate(destCandidate))
96  {
97  result.push_back(rule.second);
98  }
99  }
100 
101  return result;
102 };
103 
105 {
107 
108  auto ruleFinding = m_RuleMap.find(ruleID);
109 
110  if (ruleFinding != m_RuleMap.end())
111  {
112  result = ruleFinding->second;
113  }
114 
115  return result;
116 };
117 
119 {
120  RuleIDVectorType result;
121 
122  for (const auto& rule : m_RuleMap)
123  {
124  result.push_back(rule.first);
125  }
126  return result;
127 };
128 
129 
131 {
132  return !this->GetRulesForSource(source).empty();
133 };
134 
136 {
137  m_RuleMap.clear();
138 }
139 
141 {
142  if (!ruleID.empty())
143  {
144  m_RuleMap.erase(ruleID);
145  }
146 }
147 
148 
150 {
151  return new PropertyRelations();
152 };
virtual RuleIDType GetRuleID() const =0
Interface of property relations service.
IPropertyRelations::RuleIDVectorType RuleIDVectorType
bool HasRuleForSource(const IPropertyProvider *source) const override
Check if a passed instance has defined relation covered by the registered rules.
std::list< PropertyRelationRuleBase::ConstPointer > RuleResultVectorType
MITKCORE_EXPORT IPropertyRelations * CreateTestInstancePropertyRelations()
IPropertyRelations::RuleResultVectorType RuleResultVectorType
RuleResultVectorType GetRulesForSource(const IPropertyProvider *source) const override
Get all relation rules the passed source is really a source of. (PropertyRelationRuleBase::IsSource()...
bool AddRule(const PropertyRelationRuleBase *rule, bool overwrite=false) override
Add rule for a specific relation. If there is already a property rule instance it won&#39;t be added...
PropertyRelationRuleBase::RuleIDType RuleIDType
void RemoveRule(const RuleIDType &ruleID) override
Remove relation rule instance with the passed ID. If rule does not exist nothing happens.
RuleIDVectorType GetRuleIDs() const override
Get all IDs of registered rules.
void RemoveAllRules() override
Remove all relation rules.
RuleResultVectorType GetRulesForDestinationCandidate(const IPropertyProvider *destCandidate) const override
Get all relation rules that would accept the passed IPropertOwner as destination. ...
PropertyRelationRuleBase::ConstPointer GetRule(const RuleIDType &ruleID) const override
Get the relation rule that has the specfied ruleID.
std::vector< RuleIDType > RuleIDVectorType
RuleResultVectorType GetRulesForSourceCandidate(const IPropertyProvider *sourceCandidate) const override
Get all relation rules that would accept the passed IPropertOwner as source.