2.2.10.6. dg/Strategies.hpp¶
2.2.10.6.1. Class dg::Strategy
¶
-
class
dg
::
Strategy
¶ Derivation graph strategies are used in
Builder::execute()
.
2.2.10.6.1.1. Synopsis¶
struct MOD_DECL Strategy {
Strategy(const Strategy &) = delete;
Strategy &operator=(const Strategy &) = delete;
public:
struct GraphState {
GraphState(std::function<void(std::vector<std::shared_ptr<graph::Graph> > &)> fSubset,
std::function<void(std::vector<std::shared_ptr<graph::Graph> > &)> fUniverse);
const std::vector<std::shared_ptr<graph::Graph> > &getSubset() const;
const std::vector<std::shared_ptr<graph::Graph> > &getUniverse() const;
private:
mutable bool subsetInit, universeInit;
mutable std::vector<std::shared_ptr<graph::Graph> > subset, universe;
std::function<void(std::vector<std::shared_ptr<graph::Graph> > &)> fSubset, fUniverse;
};
private:
Strategy(std::unique_ptr<lib::DG::Strategies::Strategy> strategy);
public:
~Strategy();
std::unique_ptr<Strategy> clone() const;
MOD_DECL friend std::ostream &operator<<(std::ostream &s, const Strategy &strat);
lib::DG::Strategies::Strategy &getStrategy();
private:
struct Pimpl;
std::unique_ptr<Pimpl> p;
public:
static std::shared_ptr<Strategy>
makeAdd(bool onlyUniverse, const std::vector<std::shared_ptr<graph::Graph>> &graphs, IsomorphismPolicy graphPolicy);
static std::shared_ptr<Strategy>
makeAdd(bool onlyUniverse, const std::shared_ptr<Function<std::vector<std::shared_ptr<graph::Graph>>()>> generator,
IsomorphismPolicy graphPolicy);
static std::shared_ptr<Strategy> makeSequence(const std::vector<std::shared_ptr<Strategy> > &strategies);
static std::shared_ptr<Strategy> makeParallel(const std::vector<std::shared_ptr<Strategy> > &strategies);
static std::shared_ptr<Strategy> makeFilter(bool alsoUniverse,
std::shared_ptr<Function<bool(std::shared_ptr<graph::Graph>,
const Strategy::GraphState &,
bool)>> filterFunc);
static std::shared_ptr<Strategy> makeExecute(std::shared_ptr<Function<void(const Strategy::GraphState &)> > func);
static std::shared_ptr<Strategy> makeRule(std::shared_ptr<rule::Rule> r);
static std::shared_ptr<Strategy>
makeLeftPredicate(std::shared_ptr<Function<bool(const Derivation &)>> predicate, std::shared_ptr<Strategy> strategy);
static std::shared_ptr<Strategy>
makeRightPredicate(std::shared_ptr<Function<bool(const Derivation &)> > predicate,
std::shared_ptr<Strategy> strategy);
static std::shared_ptr<Strategy> makeRevive(std::shared_ptr<Strategy> strategy);
static std::shared_ptr<Strategy> makeRepeat(int limit, std::shared_ptr<Strategy> strategy);
};
2.2.10.6.1.2. Details¶
- Returns
an Add Universe strategy if
onlyUniverse
istrue
, otherwise an Add Subset strategy. ThegraphPolicy
refers to the checking of each added graph against the internal graph database.- Throws
LogicError
if there is anullptr
ingraphs
.
- Returns
an Add Universe strategy if
onlyUniverse
istrue
, otherwise an Add Subset strategy. ThegraphPolicy
refers to the checking of each added graph against the internal graph database.
- Retunrs
a Sequence strategy.
- Throws
LogicError
ifstrategies.empty()
.- Throws
LogicError
if there is anullptr
instrategies
.
- Returns
a Parallel strategy.
- Throws
LogicError
ifstrategies
is empty.- Throws
LogicError
if there is anullptr
instrategies
.
The filtering predicate will be called for each graph in either the subset or the universe. The predicate is called with the graph and the graph state as arguments, and a bool stating whether or not the call is the first in the filtering process.
- Returns
a Filter Universe strategy if
alsoUniverse
istrue
, otherwise a Filter Subset strategy.- Throws
LogicError
iffilterFunc
is a null pointer.
- Returns
an Execute strategy.
- Throws
LogicError
iffunc
is a null pointer.
- Returns
a Rule strategy.
- Throws
LogicError
ifr
is anullptr
.
Even though the predicate is called with a
Derivation
object, only the left side and the rule of the object is valid.- Returns
a Derivation Predicates strategy.
- Throws
LogicError
ifpredicate
orstrategy
is anullptr
.
- Returns
a Derivation Predicates strategy.
- Throws
LogicError
ifpredicate
orstrategy
is anullptr
.
- Returns
a Revive strategy.
- Throws
LogicError
ifstrategy
is anullptr
.
- Returns
a Repeat strategy.
- Throws
LogicError
iflimit <= 0
- Throws
LogicError
ifstrategy
is anullptr
.