"Fossies" - the Fresh Open Source Software Archive

Member "dune-typetree-2.8.0/dune/typetree/nodeinterface.hh" (31 Aug 2021, 3456 Bytes) of package /linux/misc/dune/dune-typetree-2.8.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "nodeinterface.hh" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 2.8.0_vs_2.9.0.

    1 // -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
    2 // vi: set et ts=8 sw=2 sts=2:
    3 
    4 #ifndef DUNE_TYPETREE_NODEINTERFACE_HH
    5 #define DUNE_TYPETREE_NODEINTERFACE_HH
    6 
    7 #include <cstddef>
    8 #include <type_traits>
    9 
   10 #include <dune/common/documentation.hh>
   11 
   12 namespace Dune {
   13   namespace TypeTree {
   14 
   15     /** \addtogroup Nodes
   16      *  \ingroup TypeTree
   17      *  \{
   18      */
   19 
   20     /** \brief Interface for nodes in a \ref TypeTree.
   21      *
   22      * This class cannot be used itself, it is for documentation purposes
   23      * only.
   24      *
   25      * \note Constructor signatures are explicitly not specified by this
   26      *       interface.
   27      * \note In addition, every node in a tree must be derived from one of
   28      *       the node base classes LeafNode, PowerNode, DynamicPowerNodeTag, or
   29      *       CompositeNode, or from a base class for a yet-to-be-defined new
   30      *       node type.
   31      */
   32     struct NodeInterface
   33     {
   34       //! Whether this is a leaf node in a \ref TypeTree.
   35       static const bool isLeaf = implementationDefined;
   36 
   37       //! Whether this is a power node in the \ref TypeTree.
   38       static const bool isPower = implementationDefined;
   39 
   40       //! Whether this is a composite node in the \ref TypeTree.
   41       static const bool isComposite = implementationDefined;
   42 
   43       //! Number of children of this node in the \ref TypeTree.
   44       /**
   45        * \note Might not be implemented for nodes with dynamic size.
   46        * Use the function `node.degree()` or `degree(node)` instead.
   47        */
   48       static const std::size_t CHILDREN = implementationDefined;
   49 
   50       //! The type tag that describes what kind of node this is
   51       /**
   52        * One of LeafNodeTag, PowerNodeTag or CompositeNodeTag.
   53        * Other tags are also possible when new
   54        * kinds of nodes are defined.
   55        */
   56       typedef ImplementationDefined NodeTag;
   57 
   58       //! container type to pass around a collection of children
   59       /**
   60        * \note This typedef is not present for leaf nodes.
   61        */
   62       typedef ImplementationDefined NodeStorage;
   63     };
   64 
   65     //! Returns the node tag of the given Node.
   66     template<typename Node>
   67     using NodeTag = typename std::decay_t<Node>::NodeTag;
   68 
   69     //! Returns the implementation tag of the given Node.
   70     template<typename T>
   71     using ImplementationTag = typename std::decay_t<T>::ImplementationTag;
   72 
   73 
   74     //! Returns the degree of node as run time information.
   75     template<typename Node>
   76     std::size_t degree(const Node& node)
   77     {
   78       return degree(&node,NodeTag<Node>());
   79     }
   80 
   81 #ifndef DOXYGEN
   82 
   83     //! Default implementation of degree dispatch function.
   84     /**
   85      * This dispatches using a pointer to the node instead of a reference,
   86      * as we can easily create a constexpr pointer to the node, while a constexpr
   87      * reference might not even be possible to manufacture (std::declval is not
   88      * constexpr).
   89      */
   90     template<typename Node, typename NodeTag>
   91     std::size_t degree(const Node* node, NodeTag)
   92     {
   93       return node->degree();
   94     }
   95 
   96 #endif // DOXYGEN
   97 
   98     //! Returns the statically known degree of the given Node type as a std::integral_constant.
   99     /**
  100      * \note If a node has a static number of children, it returns directly the degree as
  101      * integral-constant.
  102      */
  103     template<typename Node>
  104     using StaticDegree = decltype(Node::degree());
  105 
  106     //! \} group Nodes
  107 
  108   } // namespace TypeTree
  109 } //namespace Dune
  110 
  111 #endif //  DUNE_TYPETREE_NODEINTERFACE_HH