OGLplus  (0.59.0) a C++ wrapper for rendering APIs

wrappers.hpp
Go to the documentation of this file.
1 
9 #ifndef EAGINE_VALUE_TREE_WRAPPERS_HPP
10 #define EAGINE_VALUE_TREE_WRAPPERS_HPP
11 
12 #include "../assert.hpp"
13 #include "../callable_ref.hpp"
14 #include "../memory/span_algo.hpp"
15 #include "../reflect/enumerators.hpp"
16 #include "../type_identity.hpp"
17 #include "../valid_if/decl.hpp"
18 #include "interface.hpp"
19 #include <utility>
20 
21 namespace eagine::valtree {
22 //------------------------------------------------------------------------------
23 class compound;
24 
35 class attribute {
36 public:
38  attribute() noexcept = default;
39 
41  attribute(attribute&& temp) noexcept
42  : _owner{std::move(temp._owner)}
43  , _pimpl{temp._pimpl} {
44  temp._pimpl = nullptr;
45  }
46 
48  attribute(const attribute& that)
49  : _owner{that._owner}
50  , _pimpl{that._pimpl} {
51  if(_owner && _pimpl) {
52  _owner->add_ref(*_pimpl);
53  }
54  }
55 
57  auto operator=(attribute&& temp) noexcept -> attribute& {
58  if(this != std::addressof(temp)) {
59  using std::swap;
60  swap(_owner, temp._owner);
61  swap(_pimpl, temp._pimpl);
62  }
63  return *this;
64  }
65 
67  auto operator=(const attribute& that) -> attribute& {
68  if(this != std::addressof(that)) {
69  using std::swap;
70  attribute temp{std::move(*this)};
71  _owner = that._owner;
72  _pimpl = that._pimpl;
73  if(_owner && _pimpl) {
74  _owner->add_ref(*_pimpl);
75  }
76  }
77  return *this;
78  }
79 
81  ~attribute() noexcept {
82  if(_pimpl) {
83  EAGINE_ASSERT(_owner);
84  _owner->release(*_pimpl);
85  }
86  }
87 
89  explicit operator bool() const {
90  return _owner && _pimpl;
91  }
92 
94  auto type_id() const noexcept -> identifier_t {
95  if(_pimpl) {
96  return _pimpl->type_id();
97  }
98  return 0;
99  }
100 
102  auto name() const -> string_view {
103  if(_owner && _pimpl) {
104  return _owner->attribute_name(*_pimpl);
105  }
106  return {};
107  }
108 
109 private:
110  friend class compound;
111 
112  attribute(
113  std::shared_ptr<compound_interface> owner,
114  attribute_interface* pimpl) noexcept
115  : _owner{std::move(owner)}
116  , _pimpl{pimpl} {}
117 
118  std::shared_ptr<compound_interface> _owner{};
119  attribute_interface* _pimpl{nullptr};
120 };
121 //------------------------------------------------------------------------------
122 class compound_attribute;
123 //------------------------------------------------------------------------------
124 template <typename T>
125 struct not_converted_value {
126  constexpr not_converted_value(T& dest) noexcept
127  : _dest{dest} {}
128 
129  constexpr auto dest() noexcept -> auto& {
130  return _dest;
131  }
132 
133  template <identifier_t V>
134  constexpr auto apply(selector<V>) const noexcept {
135  return true;
136  }
137 
138 private:
139  T& _dest;
140 };
141 //------------------------------------------------------------------------------
142 template <typename T>
143 struct converted_enum_value {
144  static_assert(has_enumerator_mapping_v<T>);
145 
146 public:
147  constexpr converted_enum_value(T& dest) noexcept
148  : _dest{dest} {}
149 
150  constexpr auto dest() noexcept -> auto& {
151  return _temp;
152  }
153 
154  template <identifier_t V>
155  auto apply(selector<V> sel) const {
156  if(auto converted{from_string(_temp, type_identity<T>(), sel)}) {
157  _dest = extract(converted);
158  return true;
159  }
160  return false;
161  }
162 
163 private:
164  std::string _temp;
165  T& _dest;
166 };
167 //------------------------------------------------------------------------------
168 template <typename T>
169 struct converted_value
170  : std::conditional_t<
171  has_enumerator_mapping_v<T>,
172  converted_enum_value<T>,
173  not_converted_value<T>> {
174 
175  using base = std::conditional_t<
176  has_enumerator_mapping_v<T>,
177  converted_enum_value<T>,
178  not_converted_value<T>>;
179 
180  using base::base;
181 };
182 //------------------------------------------------------------------------------
183 template <>
184 struct converted_value<std::chrono::duration<float>>
185  : not_converted_value<std::chrono::duration<float>> {
186  using base = not_converted_value<std::chrono::duration<float>>;
187  using base::base;
188 };
189 //------------------------------------------------------------------------------
190 template <typename R, typename P>
191 class converted_value<std::chrono::duration<R, P>> {
192  using T = std::chrono::duration<R, P>;
193 
194 public:
195  constexpr converted_value(T& dest) noexcept
196  : _dest{dest} {}
197 
198  constexpr auto dest() noexcept -> auto& {
199  return _temp;
200  }
201 
202  template <identifier_t V>
203  auto apply(selector<V>) const {
204  _dest = std::chrono::duration_cast<T>(_temp);
205  return true;
206  }
207 
208 private:
209  std::chrono::duration<float> _temp{};
210  T& _dest;
211 };
212 //------------------------------------------------------------------------------
223 class compound {
224 public:
226  compound() noexcept = default;
227 
231  template <typename Compound, typename... Args>
232  static auto make(Args&&... args) -> std::
233  enable_if_t<std::is_base_of_v<compound_interface, Compound>, compound> {
234  return {Compound::make_shared(std::forward<Args>(args)...)};
235  }
236 
238  explicit operator bool() const noexcept {
239  return bool(_pimpl);
240  }
241 
243  auto type_id() const noexcept -> identifier_t {
244  if(_pimpl) {
245  return _pimpl->type_id();
246  }
247  return 0;
248  }
249 
255  auto structure() const -> attribute {
256  if(_pimpl) {
257  return {_pimpl, _pimpl->structure()};
258  }
259  return {};
260  }
261 
264  auto root() const -> compound_attribute;
265 
268  auto attribute_name(const attribute& attrib) const -> string_view {
269  if(_pimpl && attrib._pimpl) {
270  return _pimpl->attribute_name(*attrib._pimpl);
271  }
272  return {};
273  }
274 
281  auto canonical_type(const attribute& attrib) const -> value_type {
282  if(_pimpl && attrib._pimpl) {
283  return _pimpl->canonical_type(*attrib._pimpl);
284  }
285  return value_type::unknown;
286  }
287 
290  auto is_link(const attribute& attrib) const -> bool {
291  if(_pimpl && attrib._pimpl) {
292  return _pimpl->is_link(*attrib._pimpl);
293  }
294  return false;
295  }
296 
302  auto nested_count(const attribute& attrib) const -> span_size_t {
303  if(_pimpl && attrib._pimpl) {
304  return _pimpl->nested_count(*attrib._pimpl);
305  }
306  return 0;
307  }
308 
311  auto has_nested(const attribute& attrib) const -> bool {
312  return nested_count(attrib) != 0;
313  }
314 
319  auto nested(const attribute& attrib, span_size_t index) const -> attribute {
320  if(_pimpl && attrib._pimpl) {
321  return {_pimpl, _pimpl->nested(*attrib._pimpl, index)};
322  }
323  return {};
324  }
325 
330  auto nested(const attribute& attrib, string_view name) const -> attribute {
331  if(_pimpl && attrib._pimpl) {
332  return {_pimpl, _pimpl->nested(*attrib._pimpl, name)};
333  }
334  return {};
335  }
336 
340  auto nested(string_view name) const -> attribute {
341  return nested(structure(), name);
342  }
343 
348  auto find(const attribute& attrib, const basic_string_path& path) const
349  -> attribute {
350  if(_pimpl && attrib._pimpl) {
351  return {_pimpl, _pimpl->find(*attrib._pimpl, path)};
352  }
353  return {};
354  }
355 
360  auto find(
361  const attribute& attrib,
362  const basic_string_path& path,
363  span<const string_view> tags) const -> attribute {
364  if(_pimpl && attrib._pimpl) {
365  return {_pimpl, _pimpl->find(*attrib._pimpl, path, tags)};
366  }
367  return {};
368  }
369 
373  auto find(const basic_string_path& path) const -> attribute {
374  return find(structure(), path);
375  }
376 
380  auto find(const basic_string_path& path, span<const string_view> tags) const
381  -> attribute {
382  return find(structure(), path, tags);
383  }
384 
386  auto value_count(const attribute& attrib) const -> span_size_t {
387  if(_pimpl && attrib._pimpl) {
388  return _pimpl->value_count(*attrib._pimpl);
389  }
390  return 0;
391  }
392 
394  auto value_count(const basic_string_path& path) const -> span_size_t {
395  return value_count(find(path));
396  }
397 
400  return value_count(nested(name));
401  }
402 
404  template <typename T>
405  auto fetch_values(const attribute& attrib, span_size_t offset, span<T> dest)
406  const -> span<T> {
407  if(_pimpl && attrib._pimpl) {
408  return head(
409  dest, _pimpl->fetch_values(*attrib._pimpl, offset, dest));
410  }
411  return {};
412  }
413 
415  template <typename T>
417  const basic_string_path& path,
418  span_size_t offset,
419  span<T> dest) const -> span<T> {
420  return fetch_values(find(path), offset, dest);
421  }
422 
424  template <typename T>
425  auto fetch_values(string_view name, span_size_t offset, span<T> dest) const
426  -> span<T> {
427  return fetch_values(nested(name), offset, dest);
428  }
429 
431  template <typename T>
432  auto fetch_values(const attribute& attrib, span<T> dest) const -> span<T> {
433  return fetch_values(attrib, 0, dest);
434  }
435 
437  template <typename T>
438  auto fetch_values(const basic_string_path& path, span<T> dest) const
439  -> span<T> {
440  return fetch_values(path, 0, dest);
441  }
442 
444  template <typename T>
445  auto fetch_values(string_view name, span<T> dest) const -> span<T> {
446  return fetch_values(name, 0, dest);
447  }
448 
450  auto fetch_blob(const attribute& attrib, memory::block dest) const
451  -> memory::block {
452  return fetch_values(attrib, dest);
453  }
454 
456  auto fetch_blob(const basic_string_path& path, memory::block dest) const
457  -> memory::block {
458  return fetch_values(path, dest);
459  }
460 
462  auto fetch_blob(string_view name, memory::block dest) const
463  -> memory::block {
464  return fetch_values(name, dest);
465  }
466 
468  template <typename T, identifier_t V>
470  const attribute& attrib,
471  span_size_t offset,
472  T& dest,
473  selector<V> sel) const -> bool {
474  converted_value<T> conv{dest};
475  if(!fetch_values(attrib, offset, cover_one(conv.dest())).empty()) {
476  return conv.apply(sel);
477  }
478  return false;
479  }
480 
482  template <typename T>
483  auto fetch_value(const attribute& attrib, span_size_t offset, T& dest) const
484  -> bool {
485  return select_value(attrib, offset, dest, default_selector);
486  }
487 
489  template <typename T, identifier_t V>
491  const attribute& attrib,
492  span_size_t offset,
493  span<T> dest,
494  selector<V> sel) const -> span<T> {
495  span_size_t index = 0;
496  for(T& elem : dest) {
497  if(!select_value(attrib, offset + index, elem, sel)) {
498  return {};
499  }
500  ++index;
501  }
502  return head(dest, index);
503  }
504 
506  template <typename T, identifier_t V>
507  auto
508  select_value(string_view name, span_size_t offset, T& dest, selector<V> sel)
509  const -> bool {
510  return select_value(nested(name), offset, dest, sel);
511  }
512 
514  template <typename T>
515  auto fetch_value(string_view name, span_size_t offset, T& dest) const
516  -> bool {
517  return select_value(name, offset, dest, default_selector);
518  }
519 
521  template <typename T, identifier_t V>
523  const basic_string_path& path,
524  span_size_t offset,
525  T& dest,
526  selector<V> sel) const -> bool {
527  return select_value(find(path), offset, dest, sel);
528  }
529 
531  template <typename T>
532  auto fetch_value(const basic_string_path& path, span_size_t offset, T& dest)
533  const -> bool {
534  return select_value(path, offset, dest, default_selector);
535  }
536 
538  template <typename T, identifier_t V>
539  auto select_value(string_view name, T& dest, selector<V> sel) const
540  -> bool {
541  return select_value(name, 0, dest, sel);
542  }
543 
545  template <typename T>
546  auto fetch_value(string_view name, T& dest) const -> bool {
547  return select_value(name, 0, dest, default_selector);
548  }
549 
551  template <typename T, identifier_t V>
552  auto select_value(const attribute& attrib, T& dest, selector<V> sel) const
553  -> bool {
554  return select_value(attrib, 0, dest, sel);
555  }
556 
558  template <typename T, identifier_t V>
559  auto
560  select_values(const attribute& attrib, span<T> dest, selector<V> sel) const
561  -> span<T> {
562  return select_values(attrib, 0, dest, sel);
563  }
564 
566  template <typename T>
567  auto fetch_value(const attribute& attrib, T& dest) const -> bool {
568  return select_value(attrib, 0, dest, default_selector);
569  }
570 
572  template <typename T, identifier_t V>
573  auto
574  select_value(const basic_string_path& path, T& dest, selector<V> sel) const
575  -> bool {
576  return select_value(path, 0, dest, sel);
577  }
578 
580  template <typename T>
581  auto fetch_value(const basic_string_path& path, T& dest) const -> bool {
582  return selector_value(path, 0, dest, default_selector);
583  }
584 
586  template <std::size_t L>
587  auto has_value(const attribute& attrib, const char (&what)[L]) const
588  -> bool {
589  char temp[L]{};
590  if(fetch_values(attrib, 0, cover(temp))) {
591  return starts_with(string_view(temp), string_view(what));
592  }
593  return false;
594  }
595 
597  template <typename T, identifier_t V>
598  auto get(
599  const attribute& attrib,
600  span_size_t offset,
602  selector<V> sel) const -> optionally_valid<T> {
603  T temp{};
604  if(select_value(attrib, offset, temp, sel)) {
605  return {std::move(temp), true};
606  }
607  return {};
608  }
609 
611  template <typename T>
612  auto get(
613  const attribute& attrib,
614  span_size_t offset,
615  type_identity<T> tid = {}) const -> optionally_valid<T> {
616  return get<T>(attrib, offset, tid, default_selector);
617  }
618 
620  template <typename T, identifier_t V>
621  auto get(
622  const basic_string_path& path,
623  span_size_t offset,
625  selector<V> sel) const -> optionally_valid<T> {
626  T temp{};
627  if(select_value(path, offset, temp, sel)) {
628  return {std::move(temp), true};
629  }
630  return {};
631  }
632 
634  template <typename T>
635  auto get(
636  const basic_string_path& path,
637  span_size_t offset,
638  type_identity<T> tid = {}) const -> optionally_valid<T> {
639  return get<T>(path, offset, tid, default_selector);
640  }
641 
643  template <typename T, identifier_t V>
644  auto
646  const -> optionally_valid<T> {
647  T temp{};
648  if(select_value(name, offset, temp, sel)) {
649  return {std::move(temp), true};
650  }
651  return {};
652  }
653 
655  template <typename T>
656  auto
657  get(string_view name, span_size_t offset, type_identity<T> tid = {}) const
659  return get<T>(name, offset, tid, default_selector);
660  }
661 
663  template <typename T, identifier_t V>
664  auto
665  get(const attribute& attrib, type_identity<T> tid, selector<V> sel) const
667  return get<T>(attrib, 0, tid, sel);
668  }
669 
671  template <typename T>
672  auto get(const attribute& attrib, type_identity<T> tid = {}) const
674  return get<T>(attrib, tid, default_selector);
675  }
676 
678  template <typename T, identifier_t V>
679  auto get(
680  const basic_string_path& path,
681  type_identity<T> tid,
682  selector<V> sel) const -> optionally_valid<T> {
683  return get<T>(path, 0, tid, sel);
684  }
685 
687  template <typename T>
688  auto get(const basic_string_path& path, type_identity<T> tid = {}) const
690  return get<T>(path, tid, default_selector);
691  }
692 
694  template <typename T, identifier_t V>
695  auto get(string_view name, type_identity<T> tid, selector<V> sel) const
697  return get<T>(name, 0, tid, sel);
698  }
699 
701  template <typename T>
702  auto get(string_view name, type_identity<T> tid = {}) const
704  return get<T>(name, tid, default_selector);
705  }
706 
708  using visit_handler =
710 
712  void traverse(visit_handler visitor);
713 
715  using stack_visit_handler = callable_ref<bool(
716  compound&,
717  const attribute&,
718  const basic_string_path&,
719  span<const attribute>)>;
720 
722  void traverse(stack_visit_handler visitor);
723 
724 private:
725  compound(std::shared_ptr<compound_interface> pimpl) noexcept
726  : _pimpl{std::move(pimpl)} {}
727 
728  std::shared_ptr<compound_interface> _pimpl{};
729 };
730 //------------------------------------------------------------------------------
737 public:
739  compound_attribute() noexcept = default;
740 
744  : _c{std::move(c)}
745  , _a{std::move(a)} {
746  EAGINE_ASSERT(_c.type_id() == _a.type_id());
747  }
748 
750  explicit operator bool() const noexcept {
751  return _c && _a;
752  }
753 
755  auto type_id() const noexcept {
756  return _c.type_id();
757  }
758 
760  auto name() const noexcept -> string_view {
761  return _c.attribute_name(_a);
762  }
763 
765  auto is_link() const noexcept -> bool {
766  return _c.is_link(_a);
767  }
768 
770  auto canonical_type() const -> value_type {
771  return _c.canonical_type(_a);
772  }
773 
778  auto nested_count() const -> span_size_t {
779  return _c.nested_count(_a);
780  }
781 
783  auto has_nested() const -> span_size_t {
784  return _c.has_nested(_a);
785  }
786 
790  auto nested(span_size_t index) const -> compound_attribute {
791  return {_c, _c.nested(_a, index)};
792  }
793 
798  return {_c, _c.nested(_a, name)};
799  }
800 
804  auto find(const basic_string_path& path) const -> compound_attribute {
805  return {_c, _c.find(_a, path)};
806  }
807 
809  auto value_count() const -> span_size_t {
810  return _c.value_count(_a);
811  }
812 
814  template <typename T>
815  auto fetch_values(span_size_t offset, span<T> dest) const {
816  return _c.fetch_values(_a, offset, dest);
817  }
818 
820  template <typename T>
821  auto fetch_values(span<T> dest) const {
822  return _c.fetch_values(_a, dest);
823  }
824 
826  auto fetch_blob(memory::block dest) const {
827  return _c.fetch_blob(_a, dest);
828  }
829 
831  template <typename T, identifier_t V>
833  span_size_t offset,
834  T& dest,
835  selector<V> sel = default_selector) const -> bool {
836  return _c.select_value(_a, offset, dest, sel);
837  }
838 
840  template <typename T, identifier_t V>
841  auto select_value(T& dest, selector<V> sel) const -> bool {
842  return _c.select_value(_a, dest, sel);
843  }
844 
846  template <typename T, identifier_t V>
847  auto select_values(span<T> dest, selector<V> sel) const -> span<T> {
848  return _c.select_values(_a, dest, sel);
849  }
850 
852  template <typename T>
853  auto fetch_value(T& dest) const -> bool {
854  return _c.select_value(_a, dest, default_selector);
855  }
856 
858  template <typename T>
859  auto get(span_size_t offset, type_identity<T> tid = {}) const {
860  return _c.get(_a, offset, tid);
861  }
862 
864  template <typename T>
865  auto get(type_identity<T> tid = {}) const {
866  return _c.get(_a, tid);
867  }
868 
869 private:
870  compound _c;
871  attribute _a;
872 };
873 //------------------------------------------------------------------------------
874 inline auto compound::root() const -> compound_attribute {
875  return {*this, structure()};
876 }
877 //------------------------------------------------------------------------------
880 static inline auto operator/(compound c, attribute a) noexcept
881  -> compound_attribute {
882  return {std::move(c), std::move(a)};
883 }
884 //------------------------------------------------------------------------------
885 } // namespace eagine::valtree
886 
887 #if !EAGINE_LINK_LIBRARY || defined(EAGINE_IMPLEMENTING_LIBRARY)
888 #include <eagine/value_tree/wrappers.inl>
889 #endif
890 
891 #endif // EAGINE_VALUE_TREE_WRAPPERS_HPP
auto fetch_value(const basic_string_path &path, span_size_t offset, T &dest) const -> bool
Fetches values through the specified path, into dest.
Definition: wrappers.hpp:532
auto value_count() const -> span_size_t
Returns the number of value elements accessible through an attribute.
Definition: wrappers.hpp:809
auto nested(span_size_t index) const -> compound_attribute
Returns nested attribute of an attribute at the specified index.
Definition: wrappers.hpp:790
auto get(const attribute &attrib, span_size_t offset, type_identity< T > tid={}) const -> optionally_valid< T >
Returns the value of type T at an attribute, at the given offset.
Definition: wrappers.hpp:612
auto is_link() const noexcept -> bool
Indicates if the specified attribute is a reference or link in the tree.
Definition: wrappers.hpp:765
value_type
Value tree value element data type enumeration.
Definition: interface.hpp:27
auto canonical_type() const -> value_type
Returns the canonical value type of this attribute.
Definition: wrappers.hpp:770
std::ptrdiff_t span_size_t
Signed span size type used by eagine.
Definition: types.hpp:36
auto canonical_type(const attribute &attrib) const -> value_type
Returns the caninical value type of an attribute.
Definition: wrappers.hpp:281
Declaration of class template storing a reference to a callable object.
Definition: callable_ref.hpp:24
basic_string_span< const char > string_view
Alias for const string views.
Definition: string_span.hpp:116
auto from_string(string_view src) noexcept
Converts the string representation in src to a value of type T.
Definition: from_string.hpp:360
static auto make(Args &&... args) -> std::enable_if_t< std::is_base_of_v< compound_interface, Compound >, compound >
Instantiates a particular implementation.
Definition: wrappers.hpp:232
auto select_value(T &dest, selector< V > sel) const -> bool
Fetches a value from this attribute, with selector.
Definition: wrappers.hpp:841
compound_attribute(compound c, attribute a) noexcept
Construction from a compound and attribute pair.
Definition: wrappers.hpp:743
auto select_value(const basic_string_path &path, span_size_t offset, T &dest, selector< V > sel) const -> bool
Fetches values through the specified path, with a selector, into dest.
Definition: wrappers.hpp:522
auto select_value(const attribute &attrib, T &dest, selector< V > sel) const -> bool
Fetches a value at the specified attribute, with a selector, into dest.
Definition: wrappers.hpp:552
auto nested_count(const attribute &attrib) const -> span_size_t
Returns the count of nested attributes of an attribute.
Definition: wrappers.hpp:302
auto fetch_values(span_size_t offset, span< T > dest) const
Fetches values from this attribute, starting at offset, into dest.
Definition: wrappers.hpp:815
auto fetch_value(const attribute &attrib, span_size_t offset, T &dest) const -> bool
Fetches a single value at the specified attribute, at offset into dest.
Definition: wrappers.hpp:483
auto root() const -> compound_attribute
Returns the structure root as an compound_attribute.
Definition: wrappers.hpp:874
auto fetch_values(span< T > dest) const
Fetches values from this attribute, into dest.
Definition: wrappers.hpp:821
auto structure() const -> attribute
Returns the root of attribute hierarchy describing the tree structure.
Definition: wrappers.hpp:255
attribute(attribute &&temp) noexcept
Move constructor.
Definition: wrappers.hpp:41
auto fetch_blob(const basic_string_path &path, memory::block dest) const -> memory::block
Fetches a BLOB at the attribute with the specified path, into dest.
Definition: wrappers.hpp:456
static constexpr auto cover(T *addr, S size) noexcept -> span_if_mutable< T >
Creates a span starting at the specified pointer and specified length.
Definition: span.hpp:465
static constexpr auto extract(api_result_value< Result, api_result_validity::never > &) noexcept -> Result &
Overload of extract for api_result_value.
Definition: c_api_wrap.hpp:270
Primary template for conditionally valid values.
Definition: decl.hpp:49
Handle class for value tree compounds.
Definition: wrappers.hpp:223
auto find(const basic_string_path &path) const -> compound_attribute
Returns nested attribute of an attribute at the specified path.
Definition: wrappers.hpp:804
auto get(const attribute &attrib, span_size_t offset, type_identity< T >, selector< V > sel) const -> optionally_valid< T >
Returns the value of type T at an attribute, at offset, with selector.
Definition: wrappers.hpp:598
auto operator=(const attribute &that) -> attribute &
Copy assignment operator. Handles attribute reference counting.
Definition: wrappers.hpp:67
attribute() noexcept=default
Default constructor. Constructs empty attribute refering to nothing.
@ unknown
Unknown value type.
static constexpr auto head(basic_span< T, P, S > s, L l) noexcept -> basic_span< T, P, S >
Returns the first l elements from the front of a span.
Definition: span_algo.hpp:99
auto get(string_view name, type_identity< T > tid={}) const -> optionally_valid< T >
Returns the value of type T at name.
Definition: wrappers.hpp:702
auto select_value(string_view name, T &dest, selector< V > sel) const -> bool
Fetches values through the specified name, with a selector, into dest.
Definition: wrappers.hpp:539
Template used to construct tag-types used mostly in tag-dispatching.
Definition: selector.hpp:21
auto operator=(attribute &&temp) noexcept -> attribute &
Move assignment operator.
Definition: wrappers.hpp:57
Basic class storing paths made of string elements.
Definition: string_path.hpp:27
auto fetch_values(string_view name, span< T > dest) const -> span< T >
Fetches values at the attribute with the specified name, into dest.
Definition: wrappers.hpp:445
auto nested(string_view name) const -> compound_attribute
Returns nested attribute of an attribute with the specified name.
Definition: wrappers.hpp:797
void traverse(visit_handler visitor)
Traverses the tree, calls the visitor function on each node.
auto fetch_value(T &dest) const -> bool
Fetches a value from this attribute, into dest.
Definition: wrappers.hpp:853
auto select_values(const attribute &attrib, span< T > dest, selector< V > sel) const -> span< T >
Fetches values at the specified attribute, with a selector, into dest.
Definition: wrappers.hpp:560
auto value_count(const attribute &attrib) const -> span_size_t
Returns the number of value elements accessible through an attribute.
Definition: wrappers.hpp:386
auto nested_count() const -> span_size_t
Returns the count of nested attributes of an attribute.
Definition: wrappers.hpp:778
compound() noexcept=default
Default constructor. Constructs an empty compound.
auto find(const attribute &attrib, const basic_string_path &path, span< const string_view > tags) const -> attribute
Returns nested attribute of an attribute at path with tags.
Definition: wrappers.hpp:360
auto fetch_blob(string_view name, memory::block dest) const -> memory::block
Fetches a BLOB at the attribute with the specified name, into dest.
Definition: wrappers.hpp:462
virtual auto type_id() const noexcept -> identifier_t=0
Returns the implementation type identifier of this attribute.
auto select_value(const basic_string_path &path, T &dest, selector< V > sel) const -> bool
Fetches a value through the specified path, with selector, into dest.
Definition: wrappers.hpp:574
auto get(const basic_string_path &path, type_identity< T > tid={}) const -> optionally_valid< T >
Returns the value of type T at path.
Definition: wrappers.hpp:688
auto fetch_value(const attribute &attrib, T &dest) const -> bool
Fetches a single value at the specified attribute, into dest.
Definition: wrappers.hpp:567
auto is_link(const attribute &attrib) const -> bool
Indicates if the specified attribute is a reference or link in the tree.
Definition: wrappers.hpp:290
auto value_count(string_view name) -> span_size_t
Returns the number of value elements at attribute with the given name.
Definition: wrappers.hpp:399
auto fetch_values(const basic_string_path &path, span_size_t offset, span< T > dest) const -> span< T >
Fetches values at the given path, starting at offset into dest.
Definition: wrappers.hpp:416
Non-owning view of a contiguous range of memory with ValueType elements.
Definition: flatten_fwd.hpp:16
auto get(const basic_string_path &path, span_size_t offset, type_identity< T >, selector< V > sel) const -> optionally_valid< T >
Returns the value of type T at path, at given offset, with selector.
Definition: wrappers.hpp:621
auto get(type_identity< T > tid={}) const
Returns a value of type T, from this attribute.
Definition: wrappers.hpp:865
auto fetch_blob(memory::block dest) const
Fetches a BLOB from this attribute, into dest.
Definition: wrappers.hpp:826
auto select_values(const attribute &attrib, span_size_t offset, span< T > dest, selector< V > sel) const -> span< T >
Fetches values at the specified attribute, with a selector, into dest.
Definition: wrappers.hpp:490
auto has_nested() const -> span_size_t
Indicates if an attribute has nested attribute accessible by index.
Definition: wrappers.hpp:783
Interface for value tree attribute implementations.
Definition: interface.hpp:72
~attribute() noexcept
Destructor. Handles attribute reference counting.
Definition: wrappers.hpp:81
auto fetch_values(const basic_string_path &path, span< T > dest) const -> span< T >
Fetches values at the attribute with the specified path, into dest.
Definition: wrappers.hpp:438
auto get(string_view name, span_size_t offset, type_identity< T >, selector< V > sel) const -> optionally_valid< T >
Returns the value of type T at name, at given offset, with selector.
Definition: wrappers.hpp:645
auto fetch_value(string_view name, T &dest) const -> bool
Fetches values through the specified name, into dest.
Definition: wrappers.hpp:546
auto attribute_name(const attribute &attrib) const -> string_view
Returns the name of an attribute.
Definition: wrappers.hpp:268
Handle class for value tree attributes.
Definition: wrappers.hpp:35
compound_attribute() noexcept=default
Default constructor. Constructs empty attribute refering to nothing.
auto get(string_view name, span_size_t offset, type_identity< T > tid={}) const -> optionally_valid< T >
Returns the value of type T at name, at given offset.
Definition: wrappers.hpp:657
auto find(const basic_string_path &path, span< const string_view > tags) const -> attribute
Returns nested attribute of root attribute at path with tags.
Definition: wrappers.hpp:380
auto find(const basic_string_path &path) const -> attribute
Returns nested attribute of root attribute at the specified path.
Definition: wrappers.hpp:373
auto get(const basic_string_path &path, type_identity< T > tid, selector< V > sel) const -> optionally_valid< T >
Returns the value of type T at path, with selector.
Definition: wrappers.hpp:679
auto select_value(const attribute &attrib, span_size_t offset, T &dest, selector< V > sel) const -> bool
Fetches a single value at the specified attribute, with a selector.
Definition: wrappers.hpp:469
auto select_values(span< T > dest, selector< V > sel) const -> span< T >
Fetches a value from this attribute, with selector, into dest.
Definition: wrappers.hpp:847
auto select_value(string_view name, span_size_t offset, T &dest, selector< V > sel) const -> bool
Fetches values through the specified name, with a selector, into dest.
Definition: wrappers.hpp:508
auto get(const attribute &attrib, type_identity< T > tid, selector< V > sel) const -> optionally_valid< T >
Returns the value of type T at an attribute, with selector.
Definition: wrappers.hpp:665
Combination of a reference to a tree compound and a single attribute.
Definition: wrappers.hpp:736
auto fetch_values(string_view name, span_size_t offset, span< T > dest) const -> span< T >
Fetches values at the given name, starting at offset into dest.
Definition: wrappers.hpp:425
auto type_id() const noexcept
Returns the shared implementation type id of the attribute and compound.
Definition: wrappers.hpp:755
auto get(string_view name, type_identity< T > tid, selector< V > sel) const -> optionally_valid< T >
Returns the value of type T at name, with selector.
Definition: wrappers.hpp:695
auto type_id() const noexcept -> identifier_t
Returns the implementation type id of this attribute.
Definition: wrappers.hpp:94
auto get(const attribute &attrib, type_identity< T > tid={}) const -> optionally_valid< T >
Returns the value of type T at an attribute.
Definition: wrappers.hpp:672
auto name() const -> string_view
Returns the implementation type id of this attribute.
Definition: wrappers.hpp:102
std::uint64_t identifier_t
The underlying integer type for eagine::identifier.
Definition: identifier_t.hpp:19
Template type used mostly for function type-tag dispatching.
Definition: type_identity.hpp:19
auto nested(const attribute &attrib, span_size_t index) const -> attribute
Returns nested attribute of an attribute at the specified index.
Definition: wrappers.hpp:319
auto get(const basic_string_path &path, span_size_t offset, type_identity< T > tid={}) const -> optionally_valid< T >
Returns the value of type T at path, at given offset.
Definition: wrappers.hpp:635
auto has_nested(const attribute &attrib) const -> bool
Indicates if an attribute has nested attribute accessible by index.
Definition: wrappers.hpp:311
auto fetch_value(const basic_string_path &path, T &dest) const -> bool
Fetches a value through the specified path, into dest.
Definition: wrappers.hpp:581
auto value_count(const basic_string_path &path) const -> span_size_t
Returns the number of value elements at the specified path.
Definition: wrappers.hpp:394
auto nested(const attribute &attrib, string_view name) const -> attribute
Returns nested attribute of an attribute with the specified name.
Definition: wrappers.hpp:330
auto fetch_blob(const attribute &attrib, memory::block dest) const -> memory::block
Fetches a BLOB at the given attribute, into dest.
Definition: wrappers.hpp:450
auto fetch_values(const attribute &attrib, span_size_t offset, span< T > dest) const -> span< T >
Fetches values at the given attribute, starting at offset into dest.
Definition: wrappers.hpp:405
attribute(const attribute &that)
Copy constructor. Handles attribute reference counting.
Definition: wrappers.hpp:48
auto fetch_value(string_view name, span_size_t offset, T &dest) const -> bool
Fetches values through the specified name, into dest.
Definition: wrappers.hpp:515
static auto operator/(compound c, attribute a) noexcept -> compound_attribute
Operator for creating a compound_attribute from compound and attribute.
Definition: wrappers.hpp:880
static constexpr auto starts_with(basic_span< T1, P1, S1 > spn, basic_span< T2, P2, S2 > with) -> bool
Indicates if span spn starts with the content of with.
Definition: span_algo.hpp:170
auto nested(string_view name) const -> attribute
Returns nested attribute of the root attribute with the specified name.
Definition: wrappers.hpp:340
auto find(const attribute &attrib, const basic_string_path &path) const -> attribute
Returns nested attribute of an attribute at the specified path.
Definition: wrappers.hpp:348
auto has_value(const attribute &attrib, const char(&what)[L]) const -> bool
Tests if there is an value at an attribute, that starts with what.
Definition: wrappers.hpp:587
Value-tree code is placed in this namespace.
Definition: eagine.hpp:53
auto name() const noexcept -> string_view
Returns the name of this attribute.
Definition: wrappers.hpp:760
auto fetch_values(const attribute &attrib, span< T > dest) const -> span< T >
Fetches values at the given attribute, into dest.
Definition: wrappers.hpp:432
auto get(span_size_t offset, type_identity< T > tid={}) const
Returns a value of type T, from this attribute, at offset.
Definition: wrappers.hpp:859
callable_ref< bool(compound &, const attribute &, const basic_string_path &)> visit_handler
Type of traverse/visit handler.
Definition: wrappers.hpp:709
auto fetch_value(span_size_t offset, T &dest, selector< V > sel=default_selector) const -> bool
Fetches a value from this attribute, starting at offset, with selector.
Definition: wrappers.hpp:832
auto type_id() const noexcept -> identifier_t
Returns the implementation type id of this attribute.
Definition: wrappers.hpp:243
constexpr const default_selector_t default_selector
The default overload selector constant.
Definition: selector.hpp:34

Copyright © 2015-2021 Matúš Chochlík.
<chochlik -at -gmail.com>
Documentation generated on Tue Apr 13 2021 by Doxygen (version 1.8.17).