forked from GitHub/gf-core
a refactoring to make it easier to use C++ closures
This commit is contained in:
@@ -658,7 +658,7 @@ void namespace_iter_prefix(Namespace<V> map, PgfText *prefix, PgfItor* itor, Pgf
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <class V>
|
template <class V>
|
||||||
Namespace<V> namespace_map(Namespace<V> map, std::function<ref<V>(ref<V>)> f)
|
Namespace<V> namespace_map(Namespace<V> map, std::function<ref<V>(ref<V>)> &f)
|
||||||
{
|
{
|
||||||
if (map != 0) {
|
if (map != 0) {
|
||||||
auto left = namespace_map(map->left, f);
|
auto left = namespace_map(map->left, f);
|
||||||
|
|||||||
@@ -510,7 +510,12 @@ void pgf_iter_functions_by_cat(PgfDB *db, PgfRevision revision,
|
|||||||
DB_scope scope(db, READER_SCOPE);
|
DB_scope scope(db, READER_SCOPE);
|
||||||
ref<PgfPGF> pgf = db->revision2pgf(revision);
|
ref<PgfPGF> pgf = db->revision2pgf(revision);
|
||||||
|
|
||||||
probspace_iter(pgf->abstract.funs_by_cat, cat, itor, false, err);
|
std::function<bool(ref<PgfAbsFun>)> f =
|
||||||
|
[itor,err](ref<PgfAbsFun> fun) {
|
||||||
|
itor->fn(itor, &fun->name, fun.as_object(), err);
|
||||||
|
return (err->type == PGF_EXN_NONE);
|
||||||
|
};
|
||||||
|
probspace_iter(pgf->abstract.funs_by_cat, cat, f, false);
|
||||||
} PGF_API_END
|
} PGF_API_END
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2239,13 +2244,6 @@ void pgf_create_lincat(PgfDB *db,
|
|||||||
} PGF_API_END
|
} PGF_API_END
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
|
||||||
void iter_drop_lincat_helper(PgfItor *itor, PgfText *key, object value, PgfExn *err)
|
|
||||||
{
|
|
||||||
ref<PgfConcr> concr = ((PgfDropItor*) itor)->concrete;
|
|
||||||
drop_lin(concr, key);
|
|
||||||
}
|
|
||||||
|
|
||||||
PGF_API
|
PGF_API
|
||||||
void pgf_drop_lincat(PgfDB *db,
|
void pgf_drop_lincat(PgfDB *db,
|
||||||
PgfRevision revision,PgfConcrRevision cnc_revision,
|
PgfRevision revision,PgfConcrRevision cnc_revision,
|
||||||
@@ -2265,13 +2263,12 @@ void pgf_drop_lincat(PgfDB *db,
|
|||||||
|
|
||||||
// Remove the linearizations of all functions that
|
// Remove the linearizations of all functions that
|
||||||
// depend on it.
|
// depend on it.
|
||||||
PgfDropItor itor;
|
std::function<bool(ref<PgfAbsFun>)> f =
|
||||||
itor.fn = iter_drop_lincat_helper;
|
[concr](ref<PgfAbsFun> fun) {
|
||||||
itor.pgf = pgf;
|
drop_lin(concr, &fun->name);
|
||||||
itor.concrete = concr;
|
return true;
|
||||||
itor.name = name;
|
};
|
||||||
probspace_iter(pgf->abstract.funs_by_cat, name,
|
probspace_iter(pgf->abstract.funs_by_cat, name, f, true);
|
||||||
&itor, true, err);
|
|
||||||
|
|
||||||
// Remove the sequences comprizing the lindef and linref
|
// Remove the sequences comprizing the lindef and linref
|
||||||
object container = lincat.tagged();
|
object container = lincat.tagged();
|
||||||
|
|||||||
@@ -172,35 +172,27 @@ PgfProbspace probspace_delete_by_cat(PgfProbspace space, PgfText *cat,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void probspace_iter(PgfProbspace space, PgfText *cat,
|
bool probspace_iter(PgfProbspace space, PgfText *cat,
|
||||||
PgfItor* itor, bool all, PgfExn *err)
|
std::function<bool(ref<PgfAbsFun>)> &f, bool all)
|
||||||
{
|
{
|
||||||
if (space == 0)
|
if (space == 0)
|
||||||
return;
|
return true;
|
||||||
|
|
||||||
int cmp = textcmp(cat,&(*space->value.cat));
|
int cmp = textcmp(cat,&(*space->value.cat));
|
||||||
if (cmp < 0) {
|
if (cmp < 0) {
|
||||||
probspace_iter(space->left, cat, itor, all, err);
|
return probspace_iter(space->left, cat, f, all);
|
||||||
if (err->type != PGF_EXN_NONE)
|
|
||||||
return;
|
|
||||||
} else if (cmp > 0) {
|
} else if (cmp > 0) {
|
||||||
probspace_iter(space->right, cat, itor, all, err);
|
return probspace_iter(space->right, cat, f, all);
|
||||||
if (err->type != PGF_EXN_NONE)
|
|
||||||
return;
|
|
||||||
} else {
|
} else {
|
||||||
probspace_iter(space->left, cat, itor, all, err);
|
if (!probspace_iter(space->left, cat, f, all))
|
||||||
if (err->type != PGF_EXN_NONE)
|
return false;
|
||||||
return;
|
|
||||||
|
|
||||||
if (all || space->value.is_result()) {
|
if (all || space->value.is_result()) {
|
||||||
itor->fn(itor, &space->value.fun->name, space->value.fun.as_object(), err);
|
if (!f(space->value.fun))
|
||||||
if (err->type != PGF_EXN_NONE)
|
return false;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
probspace_iter(space->right, cat, itor, all, err);
|
return probspace_iter(space->right, cat, f, all);
|
||||||
if (err->type != PGF_EXN_NONE)
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -66,8 +66,8 @@ PgfProbspace probspace_delete_by_cat(PgfProbspace space, PgfText *cat,
|
|||||||
PgfItor* itor, PgfExn *err);
|
PgfItor* itor, PgfExn *err);
|
||||||
|
|
||||||
PGF_INTERNAL_DECL
|
PGF_INTERNAL_DECL
|
||||||
void probspace_iter(PgfProbspace space, PgfText *cat,
|
bool probspace_iter(PgfProbspace space, PgfText *cat,
|
||||||
PgfItor* itor, bool all, PgfExn *err);
|
std::function<bool(ref<PgfAbsFun>)> &f, bool all);
|
||||||
|
|
||||||
/* Given a random number from 0 to 1, select a random function from
|
/* Given a random number from 0 to 1, select a random function from
|
||||||
* the given category */
|
* the given category */
|
||||||
|
|||||||
Reference in New Issue
Block a user