Platform.Data.Doublets C++
Loading...
Searching...
No Matches
PropertyOperator.h
Go to the documentation of this file.
2{
3 template <typename...>
5 template <std::integral TLinkAddress>
6 class PropertyOperator<TLinkAddress> : public LinksOperatorBase<TLinkAddress>, IProperty<TLinkAddress, TLinkAddress>
7 {
8 private:
9 TLinkAddress _propertyMarker = 0;
10
11 private:
12 TLinkAddress _propertyValueMarker = 0;
13
14 public:
15 PropertyOperator(ILinks<TLinkAddress>& storage, TLinkAddress propertyMarker, TLinkAddress propertyValueMarker)
16 : base(storage)
17 {
18 _propertyMarker = propertyMarker;
19 _propertyValueMarker = propertyValueMarker;
20 }
21
22 public:
24 {
25 auto property = _links.SearchOrDefault(link, _propertyMarker);
26 return this->GetValue(this->GetContainer(property));
27 }
28
29 private:
30 TLinkAddress GetContainer(TLinkAddress property)
31 {
32 auto valueContainer = this->0(TLinkAddress);
33 if (property == 0)
34 {
35 return valueContainer;
36 }
37 auto storage = _links;
38 constexpr auto constants = std::remove_cvref_t<decltype(storage)>::Constants;
39 auto countinueConstant = constants.Continue;
40 auto breakConstant = constants.Break;
41 auto anyConstant = constants.Any;
42 auto query = Link<TLinkAddress>(anyConstant, property, anyConstant);
43 storage.Each(
44 candidate = >
45 {
46 auto candidateTarget = storage.GetTarget(candidate);
47 auto valueTarget = storage.GetTarget(candidateTarget);
48 if (valueTarget == _propertyValueMarker)
49 {
50 valueContainer = storage.GetIndex(candidate);
51 return breakConstant;
52 }
53 return countinueConstant;
54 },
55 query);
56 return valueContainer;
57 }
58
59 private:
60 TLinkAddress GetValue(TLinkAddress container)
61 {
62 return container == 0 ? 0 : _links.GetTarget(container);
63 }
64
65 public:
66 void Set(TLinkAddress link, TLinkAddress value)
67 {
68 auto storage = _links;
69 auto property = storage.GetOrCreate(link, _propertyMarker);
70 auto container = this->GetContainer(property);
71 if (container == 0)
72 {
73 storage.GetOrCreate(property, value);
74 }
75 else
76 {
77 storage.Update(container, property, value);
78 }
79 }
80 };
81} // namespace Platform::Data::Doublets::PropertyOperators
void Set(TLinkAddress link, TLinkAddress value)
Definition PropertyOperator.h:66
PropertyOperator(ILinks< TLinkAddress > &storage, TLinkAddress propertyMarker, TLinkAddress propertyValueMarker)
Definition PropertyOperator.h:15
TLinkAddress Get(TLinkAddress link)
Definition PropertyOperator.h:23
Definition PropertiesOperator.h:2