2.2.10.1. dg/Builder.hpp¶
2.2.10.1.1. Class dg::Builder
¶
-
class
dg
::
Builder
¶ An RAII-style object obtained from
DG::build()
. On destruction of an active builder object the owningDG
will be locked for further modifications. Builder objects are move-only types, and a moved from object becomes an inactive builder, not associated with anyDG
.
2.2.10.1.1.1. Synopsis¶
class MOD_DECL Builder {
friend class DG;
explicit Builder(lib::DG::NonHyperBuilder &dg_);
public:
Builder(Builder &&other);
Builder &operator=(Builder &&other);
~Builder();
bool isActive() const;
public:
DG::HyperEdge addDerivation(const Derivations &d);
DG::HyperEdge addDerivation(const Derivations &d, IsomorphismPolicy graphPolicy);
ExecuteResult execute(std::shared_ptr<Strategy> strategy);
ExecuteResult execute(std::shared_ptr<Strategy> strategy, int verbosity);
ExecuteResult execute(std::shared_ptr<Strategy> strategy, int verbosity, bool ignoreRuleLabelTypes);
// rst: - 10: Print information about morphism generation for rule composition.
// rst: - 20: Print rule composition information.
std::vector<DG::HyperEdge> apply(const std::vector<std::shared_ptr<graph::Graph> > &graphs,
std::shared_ptr<rule::Rule> r);
std::vector<DG::HyperEdge> apply(const std::vector<std::shared_ptr<graph::Graph> > &graphs,
std::shared_ptr<rule::Rule> r,
int verbosity);
std::vector<DG::HyperEdge> apply(const std::vector<std::shared_ptr<graph::Graph> > &graphs,
std::shared_ptr<rule::Rule> r,
int verbosity, IsomorphismPolicy graphPolicy);
void addAbstract(const std::string &description);
void load(const std::vector<std::shared_ptr<rule::Rule>> &ruleDatabase, const std::string &file, int verbosity);
private:
struct Pimpl;
std::unique_ptr<Pimpl> p;
};
2.2.10.1.1.2. Details¶
-
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
DG
. If it already exists, only add the given rules to the edge. The givengraphPolicy
refers to adding the graphs ind
, and it defaults toIsomorphismPolicy::Check
.- Returns
the hyperedge corresponding to the given derivation.
- Throws
LogicError
if!isActive()
.- Throws
LogicError
ifd.left.empty()
.- Throws
LogicError
ifd.right.empty()
.- Throws
LogicError
if anullptr
is ind.left
,d.right
, ord.rules
.- Throws
LogicError
ifgraphPolicy == 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.
Execute the given strategy (Derivation Graph Strategies) and as a side-effect add vertices and hyperedges to the underlying derivation graph.
The
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
LogicError
if a static “add” strategy hasIsomorphismPolicy::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
LogicError
if a dynamic “add” strategy hasIsomorphismPolicy::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
LogicError
if a dynamic “add” strategy is executed where a returned graph is anullptr
.Warning
This is checked during execution, so while the basic exception guarantee is provided, there may be modifications to the underlying derivation graph.
- Throws
LogicError
: ifignoreRuleLabelTypes
isfalse
, which is the default, and a rule in the given strategy has an associatedLabelType
which is different from the one in the derivation graph.
Compute proper direct derivations with
graphs
the left-hand side andr
as the rule.The given
graphPolicy
refers to adding the graphs ingraphs
, and it defaults toIsomorphismPolicy::Check
.The
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.
- 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
LogicError
if there is anullptr
ingraphs
.- Throws
LogicError
ifr == nullptr
.- Throws
LogicError
ifgraphPolicy == 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.
-
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 Abstract Derivation Graphs.
For each vertex named in the description a graph object with no vertices will be created, and its name set to the given identifier.
- Throws
InputError
if the description could not be parsed.
Load and add a derivation graph dump. Use
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
DG::load()
for an explanation of the verbosity levels.- Throws
LogicError
if there is anullptr
inruleDatabase
.- Throws
LogicError
if the label settings of the dump does not match those of this DG. :throws:InputError
if the file can not be opened or its content is bad.
2.2.10.1.2. Class dg::ExecuteResult
¶
-
class
dg
::
ExecuteResult
¶ The result from calling
Builder::execute()
.
2.2.10.1.2.1. Synopsis¶
class MOD_DECL ExecuteResult {
friend class Builder;
explicit ExecuteResult(std::shared_ptr<DG> dg_, lib::DG::ExecuteResult innerRes);
public:
ExecuteResult(ExecuteResult &&other);
ExecuteResult &operator=(ExecuteResult &&other);
~ExecuteResult();
const std::vector<std::shared_ptr<graph::Graph>> &getSubset() const;
const std::vector<std::shared_ptr<graph::Graph>> &getUniverse() const;
void list(bool withUniverse) const;
private:
struct Pimpl;
std::unique_ptr<Pimpl> p;
};
2.2.10.1.2.2. Details¶
-
const std::vector<std::shared_ptr<graph::Graph>> &
getSubset
() const¶ -
const std::vector<std::shared_ptr<graph::Graph>> &
getUniverse
() const¶ - Returns
respectively the subset and the universe computed by the strategy execution (see also Derivation Graph Strategies).
-
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.