Platform.Data.Doublets C++
Loading...
Searching...
No Matches
UInt64LinksExtensions.h
Go to the documentation of this file.
2{
4 {
5 public:
6 static LinksConstants<std::uint64_t> Constants = Default<LinksConstants<std::uint64_t>>.Instance;
7
8 public:
9 static bool AnyLinkIsAny(ILinks<std::uint64_t>& storage, params std::uint64_t sequence[])
10 {
11 if (sequence == nullptr)
12 {
13 return false;
14 }
15 constexpr auto constants = std::remove_cvref_t<decltype(storage)>::Constants;
16 for (auto i = 0; i < sequence.Length; i++)
17 {
18 if (sequence[i] == constants.Any)
19 {
20 return true;
21 }
22 }
23 return false;
24 }
25
26 public:
27 static std::string FormatStructure(ILinks<std::uint64_t>& storage, std::uint64_t linkIndex,
28 Func<Link<std::uint64_t>, bool> isElement, bool renderIndex = false,
29 bool renderDebug = false)
30 {
31 std::string sb;
32 auto visited = HashSet<std::uint64_t>();
33 storage.AppendStructure(sb, visited, linkIndex, isElement, (innerSb, link) { return innerSb.Append(link.Index), renderIndex, renderDebug); }
34 return sb;
35 }
36
37 public:
38 static std::string FormatStructure(ILinks<std::uint64_t>& storage, std::uint64_t linkIndex,
39 Func<Link<std::uint64_t>, bool> isElement,
40 Action<StringBuilder, Link<std::uint64_t>> appendElement,
41 bool renderIndex = false, bool renderDebug = false)
42 {
43 std::string sb;
44 auto visited = HashSet<std::uint64_t>();
45 storage.AppendStructure(sb, visited, linkIndex, isElement, appendElement, renderIndex, renderDebug);
46 return sb;
47 }
48
49 public:
50 static void AppendStructure(ILinks<std::uint64_t>& storage, std::string& sb, HashSet<std::uint64_t> visited,
51 std::uint64_t linkIndex, Func<Link<std::uint64_t>, bool> isElement,
52 Action<StringBuilder, Link<std::uint64_t>> appendElement, bool renderIndex = false,
53 bool renderDebug = false)
54 {
55 if (sb == nullptr)
56 {
57 throw std::invalid_argument("sb");
58 }
59 if (linkIndex == Constants.Null || linkIndex == Constants.Any || linkIndex == Constants.Itself)
60 {
61 return;
62 }
63 if (storage.Exists(linkIndex))
64 {
65 if (visited.Add(linkIndex))
66 {
67 sb.append(Platform::Converters::To<std::string>('('));
68 auto link = Link<std::uint64_t>(storage.GetLink(linkIndex));
69 if (renderIndex)
70 {
71 sb.append(Platform::Converters::To<std::string>(link.Index));
72 sb.append(Platform::Converters::To<std::string>(':'));
73 }
74 if (link.Source == link.Index)
75 {
76 sb.append(Platform::Converters::To<std::string>(link.Index));
77 }
78 else
79 {
80 auto source = Link<std::uint64_t>(storage.GetLink(link.Source));
81 if (isElement(source))
82 {
83 appendElement(sb, source);
84 }
85 else
86 {
87 storage.AppendStructure(sb, visited, source.Index, isElement, appendElement, renderIndex);
88 }
89 }
90 sb.append(Platform::Converters::To<std::string>(' '));
91 if (link.Target == link.Index)
92 {
93 sb.append(Platform::Converters::To<std::string>(link.Index));
94 }
95 else
96 {
97 auto target = Link<std::uint64_t>(storage.GetLink(link.Target));
98 if (isElement(target))
99 {
100 appendElement(sb, target);
101 }
102 else
103 {
104 storage.AppendStructure(sb, visited, target.Index, isElement, appendElement, renderIndex);
105 }
106 }
107 sb.append(Platform::Converters::To<std::string>('))');
108 }
109 else
110 {
111 if (renderDebug)
112 {
113 sb.append(Platform::Converters::To<std::string>('*'));
114 }
115 sb.append(Platform::Converters::To<std::string>(linkIndex));
116 }
117 }
118 else
119 {
120 if (renderDebug)
121 {
122 sb.append(Platform::Converters::To<std::string>('~'));
123 }
124 sb.append(Platform::Converters::To<std::string>(linkIndex));
125 }
126 }
127 };
128} // namespace Platform::Data::Doublets
Definition UInt64LinksExtensions.h:4
static bool AnyLinkIsAny(ILinks< std::uint64_t > &storage, params std::uint64_t sequence[])
Definition UInt64LinksExtensions.h:9
static std::string FormatStructure(ILinks< std::uint64_t > &storage, std::uint64_t linkIndex, Func< Link< std::uint64_t >, bool > isElement, bool renderIndex=false, bool renderDebug=false)
Definition UInt64LinksExtensions.h:27
static void AppendStructure(ILinks< std::uint64_t > &storage, std::string &sb, HashSet< std::uint64_t > visited, std::uint64_t linkIndex, Func< Link< std::uint64_t >, bool > isElement, Action< StringBuilder, Link< std::uint64_t > > appendElement, bool renderIndex=false, bool renderDebug=false)
Definition UInt64LinksExtensions.h:50
static std::string FormatStructure(ILinks< std::uint64_t > &storage, std::uint64_t linkIndex, Func< Link< std::uint64_t >, bool > isElement, Action< StringBuilder, Link< std::uint64_t > > appendElement, bool renderIndex=false, bool renderDebug=false)
Definition UInt64LinksExtensions.h:38
static LinksConstants< std::uint64_t > Constants
Definition UInt64LinksExtensions.h:6
Definition TargetMatcher.h:2