OGS
BaseLib::ConfigTree::Child Class Reference

Detailed Description

Read-only view of a child produced by getAllChildren().

A thin move-only wrapper around the child's own ConfigTree subtree. getAllChildren() marks every child tag as consumed in the parent, so the parent does not additionally warn about the tags themselves; instead each child polices itself.

A child counts as read once it is dereferenced via operator->() / operator*(). A child that is never dereferenced warns on destruction as unread whatever its content - this catches a whole child that was silently ignored, e.g. one whose tag name was mistyped. Once dereferenced, the child behaves exactly like a ConfigTree obtained from getConfigSubtree(): it owns its subtree and runs the normal checkAndInvalidate() on destruction, so any of its sub-children / attributes / immediate data that were not read produce the usual unread-element warnings.

Like a getConfigSubtree() result, a Child keeps the underlying tree alive through its shared top-level pointer, so it may safely outlive the ConfigTree it came from.

Definition at line 57 of file ConfigTree-impl.h.

#include <ConfigTree-impl.h>

Collaboration diagram for BaseLib::ConfigTree::Child:
[legend]

Public Member Functions

 Child (Child &&other) noexcept
 Child (Child const &)=delete
ConfigTree const * operator-> () const
ConfigTree const & operator* () const
 ~Child ()

Private Member Functions

 Child (ConfigTree &&ct)

Private Attributes

ConfigTree ct_
bool accessed_ = false

Friends

class ConfigTree

Constructor & Destructor Documentation

◆ Child() [1/3]

BaseLib::ConfigTree::Child::Child ( Child && other)
inlinenoexcept

Definition at line 60 of file ConfigTree-impl.h.

61 : ct_(std::move(other.ct_)), accessed_(other.accessed_)
62 {
63 }

References Child().

Referenced by Child(), and Child().

◆ Child() [2/3]

BaseLib::ConfigTree::Child::Child ( Child const & )
delete

References Child().

◆ ~Child()

BaseLib::ConfigTree::Child::~Child ( )
inline

A child returned by getAllChildren() but never dereferenced counts as unread and warns on destruction, whatever its content.

This is what makes getAllChildren() catch a whole child that was silently ignored - e.g. one whose tag name was mistyped - which the subtree's own content check cannot: a content-less child has nothing to report. A dereferenced child instead defers to that content check (its unread sub-children / attributes / immediate data warn as usual), so the warning here is suppressed and not duplicated.

Definition at line 87 of file ConfigTree-impl.h.

88 {
89 // ct_.tree_ == nullptr means this Child was moved from (the moved-to
90 // Child owns the subtree now); std::uncaught_exceptions() > 0 mirrors
91 // ConfigTree's own destructor, which stays silent during unwinding.
92 if (!accessed_ && ct_.tree_ != nullptr &&
93 std::uncaught_exceptions() == 0)
94 {
95 ct_.warning(
96 "This child, returned by getAllChildren(), has not been "
97 "read.");
98 ct_.tree_ = nullptr; // skip the subtree's own redundant check
99 }
100 }

References accessed_, and ct_.

◆ Child() [3/3]

BaseLib::ConfigTree::Child::Child ( ConfigTree && ct)
inlineexplicitprivate

Definition at line 104 of file ConfigTree-impl.h.

104: ct_(std::move(ct)) {}

References ConfigTree, and ct_.

Member Function Documentation

◆ operator*()

ConfigTree const & BaseLib::ConfigTree::Child::operator* ( ) const
inline

Definition at line 71 of file ConfigTree-impl.h.

72 {
73 accessed_ = true;
74 return ct_;
75 }

References accessed_, ConfigTree, and ct_.

◆ operator->()

ConfigTree const * BaseLib::ConfigTree::Child::operator-> ( ) const
inline

Definition at line 66 of file ConfigTree-impl.h.

67 {
68 accessed_ = true;
69 return &ct_;
70 }

References accessed_, ConfigTree, and ct_.

◆ ConfigTree

friend class ConfigTree
friend

Definition at line 103 of file ConfigTree-impl.h.

References ConfigTree.

Referenced by Child(), ConfigTree, operator*(), and operator->().

Member Data Documentation

◆ accessed_

bool BaseLib::ConfigTree::Child::accessed_ = false
mutableprivate

Whether operator->() / operator*() was ever called. Mutable because both are const accessors; a Child is logically const while being read.

Definition at line 109 of file ConfigTree-impl.h.

Referenced by ~Child(), operator*(), and operator->().

◆ ct_

ConfigTree BaseLib::ConfigTree::Child::ct_
private

Definition at line 106 of file ConfigTree-impl.h.

Referenced by Child(), ~Child(), operator*(), and operator->().


The documentation for this class was generated from the following file: