|
1 | 1 | namespace Platform::Data
|
2 | 2 | {
|
| 3 | + template<typename TLinkAddress> |
| 4 | + static TLinkAddress Create(auto&& storage, Interfaces::CArray auto&& substitution) |
| 5 | + { |
| 6 | + auto _continue { storage.Constants.Continue }; |
| 7 | + TLinkAddress createdLinkAddress; |
| 8 | + storage.Create(substitution, [&createdLinkAddress, _continue] (Interfaces::CArray auto&& before, Interfaces::CArray auto&& after) |
| 9 | + { |
| 10 | + createdLinkAddress = after[0]; |
| 11 | + return _continue; |
| 12 | + }); |
| 13 | + return createdLinkAddress; |
| 14 | + } |
3 | 15 |
|
| 16 | + template<typename TLinkAddress> |
| 17 | + static TLinkAddress Create(auto&& storage) |
| 18 | + { |
| 19 | + constexpr std::array<TLinkAddress, 0> empty{}; |
| 20 | + return Create<TLinkAddress>(storage, empty); |
| 21 | + } |
| 22 | + |
| 23 | + template<typename TLinkAddress> |
| 24 | + static TLinkAddress Count(auto&& storage) |
| 25 | + // TODO: later add noexcept(expr) |
| 26 | + { |
| 27 | + constexpr std::array<TLinkAddress, 0> empty {}; |
| 28 | + return storage.Count(empty); |
| 29 | + } |
| 30 | + |
| 31 | + template<typename TLinkAddress> |
| 32 | + static TLinkAddress Count(auto&& storage, std::convertible_to<TLinkAddress> auto... restriction) |
| 33 | + // TODO: later add noexcept(expr) |
| 34 | + { |
| 35 | + std::array<TLinkAddress, sizeof...(restriction)> array { static_cast<TLinkAddress>(restriction)... }; |
| 36 | + return storage.Count(array); |
| 37 | + } |
| 38 | + |
| 39 | + template<typename TLinkAddress> |
| 40 | + static bool Exists(auto&& storage, TLinkAddress link) noexcept |
| 41 | + { |
| 42 | + auto&& constants = storage.Constants; |
| 43 | + return IsExternalReference(constants, link) || (IsInternalReference(constants, link) && Count<TLinkAddress>(storage, link) != 0); |
| 44 | + } |
| 45 | + |
| 46 | + template<typename TLinkAddress> |
| 47 | + static void EnsureLinkExists(auto&& storage, TLinkAddress link, const std::string& argument = {}) |
| 48 | + { |
| 49 | + if (!storage.Exists(link)) |
| 50 | + { |
| 51 | + throw ArgumentLinkDoesNotExistsException<TLinkAddress>(link, argument); |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + template<typename TLinkAddress> |
| 56 | + static TLinkAddress Each(auto&& storage, auto&& handler, std::convertible_to<TLinkAddress> auto... restrictions) |
| 57 | + // TODO: later create noexcept(expr) |
| 58 | + { |
| 59 | + TLinkAddress array[] = { static_cast<TLinkAddress>(restrictions)... }; |
| 60 | + return storage.Each(handler, array); |
| 61 | + } |
| 62 | + |
| 63 | + template<typename TLinkAddress> |
| 64 | + static Interfaces::CArray auto GetLink(auto&& storage, TLinkAddress link) |
| 65 | + { |
| 66 | + auto constants = storage.Constants; |
| 67 | + auto _continue = constants.Continue; |
| 68 | + auto any = constants.Any; |
| 69 | + if (IsExternalReference(constants, link)) |
| 70 | + { |
| 71 | + std::vector resultLink {link,link,link}; |
| 72 | + return resultLink; |
| 73 | + } |
| 74 | + |
| 75 | + std::vector<TLinkAddress> resultLink; |
| 76 | + storage.Each(std::array{link, any, any}, [&resultLink, _continue](Interfaces::CArray auto&& link) |
| 77 | + { |
| 78 | + resultLink = { std::ranges::begin(link), std::ranges::end(link) }; |
| 79 | + return _continue; |
| 80 | + }); |
| 81 | + Expects(!resultLink.empty()); |
| 82 | + return resultLink; |
| 83 | + } |
| 84 | + |
| 85 | + template<typename TLinkAddress> |
| 86 | + static bool IsFullPoint(auto&& storage, TLinkAddress link) |
| 87 | + { |
| 88 | + if (IsExternalReference(storage.Constants, link)) |
| 89 | + { |
| 90 | + return true; |
| 91 | + } |
| 92 | + storage.EnsureLinkExists(link); |
| 93 | + return Point<TLinkAddress>::IsFullPoint(storage.GetLink(link)); |
| 94 | + } |
| 95 | + |
| 96 | + template<typename TLinkAddress> |
| 97 | + static bool IsPartialPoint(auto&& storage, TLinkAddress link) |
| 98 | + { |
| 99 | + if (IsExternalReference(storage.Constants, link)) |
| 100 | + { |
| 101 | + return true; |
| 102 | + } |
| 103 | + storage.EnsureLinkExists(link); |
| 104 | + return Point<TLinkAddress>::IsPartialPoint(storage.GetLink(link)); |
| 105 | + } |
| 106 | + |
| 107 | + template<typename TLinkAddress> |
| 108 | + static TLinkAddress Delete(auto&& storage, std::convertible_to<TLinkAddress> auto ...restriction) |
| 109 | + { |
| 110 | + auto constants = storage.Constants; |
| 111 | + auto _continue = constants.Continue; |
| 112 | + std::array restrictionArray { static_cast<TLinkAddress>(restriction)... }; |
| 113 | + TLinkAddress deletedLinkAddress; |
| 114 | + storage.Delete(restrictionArray, [&deletedLinkAddress, _continue](Interfaces::CArray auto before, Interfaces::CArray auto after) |
| 115 | + { |
| 116 | + deletedLinkAddress = before[0]; |
| 117 | + return _continue; |
| 118 | + }); |
| 119 | + return deletedLinkAddress; |
| 120 | + } |
| 121 | + |
| 122 | + template<typename TLinkAddress> |
| 123 | + static bool Exists(const auto&& storage, TLinkAddress linkAddress) |
| 124 | + { |
| 125 | + auto constants = storage.Constants; |
| 126 | + return constants.IsExternalReference(linkAddress) || (constants.IsInternalReference(linkAddress) && (Count(storage, linkAddress) > 0)); |
| 127 | + } |
4 | 128 | }
|
0 commit comments