YSTest: ValueNode.h 源文件

YSTest PreAlpha_b900_20201012 The YSLib Test Project

ValueNode.h
浏览该文件的文档.
1 /*
2 © 2012-2020 FrankHB.
3
4 This file is part of the YSLib project, and may only be used,
5 modified, and distributed under the terms of the YSLib project
6 license, LICENSE.TXT. By continuing to use, modify, or distribute
7 this file you indicate that you have read the license and
8 understand and accept it fully.
9 */
10
28 #ifndef YSL_INC_Core_ValueNode_h_
29 #define YSL_INC_Core_ValueNode_h_ 1
30
31 #include "YModules.h"
32 #include YFM_YSLib_Core_YObject // for pmr, ystdex::invoke,
33 // ystdex::is_interoperable, ystdex::enable_if_t, std::allocator_arg_t,
34 // std::allocator_arg, ystdex::and_, ystdex::remove_cvref_t, in_place_type,
35 // to_string, to_pmr_string;
36 #include <ystdex/operators.hpp> // for ystdex::totally_ordered;
37 #include <ystdex/set.hpp> // for ystdex::mapped_set;
38 #include <ystdex/variadic.hpp> // for ystdex::vseq;
39 #include <ystdex/tuple.hpp> // for ystdex::make_from_tuple;
40 #include <ystdex/swap.hpp> // for ystdex::copy_and_swap;
41 #include <ystdex/path.hpp> // for ystdex::path;
42 #include <ystdex/utility.hpp> // for ystdex::forward_like;
43 #include <ystdex/algorithm.hpp> // for std::for_each_if;
44 #include <numeric> // for std::accumulate;
45
46 namespace YSLib
47 {
48
50
51 yconstexpr const struct ListContainerTag{} ListContainer{};
53
55 yconstexpr const struct NoContainerTag{} NoContainer{};
57
58
71 class YF_API ValueNode : private ystdex::totally_ordered<ValueNode>,
72 private ystdex::totally_ordered<ValueNode, string>
73 {
74 public:
76
77
81 using allocator_type = pmr::polymorphic_allocator<ValueNode>;
82 template<typename _type>
83 using is_key_t = ystdex::is_interoperable<const _type&, const string&>;
84 template<typename _tKey>
85 using enable_if_key_t = ystdex::enable_if_t<is_key_t<_tKey>::value>;
86 template<typename _tOther>
87 using enable_not_key_t = ystdex::enable_if_t<!is_key_t<_tOther>::value>;
89
90 private:
92 template<typename... _tParams>
93 using enable_value_constructible_t = ystdex::enable_if_t<
94 std::is_constructible<ValueObject, _tParams...>::value>;
95
96 public:
101 struct YF_API MappedSetTraits
102 {
104
105 template<typename _tKey, class _tCon>
106 YB_ATTR_nodiscard YB_PURE static inline auto
107 extend_key(_tKey&& k, _tCon& con) ynothrow -> decltype(
108 ValueNode(std::allocator_arg, con.get_allocator(), NoContainer,
109 yforward(k)))
110 {
111 return {std::allocator_arg, con.get_allocator(), NoContainer,
112 yforward(k)};
113 }
114
116
117 YB_ATTR_nodiscard YB_PURE static inline
118 PDefH(string, get_value_key, allocator_type = {}) ynothrow
119 ImplRet({})
120 YB_ATTR_nodiscard YB_PURE static PDefH(const string&, get_value_key,
121 const ValueNode& nd, allocator_type = {}) ynothrow
122 ImplRet(nd.name)
123 YB_ATTR_nodiscard YB_PURE static PDefH(string&&, get_value_key,
124 ValueNode&& nd, allocator_type = {}) ynothrow
125 ImplRet(std::move(nd.name))
127
128 template<typename _tParam, typename _tOther, typename... _tParams,
129 yimpl(typename = enable_not_key_t<_tOther>)>
130 static PDefH(string, get_value_key, _tOther&&, allocator_type = {})
131 ynothrow
132 ImplRet({})
133 template<typename _tString, typename _tOther, typename... _tParams,
134 yimpl(typename = enable_value_constructible_t<_tParams...>),
135 yimpl(typename = enable_not_key_t<_tOther>)>
136 YB_ATTR_nodiscard YB_PURE static inline _tString&&
137 get_value_key(_tOther&&, _tString&& str, _tParams&&...)
138 {
139 return yforward(str);
140 }
141 template<typename _tString, typename _tOther, typename... _tParams,
142 yimpl(typename = enable_value_constructible_t<_tParams...>),
143 yimpl(typename = enable_not_key_t<_tOther>)>
144 YB_ATTR_nodiscard YB_PURE static inline _tString&&
145 get_value_key(std::allocator_arg_t, allocator_type, _tOther&&,
146 _tString&& str, _tParams&&...)
147 {
148 return yforward(str);
149 }
150 template<typename _tIn>
151 YB_ATTR_nodiscard YB_PURE static inline string
152 get_value_key(const pair<_tIn, _tIn>&, allocator_type = {})
153 {
154 return {};
155 }
156 template<typename _tIn, typename _tString>
157 YB_ATTR_nodiscard YB_PURE static inline _tString&&
158 get_value_key(const pair<_tIn, _tIn>&, _tString&& str,
159 allocator_type = {})
160 {
161 return yforward(str);
162 }
163 template<typename... _tParams1>
164 YB_ATTR_nodiscard YB_PURE static inline string
165 get_value_key(tuple<_tParams1...>, allocator_type = {})
166 {
167 return {};
168 }
169 template<typename... _tParams1, typename... _tParams2>
170 YB_ATTR_nodiscard YB_PURE static inline string
171 get_value_key(tuple<_tParams1...>, tuple<_tParams2...> args2,
172 allocator_type = {})
173 {
174 return ystdex::make_from_tuple<string>(args2);
175 }
176 template<typename... _tParams1, typename... _tParams2,
177 typename... _tParams3>
178 YB_ATTR_nodiscard YB_PURE static inline string
179 get_value_key(tuple<_tParams1...>, tuple<_tParams2...> args2,
180 tuple<_tParams3...>, allocator_type = {})
181 {
182 return ystdex::make_from_tuple<string>(args2);
183 }
185
186
191 static PDefH(void, restore_key, ValueNode& node, ValueNode&& ek)
192 ImplExpr(node.name = std::move(ek.name))
193
194
195 static PDefH(ValueNode, set_value_move, ValueNode& node)
196 ImplRet({std::move(node.GetContainerRef()),
197 node.GetName(), std::move(node.Value)})
199 };
200 using Container = ystdex::mapped_set<ValueNode, ystdex::less<>,
201 MappedSetTraits, allocator_type>;
203 using key_type = Container::key_type;
205 using iterator = Container::iterator;
207 using const_iterator = Container::const_iterator;
209 using reverse_iterator = Container::reverse_iterator;
211 using const_reverse_iterator = Container::const_reverse_iterator;
212
213 private:
214 string name{};
219 Container container{};
220
221 public:
223 ValueObject Value{};
224
226 DefDeCtor(ValueNode)
228
229 explicit
231 ValueNode(allocator_type a)
232 : container(a)
233 {}
242 ValueNode(const Container& con)
243 : container(con)
244 {}
245 ValueNode(const Container& con, allocator_type a)
246 : container(con, a)
247 {}
248 ValueNode(Container&& con)
249 : container(std::move(con))
250 {}
251 ValueNode(Container&& con, allocator_type a)
252 : container(std::move(con), a)
253 {}
255
259 template<typename _tString, typename... _tParams,
260 yimpl(typename = enable_value_constructible_t<_tParams...>)>
261 inline
262 ValueNode(NoContainerTag, _tString&& str, _tParams&&... args)
263 : name(yforward(str)), Value(yforward(args)...)
264 {}
269 template<typename _tString, typename... _tParams,
270 yimpl(typename = enable_value_constructible_t<_tParams...>)>
271 inline
272 ValueNode(std::allocator_arg_t, allocator_type a, NoContainerTag,
273 _tString&& str, _tParams&&... args)
274 : name(yforward(str)), container(a), Value(yforward(args)...)
275 {}
277
278 template<typename _tString, typename... _tParams,
279 yimpl(typename = enable_value_constructible_t<_tParams...>)>
280 ValueNode(const Container& con, _tString&& str, _tParams&&... args)
281 : name(yforward(str)), container(con), Value(yforward(args)...)
282 {}
283 template<typename _tString, typename... _tParams,
284 yimpl(typename = enable_value_constructible_t<_tParams...>)>
285 ValueNode(Container&& con, _tString&& str, _tParams&&... args)
286 : name(yforward(str)), container(std::move(con)),
287 Value(yforward(args)...)
288 {}
290
292 template<typename _tString, typename... _tParams,
293 yimpl(typename = enable_value_constructible_t<_tParams...>)>
294 inline
295 ValueNode(std::allocator_arg_t, allocator_type a, const Container& con,
296 _tString&& str, _tParams&&... args)
297 : name(yforward(str)), container(con, a),
298 Value(yforward(args)...)
299 {}
300 template<typename _tString, typename... _tParams,
301 yimpl(typename = enable_value_constructible_t<_tParams...>)>
302 inline
303 ValueNode(std::allocator_arg_t, allocator_type a, Container&& con,
304 _tString&& str, _tParams&&... args)
305 : name(yforward(str)), container(std::move(con), a),
306 Value(yforward(args)...)
307 {}
309 template<typename _tIn>
311 inline
312 ValueNode(const pair<_tIn, _tIn>& pr, allocator_type a = {})
313 : container(pr.first, pr.second, a)
314 {}
316 template<typename _tIn, typename _tString>
317 inline
318 ValueNode(const pair<_tIn, _tIn>& pr, _tString&& str,
319 allocator_type a = {})
320 : name(yforward(str)), container(pr.first, pr.second, a)
321 {}
323
324 template<typename... _tParams1>
325 inline
326 ValueNode(tuple<_tParams1...> args1, allocator_type a = {})
327 : container(ystdex::make_from_tuple<Container>(args1), a)
328 {}
329 template<typename... _tParams1, typename... _tParams2>
330 inline
331 ValueNode(tuple<_tParams1...> args1, tuple<_tParams2...> args2,
332 allocator_type a = {})
333 : name(ystdex::make_from_tuple<string>(args2)),
334 container(ystdex::make_from_tuple<Container>(args1), a)
335 {}
336 template<typename... _tParams1, typename... _tParams2,
337 typename... _tParams3>
338 inline
339 ValueNode(tuple<_tParams1...> args1, tuple<_tParams2...> args2,
340 tuple<_tParams3...> args3, allocator_type a = {})
341 : name(ystdex::make_from_tuple<string>(args2)),
342 container(ystdex::make_from_tuple<Container>(args1), a),
343 Value(ystdex::make_from_tuple<ValueObject>(args3))
344 {}
346
350 ValueNode(const ValueNode& nd)
351 : ValueNode(nd, nd.get_allocator())
352 {}
353 ValueNode(const ValueNode& nd, allocator_type a)
354 : name(nd.name), container(nd.container, a), Value(nd.Value)
355 {}
357 DefDeMoveCtor(ValueNode)
358 ValueNode(ValueNode&& nd, allocator_type a) ynothrowv
359 : name(std::move(nd.name)), container(std::move(nd.container), a),
360 Value(std::move(nd.Value))
361 {}
363
365
366 PDefHOp(ValueNode&, =, const ValueNode& node)
368 ImplRet(ystdex::copy_and_swap(*this, node))
373 DefDeMoveAssignment(ValueNode)
375
377
378 PDefHOp(const ValueNode&, +=, const ValueNode& node)
379 ImplRet(Add(node), *this)
380 PDefHOp(const ValueNode&, +=, ValueNode&& node)
381 ImplRet(Add(std::move(node)), *this)
382
383 PDefHOp(const ValueNode&, -=, const ValueNode& node)
384 ImplRet(Remove(node), *this)
385 PDefHOp(const ValueNode&, -=, const string& str)
386 ImplRet(Remove(str), *this)
392 PDefHOp(ValueNode&, /=, const ValueNode& node)
393 ImplRet(*this %= node, *this)
394 PDefHOp(ValueNode&, /=, ValueNode&& node)
395 ImplRet(*this %= std::move(node), *this)
397
403 ValueNode&
404 operator%=(const ValueNode&);
405 ValueNode&
406 operator%=(ValueNode&&);
408
409
411 DefBoolNeg(explicit, bool(Value) || !container.empty())
412
414 friend PDefHOp(bool, ==, const ValueNode& x, const ValueNode& y) ynothrow
415 ImplRet(x.name == y.name)
417 friend PDefHOp(bool, ==, const ValueNode& x, const string& str) ynothrow
418 ImplRet(x.name == str)
420 template<typename _tKey>
421 YB_ATTR_nodiscard YB_PURE friend bool
422 operator==(const ValueNode& x, const _tKey& k) ynothrow
423 {
424 return x.name == k;
425 }
426
428 YB_ATTR_nodiscard YB_PURE friend
429 PDefHOp(bool, <, const ValueNode& x, const ValueNode& y) ynothrow
430 ImplRet(x.name < y.name)
432 YB_ATTR_nodiscard YB_PURE friend
433 PDefHOp(bool, <, const ValueNode& x, const string& str) ynothrow
434 ImplRet(x.name < str)
436 template<typename _tKey>
437 YB_ATTR_nodiscard YB_PURE friend bool
438 operator<(const ValueNode& x, const _tKey& k) ynothrow
439 {
440 return x.name < k;
441 }
443 template<typename _tKey>
444 YB_ATTR_nodiscard YB_PURE friend bool
445 operator<(const _tKey& k, const ValueNode& y) ynothrow
446 {
447 return k < y.name;
448 }
450 YB_ATTR_nodiscard YB_PURE friend
451 PDefHOp(bool, >, const ValueNode& x, const string& str) ynothrow
452 ImplRet(x.name > str)
454 template<typename _tKey>
455 YB_ATTR_nodiscard YB_PURE friend bool
456 operator>(const ValueNode& x, const _tKey& k) ynothrow
457 {
458 return x.name > k;
459 }
461 template<typename _tKey>
462 YB_ATTR_nodiscard YB_PURE friend bool
463 operator>(const _tKey& k, const ValueNode& y) ynothrow
464 {
465 return k > y.name;
466 }
467
469 template<typename _tKey>
470 ValueNode&
471 operator[](_tKey&& k)
472 {
473 return Deref(try_emplace(k, NoContainer, yforward(k)).first);
474 }
476 template<class _tCon>
477 ValueNode&
478 operator[](const ystdex::path<_tCon>& pth)
479 {
480 auto p(this);
481
482 for(const auto& n : pth)
483 p = &(*p)[n];
484 return *p;
485 }
486
491 DefGetter(const ynothrow, const Container&, Container, container)
496 DefGetter(ynothrow, Container&, ContainerRef, container)
497 DefGetter(const ynothrow, const string&, Name, name)
498
499
509 PDefH(void, SetChildren, const Container& con)
510 ImplExpr(container = con)
511 PDefH(void, SetChildren, Container&& con)
512 ImplExpr(container = std::move(con))
514 PDefH(void, SetChildren, ValueNode&& node)
515 ImplExpr(container = std::move(node.container))
517
524 template<class _tCon, class _type>
526 yimpl(ystdex::enable_if_t)<
527 ystdex::and_<std::is_assignable<Container, _tCon&&>,
528 std::is_assignable<ValueObject, _type&&>>::value>
529 SetContent(_tCon&& con, _type&& val) ynoexcept(ystdex::and_<
530 std::is_nothrow_assignable<Container, _tCon&&>,
531 std::is_nothrow_assignable<ValueObject, _type&&>>())
532 {
533 container = yforward(con);
534 Value = yforward(val);
535 }
536 PDefH(void, SetContent, const ValueNode& node)
537 ImplExpr(SetContent(node.GetContainer(), node.Value))
538 PDefH(void, SetContent, ValueNode&& node)
539 ImplExpr(SetContent(std::move(node.GetContainerRef()),
540 std::move(node.Value)))
542
543
545 PDefH(bool, Add, const ValueNode& node)
546 ImplRet(insert(node).second)
548 PDefH(bool, Add, ValueNode&& node)
549 ImplRet(insert(std::move(node)).second)
550
556 template<typename _tKey, typename _tNode,
558 yimpl(typename = ystdex::enable_if_t<
559 std::is_same<ValueNode&, ystdex::remove_cvref_t<_tNode>&>::value>)>
560 yimpl(ystdex::enable_if_inconvertible_t)<_tKey&&, const_iterator, bool>
561 AddChild(_tKey&& k, _tNode&& node)
562 {
563 return try_emplace(k, yforward(node).container, yforward(k),
564 yforward(node).Value).second;
565 }
567
568 template<typename _tKey, typename _tNode,
569 yimpl(typename = ystdex::enable_if_t<
570 std::is_same<ValueNode&, ystdex::remove_cvref_t<_tNode>&>::value>)>
571 bool
572 AddChild(const_iterator hint, _tKey&& k, _tNode&& node)
573 {
574 return try_emplace_hint(hint, k, yforward(node).container, yforward(k),
575 yforward(node).Value);
576 }
578
579
586 template<typename _tKey, typename... _tParams>
587 inline
588 yimpl(ystdex::enable_if_inconvertible_t)<_tKey&&, const_iterator, bool>
589 AddValue(_tKey&& k, _tParams&&... args)
590 {
591 return AddValueTo(container, k, yforward(args)...);
592 }
593 template<typename _tKey, typename... _tParams>
594 inline bool
595 AddValue(const_iterator hint, _tKey&& k, _tParams&&... args)
596 {
597 return AddValueTo(hint, container, k, yforward(args)...);
598 }
600
602
603
607 template<typename _tKey, typename... _tParams>
608 static inline bool
609 AddValueTo(Container& con, _tKey&& k, _tParams&&... args)
610 {
611 return ystdex::try_emplace(con, k, NoContainer, yforward(k),
612 yforward(args)...).second;
613 }
618 template<typename _tKey, typename... _tParams>
619 static inline bool
620 AddValueTo(const_iterator hint, Container& con, _tKey&& k,
621 _tParams&&... args)
622 {
623 return ystdex::try_emplace_hint(con, hint, k, NoContainer, yforward(k),
624 yforward(args)...).second;
625 }
627
629
630
635 PDefH(void, Clear, ) ynothrow
636 ImplExpr(Value.Clear(), ClearContainer())
638
644 PDefH(void, ClearContainer, ) ynothrow
645 ImplExpr(container.clear())
646
648
649 static Container
651 CreateRecursively(const Container&, IValueHolder::Creation);
653 template<class _tCon, typename _fCallable,
654 yimpl(typename = ystdex::enable_if_t<
655 std::is_same<Container&, ystdex::remove_cvref_t<_tCon>&>::value>)>
656 static Container
657 CreateRecursively(_tCon&& con, _fCallable f)
658 {
659 Container res(con.get_allocator());
660
661 for(auto&& tm : con)
662 res.emplace(CreateRecursively(
663 ystdex::forward_like<_tCon>(tm.container), f), tm.GetName(),
664 ystdex::invoke(f, ystdex::forward_like<_tCon>(tm.Value)));
665 return res;
666 }
667
669 PDefH(Container, CreateWith, IValueHolder::Creation c) const
670 ImplRet(CreateRecursively(container, c))
672
673 template<typename _fCallable>
674 Container
675 CreateWith(_fCallable f) &
676 {
677 return CreateRecursively(container, f);
678 }
679 template<typename _fCallable>
680 Container
681 CreateWith(_fCallable f) const&
682 {
683 return CreateRecursively(container, f);
684 }
685 template<typename _fCallable>
686 Container
687 CreateWith(_fCallable f) &&
688 {
689 return CreateRecursively(std::move(container), f);
690 }
691 template<typename _fCallable>
692 Container
693 CreateWith(_fCallable f) const&&
694 {
695 return CreateRecursively(std::move(container), f);
696 }
698
699
708 void
709 MoveContent(ValueNode&&);
710
716
718
722 template<typename _type, typename _tString, typename... _tParams>
723 inline _type&
724 Place(_tString&& str, _tParams&&... args)
725 {
726 return PlaceValue<_type>(yforward(str), yforward(args)...).template
727 Access<_type>();
728 }
729
734 template<typename _type, typename _tString, typename... _tParams>
735 inline _type&
736 PlaceUnchecked(_tString&& str, _tParams&&... args)
737 {
738 return PlaceValue<_type>(yforward(str), yforward(args)...).template
739 GetObject<_type>();
740 }
742
744 template<typename _type, typename _tString, typename... _tParams>
745 inline ValueObject&
746 PlaceValue(_tString&& str, _tParams&&... args)
747 {
748 return try_emplace(str, NoContainer, yforward(str),
749 in_place_type<_type>, yforward(args)...).first->Value;
750 }
752
753 PDefH(bool, Remove, const ValueNode& node)
754 ImplRet(erase(node) != 0)
756 PDefH(iterator, Remove, const_iterator i)
757 ImplRet(erase(i))
759 template<typename _tKey, yimpl(typename = enable_if_key_t<_tKey>)>
760 inline bool
761 Remove(const _tKey& k)
762 {
763 return ystdex::erase_first(container, k);
764 }
765
770 template<typename _func>
771 Container
772 SelectChildren(_func f) const
773 {
774 Container res(get_allocator());
775
776 ystdex::for_each_if(begin(), end(), f, [&](const ValueNode& nd){
777 res.insert(nd);
778 });
779 return res;
780 }
781
783
784 template<typename _func>
786 Container
787 SplitChildren(_func f)
788 {
789 Container res(get_allocator());
790
791 std::for_each(begin(), end(), [&](const ValueNode& nd){
792 res.emplace(NoContainer, nd.GetName());
793 });
794 ystdex::for_each_if(begin(), end(), f, [&, this](const ValueNode& nd){
795 const auto& child_name(nd.GetName());
796
797 Deref(res.find(child_name)).Value = std::move(nd.Value);
798 Remove(child_name);
799 });
800 return res;
801 }
802
809 PDefH(void, SwapContainer, ValueNode& node) ynothrowv
811 ImplExpr(YAssert(get_allocator() == node.get_allocator(),
812 "Invalid allocator found."), container.swap(node.container))
813
814
815 void
816 SwapContent(ValueNode&) ynothrowv;
818
819
825 YB_NORETURN static void
826 ThrowIndexOutOfRange(size_t);
827
834 YB_NORETURN static void
835 ThrowWrongNameFound(string_view);
836
838
839 PDefH(iterator, begin, )
840 ImplRet(GetContainerRef().begin())
841 PDefH(const_iterator, begin, ) const
842 ImplRet(GetContainer().begin())
843
845 DefFwdTmpl(, pair<iterator YPP_Comma bool>, emplace,
846 container.emplace(yforward(args)...))
847
849 DefFwdTmpl(, iterator, emplace_hint,
850 container.emplace_hint(yforward(args)...))
851
853 YB_ATTR_nodiscard PDefH(bool, empty, ) const ynothrow
854 ImplRet(container.empty())
855
856 PDefH(iterator, end, )
857 ImplRet(GetContainerRef().end())
858 PDefH(const_iterator, end, ) const
859 ImplRet(GetContainer().end())
861
863 DefFwdTmpl(-> decltype(container.erase(yforward(args)...)), auto,
864 erase, container.erase(yforward(args)...))
865
867 YB_ATTR_nodiscard YB_PURE
868 PDefH(allocator_type, get_allocator, ) const ynothrow
869 ImplRet(container.get_allocator())
870
872 DefFwdTmpl(-> decltype(container.insert(yforward(args)...)), auto,
873 insert, container.insert(yforward(args)...))
874
876
877 template<typename _tKey, class _tParam>
878 yimpl(ystdex::enable_if_inconvertible_t)<_tKey&&, const_iterator,
879 std::pair<iterator, bool>>
880 insert_or_assign(_tKey&& k, _tParam&& arg)
881 {
882 // NOTE: See comments in %try_emplace.
883 return ystdex::insert_or_assign(container, yforward(k), yforward(arg));
884 }
885 template<typename _tKey, class _tParam>
886 iterator
887 insert_or_assign(const_iterator hint, _tKey&& k, _tParam&& arg)
888 {
889 return ystdex::insert_or_assign_hint(container, hint, yforward(k),
890 yforward(arg));
891 }
893
895
896 YB_ATTR_nodiscard YB_PURE PDefH(reverse_iterator, rbegin, )
897 ImplRet(GetContainerRef().rbegin())
898 YB_ATTR_nodiscard YB_PURE PDefH(const_reverse_iterator, rbegin, ) const
899 ImplRet(GetContainer().rbegin())
900
901 YB_ATTR_nodiscard YB_PURE PDefH(reverse_iterator, rend, )
902 ImplRet(GetContainerRef().rend())
903 YB_ATTR_nodiscard YB_PURE PDefH(const_reverse_iterator, rend, ) const
904 ImplRet(GetContainer().rend())
906
908 YB_ATTR_nodiscard YB_PURE PDefH(size_t, size, ) const ynothrow
909 ImplRet(container.size())
910
916 YF_API friend void
917 swap(ValueNode&, ValueNode&) ynothrowv;
918
920 template<typename _tKey, typename... _tParams>
921 yimpl(ystdex::enable_if_inconvertible_t)<_tKey&&, const_iterator,
922 std::pair<iterator, bool>>
923 try_emplace(_tKey&& k, _tParams&&... args)
924 {
925 // NOTE: This is not efficient as a single %emplace when %k is not
926 // equivalent to %cont_traits::get_value_key(yforward(args)...), as
927 // per the notes in %ystdex::mapped_set. However, this function is
928 // needed as a convenient base to other operations and there is in
929 // general no superior alternatives (when it is needed to decide to
930 // insert on two different keys). Thus, it is kept as a public
931 // function. All other functions using this one would keep the
932 // equivalence, so they are still preferred unless the difference of
933 // keys is intended, though.
934 return ystdex::try_emplace(container, yforward(k), yforward(args)...);
935 }
936
938 template<typename _tKey, typename... _tParams>
939 iterator
940 try_emplace_hint(const_iterator hint, _tKey&& k, _tParams&&... args)
941 {
942 return ystdex::try_emplace_hint(container, hint, yforward(k),
943 yforward(args)...);
944 }
945 };
946
948
949
951
956 template<typename _type>
957 YB_ATTR_nodiscard YB_PURE inline _type&
958 Access(ValueNode& node)
959 {
960 return node.Value.Access<_type>();
961 }
962 template<typename _type>
963 YB_ATTR_nodiscard YB_PURE inline const _type&
964 Access(const ValueNode& node)
965 {
966 return node.Value.Access<_type>();
967 }
969
971
972
974 template<typename _type>
975 YB_ATTR_nodiscard YB_PURE inline observer_ptr<_type>
976 AccessPtr(ValueNode& node) ynothrow
977 {
978 return node.Value.AccessPtr<_type>();
979 }
980 template<typename _type>
981 YB_ATTR_nodiscard YB_PURE inline observer_ptr<const _type>
982 AccessPtr(const ValueNode& node) ynothrow
983 {
984 return node.Value.AccessPtr<_type>();
985 }
987
992 template<typename _type, typename _tNodeOrPointer>
993 YB_ATTR_nodiscard YB_PURE inline auto
994 AccessPtr(observer_ptr<_tNodeOrPointer> p) ynothrow
995 -> decltype(YSLib::AccessPtr<_type>(*p))
996 {
997 return p ? YSLib::AccessPtr<_type>(*p) : nullptr;
998 }
1000
1001
1002
1004
1005 YB_ATTR_nodiscard YF_API YB_PURE ValueObject
1007 GetValueOf(observer_ptr<const ValueNode>);
1008
1010 YB_ATTR_nodiscard YF_API YB_PURE observer_ptr<const ValueObject>
1011 GetValuePtrOf(observer_ptr<const ValueNode>);
1013
1014
1015
1017
1018 template<typename _tKey>
1019 YB_ATTR_nodiscard YB_PURE observer_ptr<ValueNode>
1020 AccessNodePtr(ValueNode::Container*, const _tKey&) ynothrow;
1021 template<typename _tKey>
1022 YB_ATTR_nodiscard YB_PURE observer_ptr<const ValueNode>
1023 AccessNodePtr(const ValueNode::Container*, const _tKey&) ynothrow;
1024
1030 YB_ATTR_nodiscard YF_API YB_PURE ValueNode&
1032 AccessNode(ValueNode::Container*, const string&);
1034 YB_ATTR_nodiscard YF_API YB_PURE const ValueNode&
1035 AccessNode(const ValueNode::Container*, const string&);
1036 template<typename _tKey>
1037 YB_ATTR_nodiscard YB_PURE ValueNode&
1038 AccessNode(ValueNode::Container* p_con, const _tKey& name)
1039 {
1040 if(const auto p = YSLib::AccessNodePtr(p_con, name))
1041 return *p;
1042 ValueNode::ThrowWrongNameFound(name);
1043 }
1044 template<typename _tKey>
1045 YB_ATTR_nodiscard YB_PURE const ValueNode&
1046 AccessNode(const ValueNode::Container* p_con, const _tKey& name)
1047 {
1048 if(const auto p = YSLib::AccessNodePtr(p_con, name))
1049 return *p;
1050 ValueNode::ThrowWrongNameFound(name);
1051 }
1052 template<typename _tKey>
1053 YB_ATTR_nodiscard YB_PURE inline ValueNode&
1054 AccessNode(observer_ptr<ValueNode::Container> p_con, const _tKey& name)
1055 {
1056 return YSLib::AccessNode(p_con.get(), name);
1057 }
1058 template<typename _tKey>
1059 YB_ATTR_nodiscard YB_PURE inline const ValueNode&
1060 AccessNode(observer_ptr<const ValueNode::Container> p_con, const _tKey& name)
1061 {
1062 return YSLib::AccessNode(p_con.get(), name);
1063 }
1064 template<typename _tKey>
1065 YB_ATTR_nodiscard YB_PURE inline ValueNode&
1066 AccessNode(ValueNode::Container& con, const _tKey& name)
1067 {
1068 return YSLib::AccessNode(&con, name);
1069 }
1070 template<typename _tKey>
1071 YB_ATTR_nodiscard YB_PURE inline const ValueNode&
1072 AccessNode(const ValueNode::Container& con, const _tKey& name)
1073 {
1074 return YSLib::AccessNode(&con, name);
1075 }
1081 YB_ATTR_nodiscard YF_API YB_PURE ValueNode&
1082 AccessNode(ValueNode&, size_t);
1083 YB_ATTR_nodiscard YF_API YB_PURE const ValueNode&
1084 AccessNode(const ValueNode&, size_t);
1086 template<typename _tKey,
1087 yimpl(typename = ValueNode::enable_if_key_t<_tKey>)>
1088 YB_ATTR_nodiscard YB_PURE inline ValueNode&
1089 AccessNode(ValueNode& node, const _tKey& name)
1090 {
1091 return YSLib::AccessNode(node.GetContainerRef(), name);
1092 }
1093 template<typename _tKey,
1094 yimpl(typename = ValueNode::enable_if_key_t<_tKey>)>
1095 YB_ATTR_nodiscard YB_PURE inline const ValueNode&
1096 AccessNode(const ValueNode& node, const _tKey& name)
1097 {
1098 return YSLib::AccessNode(node.GetContainer(), name);
1099 }
1101
1102 template<class _tNode, typename _tIn>
1104 YB_ATTR_nodiscard YB_PURE _tNode&&
1105 AccessNode(_tNode&& node, _tIn first, _tIn last)
1106 {
1107 return std::accumulate(first, last, ystdex::ref(node),
1108 [](_tNode&& nd, decltype(*first) c){
1109 return ystdex::ref(AccessNode(nd, c));
1110 });
1111 }
1113 template<class _tNode, typename _tRange,
1114 yimpl(typename = typename ystdex::enable_if_t<
1115 !std::is_constructible<const string&, const _tRange&>::value>)>
1116 YB_ATTR_nodiscard YB_PURE inline auto
1117 AccessNode(_tNode&& node, const _tRange& c)
1118 -> decltype(YSLib::AccessNode(yforward(node), begin(c), end(c)))
1119 {
1120 return YSLib::AccessNode(yforward(node), begin(c), end(c));
1121 }
1123
1124
1126
1127 YB_ATTR_nodiscard YF_API YB_PURE observer_ptr<ValueNode>
1129 AccessNodePtr(ValueNode::Container&, const string&) ynothrow;
1131 YB_ATTR_nodiscard YF_API YB_PURE observer_ptr<const ValueNode>
1132 AccessNodePtr(const ValueNode::Container&, const string&) ynothrow;
1133 template<typename _tKey>
1134 YB_ATTR_nodiscard YB_PURE observer_ptr<ValueNode>
1135 AccessNodePtr(ValueNode::Container& con, const _tKey& name) ynothrow
1136 {
1137 return make_observer(ystdex::call_value_or<ValueNode*>(ystdex::addrof<>(),
1138 con.find(name), {}, ystdex::end(con)));
1139 }
1140 template<typename _tKey>
1141 YB_ATTR_nodiscard YB_PURE observer_ptr<const ValueNode>
1142 AccessNodePtr(const ValueNode::Container& con, const _tKey& name) ynothrow
1143 {
1144 return make_observer(ystdex::call_value_or<const ValueNode*>(
1145 ystdex::addrof<>(), con.find(name), {}, ystdex::end(con)));
1146 }
1147 template<typename _tKey>
1148 YB_ATTR_nodiscard YB_PURE inline observer_ptr<ValueNode>
1149 AccessNodePtr(ValueNode::Container* p_con, const _tKey& name) ynothrow
1150 {
1151 return p_con ? YSLib::AccessNodePtr(*p_con, name) : nullptr;
1152 }
1153 template<typename _tKey>
1154 YB_ATTR_nodiscard YB_PURE inline observer_ptr<const ValueNode>
1155 AccessNodePtr(const ValueNode::Container* p_con, const _tKey& name) ynothrow
1156 {
1157 return p_con ? YSLib::AccessNodePtr(*p_con, name) : nullptr;
1158 }
1159 template<typename _tKey>
1160 YB_ATTR_nodiscard YB_PURE inline observer_ptr<ValueNode>
1161 AccessNodePtr(observer_ptr<ValueNode::Container> p_con, const _tKey& name)
1162 ynothrow
1163 {
1164 return p_con ? YSLib::AccessNodePtr(*p_con, name) : nullptr;
1165 }
1166 template<typename _tKey>
1167 YB_ATTR_nodiscard YB_PURE inline observer_ptr<const ValueNode>
1168 AccessNodePtr(observer_ptr<const ValueNode::Container> p_con, const _tKey& name)
1169 ynothrow
1170 {
1171 return p_con ? YSLib::AccessNodePtr(*p_con, name) : nullptr;
1172 }
1178 YB_ATTR_nodiscard YF_API YB_PURE observer_ptr<ValueNode>
1179 AccessNodePtr(ValueNode&, size_t);
1180 YB_ATTR_nodiscard YF_API YB_PURE observer_ptr<const ValueNode>
1181 AccessNodePtr(const ValueNode&, size_t);
1183 template<typename _tKey, yimpl(typename = typename ystdex::enable_if_t<
1184 ystdex::is_interoperable<const _tKey&, const string&>::value>)>
1185 YB_ATTR_nodiscard YB_PURE inline observer_ptr<ValueNode>
1186 AccessNodePtr(ValueNode& node, const _tKey& name)
1187 {
1188 return YSLib::AccessNodePtr(node.GetContainerRef(), name);
1189 }
1190 template<typename _tKey, yimpl(typename = typename ystdex::enable_if_t<
1191 ystdex::is_interoperable<const _tKey&, const string&>::value>)>
1192 YB_ATTR_nodiscard YB_PURE inline observer_ptr<const ValueNode>
1193 AccessNodePtr(const ValueNode& node, const _tKey& name)
1194 {
1195 return YSLib::AccessNodePtr(node.GetContainer(), name);
1196 }
1198
1199 template<class _tNode, typename _tIn>
1201 YB_ATTR_nodiscard YB_PURE auto
1202 AccessNodePtr(_tNode&& node, _tIn first, _tIn last)
1203 -> decltype(make_obsrever(std::addressof(node)))
1204 {
1205 // TODO: Simplified using algorithm template?
1206 for(auto p(make_observer(std::addressof(node))); p && first != last;
1207 ++first)
1208 p = AccessNodePtr(*p, *first);
1209 return first;
1210 }
1212 template<class _tNode, typename _tRange,
1213 yimpl(typename = typename ystdex::enable_if_t<
1214 !std::is_constructible<const string&, const _tRange&>::value>)>
1215 YB_ATTR_nodiscard YB_PURE inline auto
1216 AccessNodePtr(_tNode&& node, const _tRange& c)
1217 -> decltype(YSLib::AccessNodePtr(yforward(node), begin(c), end(c)))
1218 {
1219 return YSLib::AccessNodePtr(yforward(node), begin(c), end(c));
1220 }
1222
1223
1224
1226
1227
1237 template<typename _type, typename... _tParams>
1238 YB_ATTR_nodiscard YB_PURE inline _type&
1239 AccessChild(ValueNode& node, _tParams&&... args)
1240 {
1241 return Access<_type>(AccessNode(node, yforward(args)...));
1242 }
1243 template<typename _type, typename... _tParams>
1244 inline const _type&
1245 AccessChild(const ValueNode& node, _tParams&&... args)
1246 {
1247 return Access<_type>(AccessNode(node, yforward(args)...));
1248 }
1250
1252
1253 template<typename _type, typename... _tParams>
1254 YB_ATTR_nodiscard YB_PURE inline observer_ptr<_type>
1255 AccessChildPtr(ValueNode& node, _tParams&&... args) ynothrow
1256 {
1257 return AccessPtr<_type>(
1258 AccessNodePtr(node.GetContainerRef(), yforward(args)...));
1259 }
1260 template<typename _type, typename... _tParams>
1261 YB_ATTR_nodiscard YB_PURE inline observer_ptr<const _type>
1262 AccessChildPtr(const ValueNode& node, _tParams&&... args) ynothrow
1263 {
1264 return AccessPtr<_type>(
1265 AccessNodePtr(node.GetContainer(), yforward(args)...));
1266 }
1267 template<typename _type, typename... _tParams>
1268 YB_ATTR_nodiscard YB_PURE inline observer_ptr<_type>
1269 AccessChildPtr(ValueNode* p_node, _tParams&&... args) ynothrow
1270 {
1271 return p_node ? AccessChildPtr<_type>(*p_node, yforward(args)...) : nullptr;
1272 }
1273 template<typename _type, typename... _tParams>
1274 YB_ATTR_nodiscard YB_PURE inline observer_ptr<const _type>
1275 AccessChildPtr(const ValueNode* p_node, _tParams&&... args) ynothrow
1276 {
1277 return p_node ? AccessChildPtr<_type>(*p_node, yforward(args)...) : nullptr;
1278 }
1280
1281
1282
1283
1285
1286
1288 YB_ATTR_nodiscard YB_PURE inline
1290 PDefH(const ValueNode&, AsNode, const ValueNode& node) ynothrow
1291 ImplRet(node)
1293
1294 template<typename _tString, typename... _tParams,
1295 yimpl(typename = ystdex::enable_if_inconvertible_t<_tString&&,
1296 const ValueNode::allocator_type&>)>
1297 YB_ATTR_nodiscard YB_PURE inline ValueNode
1298 AsNode(_tString&& str, _tParams&&... args)
1299 {
1300 return {NoContainer, yforward(str), yforward(args)...};
1301 }
1302 template<typename _tString, typename... _tParams>
1303 YB_ATTR_nodiscard YB_PURE inline ValueNode
1304 AsNode(const ValueNode::allocator_type& a, _tString&& str, _tParams&&... args)
1305 {
1306 return {std::allocator_arg, a, NoContainer, yforward(str),
1307 yforward(args)...};
1308 }
1310
1312
1313 template<typename _tString, typename... _tParams,
1314 yimpl(typename = ystdex::enable_if_inconvertible_t<_tString&&,
1315 const ValueNode::allocator_type&>)>
1316 YB_ATTR_nodiscard YB_PURE inline ValueNode
1317 MakeNode(_tString&& str, _tParams&&... args)
1318 {
1319 return {NoContainer, yforward(str), ystdex::decay_copy(args)...};
1320 }
1321 template<typename _tString, typename... _tParams>
1322 YB_ATTR_nodiscard YB_PURE inline ValueNode
1323 MakeNode(const ValueNode::allocator_type& a, _tString&& str, _tParams&&... args)
1324 {
1325 return {std::allocator_arg, a, NoContainer, yforward(str),
1326 ystdex::decay_copy(args)...};
1327 }
1329
1330
1337 template<typename _tString, typename... _tParams,
1338 yimpl(typename = ystdex::enable_if_inconvertible_t<_tString&&,
1339 const ValueNode::allocator_type&>)>
1340 YB_ATTR_nodiscard YB_PURE inline ValueNode
1341 StringifyToNode(_tString&& str, _tParams&&... args)
1342 {
1343 return {NoContainer, yforward(str),
1344 to_pmr_string(to_string(yforward(args)...))};
1345 }
1346 template<typename _tString, typename... _tParams>
1347 YB_ATTR_nodiscard YB_PURE inline ValueNode
1348 StringifyToNode(const ValueNode::allocator_type& a, _tString&& str,
1349 _tParams&&... args)
1350 {
1351 return {std::allocator_arg, a, NoContainer, yforward(str),
1352 to_pmr_string(to_string(yforward(args)...))};
1353 }
1355
1356
1357
1363 YB_ATTR_nodiscard YB_PURE inline
1364 PDefH(const ValueNode&, UnpackToNode, const ValueNode& arg)
1365 ImplRet(arg)
1366 YB_ATTR_nodiscard YB_PURE inline
1367 PDefH(ValueNode&&, UnpackToNode, ValueNode&& arg)
1368 ImplRet(std::move(arg))
1370
1375 template<class _tPack>
1376 YB_ATTR_nodiscard YB_PURE inline ValueNode
1377 UnpackToNode(_tPack&& pk)
1378 {
1379 return {0, get<0>(yforward(pk)),
1380 ValueObject(ystdex::decay_copy(get<1>(yforward(pk))))};
1381 }
1382
1388 template<typename _tElem>
1389 YB_ATTR_nodiscard YB_PURE inline ValueNode::Container
1390 CollectNodes(std::initializer_list<_tElem> il)
1391 {
1392 return il;
1393 }
1394 template<typename... _tParams>
1395 YB_ATTR_nodiscard YB_PURE inline ValueNode::Container
1396 CollectNodes(_tParams&&... args)
1397 {
1398 return {yforward(args)...};
1399 }
1401
1406 template<typename _tString, typename... _tParams>
1407 YB_ATTR_nodiscard YB_PURE inline ValueNode
1408 PackNodes(_tString&& name, _tParams&&... args)
1409 {
1410 return {CollectNodes(UnpackToNode(yforward(args))...), yforward(name)};
1411 }
1412
1413
1415
1416 YF_API void
1418 RemoveEmptyChildren(ValueNode::Container&) ynothrow;
1419
1425 YF_API void
1426 RemoveHead(ValueNode::Container&) ynothrowv;
1427 inline PDefH(void, RemoveHead, ValueNode& node) ynothrowv
1428 ImplExpr(RemoveHead(node.GetContainerRef()))
1430
1431
1438 template<typename _tNode, typename _fCallable>
1439 void
1440 SetContentWith(ValueNode& dst, _tNode&& node, _fCallable f)
1441 {
1442 // NOTE: Similar reason but different to the implementation of
1443 // %ValueNode::MoveContent.
1444 auto con(yforward(node).CreateWith(f));
1445 auto vo(ystdex::invoke(f, yforward(node).Value));
1446
1447 dst.SetContent(std::move(con), std::move(vo));
1448 }
1449
1450
1457 YB_ATTR_nodiscard YF_API YB_PURE bool
1458 IsPrefixedIndex(string_view, char = '$');
1459
1468 YB_ATTR_nodiscard YF_API YB_PURE string
1469 MakeIndex(size_t);
1470
1472
1473
1479 YB_ATTR_nodiscard YF_API size_t
1480 DecodeIndex(string_view);
1482
1483
1490 using NodeSequence = yimpl(YSLib::vector)<ValueNode>;
1491
1492
1497 class YF_API NodeLiteral final
1498 {
1499 private:
1500 ValueNode node;
1501
1502 public:
1504 NodeLiteral(const ValueNode& nd)
1505 : node(nd)
1506 {}
1508 NodeLiteral(ValueNode&& nd)
1509 : node(std::move(nd))
1510 {}
1511 NodeLiteral(const string& str)
1512 : node(NoContainer, str)
1513 {}
1514 NodeLiteral(const string& str, string val)
1515 : node(NoContainer, str, std::move(val))
1516 {}
1517 template<typename _tLiteral = NodeLiteral>
1518 NodeLiteral(const string& str, std::initializer_list<_tLiteral> il)
1519 : node(NoContainer, str, NodeSequence(il.begin(), il.end()))
1520 {}
1522 template<typename _tLiteral = NodeLiteral, class _tString,
1523 typename... _tParams>
1524 NodeLiteral(ListContainerTag, _tString&& str,
1525 std::initializer_list<_tLiteral> il, _tParams&&... args)
1526 : node(ValueNode::Container(il.begin(), il.end()), yforward(str),
1527 yforward(args)...)
1528 {}
1529 DefDeCopyMoveCtorAssignment(NodeLiteral)
1530
1531 DefCvt(ynothrow, ValueNode&, node)
1532 DefCvt(const ynothrow, const ValueNode&, node)
1533
1535 DefGetter(ynothrow, ValueNode&, NodeRef, node)
1536 };
1537
1543 template<typename _tString, typename _tLiteral = NodeLiteral>
1544 YB_ATTR_nodiscard inline YB_PURE NodeLiteral
1545 AsNodeLiteral(_tString&& name, std::initializer_list<_tLiteral> il)
1546 {
1547 return {ListContainer, yforward(name), il};
1548 }
1549
1550 } // namespace YSLib;
1551
1552 #endif
1553
YSLib::ValueNode::MappedSetTraits::get_value_key
YB_ATTR_nodiscard static YB_PURE string get_value_key(const pair< _tIn, _tIn > &, allocator_type={})
Definition: ValueNode.h:152
ystdex::mapped_set< ValueNode, ystdex::less<>, MappedSetTraits, allocator_type >
YSLib::ValueNode::ValueNode
ValueNode(const Container &con, _tString &&str, _tParams &&... args)
构造：使用容器对象引用、字符串引用和值类型对象构造参数。
Definition: ValueNode.h:280
YSLib::ValueNode::MappedSetTraits::get_value_key
YB_ATTR_nodiscard static YB_PURE ValueNode typename _tOther typename _tString _tParams &&YB_ATTR_nodiscard static YB_PURE _tString && get_value_key(std::allocator_arg_t, allocator_type, _tOther &&, _tString &&str, _tParams &&...)
Definition: ValueNode.h:145
YB_ATTR_nodiscard
#define YB_ATTR_nodiscard
标记返回值不被忽略的属性。
Definition: ydef.h:715
YSLib::AccessChildPtr
YB_ATTR_nodiscard YB_PURE observer_ptr< _type > AccessChildPtr(ValueNode &node, _tParams &&... args) ynothrow
访问指定名称的子节点的指定类型对象的指针。
Definition: ValueNode.h:1255
YSLib::ValueNode::ValueNode
ValueNode(const pair< _tIn, _tIn > &pr, _tString &&str, allocator_type a={})
构造：使用输入迭代器对、字符串引用、值参数和可选的分配器。
Definition: ValueNode.h:318
x
const EncapsulationBase & x
Definition: NPLA1Forms.cpp:1536
YSLib::swap
void swap(ValueNode &x, ValueNode &y) ynothrowv
Definition: ValueNode.cpp:95
path.hpp
抽象路径模板。
YSLib::ValueNode::MappedSetTraits
Definition: ValueNode.h:102
size
size_t size
Definition: memory_resource.cpp:295
YSLib::NodeLiteral::NodeLiteral
NodeLiteral(const string &str, std::initializer_list< _tLiteral > il)
Definition: ValueNode.h:1518
YSLib::ValueNode::MappedSetTraits::PDefH
YB_ATTR_nodiscard static YB_PURE PDefH(const string &, get_value_key, const ValueNode &nd, allocator_type={}) ynothrow ImplRet(nd.name) YB_ATTR_nodiscard YB_PURE static PDefH(string &&
CHRLib::c
c
Definition: CharacterProcessing.h:84
YSLib::RemoveEmptyChildren
YF_API void RemoveEmptyChildren(ValueNode::Container &) ynothrow
移除空子节点。
Definition: ValueNode.cpp:180
ystdex::invoke
invoke_result_t< _fCallable, _tParams... > invoke(_fCallable &&f, _tParams &&... args)
调用可调用对象。
Definition: invoke.hpp:538
YSLib::SetContentWith
_fCallable void SetContentWith(ValueNode &dst, _tNode &&node, _fCallable f)
Definition: ValueNode.h:1440
yconstexpr
#define yconstexpr
指定编译时常量表达式。
Definition: ydef.h:1072
YB_PURE
#define YB_PURE
指示函数或函数模板实例为纯函数。
Definition: ydef.h:919
YSLib::ValueNode::ValueNode
ValueNode(const Container &con, allocator_type a)
Definition: ValueNode.h:245
YSLib::ValueNode::PDefH
PDefH(bool, Remove, const ValueNode &node) ImplRet(erase(node) !=0) PDefH(iterator
YSLib::ValueNode::enable_if_key_t
ystdex::enable_if_t< is_key_t< _tKey >::value > enable_if_key_t
Definition: ValueNode.h:85
YSLib::ValueNode::PlaceValue
ValueObject & PlaceValue(_tString &&str, _tParams &&... args)
初始化的值对象引用。
Definition: ValueNode.h:746
YSLib::IsPrefixedIndex
YB_ATTR_nodiscard YF_API YB_PURE bool IsPrefixedIndex(string_view, char='$')
判断字符串是否是前缀索引：一个指定字符和非负整数的组合。
Definition: ValueNode.cpp:194
ystdex::details::insert_or_assign
std::pair< typename _tAssocCon::iterator, bool > insert_or_assign(std::pair< typename _tAssocCon::iterator, bool > pr, _tAssocCon &con, _tKey &&k, _tParam &&arg)
Definition: container.hpp:919
ystdex::cpp2017::string_view
basic_string_view< char > string_view
Definition: string_view.hpp:437
tuple.hpp
元组类型和操作。
ystdex::addrof
一元 & 操作。
Definition: functor.hpp:441
YSLib::ValueNode::name
string name
Definition: ValueNode.h:214
ystdex::cpp2017::reverse_iterator
Definition: range.hpp:116
ystdex::mapped_set::insert
std::pair< iterator, bool > insert(const value_type &x)
Definition: set.hpp:528
YSLib::GetValuePtrOf
YB_ATTR_nodiscard YF_API YB_PURE observer_ptr< const ValueObject > GetValuePtrOf(observer_ptr< const ValueNode >)
取指定名称指称的值的指针。
Definition: ValueNode.cpp:172
ystdex::cpp2014::enable_if_t
typename enable_if< _bCond, _type >::type enable_if_t
Definition: meta.hpp:199
YSLib::ValueNode::ValueNode
ValueNode(tuple< _tParams1... > args1, tuple< _tParams2... > args2, tuple< _tParams3... > args3, allocator_type a={})
Definition: ValueNode.h:339
swap.hpp
交换操作。
YSLib::NodeLiteral::NodeLiteral
NodeLiteral(const string &str)
Definition: ValueNode.h:1511
ystdex::path
一般路径模板。
Definition: path.hpp:268
YSLib::ValueNode::DefDeCtor
DefDeCtor(ValueNode) explicit ValueNode(allocator_type a)
构造：使用分配器。
Definition: ValueNode.h:226
YF_API
#define YF_API
Definition: Platform.h:56
ystdex::copy_and_swap
_type & copy_and_swap(_type &obj, const _type2 &new_val)
复制对象并交换。
Definition: swap.hpp:514
YSLib::ValueNode::PDefH
PDefH(Container, CreateWith, IValueHolder::Creation c) const ImplRet(CreateRecursively(container
YPP_Comma
#define YPP_Comma
替换为逗号的预处理记号。
Definition: ydef.h:370
ystdex::rend
reverse_iterator< _type * > rend(_type(&&array)[_vN])
Definition: range.hpp:397
YSLib::ListContainerTag
标记列表构造容器。
Definition: ValueNode.h:52
ystdex::for_each_if
_func for_each_if(_tIn first, _tIn last, _fPred pred, _func f)
Definition: algorithm.hpp:185
CHRLib::f
f(d, s)
YSLib::ValueNode::ThrowWrongNameFound
static YB_NORETURN void ThrowWrongNameFound(string_view)
抛出名称错误异常。
Definition: ValueNode.cpp:88
YSLib::MakeIndex
YB_ATTR_nodiscard YF_API YB_PURE string MakeIndex(size_t)
转换节点大小为新的节点索引值。
Definition: ValueNode.cpp:209
YSLib::ValueNode::key_type
Container::key_type key_type
Definition: ValueNode.h:203
YSLib::Access
YB_ATTR_nodiscard YB_PURE const _type & Access(const ValueNode &node)
Definition: ValueNode.h:964
YSLib::NodeLiteral::node
ValueNode node
Definition: ValueNode.h:1500
YSLib::ValueNode::SplitChildren
Container SplitChildren(_func f)
转移满足条件的子节点。
Definition: ValueNode.h:787
NPL::tm
tm
Definition: NPLA.h:1941
ystdex::enable_if_inconvertible_t
enable_if_t<!is_convertible< _tFrom, _tTo >::value, _type > enable_if_inconvertible_t
Definition: meta.hpp:842
YSLib::ValueNode::CreateWith
c Container CreateWith(_fCallable f) &
Definition: ValueNode.h:675
YSLib::ValueNode::PDefH
YB_ATTR_nodiscard YB_PURE PDefH(reverse_iterator, rbegin,) ImplRet(GetContainerRef().rbegin()) YB_ATTR_nodiscard YB_PURE PDefH(const_reverse_iterator
YSLib::ValueNode::SelectChildren
Container SelectChildren(_func f) const
复制满足条件的子节点。
Definition: ValueNode.h:772
ystdex::erase_first
bool erase_first(_tAssocCon &con, const _tKey &k)
删除指定关联容器中等价于指定键的起始元素。
Definition: container.hpp:547
YSLib::NodeLiteral::NodeLiteral
NodeLiteral(const string &str, string val)
Definition: ValueNode.h:1514
DefBoolNeg
#define DefBoolNeg(_spec,...)
定义表示显式转换 bool 操作符及其否定的 operator! 。
Definition: YBaseMacro.h:228
DefFwdTmpl
#define DefFwdTmpl(_q, _t, _n,...)
传递模板。
Definition: YBaseMacro.h:332
YSLib::ValueNode::MappedSetTraits::PDefH
YB_ATTR_nodiscard static YB_PURE PDefH(string, get_value_key, allocator_type={}) ynothrow ImplRet(
Definition: ValueNode.h:118
YSLib::YAssert
YAssert(!(v< Deref(a)), "Value less than lower bound found.")
YSLib::PackNodes
YB_ATTR_nodiscard YB_PURE ValueNode PackNodes(_tString &&name, _tParams &&... args)
取以指定分量为参数对应初始化得到的值类型节点为子节点的值类型节点。
Definition: ValueNode.h:1408
YSLib::IO::_tString
const string &path const String &path class class class _tString
Definition: YSLib/Service/FileSystem.h:612
YSLib::RemoveHead
YF_API void RemoveHead(ValueNode::Container &) ynothrowv
移除第一个子节点。
Definition: ValueNode.cpp:186
YB_NORETURN
#define YB_NORETURN
指定无返回值函数。
Definition: ydef.h:877
ystdex::make_observer
observer_ptr< _type > make_observer(_type *p)
Definition: pointer.hpp:405
YSLib::ValueNode::MappedSetTraits::get_value_key
YB_ATTR_nodiscard static YB_PURE string get_value_key(tuple< _tParams1... >, tuple< _tParams2... > args2, allocator_type={})
Definition: ValueNode.h:171
yforward
#define yforward(_expr)
根据参数类型使用 std::forward 转发对应参数。
Definition: ydef.h:1508
ystdex::decay_copy
enable_if_convertible_t< _type, decay_t< _type >, decay_t< _type > > decay_copy(_type &&arg)
退化复制。
Definition: utility.hpp:114
YSLib::ValueObject
值类型对象类。
Definition: YObject.h:1068
ystdex::try_emplace
std::pair< typename _tAssocCon::iterator, bool > try_emplace(_tAssocCon &con, _tKey &&k, _tParams &&... args)
Definition: container.hpp:1039
ystdex::mapped_set::emplace
std::pair< iterator, bool > emplace(_tParams &&... args)
Definition: set.hpp:466
YSLib::NodeLiteral::NodeLiteral
NodeLiteral(ValueNode &&nd)
Definition: ValueNode.h:1508
ystdex::insert_or_assign_hint
std::pair< typename _tAssocCon::iterator, bool > insert_or_assign_hint(_tAssocCon &con, typename _tAssocCon::const_iterator hint, _tKey &&k, _tParam &&arg)
Definition: container.hpp:1076
ystdex::mapped_set< ValueNode, ystdex::less<>, MappedSetTraits, allocator_type >::key_type
ValueNode key_type
Definition: set.hpp:245
ystdex::cpp2017::operator<
auto operator<(const optional< _type > &x, const optional< _tOther > &y) -> optional_relop_t< decltype(std::declval< _type >()< std::declval< _tOther >())>
Definition: optional.h:719
YSLib::DecodeIndex
YB_ATTR_nodiscard YF_API size_t DecodeIndex(string_view)
解码节点名称的前缀索引。
Definition: ValueNode.cpp:235
ystdex::cpp2017::end
auto end(_tRange &c) -> decltype(c.end())
Definition: range.hpp:345
ystdex::mapped_set::find
iterator find(const key_type &x)
Definition: set.hpp:661
YSLib::ValueNode::MappedSetTraits::yimpl
YB_ATTR_nodiscard static YB_PURE ValueNode typename _tOther typename yimpl(typename=enable_not_key_t< _tOther >)> YB_ATTR_nodiscard YB_PURE static inline _tString &&get_value_key(_tOther &&
YSLib::ValueNode
值类型节点。
Definition: ValueNode.h:73
std
Definition: optional.h:982
platform::strings::to_pmr_string
_tString to_pmr_string(basic_string_view< _tChar > sv)
Definition: Container.h:226
YSLib::ValueNode::ValueNode
ValueNode(tuple< _tParams1... > args1, allocator_type a={})
原地构造：使用容器、名称、值的参数元组和可选的分配器。
Definition: ValueNode.h:326
YSLib::yimpl
YF_API yimpl(GUIApplication &) FetchGlobalInstance()
取全局应用程序实例。
YSLib::StringifyToNode
YB_ATTR_nodiscard YB_PURE ValueNode StringifyToNode(_tString &&str, _tParams &&... args)
取指定名称和转换为字符串的值类型节点。
Definition: ValueNode.h:1341
operators.hpp
重载操作符。
set.hpp
集合容器。
YSLib::i
return i
Definition: YCoreUtilities.h:177
YSLib::ValueNode::ValueNode
ValueNode(const ValueNode &nd)
复制构造：使用参数和参数指定的分配器。
Definition: ValueNode.h:350
ystdex::dep_ops::totally_ordered
details::flat_ops< _type, _type2, _tOpt, less_than_comparable, equality_comparable > totally_ordered
Definition: operators.hpp:389
YSLib::ValueNode::ValueNode
ValueNode(const pair< _tIn, _tIn > &pr, allocator_type a={})
构造：使用输入迭代器对和可选的分配器。
Definition: ValueNode.h:312
YSLib::ValueNode::Place
_type & Place(_tString &&str, _tParams &&... args)
若指定名称子节点不存在则按指定值初始化。
Definition: ValueNode.h:724
utility.hpp
实用设施。
platform::containers::vector
std::vector< _type, _tAlloc > vector
Definition: Container.h:102
YSLib::NodeLiteral
包装节点的组合字面量。
Definition: ValueNode.h:1498
YSLib::ListContainer
yconstexpr const struct YSLib::ListContainerTag ListContainer
YSLib::UI::y
SPos SPos y
Definition: YWidget.cpp:44
ystdex::cpp2017::operator>
auto operator>(const optional< _type > &x, const optional< _tOther > &y) -> optional_relop_t< decltype(std::declval< _type >() > std::declval< _tOther >())>
Definition: optional.h:728
ystdex::to_string
std::string to_string(const std::thread::id &)
转换 thread::id 为字符串表示。
YSLib::AsNode
YB_ATTR_nodiscard YB_PURE ValueNode AsNode(const ValueNode::allocator_type &a, _tString &&str, _tParams &&... args)
Definition: ValueNode.h:1304
YSLib::NodeSequence
yimpl(YSLib::vector)< ValueNode > NodeSequence
节点序列容器。
Definition: ValueNode.h:1490
YSLib
YSLib 命名空间。
Definition: AndroidHost.h:46
variadic.hpp
C++ 变长参数相关操作。
YModules.h
YSLib 用户界面模块配置文件。
YSLib::ValueNode::ValueNode
ValueNode(Container &&con, allocator_type a)
Definition: ValueNode.h:251
YSLib::ValueNode::ValueNode
ValueNode(Container &&con, _tString &&str, _tParams &&... args)
Definition: ValueNode.h:285
YSLib::str
const char * str
Definition: YException.cpp:60
YSLib::ynothrow
YB_PURE const _type size_t n ynothrow
Definition: YCoreUtilities.h:169
YSLib::ValueNode::Container
ystdex::mapped_set< ValueNode, ystdex::less<>, MappedSetTraits, allocator_type > Container
Definition: ValueNode.h:201
NPL::A1::name
const char * name
Definition: NPLA1.h:1876
YSLib::ValueNode::ValueNode
ValueNode(Container &&con)
Definition: ValueNode.h:248
YSLib::ValueNode::Access
YB_ATTR_nodiscard YB_PURE _type & Access(ValueNode &node)
访问节点的指定类型对象。
Definition: ValueNode.h:958
platform::Deref
YB_PURE yconstfn auto Deref(_type &&p) -> decltype(*p)
断言并解引用非空指针。
Definition: Debug.h:547
YSLib::ValueNode::try_emplace_hint
iterator try_emplace_hint(const_iterator hint, _tKey &&k, _tParams &&... args)
Definition: ValueNode.h:940
YSLib::ImplRet
ImplRet(FetchGlobalInstance().GetGUIHostRef()) YF_API void Execute(GUIApplication &
执行程序主消息循环。
YSLib::NodeLiteral::DefDeCopyMoveCtorAssignment
DefDeCopyMoveCtorAssignment(NodeLiteral) DefCvt(ynothrow
YSLib::ValueNode::ValueNode
ValueNode(tuple< _tParams1... > args1, tuple< _tParams2... > args2, allocator_type a={})
Definition: ValueNode.h:331
ynothrowv
#define ynothrowv
YSLib 无异常抛出保证验证：有条件地使用无异常抛出规范。
Definition: ydef.h:1219
ystdex::insert_or_assign
std::pair< typename _tAssocCon::iterator, bool > insert_or_assign(_tAssocCon &con, _tKey &&k, _tParam &&arg)
Definition: container.hpp:1068
ystdex
<memory> 特性测试宏。
Definition: ydef.h:1262
YSLib::ValueNode::MappedSetTraits::get_value_key
YB_ATTR_nodiscard static YB_PURE string get_value_key(tuple< _tParams1... >, tuple< _tParams2... > args2, tuple< _tParams3... >, allocator_type={})
Definition: ValueNode.h:179
YSLib::ValueNode::ValueNode
ValueNode(std::allocator_arg_t, allocator_type a, const Container &con, _tString &&str, _tParams &&... args)
构造：使用容器对象引用、字符串引用、值类型对象构造参数和分配器。
Definition: ValueNode.h:295
YSLib::ValueNode::CreateWith
Container CreateWith(_fCallable f) const &&
Definition: ValueNode.h:693
YSLib::AccessPtr
YB_ATTR_nodiscard YB_PURE observer_ptr< _type > AccessPtr(ValueNode &node) ynothrow
访问节点的指定类型对象指针。
Definition: ValueNode.h:976
YSLib::_tParams
YB_ATTR_nodiscard YB_PURE typename _tParams
Definition: ValueNode.h:1294
ystdex::is_interoperable
判断指定类型之间是否相同或可互相转换。
Definition: meta.hpp:716
YSLib::ValueNode::MappedSetTraits::yimpl
YB_ATTR_nodiscard static YB_PURE ValueNode typename _tOther typename yimpl(typename=enable_value_constructible_t< _tParams... >)
YSLib::ValueNode::PlaceUnchecked
_type & PlaceUnchecked(_tString &&str, _tParams &&... args)
Definition: ValueNode.h:736
YSLib::ValueNode::enable_not_key_t
ystdex::enable_if_t<!is_key_t< _tOther >::value > enable_not_key_t
Definition: ValueNode.h:87
YSLib::ValueNode::MappedSetTraits::extend_key
YB_ATTR_nodiscard static YB_PURE auto extend_key(_tKey &&k, _tCon &con) ynothrow -> decltype(ValueNode(std::allocator_arg, con.get_allocator(), NoContainer, yforward(k)))
Definition: ValueNode.h:107
ystdex::addressof
enable_if_t< has_no_overloaded_addressof< _type >::value, _type * > addressof(_type &r)
尝试对非重载 operator& 提供 constexpr 的 std::addressof 替代。
Definition: addressof.hpp:131
YSLib::ValueNode::AccessChild
YB_ATTR_nodiscard YB_PURE _type & AccessChild(ValueNode &node, _tParams &&... args)
访问子节点的指定类型对象。
Definition: ValueNode.h:1239
DefCvt
#define DefCvt(_q, _t,...)
Definition: YBaseMacro.h:206
YSLib::MakeNode
YB_ATTR_nodiscard YB_PURE ValueNode MakeNode(_tString &&str, _tParams &&... args)
传递指定名称和退化值参数构造值类型节点。
Definition: ValueNode.h:1317
YSLib::ValueNode::enable_value_constructible_t
ystdex::enable_if_t< std::is_constructible< ValueObject, _tParams... >::value > enable_value_constructible_t
Definition: ValueNode.h:94
ImplExpr
#define ImplExpr(...)
简单通用函数实现。
Definition: YBaseMacro.h:96
YSLib::ValueNode::insert_or_assign
iterator insert_or_assign(const_iterator hint, _tKey &&k, _tParam &&arg)
Definition: ValueNode.h:887
YSLib::ValueNode::ValueNode
ValueNode(std::allocator_arg_t, allocator_type a, NoContainerTag, _tString &&str, _tParams &&... args)
构造：使用字符串引用、值类型对象构造参数和分配器。
Definition: ValueNode.h:272
YSLib::ValueNode::MappedSetTraits::get_value_key
YB_ATTR_nodiscard static YB_PURE _tString && get_value_key(const pair< _tIn, _tIn > &, _tString &&str, allocator_type={})
Definition: ValueNode.h:158
DefGetter
#define DefGetter(_q, _t, _n,...)
Definition: YBaseMacro.h:241
YSLib::AccessNodePtr
YB_ATTR_nodiscard YB_PURE observer_ptr< ValueNode > AccessNodePtr(ValueNode::Container *, const _tKey &) ynothrow
Definition: ValueNode.h:1149
YSLib::ValueNode::CreateWith
Container CreateWith(_fCallable f) &&
Definition: ValueNode.h:687
YSLib::ValueNode::CreateWith
Container CreateWith(_fCallable f) const &
Definition: ValueNode.h:681
platform::p
return p p
Definition: YCLib/FileSystem.h:209
YSLib::ValueNode::allocator_type
pmr::polymorphic_allocator< ValueNode > allocator_type
分配器类型。
Definition: ValueNode.h:81
YSLib::ValueNode::ValueNode
ValueNode(std::allocator_arg_t, allocator_type a, Container &&con, _tString &&str, _tParams &&... args)
Definition: ValueNode.h:303
YSLib::AccessChild
const _type & AccessChild(const ValueNode &node, _tParams &&... args)
Definition: ValueNode.h:1245
const
const Decapsulate const Decapsulate &y ynothrow ContextNode &ctx const
Definition: NPLA1Forms.cpp:1629
ystdex::rbegin
reverse_iterator< _type * > rbegin(_type(&&array)[_vN])
Definition: range.hpp:390
ystdex::path_category::node
@ node
NPL::dst
YF_API const char src const string const char * dst
Definition: Dependency.h:96
DefDeMoveAssignment
#define DefDeMoveAssignment(_t)
Definition: YBaseMacro.h:191
YSLib::ValueNode::ValueNode
ValueNode(const Container &con)
构造：使用容器对象引用和可选的分配器。
Definition: ValueNode.h:242
YSLib::NodeLiteral::NodeLiteral
NodeLiteral(ListContainerTag, _tString &&str, std::initializer_list< _tLiteral > il, _tParams &&... args)
Definition: ValueNode.h:1524
YSLib::GetValueOf
YB_ATTR_nodiscard YF_API YB_PURE ValueObject GetValueOf(observer_ptr< const ValueNode >)
取指定名称指称的值。
Definition: ValueNode.cpp:166
YSLib::NodeLiteral::NodeLiteral
NodeLiteral(const ValueNode &nd)
Definition: ValueNode.h:1504
ystdex::try_emplace_hint
std::pair< typename _tAssocCon::iterator, bool > try_emplace_hint(_tAssocCon &con, typename _tAssocCon::const_iterator hint, _tKey &&k, _tParams &&... args)
Definition: container.hpp:1050
YSLib::vo
vo
Definition: YApplication.h:231
YSLib::ValueNode::ValueNode
ValueNode(const ValueNode &nd, allocator_type a)
Definition: ValueNode.h:353
YSLib::args
YB_ATTR_nodiscard YB_PURE typename _tParams && args
Definition: ValueNode.h:1299
ynoexcept
#define ynoexcept(...)
YSLib 无异常抛出保证：指定特定的异常规范。
Definition: ydef.h:1151
YSLib::ValueNode::DefDeMoveCtor
DefDeMoveCtor(ValueNode) ValueNode(ValueNode &&nd
YSLib::ValueNode::MappedSetTraits::get_value_key
YB_ATTR_nodiscard static YB_PURE string get_value_key(tuple< _tParams1... >, allocator_type={})
Definition: ValueNode.h:165
ystdex::transformed_iterator
变换迭代器。
Definition: iterator.hpp:196
YSLib::ValueNode::Value
ValueObject Value
Definition: ValueNode.h:223
YSLib::UnpackToNode
YB_ATTR_nodiscard YB_PURE UnpackToNode
Definition: ValueNode.h:1367
ystdex::ref
void ref(const _type &&)=delete
YSLib::ValueNode::ValueNode
ValueNode(NoContainerTag, _tString &&str, _tParams &&... args)
构造：使用字符串引用和值类型对象构造参数。
Definition: ValueNode.h:262
YSLib::NoContainer
yconstexpr const struct YSLib::NoContainerTag NoContainer
ystdex::remove_cvref_t
_t< remove_cvref< _type > > remove_cvref_t
Definition: meta.hpp:236
YSLib::CollectNodes
YB_ATTR_nodiscard YB_PURE ValueNode::Container CollectNodes(std::initializer_list< _tElem > il)
取指定值类型节点为成员的节点容器。
Definition: ValueNode.h:1390
YSLib::PDefH
PDefH(Environment &, FetchEnvironment,) ImplRet(FetchGlobalInstance().GetEnvironmentRef()) inline PDefH(GUIHost &
取单一环境对象引用。
YSLib::NoContainerTag
标记不使用容器。
Definition: ValueNode.h:55
YSLib::AccessNode
YB_ATTR_nodiscard YF_API YB_PURE ValueNode & AccessNode(ValueNode::Container *, const string &)
访问节点。
Definition: ValueNode.cpp:102
ystdex::cpp2017::begin
auto begin(_tRange &c) -> decltype(c.begin())
Definition: range.hpp:323
YSLib::a
YB_PURE const _type * a
Definition: YCoreUtilities.h:168
NPL::_tParam
_tParam
Definition: NPLA.h:2367
algorithm.hpp
泛型算法。