Platform.Data.Doublets C++
Loading...
Searching...
No Matches
UniLinks.h
Go to the documentation of this file.
2{
3 template <typename...>
4 class UniLinks;
5 template <std::integral TLinkAddress>
6 class UniLinks<TLinkAddress> : public DecoratorBase<TFacade, TDecorated>, IUniLinks<TLinkAddress>
7 {
8 public:
9 UniLinks(ILinks<TLinkAddress>& storage) : base(storage) {}
10
12 {
13 public:
14 IList<TLinkAddress>* Before;
15
16 public:
17 IList<TLinkAddress>* After;
18
19 public:
20 Transition(const LinkType& before, const LinkType& after)
21 {
22 Before = before;
23 After = after;
24 }
25 }
26
27 public : TLinkAddress
28 Trigger(const LinkType& restriction,
29 Func<IList<TLinkAddress>, IList<TLinkAddress>, TLinkAddress> matchedHandler,
30 const LinkType& substitution,
31 Func<IList<TLinkAddress>, IList<TLinkAddress>, TLinkAddress> substitutedHandler)
32 {
33 return _constants.Continue;
34 }
35
36 public:
37 TLinkAddress Trigger(const LinkType& patternOrCondition, Func<IList<TLinkAddress>, TLinkAddress> matchHandler,
38 const LinkType& substitution,
39 Func<IList<TLinkAddress>, IList<TLinkAddress>, TLinkAddress> substitutionHandler)
40 {
41 auto constants = _constants;
42 if (patternOrCondition.IsNullOrEmpty() && substitution.IsNullOrEmpty())
43 {
44 return constants.Continue;
45 }
46 else if (patternOrCondition.EqualTo(substitution))
47 {
48 throw std::logic_error("Not implemented exception.");
49 }
50 else if (!substitution.IsNullOrEmpty())
51 {
52 auto before = Array.Empty<TLinkAddress>();
53 if (matchHandler != nullptr && this->matchHandler(before) == constants.Break)
54 {
55 return constants.Break;
56 }
57 auto after = (IList<TLinkAddress>)substitution.ToArray();
58 if (after[0] == 0)
59 {
60 auto newLink = this->decorated().TDecorated::Create();
61 after[0] = newLink;
62 }
63 if (substitution.Count() == 1)
64 {
65 after = this->decorated().TDecorated::GetLink(substitution[0]);
66 }
67 else if (substitution.Count() == 3)
68 {
69 }
70 else
71 {
72 throw std::logic_error("Not supported exception.");
73 }
74 if (matchHandler != nullptr)
75 {
76 return this->substitutionHandler(before, after);
77 }
78 return constants.Continue;
79 }
80 else if (!patternOrCondition.IsNullOrEmpty())
81 {
82 if (patternOrCondition.Count() == 1)
83 {
84 auto linkToDelete = patternOrCondition[0];
85 auto before = this->decorated().TDecorated::GetLink(linkToDelete);
86 if (matchHandler != nullptr && this->matchHandler(before) == constants.Break)
87 {
88 return constants.Break;
89 }
90 auto after = Array.Empty<TLinkAddress>();
91 this->decorated().TDecorated::Update(linkToDelete, constants.Null, constants.Null);
92 this->decorated().TDecorated::Delete(linkToDelete);
93 if (matchHandler != nullptr)
94 {
95 return this->substitutionHandler(before, after);
96 }
97 return constants.Continue;
98 }
99 else
100 {
101 throw std::logic_error("Not supported exception.");
102 }
103 }
104 else
105 {
106 if (patternOrCondition.Count() == 1)
107 {
108 auto linkToUpdate = patternOrCondition[0];
109 auto before = this->decorated().TDecorated::GetLink(linkToUpdate);
110 if (matchHandler != nullptr && this->matchHandler(before) == constants.Break)
111 {
112 return constants.Break;
113 }
114 auto after = (IList<TLinkAddress>)substitution.ToArray();
115 if (after[0] == 0)
116 {
117 after[0] = linkToUpdate;
118 }
119 if (substitution.Count() == 1)
120 {
121 if (!substitution[0] == linkToUpdate)
122 {
123 after = this->decorated().TDecorated::GetLink(substitution[0]);
124 this->decorated().TDecorated::Update(linkToUpdate, constants.Null, constants.Null);
125 this->decorated().TDecorated::Delete(linkToUpdate);
126 }
127 }
128 else if (substitution.Count() == 3)
129 {
130 }
131 else
132 {
133 throw std::logic_error("Not supported exception.");
134 }
135 if (matchHandler != nullptr)
136 {
137 return this->substitutionHandler(before, after);
138 }
139 return constants.Continue;
140 }
141 else
142 {
143 throw std::logic_error("Not supported exception.");
144 }
145 }
146 }
147
148 public:
149 IList<IList<IList<TLinkAddress>>> Trigger(const LinkType& condition, const LinkType& substitution)
150 {
151 auto changes = List<IList<IList<TLinkAddress>>>();
152 auto continue = _constants.Continue;
153 Trigger(
154 condition, AlwaysContinue, substitution, (before, after) = > {
155 auto change = new[]{before, after};
156 changes.Add(change);
157 return continue;
158 });
159 return changes;
160 }
161
162 private:
163 TLinkAddress AlwaysContinue(const LinkType& linkToMatch)
164 {
165 return _constants.Continue;
166 }
167 };
168} // namespace Platform::Data::Doublets::Decorators
Definition Decorators.h:4