38 const LinkType& substitution,
39 Func<IList<TLinkAddress>, IList<TLinkAddress>,
TLinkAddress> substitutionHandler)
41 auto constants = _constants;
42 if (patternOrCondition.IsNullOrEmpty() && substitution.IsNullOrEmpty())
44 return constants.Continue;
46 else if (patternOrCondition.EqualTo(substitution))
48 throw std::logic_error(
"Not implemented exception.");
50 else if (!substitution.IsNullOrEmpty())
53 if (matchHandler !=
nullptr && this->matchHandler(before) == constants.Break)
55 return constants.Break;
57 auto after = (IList<TLinkAddress>)substitution.ToArray();
60 auto newLink = this->decorated().TDecorated::Create();
63 if (substitution.Count() == 1)
65 after = this->decorated().TDecorated::GetLink(substitution[0]);
67 else if (substitution.Count() == 3)
72 throw std::logic_error(
"Not supported exception.");
74 if (matchHandler !=
nullptr)
76 return this->substitutionHandler(before, after);
78 return constants.Continue;
80 else if (!patternOrCondition.IsNullOrEmpty())
82 if (patternOrCondition.Count() == 1)
84 auto linkToDelete = patternOrCondition[0];
85 auto before = this->decorated().TDecorated::GetLink(linkToDelete);
86 if (matchHandler !=
nullptr && this->matchHandler(before) == constants.Break)
88 return constants.Break;
91 this->decorated().TDecorated::Update(linkToDelete, constants.Null, constants.Null);
92 this->decorated().TDecorated::Delete(linkToDelete);
93 if (matchHandler !=
nullptr)
95 return this->substitutionHandler(before, after);
97 return constants.Continue;
101 throw std::logic_error(
"Not supported exception.");
106 if (patternOrCondition.Count() == 1)
108 auto linkToUpdate = patternOrCondition[0];
109 auto before = this->decorated().TDecorated::GetLink(linkToUpdate);
110 if (matchHandler !=
nullptr && this->matchHandler(before) == constants.Break)
112 return constants.Break;
114 auto after = (IList<TLinkAddress>)substitution.ToArray();
117 after[0] = linkToUpdate;
119 if (substitution.Count() == 1)
121 if (!substitution[0] == linkToUpdate)
123 after = this->decorated().TDecorated::GetLink(substitution[0]);
124 this->decorated().TDecorated::Update(linkToUpdate, constants.Null, constants.Null);
125 this->decorated().TDecorated::Delete(linkToUpdate);
128 else if (substitution.Count() == 3)
133 throw std::logic_error(
"Not supported exception.");
135 if (matchHandler !=
nullptr)
137 return this->substitutionHandler(before, after);
139 return constants.Continue;
143 throw std::logic_error(
"Not supported exception.");
149 IList<IList<IList<TLinkAddress>>>
Trigger(
const LinkType& condition,
const LinkType& substitution)
151 auto changes = List<IList<IList<TLinkAddress>>>();
152 auto continue = _constants.Continue;
154 condition, AlwaysContinue, substitution, (before, after) = > {
155 auto change =
new[]{before, after};