1#############################################################################
2##
3##  This file is part of GAP, a system for computational discrete algebra.
4##
5##  Copyright of GAP belongs to its developers, whose names are too numerous
6##  to list here. Please refer to the COPYRIGHT file for details.
7##
8##  SPDX-License-Identifier: GPL-2.0-or-later
9##
10
11#############################################################################
12##
13#V  IdOfFilter
14##
15##  <#GAPDoc Label="IdOfFilter">
16##  <ManSection>
17##  <Func Name="IdOfFilter" Arg="filter"/>
18##  <Func Name="IdOfFilterByName" Arg="name"/>
19##
20##  <Description>
21##  finds the id of the filter <A>filter</A>, or the id of the filter
22##  with name <A>name</A> respectively.
23##  The id of a filter is equal to the
24##  position of this filter in the global FILTERS list.
25##  <P/>
26##  Note that not every <C>filter</C> for which <C>IsFilter(filter)</C>
27##  returns <C>true</C> has an ID, only elementary filters do.
28##  </Description>
29##  </ManSection>
30##  <#/GAPDoc>
31##
32##  Note that the filter ID is stored in FLAG1_FILTER for most filters,
33##  testers have the ID stored in FLAG2_FILTER, so the code below is
34##  more efficient than just iterating over the FILTERS list.
35##
36##
37BIND_GLOBAL( "IdOfFilter",
38function(filter)
39    local fid;
40    fid := FLAG1_FILTER(filter);
41    if fid > 0 and FILTERS[fid] = filter then
42        return fid;
43    fi;
44    fid := FLAG2_FILTER(filter);
45    if fid > 0 and FILTERS[fid] = filter then
46        return fid;
47    fi;
48    return fail;
49end);
50
51BIND_GLOBAL( "IdOfFilterByName",
52             name -> PositionProperty(FILTERS, f -> NAME_FUNC(f) = name) );
53
54#############################################################################
55##
56#V  FilterByName
57##
58##  <#GAPDoc Label="FilterByName">
59##  <ManSection>
60##  <Func Name="FilterByName" Arg="name"/>
61##
62##  <Description>
63##  finds the filter with name <A>name</A> in the global FILTERS list. This
64##  is useful to find filters that were created but not bound to a global
65##  variable.
66##  </Description>
67##  </ManSection>
68##  <#/GAPDoc>
69##
70BIND_GLOBAL( "FilterByName",
71             name -> First(FILTERS, f -> NAME_FUNC(f) = name) );
72