template class detangled::virtual_accessor

Overview

A virtual_accessor is an accessor on a virtual tree. More…

#include <virtual_accessor.h>

template <class ContainerType>
class virtual_accessor: public detangled::accessor {
public:
    // typedefs

    typedef accessor<ContainerType> base_type;
    typedef typename base_type::container_type container_type;
    typedef typename base_type::node_type node_type;
    typedef typename base_type::value_type_t value_type_t;

    // construction

    virtual_accessor(base_type& pos);
    virtual_accessor(node_type& node, int16_t depth);
    virtual_accessor(const virtual_accessor&);
    virtual_accessor(virtual_accessor&&);

    // methods

    virtual_accessor&
    operator=(const virtual_accessor&);

    virtual_accessor&
    operator=(virtual_accessor&&);

    operator bool() const;

    bool
    operator==(const virtual_accessor& other) const;

    bool
    operator!=(const virtual_accessor& other) const;

    bool
    is_root() const;

    uint32_t
    depth() const;

    void
    up();

    void
    root();

    template <side wing>
    bool
    down();

    bool
    down(side wing);
};

Inherited Members

public:
    // typedefs

    typedef typename ::std::remove_cv<Container>::type container_type;
    typedef typename std::conditional<is_const, const container_type, container_type>::type node_type;
    typedef typename std::conditional<is_const, const typename container_type::value_type, typename container_type::value_type>::type value_type_t;

    // fields

    static constexpr bool is_const = ::std::is_const<Container>::value;

    // methods

    accessor&
    operator=(const accessor&);

    accessor&
    operator=(accessor&&);

    value_type_t&
    operator*() const;

    node_type&
    node() const;

    node_type*
    operator->() const;

    operator bool() const;

    bool
    operator==(const accessor& other) const;

    bool
    operator!=(const accessor& other) const;

    bool
    is_root() const;

    uint32_t
    depth() const;

    void
    up();

    void
    root();

    template <side wing>
    bool
    down();

    bool
    down(side wing);

    template <side wing>
    bool
    ancestor();

    bool
    ancestor(side wing);

    accessor
    common_ancestor(const accessor& other) const;

    accessor<container_type>
    non_const() const;

Detailed Documentation

A virtual_accessor is an accessor on a virtual tree.

Overview:

It’s domain of operation may be limited to a subtree of a physical tree. All objects created from copying moving this object will retain this behaviour. All virtual_accessors created with the same logical subtree are semantically compatible. See constructor for notes.

Minor modifications are done on methods defined on the parent detangled::accessor class. These are not done through virtual methods for efficiency but also because clients are reasonably expected to not need to erase type information when dealing with detangled::accessor and virtual_accessor class family objects.

Properties:

Operations on end accessors:

All operations are well-defined on end accessor except the derefernce operations. Specifically movement operations on end accessor are well defined. Even more specifically in detangled::accessor an *end*ed accessor can in no way be navigated back to the tree (except through reassignment which is really not navigating it). In the virtual_accessor objects navigatiion using down / root etc. for navigating back to the tree is well defined.

Validity in the face of Mutating methods:

virtual_accessors are not stable (see accessor Validity in the face of …). Specifically modifying the underlying tree may make the iterator invalid. More specifically modifying the ‘virtual tree’ in such a way as to change the ‘depth’ of a node that any virtual_accessor is pointing to would invalidate this accessor. This also means that modifications including height changes done to any physical ancestor of the virtual root of the tree would not invalidate an accessor. A clean way to read it is ‘any modification which changes the ‘depth’ of the pointed-to node in the virtual tree that an accessor is referring to would invalidate it.

Parameters:

ContainerType

is the same as that for detangled::accessor.

Construction

virtual_accessor(base_type& pos)

Parameters:

pos

is the position of the accessor type which is treated as root.

virtual_accessor(node_type& node, int16_t depth)

An accessor with node set as the root of a virtual tree. All operations on this object will restrict the accessor to this virtual tree. See up(), root() for noticeable differences from how detangled::accessor objects behave.

Parameters:

node

is used in detangled::accessor::accessor() parent constructor call.

depth

of 0 indicates the root node. It can also be given a special value of -1 which indicates an accessor which is indicative of an end accessor. Any other value will cause a std::abort.

Methods

operator bool() const

Returns:

true iff we are not at end.

bool
operator==(const virtual_accessor& other) const

Returns:

true iff node being pointed to is the same and the virtual tree that we are part of is the same.

uint32_t
depth() const

Depth with respect to the virtual root that we operating under. 0 at virtual root. See class documentation for more information. Invalid at end.

Complexity: O(1)

void
root()

Same as parent with the difference that calling on end objects will move it to the virtual root of the subtree this is operating under.

template <side wing>
bool
down()

Same as parent with the difference that calling down<*> on end objects is identical to calling root and always returns true in that case.