.. _cpp-dg/Builder: ********************************************************** dg/Builder.hpp ********************************************************** .. default-domain:: cpp .. default-role:: cpp:expr .. py:currentmodule:: mod .. cpp:namespace:: mod Class ``dg::Builder`` -------------------------------------------------------------------------------------------------------------------------------- .. class:: dg::Builder An RAII-style object obtained from :cpp:func:`DG::build`. On destruction of an active builder object the owning :cpp:class:`DG` will be locked for further modifications. Builder objects are move-only types, and a moved from object becomes an inactive builder, not associated with any :cpp:class:`DG`. Synopsis ^^^^^^^^ .. alias:: dg::Builder :maxdepth: 2 :noroot: Details ^^^^^^^ .. cpp:namespace-push:: dg::Builder .. function:: std::shared_ptr getDG() const :returns: the derivation graph this builder can modify. .. function:: bool isActive() const :returns: whether this object is associated with a :cpp:class:`DG`. .. function:: DG::HyperEdge addDerivation(const Derivations &d) DG::HyperEdge addDerivation(const Derivations &d, IsomorphismPolicy graphPolicy) Adds a hyperedge corresponding to the given derivation to the associated :class:`DG`. If it already exists, only add the given rules to the edge. The given :var:`graphPolicy` refers to adding the graphs in :var:`d`, and it defaults to :enumerator:`IsomorphismPolicy::Check`. :returns: the hyperedge corresponding to the given derivation. :throws: :class:`LogicError` if `!isActive()`. :throws: :class:`LogicError` if `d.left.empty()`. :throws: :class:`LogicError` if `d.right.empty()`. :throws: :class:`LogicError` if a `nullptr` is in `d.left`, `d.right`, or `d.rules`. :throws: :class:`LogicError` if `graphPolicy == IsomorphismPolicy::Check` and a given graph object is different but isomorphic to another given graph object or to a graph object already in the internal graph database in the associated derivation graph. .. function:: DG::HyperEdge addHyperEdge(const DG::HyperEdge &e) DG::HyperEdge addHyperEdge(const DG::HyperEdge &e, IsomorphismPolicy graphPolicy) Adds a hyperedge to the associated :class:`DG` from a copy of the given hyperedge (from a different :class:`DG`). If it already exists, only add the rules to the edge. The given :var:`graphPolicy` refers to adding the graphs associated with :var:`e`, and it defaults to :enumerator:`IsomorphismPolicy::Check`. :returns: the hyperedge corresponding to the given derivation. :throws: :class:`LogicError` if `!isActive()`. :throws: :class:`LogicError` if `!e`. :throws: :class:`LogicError` if `graphPolicy == IsomorphismPolicy::Check` and a given graph object is different but isomorphic to another given graph object or to a graph object already in the internal graph database in the associated derivation graph. .. function:: ExecuteResult execute(std::shared_ptr strategy) ExecuteResult execute(std::shared_ptr strategy, int verbosity) ExecuteResult execute(std::shared_ptr strategy, int verbosity, bool ignoreRuleLabelTypes) Execute the given strategy (:ref:`dgStrat`) and as a side effect add vertices and hyperedges to the underlying derivation graph. The :cpp:var:`verbosity` defaults to level 2. The levels have the following meaning: - 0 (or less): no information is printed. - 2: Repetition strategies print information for each round. - 4: All strategies print minimal information. - 6: Derivation predicate strategies and filtering strategies also print their predicates. - 8: Rule strategies print minimal information about graph binding. - 10: Rule strategies print more information about graph binding, including failure due to derivation predicates. - 50: Print information about morphism generation for rule composition. - 60: Print rule composition information. :throws: :class:`LogicError` if a static "add" strategy has `IsomorphismPolicy::Check` as graph policy, and it tries to add a graph object isomorphic to an already known, but different, graph object in the database. This is checked before execution, so there is strong exception guarantee. :throws: :class:`LogicError` if a dynamic "add" strategy has `IsomorphismPolicy::Check` as graph policy, and it tries to add a graph object isomorphic to an already known, but different, graph object in the database. .. warning:: This is checked during execution, so while the basic exception guarantee is provided, there may be modifications to the underlying derivation graph. :throws: :class:`LogicError` if a dynamic "add" strategy is executed where a returned graph is a `nullptr`. .. warning:: This is checked during execution, so while the basic exception guarantee is provided, there may be modifications to the underlying derivation graph. :throws: :class:`LogicError`: if `ignoreRuleLabelTypes` is `false`, which is the default, and a rule in the given strategy has an associated :enum:`LabelType` which is different from the one in the derivation graph. .. function:: std::vector apply(const std::vector > &graphs, \ std::shared_ptr r) std::vector apply(const std::vector > &graphs, \ std::shared_ptr r, bool onlyProper, \ int verbosity) std::vector apply(const std::vector > &graphs, \ std::shared_ptr r, bool onlyProper, \ int verbosity, IsomorphismPolicy graphPolicy) Compute direct derivations using `graphs` for the left-hand side and `r` as the rule. When `onlyProper` is `true`, then all of `graphs` must be used in each direct derivation. The default is `true`. The given :var:`graphPolicy` refers to adding the graphs in :var:`graphs`, and it defaults to :enumerator:`IsomorphismPolicy::Check`. The :cpp:var:`verbosity` defaults to level 0. The levels have the following meaning: - 0 (or less): no information is printed. - 2: Print minimal information about graph binding. - 10: Print information about morphism generation for rule composition. - 20: Print rule composition information. :returns: a list of hyper edges representing the found direct derivations. The list may contain duplicates if there are multiple ways of constructing the same direct derivation when ignoring the specific match morphism. :throws: :class:`LogicError` if there is a `nullptr` in `graphs`. :throws: :class:`LogicError` if `r == nullptr`. :throws: :class:`LogicError` if `graphPolicy == IsomorphismPolicy::Check` and a given graph object is different but isomorphic to another given graph object or to a graph object already in the internal graph database in the associated derivation graph. .. function:: void addAbstract(const std::string &description) Add vertices and hyperedges based on the given abstract description. The description must adhere to the grammar described at :ref:`dg_abstract-desc`. For each vertex named in the description a graph object with a single vertex will be created. The label of that vertex and the name of the graph is set to the given identifier. :throws: :class:`InputError` if the description could not be parsed. .. function:: void load(const std::vector> &ruleDatabase, \ const std::string &file, int verbosity) Load and add a derivation graph dump. Use :cpp:func:`DG::load` to load a dump as a locked derivation graph. The label settings of this DG and the ones retrieved from the dump file must match. Vertices with graphs and hyperedges with rules are then added from the dump. Any graph in the dump which is isomorphic to a graph in the internal graph database of the DG is replaced by the given graph. The same procedure is done for the rules, but compared against the given rules. If a graph/rule is not found in the given lists, a new object is instantiated and used. See :cpp:func:`DG::load` for an explanation of the verbosity levels. :throws: :class:`LogicError` if there is a `nullptr` in `ruleDatabase`. :throws: :class:`LogicError` if the label settings of the dump does not match those of this DG. :throws: :class:`InputError` if the file can not be opened or its content is bad. .. cpp:namespace-pop:: Class ``dg::ExecuteResult`` -------------------------------------------------------------------------------------------------------------------------------- .. class:: dg::ExecuteResult The result from calling :func:`Builder::execute`. Synopsis ^^^^^^^^ .. alias:: dg::ExecuteResult :maxdepth: 2 :noroot: Details ^^^^^^^ .. cpp:namespace-push:: dg::ExecuteResult .. function:: const std::vector> &getSubset() const const std::vector> &getUniverse() const :returns: respectively the subset and the universe computed by the strategy execution (see also :ref:`dgStrat`). .. function:: void list(bool withUniverse) const Output information from the execution of the strategy. The universe lists can be rather long so with `withUniverse == false` they are omitted. .. cpp:namespace-pop::