1 // ----------------------------------------------------------------------------
2 // Copyright (C) 2002-2006 Marcin Kalicinski
3 // Copyright (C) 2009 Sebastian Redl
5 // Distributed under the Boost Software License, Version 1.0.
6 // (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
9 // For more information, see www.boost.org
10 // ----------------------------------------------------------------------------
11 #ifndef BOOST_PROPERTY_TREE_DETAIL_PTREE_IMPLEMENTATION_HPP_INCLUDED
12 #define BOOST_PROPERTY_TREE_DETAIL_PTREE_IMPLEMENTATION_HPP_INCLUDED
14 #include <boost/iterator/iterator_adaptor.hpp>
15 #include <boost/iterator/reverse_iterator.hpp>
16 #include <boost/assert.hpp>
17 #include <boost/utility/swap.hpp>
20 #if (defined(BOOST_MSVC) && \
21 (_MSC_FULL_VER >= 160000000 && _MSC_FULL_VER < 170000000)) || \
22 (defined(BOOST_INTEL_WIN) && \
23 defined(BOOST_DINKUMWARE_STDLIB))
24 #define BOOST_PROPERTY_TREE_PAIR_BUG
27 namespace boost { namespace property_tree
29 template <class K, class D, class C>
30 struct basic_ptree<K, D, C>::subs
33 // The actual child container.
34 #if defined(BOOST_PROPERTY_TREE_PAIR_BUG)
35 // MSVC 10 has moved std::pair's members to a base
36 // class. Unfortunately this does break the interface.
37 BOOST_STATIC_CONSTANT(unsigned,
38 first_offset = offsetof(value_type, first));
40 typedef multi_index_container<value_type,
41 multi_index::indexed_by<
42 multi_index::sequenced<>,
43 multi_index::ordered_non_unique<multi_index::tag<by_name>,
44 #if defined(BOOST_PROPERTY_TREE_PAIR_BUG)
45 multi_index::member_offset<value_type, const key_type,
48 multi_index::member<value_type, const key_type,
56 // The by-name lookup index.
57 typedef typename base_container::template index<by_name>::type
60 // Access functions for getting to the children of a tree.
61 static base_container& ch(self_type *s) {
62 return *static_cast<base_container*>(s->m_children);
64 static const base_container& ch(const self_type *s) {
65 return *static_cast<const base_container*>(s->m_children);
67 static by_name_index& assoc(self_type *s) {
68 return ch(s).BOOST_NESTED_TEMPLATE get<by_name>();
70 static const by_name_index& assoc(const self_type *s) {
71 return ch(s).BOOST_NESTED_TEMPLATE get<by_name>();
74 template <class K, class D, class C>
75 class basic_ptree<K, D, C>::iterator : public boost::iterator_adaptor<
76 iterator, typename subs::base_container::iterator, value_type>
78 friend class boost::iterator_core_access;
79 typedef boost::iterator_adaptor<
80 iterator, typename subs::base_container::iterator, value_type>
83 typedef typename baset::reference reference;
85 explicit iterator(typename iterator::base_type b)
86 : iterator::iterator_adaptor_(b)
88 reference dereference() const
90 // multi_index doesn't allow modification of its values, because
91 // indexes could sort by anything, and modification screws that up.
92 // However, we only sort by the key, and it's protected against
93 // modification in the value_type, so this const_cast is safe.
94 return const_cast<reference>(*this->base_reference());
97 template <class K, class D, class C>
98 class basic_ptree<K, D, C>::const_iterator : public boost::iterator_adaptor<
99 const_iterator, typename subs::base_container::const_iterator>
103 explicit const_iterator(typename const_iterator::base_type b)
104 : const_iterator::iterator_adaptor_(b)
106 const_iterator(iterator b)
107 : const_iterator::iterator_adaptor_(b.base())
110 template <class K, class D, class C>
111 class basic_ptree<K, D, C>::reverse_iterator
112 : public boost::reverse_iterator<iterator>
115 reverse_iterator() {}
116 explicit reverse_iterator(iterator b)
117 : boost::reverse_iterator<iterator>(b)
120 template <class K, class D, class C>
121 class basic_ptree<K, D, C>::const_reverse_iterator
122 : public boost::reverse_iterator<const_iterator>
125 const_reverse_iterator() {}
126 explicit const_reverse_iterator(const_iterator b)
127 : boost::reverse_iterator<const_iterator>(b)
129 const_reverse_iterator(
130 typename basic_ptree<K, D, C>::reverse_iterator b)
131 : boost::reverse_iterator<const_iterator>(b)
134 template <class K, class D, class C>
135 class basic_ptree<K, D, C>::assoc_iterator
136 : public boost::iterator_adaptor<assoc_iterator,
137 typename subs::by_name_index::iterator,
140 friend class boost::iterator_core_access;
141 typedef boost::iterator_adaptor<assoc_iterator,
142 typename subs::by_name_index::iterator,
146 typedef typename baset::reference reference;
148 explicit assoc_iterator(typename assoc_iterator::base_type b)
149 : assoc_iterator::iterator_adaptor_(b)
151 reference dereference() const
153 return const_cast<reference>(*this->base_reference());
156 template <class K, class D, class C>
157 class basic_ptree<K, D, C>::const_assoc_iterator
158 : public boost::iterator_adaptor<const_assoc_iterator,
159 typename subs::by_name_index::const_iterator>
162 const_assoc_iterator() {}
163 explicit const_assoc_iterator(
164 typename const_assoc_iterator::base_type b)
165 : const_assoc_iterator::iterator_adaptor_(b)
167 const_assoc_iterator(assoc_iterator b)
168 : const_assoc_iterator::iterator_adaptor_(b.base())
175 // Perhaps the children collection could be created on-demand only, to
176 // reduce heap traffic. But that's a lot more work to implement.
178 template<class K, class D, class C> inline
179 basic_ptree<K, D, C>::basic_ptree()
180 : m_children(new typename subs::base_container)
184 template<class K, class D, class C> inline
185 basic_ptree<K, D, C>::basic_ptree(const data_type &d)
186 : m_data(d), m_children(new typename subs::base_container)
190 template<class K, class D, class C> inline
191 basic_ptree<K, D, C>::basic_ptree(const basic_ptree<K, D, C> &rhs)
192 : m_data(rhs.m_data),
193 m_children(new typename subs::base_container(subs::ch(&rhs)))
197 template<class K, class D, class C>
198 basic_ptree<K, D, C> &
199 basic_ptree<K, D, C>::operator =(const basic_ptree<K, D, C> &rhs)
201 self_type(rhs).swap(*this);
205 template<class K, class D, class C>
206 basic_ptree<K, D, C>::~basic_ptree()
208 delete &subs::ch(this);
211 template<class K, class D, class C> inline
212 void basic_ptree<K, D, C>::swap(basic_ptree<K, D, C> &rhs)
214 boost::swap(m_data, rhs.m_data);
215 // Void pointers, no ADL necessary
216 std::swap(m_children, rhs.m_children);
221 template<class K, class D, class C> inline
222 typename basic_ptree<K, D, C>::size_type
223 basic_ptree<K, D, C>::size() const
225 return subs::ch(this).size();
228 template<class K, class D, class C> inline
229 typename basic_ptree<K, D, C>::size_type
230 basic_ptree<K, D, C>::max_size() const
232 return subs::ch(this).max_size();
235 template<class K, class D, class C> inline
236 bool basic_ptree<K, D, C>::empty() const
238 return subs::ch(this).empty();
241 template<class K, class D, class C> inline
242 typename basic_ptree<K, D, C>::iterator
243 basic_ptree<K, D, C>::begin()
245 return iterator(subs::ch(this).begin());
248 template<class K, class D, class C> inline
249 typename basic_ptree<K, D, C>::const_iterator
250 basic_ptree<K, D, C>::begin() const
252 return const_iterator(subs::ch(this).begin());
255 template<class K, class D, class C> inline
256 typename basic_ptree<K, D, C>::iterator
257 basic_ptree<K, D, C>::end()
259 return iterator(subs::ch(this).end());
262 template<class K, class D, class C> inline
263 typename basic_ptree<K, D, C>::const_iterator
264 basic_ptree<K, D, C>::end() const
266 return const_iterator(subs::ch(this).end());
269 template<class K, class D, class C> inline
270 typename basic_ptree<K, D, C>::reverse_iterator
271 basic_ptree<K, D, C>::rbegin()
273 return reverse_iterator(this->end());
276 template<class K, class D, class C> inline
277 typename basic_ptree<K, D, C>::const_reverse_iterator
278 basic_ptree<K, D, C>::rbegin() const
280 return const_reverse_iterator(this->end());
283 template<class K, class D, class C> inline
284 typename basic_ptree<K, D, C>::reverse_iterator
285 basic_ptree<K, D, C>::rend()
287 return reverse_iterator(this->begin());
290 template<class K, class D, class C> inline
291 typename basic_ptree<K, D, C>::const_reverse_iterator
292 basic_ptree<K, D, C>::rend() const
294 return const_reverse_iterator(this->begin());
297 template<class K, class D, class C> inline
298 typename basic_ptree<K, D, C>::value_type &
299 basic_ptree<K, D, C>::front()
301 return const_cast<value_type&>(subs::ch(this).front());
304 template<class K, class D, class C> inline
305 const typename basic_ptree<K, D, C>::value_type &
306 basic_ptree<K, D, C>::front() const
308 return subs::ch(this).front();
311 template<class K, class D, class C> inline
312 typename basic_ptree<K, D, C>::value_type &
313 basic_ptree<K, D, C>::back()
315 return const_cast<value_type&>(subs::ch(this).back());
318 template<class K, class D, class C> inline
319 const typename basic_ptree<K, D, C>::value_type &
320 basic_ptree<K, D, C>::back() const
322 return subs::ch(this).back();
325 template<class K, class D, class C> inline
326 typename basic_ptree<K, D, C>::iterator
327 basic_ptree<K, D, C>::insert(iterator where, const value_type &value)
329 return iterator(subs::ch(this).insert(where.base(), value).first);
332 template<class K, class D, class C>
333 template<class It> inline
334 void basic_ptree<K, D, C>::insert(iterator where, It first, It last)
336 subs::ch(this).insert(where.base(), first, last);
339 template<class K, class D, class C> inline
340 typename basic_ptree<K, D, C>::iterator
341 basic_ptree<K, D, C>::erase(iterator where)
343 return iterator(subs::ch(this).erase(where.base()));
346 template<class K, class D, class C> inline
347 typename basic_ptree<K, D, C>::iterator
348 basic_ptree<K, D, C>::erase(iterator first, iterator last)
350 return iterator(subs::ch(this).erase(first.base(), last.base()));
353 template<class K, class D, class C> inline
354 typename basic_ptree<K, D, C>::iterator
355 basic_ptree<K, D, C>::push_front(const value_type &value)
357 return iterator(subs::ch(this).push_front(value).first);
360 template<class K, class D, class C> inline
361 typename basic_ptree<K, D, C>::iterator
362 basic_ptree<K, D, C>::push_back(const value_type &value)
364 return iterator(subs::ch(this).push_back(value).first);
367 template<class K, class D, class C> inline
368 void basic_ptree<K, D, C>::pop_front()
370 subs::ch(this).pop_front();
373 template<class K, class D, class C> inline
374 void basic_ptree<K, D, C>::pop_back()
376 subs::ch(this).pop_back();
379 template<class K, class D, class C> inline
380 void basic_ptree<K, D, C>::reverse()
382 subs::ch(this).reverse();
389 template <typename P>
390 bool operator ()(const P& lhs, const P& rhs) const {
391 return lhs.first < rhs.first;
395 template <typename C>
398 template <typename P>
399 bool operator ()(const P& lhs, const P& rhs) const {
401 return !c(lhs.first, rhs.first) &&
402 !c(rhs.first, lhs.first) &&
403 lhs.second == rhs.second;
407 template <typename C, typename MI>
408 bool equal_children(const MI& ch1, const MI& ch2) {
409 // Assumes ch1.size() == ch2.size()
410 return std::equal(ch1.begin(), ch1.end(),
411 ch2.begin(), equal_pred<C>());
415 template<class K, class D, class C> inline
416 void basic_ptree<K, D, C>::sort()
418 sort(impl::by_first());
421 template<class K, class D, class C>
422 template<class Compare> inline
423 void basic_ptree<K, D, C>::sort(Compare comp)
425 subs::ch(this).sort(comp);
430 template<class K, class D, class C> inline
431 bool basic_ptree<K, D, C>::operator ==(
432 const basic_ptree<K, D, C> &rhs) const
434 // The size test is cheap, so add it as an optimization
435 return size() == rhs.size() && data() == rhs.data() &&
436 impl::equal_children<C>(subs::ch(this), subs::ch(&rhs));
439 template<class K, class D, class C> inline
440 bool basic_ptree<K, D, C>::operator !=(
441 const basic_ptree<K, D, C> &rhs) const
443 return !(*this == rhs);
448 template<class K, class D, class C> inline
449 typename basic_ptree<K, D, C>::assoc_iterator
450 basic_ptree<K, D, C>::ordered_begin()
452 return assoc_iterator(subs::assoc(this).begin());
455 template<class K, class D, class C> inline
456 typename basic_ptree<K, D, C>::const_assoc_iterator
457 basic_ptree<K, D, C>::ordered_begin() const
459 return const_assoc_iterator(subs::assoc(this).begin());
462 template<class K, class D, class C> inline
463 typename basic_ptree<K, D, C>::assoc_iterator
464 basic_ptree<K, D, C>::not_found()
466 return assoc_iterator(subs::assoc(this).end());
469 template<class K, class D, class C> inline
470 typename basic_ptree<K, D, C>::const_assoc_iterator
471 basic_ptree<K, D, C>::not_found() const
473 return const_assoc_iterator(subs::assoc(this).end());
476 template<class K, class D, class C> inline
477 typename basic_ptree<K, D, C>::assoc_iterator
478 basic_ptree<K, D, C>::find(const key_type &key)
480 return assoc_iterator(subs::assoc(this).find(key));
483 template<class K, class D, class C> inline
484 typename basic_ptree<K, D, C>::const_assoc_iterator
485 basic_ptree<K, D, C>::find(const key_type &key) const
487 return const_assoc_iterator(subs::assoc(this).find(key));
490 template<class K, class D, class C> inline
492 typename basic_ptree<K, D, C>::assoc_iterator,
493 typename basic_ptree<K, D, C>::assoc_iterator
494 > basic_ptree<K, D, C>::equal_range(const key_type &key)
496 std::pair<typename subs::by_name_index::iterator,
497 typename subs::by_name_index::iterator> r(
498 subs::assoc(this).equal_range(key));
499 return std::pair<assoc_iterator, assoc_iterator>(
500 assoc_iterator(r.first), assoc_iterator(r.second));
503 template<class K, class D, class C> inline
505 typename basic_ptree<K, D, C>::const_assoc_iterator,
506 typename basic_ptree<K, D, C>::const_assoc_iterator
507 > basic_ptree<K, D, C>::equal_range(const key_type &key) const
509 std::pair<typename subs::by_name_index::const_iterator,
510 typename subs::by_name_index::const_iterator> r(
511 subs::assoc(this).equal_range(key));
512 return std::pair<const_assoc_iterator, const_assoc_iterator>(
513 const_assoc_iterator(r.first), const_assoc_iterator(r.second));
516 template<class K, class D, class C> inline
517 typename basic_ptree<K, D, C>::size_type
518 basic_ptree<K, D, C>::count(const key_type &key) const
520 return subs::assoc(this).count(key);
523 template<class K, class D, class C> inline
524 typename basic_ptree<K, D, C>::size_type
525 basic_ptree<K, D, C>::erase(const key_type &key)
527 return subs::assoc(this).erase(key);
530 template<class K, class D, class C> inline
531 typename basic_ptree<K, D, C>::iterator
532 basic_ptree<K, D, C>::to_iterator(assoc_iterator ai)
534 return iterator(subs::ch(this).
535 BOOST_NESTED_TEMPLATE project<0>(ai.base()));
538 template<class K, class D, class C> inline
539 typename basic_ptree<K, D, C>::const_iterator
540 basic_ptree<K, D, C>::to_iterator(const_assoc_iterator ai) const
542 return const_iterator(subs::ch(this).
543 BOOST_NESTED_TEMPLATE project<0>(ai.base()));
546 // Property tree view
548 template<class K, class D, class C> inline
549 typename basic_ptree<K, D, C>::data_type &
550 basic_ptree<K, D, C>::data()
555 template<class K, class D, class C> inline
556 const typename basic_ptree<K, D, C>::data_type &
557 basic_ptree<K, D, C>::data() const
562 template<class K, class D, class C> inline
563 void basic_ptree<K, D, C>::clear()
565 m_data = data_type();
566 subs::ch(this).clear();
569 template<class K, class D, class C>
570 basic_ptree<K, D, C> &
571 basic_ptree<K, D, C>::get_child(const path_type &path)
574 self_type *n = walk_path(p);
576 BOOST_PROPERTY_TREE_THROW(ptree_bad_path("No such node", path));
581 template<class K, class D, class C> inline
582 const basic_ptree<K, D, C> &
583 basic_ptree<K, D, C>::get_child(const path_type &path) const
585 return const_cast<self_type*>(this)->get_child(path);
588 template<class K, class D, class C> inline
589 basic_ptree<K, D, C> &
590 basic_ptree<K, D, C>::get_child(const path_type &path,
591 self_type &default_value)
594 self_type *n = walk_path(p);
595 return n ? *n : default_value;
598 template<class K, class D, class C> inline
599 const basic_ptree<K, D, C> &
600 basic_ptree<K, D, C>::get_child(const path_type &path,
601 const self_type &default_value) const
603 return const_cast<self_type*>(this)->get_child(path,
604 const_cast<self_type&>(default_value));
608 template<class K, class D, class C>
609 optional<basic_ptree<K, D, C> &>
610 basic_ptree<K, D, C>::get_child_optional(const path_type &path)
613 self_type *n = walk_path(p);
615 return optional<self_type&>();
620 template<class K, class D, class C>
621 optional<const basic_ptree<K, D, C> &>
622 basic_ptree<K, D, C>::get_child_optional(const path_type &path) const
625 self_type *n = walk_path(p);
627 return optional<const self_type&>();
632 template<class K, class D, class C>
633 basic_ptree<K, D, C> &
634 basic_ptree<K, D, C>::put_child(const path_type &path,
635 const self_type &value)
638 self_type &parent = force_path(p);
639 // Got the parent. Now get the correct child.
640 key_type fragment = p.reduce();
641 assoc_iterator el = parent.find(fragment);
642 // If the new child exists, replace it.
643 if(el != parent.not_found()) {
644 return el->second = value;
646 return parent.push_back(value_type(fragment, value))->second;
650 template<class K, class D, class C>
651 basic_ptree<K, D, C> &
652 basic_ptree<K, D, C>::add_child(const path_type &path,
653 const self_type &value)
656 self_type &parent = force_path(p);
658 key_type fragment = p.reduce();
659 return parent.push_back(value_type(fragment, value))->second;
662 template<class K, class D, class C>
663 template<class Type, class Translator>
664 typename boost::enable_if<detail::is_translator<Translator>, Type>::type
665 basic_ptree<K, D, C>::get_value(Translator tr) const
667 if(boost::optional<Type> o = get_value_optional<Type>(tr)) {
670 BOOST_PROPERTY_TREE_THROW(ptree_bad_data(
671 std::string("conversion of data to type \"") +
672 typeid(Type).name() + "\" failed", data()));
675 template<class K, class D, class C>
676 template<class Type> inline
677 Type basic_ptree<K, D, C>::get_value() const
679 return get_value<Type>(
680 typename translator_between<data_type, Type>::type());
683 template<class K, class D, class C>
684 template<class Type, class Translator> inline
685 Type basic_ptree<K, D, C>::get_value(const Type &default_value,
688 return get_value_optional<Type>(tr).get_value_or(default_value);
691 template<class K, class D, class C>
692 template <class Ch, class Translator>
693 typename boost::enable_if<
694 detail::is_character<Ch>,
695 std::basic_string<Ch>
697 basic_ptree<K, D, C>::get_value(const Ch *default_value, Translator tr)const
699 return get_value<std::basic_string<Ch>, Translator>(default_value, tr);
702 template<class K, class D, class C>
703 template<class Type> inline
704 typename boost::disable_if<detail::is_translator<Type>, Type>::type
705 basic_ptree<K, D, C>::get_value(const Type &default_value) const
707 return get_value(default_value,
708 typename translator_between<data_type, Type>::type());
711 template<class K, class D, class C>
713 typename boost::enable_if<
714 detail::is_character<Ch>,
715 std::basic_string<Ch>
717 basic_ptree<K, D, C>::get_value(const Ch *default_value) const
719 return get_value< std::basic_string<Ch> >(default_value);
722 template<class K, class D, class C>
723 template<class Type, class Translator> inline
724 optional<Type> basic_ptree<K, D, C>::get_value_optional(
727 return tr.get_value(data());
730 template<class K, class D, class C>
731 template<class Type> inline
732 optional<Type> basic_ptree<K, D, C>::get_value_optional() const
734 return get_value_optional<Type>(
735 typename translator_between<data_type, Type>::type());
738 template<class K, class D, class C>
739 template<class Type, class Translator> inline
740 typename boost::enable_if<detail::is_translator<Translator>, Type>::type
741 basic_ptree<K, D, C>::get(const path_type &path,
744 return get_child(path).BOOST_NESTED_TEMPLATE get_value<Type>(tr);
747 template<class K, class D, class C>
748 template<class Type> inline
749 Type basic_ptree<K, D, C>::get(const path_type &path) const
751 return get_child(path).BOOST_NESTED_TEMPLATE get_value<Type>();
754 template<class K, class D, class C>
755 template<class Type, class Translator> inline
756 Type basic_ptree<K, D, C>::get(const path_type &path,
757 const Type &default_value,
760 return get_optional<Type>(path, tr).get_value_or(default_value);
763 template<class K, class D, class C>
764 template <class Ch, class Translator>
765 typename boost::enable_if<
766 detail::is_character<Ch>,
767 std::basic_string<Ch>
769 basic_ptree<K, D, C>::get(
770 const path_type &path, const Ch *default_value, Translator tr) const
772 return get<std::basic_string<Ch>, Translator>(path, default_value, tr);
775 template<class K, class D, class C>
776 template<class Type> inline
777 typename boost::disable_if<detail::is_translator<Type>, Type>::type
778 basic_ptree<K, D, C>::get(const path_type &path,
779 const Type &default_value) const
781 return get_optional<Type>(path).get_value_or(default_value);
784 template<class K, class D, class C>
786 typename boost::enable_if<
787 detail::is_character<Ch>,
788 std::basic_string<Ch>
790 basic_ptree<K, D, C>::get(
791 const path_type &path, const Ch *default_value) const
793 return get< std::basic_string<Ch> >(path, default_value);
796 template<class K, class D, class C>
797 template<class Type, class Translator>
798 optional<Type> basic_ptree<K, D, C>::get_optional(const path_type &path,
801 if (optional<const self_type&> child = get_child_optional(path))
803 BOOST_NESTED_TEMPLATE get_value_optional<Type>(tr);
805 return optional<Type>();
808 template<class K, class D, class C>
810 optional<Type> basic_ptree<K, D, C>::get_optional(
811 const path_type &path) const
813 if (optional<const self_type&> child = get_child_optional(path))
814 return child.get().BOOST_NESTED_TEMPLATE get_value_optional<Type>();
816 return optional<Type>();
819 template<class K, class D, class C>
820 template<class Type, class Translator>
821 void basic_ptree<K, D, C>::put_value(const Type &value, Translator tr)
823 if(optional<data_type> o = tr.put_value(value)) {
826 BOOST_PROPERTY_TREE_THROW(ptree_bad_data(
827 std::string("conversion of type \"") + typeid(Type).name() +
828 "\" to data failed", boost::any()));
832 template<class K, class D, class C>
833 template<class Type> inline
834 void basic_ptree<K, D, C>::put_value(const Type &value)
836 put_value(value, typename translator_between<data_type, Type>::type());
839 template<class K, class D, class C>
840 template<class Type, typename Translator>
841 basic_ptree<K, D, C> & basic_ptree<K, D, C>::put(
842 const path_type &path, const Type &value, Translator tr)
844 if(optional<self_type &> child = get_child_optional(path)) {
845 child.get().put_value(value, tr);
848 self_type &child2 = put_child(path, self_type());
849 child2.put_value(value, tr);
854 template<class K, class D, class C>
855 template<class Type> inline
856 basic_ptree<K, D, C> & basic_ptree<K, D, C>::put(
857 const path_type &path, const Type &value)
859 return put(path, value,
860 typename translator_between<data_type, Type>::type());
863 template<class K, class D, class C>
864 template<class Type, typename Translator> inline
865 basic_ptree<K, D, C> & basic_ptree<K, D, C>::add(
866 const path_type &path, const Type &value, Translator tr)
868 self_type &child = add_child(path, self_type());
869 child.put_value(value, tr);
873 template<class K, class D, class C>
874 template<class Type> inline
875 basic_ptree<K, D, C> & basic_ptree<K, D, C>::add(
876 const path_type &path, const Type &value)
878 return add(path, value,
879 typename translator_between<data_type, Type>::type());
883 template<class K, class D, class C>
884 basic_ptree<K, D, C> *
885 basic_ptree<K, D, C>::walk_path(path_type &p) const
888 // I'm the child we're looking for.
889 return const_cast<basic_ptree*>(this);
891 // Recurse down the tree to find the path.
892 key_type fragment = p.reduce();
893 const_assoc_iterator el = find(fragment);
894 if(el == not_found()) {
898 // Not done yet, recurse.
899 return el->second.walk_path(p);
902 template<class K, class D, class C>
903 basic_ptree<K, D, C> & basic_ptree<K, D, C>::force_path(path_type &p)
905 BOOST_ASSERT(!p.empty() && "Empty path not allowed for put_child.");
907 // I'm the parent we're looking for.
910 key_type fragment = p.reduce();
911 assoc_iterator el = find(fragment);
912 // If we've found an existing child, go down that path. Else
914 self_type& child = el == not_found() ?
915 push_back(value_type(fragment, self_type()))->second : el->second;
916 return child.force_path(p);
921 template<class K, class D, class C>
922 inline void swap(basic_ptree<K, D, C> &pt1, basic_ptree<K, D, C> &pt2)
929 #if defined(BOOST_PROPERTY_TREE_PAIR_BUG)
930 #undef BOOST_PROPERTY_TREE_PAIR_BUG