Platform.Data.Doublets C++
Loading...
Searching...
No Matches
LinksUniquenessResolver.h
Go to the documentation of this file.
2{
3 template <typename TFacade, typename TDecorated>
4 struct LinksUniquenessResolver : DecoratorBase<TFacade, TDecorated>
5 {
6 public:
7 using base = DecoratorBase<TFacade, TDecorated>;
8 using base::Constants;
9 using typename base::LinkAddressType;
10 using typename base::LinkType;
11 using typename base::ReadHandlerType;
12 using typename base::WriteHandlerType;
13
14 public:
16
17 public:
18 LinkAddressType Update(const LinkType& restriction, const LinkType& substitution,
19 const WriteHandlerType& handler)
20 {
21 auto newLinkAddress = SearchOrDefault(this->decorated(), substitution[Constants.SourcePart],
22 substitution[Constants.TargetPart]);
23 if (newLinkAddress == LinkAddressType{})
24 {
25 return this->decorated().TDecorated::Update(restriction, substitution, handler);
26 }
27 return this->ResolveAddressChangeConflict(restriction[Constants.IndexPart], newLinkAddress, handler);
28 }
29
30 public:
31 LinkAddressType ResolveAddressChangeConflict(LinkAddressType oldLinkAddress, LinkAddressType newLinkAddress,
32 const WriteHandlerType& handler)
33 {
34 if (oldLinkAddress != newLinkAddress && Exists(this->decorated(), oldLinkAddress))
35 {
36 this->facade().Delete(LinkType{oldLinkAddress}, handler);
37 }
38 return Constants.Continue;
39 }
40 };
41} // namespace Platform::Data::Doublets::Decorators
Definition Decorators.h:4
TStorage::LinkAddressType SearchOrDefault(TStorage &storage, typename TStorage::LinkAddressType source, typename TStorage::LinkAddressType target)
Definition ILinksExtensions.h:470
DecoratorBase< TFacade, TDecorated > base
Definition LinksUniquenessResolver.h:7
LinkAddressType Update(const LinkType &restriction, const LinkType &substitution, const WriteHandlerType &handler)
Definition LinksUniquenessResolver.h:18
LinkAddressType ResolveAddressChangeConflict(LinkAddressType oldLinkAddress, LinkAddressType newLinkAddress, const WriteHandlerType &handler)
Definition LinksUniquenessResolver.h:31