Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
opendht
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
savoirfairelinux
opendht
Commits
aa958b0f
Commit
aa958b0f
authored
2 years ago
by
Adrien Béraud
Browse files
Options
Downloads
Patches
Plain Diff
value: inline filter
parent
58be07a8
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
include/opendht/value.h
+17
-17
17 additions, 17 deletions
include/opendht/value.h
with
17 additions
and
17 deletions
include/opendht/value.h
+
17
−
17
View file @
aa958b0f
...
...
@@ -171,29 +171,29 @@ struct OPENDHT_PUBLIC Value
template
<
typename
Functor
>
Filter
(
Functor
f
)
:
std
::
function
<
bool
(
const
Value
&
)
>::
function
(
f
)
{}
Filter
chain
(
Filter
&&
f2
)
{
inline
Filter
chain
(
Filter
&&
f2
)
{
auto
f1
=
*
this
;
return
chain
(
std
::
move
(
f1
),
std
::
move
(
f2
));
}
Filter
chainOr
(
Filter
&&
f2
)
{
inline
Filter
chainOr
(
Filter
&&
f2
)
{
auto
f1
=
*
this
;
return
chainOr
(
std
::
move
(
f1
),
std
::
move
(
f2
));
}
static
Filter
chain
(
Filter
&&
f1
,
Filter
&&
f2
)
{
static
inline
Filter
chain
(
Filter
&&
f1
,
Filter
&&
f2
)
{
if
(
not
f1
)
return
std
::
move
(
f2
);
if
(
not
f2
)
return
std
::
move
(
f1
);
return
[
f1
=
std
::
move
(
f1
),
f2
=
std
::
move
(
f2
)](
const
Value
&
v
)
{
return
f1
(
v
)
and
f2
(
v
);
};
}
static
Filter
chain
(
const
Filter
&
f1
,
const
Filter
&
f2
)
{
static
inline
Filter
chain
(
const
Filter
&
f1
,
const
Filter
&
f2
)
{
if
(
not
f1
)
return
f2
;
if
(
not
f2
)
return
f1
;
return
[
f1
,
f2
](
const
Value
&
v
)
{
return
f1
(
v
)
and
f2
(
v
);
};
}
static
Filter
chainAll
(
std
::
vector
<
Filter
>&&
set
)
{
static
inline
Filter
chainAll
(
std
::
vector
<
Filter
>&&
set
)
{
if
(
set
.
empty
())
return
{};
return
[
set
=
std
::
move
(
set
)](
const
Value
&
v
)
{
for
(
const
auto
&
f
:
set
)
...
...
@@ -202,16 +202,16 @@ struct OPENDHT_PUBLIC Value
return
true
;
};
}
static
Filter
chain
(
std
::
initializer_list
<
Filter
>
l
)
{
static
inline
Filter
chain
(
std
::
initializer_list
<
Filter
>
l
)
{
return
chainAll
(
std
::
vector
<
Filter
>
(
l
.
begin
(),
l
.
end
()));
}
static
Filter
chainOr
(
Filter
&&
f1
,
Filter
&&
f2
)
{
static
inline
Filter
chainOr
(
Filter
&&
f1
,
Filter
&&
f2
)
{
if
(
not
f1
or
not
f2
)
return
{};
return
[
f1
=
std
::
move
(
f1
),
f2
=
std
::
move
(
f2
)](
const
Value
&
v
)
{
return
f1
(
v
)
or
f2
(
v
);
};
}
static
Filter
notFilter
(
Filter
&&
f
)
{
static
inline
Filter
notFilter
(
Filter
&&
f
)
{
if
(
not
f
)
return
[](
const
Value
&
)
{
return
false
;
};
return
[
f
=
std
::
move
(
f
)](
const
Value
&
v
)
{
return
not
f
(
v
);
};
}
...
...
@@ -228,50 +228,50 @@ struct OPENDHT_PUBLIC Value
/* Sneaky functions disguised in classes */
static
const
Filter
AllFilter
()
{
static
inline
Filter
AllFilter
()
{
return
{};
}
static
Filter
TypeFilter
(
const
ValueType
&
t
)
{
static
inline
Filter
TypeFilter
(
const
ValueType
&
t
)
{
return
[
tid
=
t
.
id
](
const
Value
&
v
)
{
return
v
.
type
==
tid
;
};
}
static
Filter
TypeFilter
(
const
ValueType
::
Id
&
tid
)
{
static
inline
Filter
TypeFilter
(
const
ValueType
::
Id
&
tid
)
{
return
[
tid
](
const
Value
&
v
)
{
return
v
.
type
==
tid
;
};
}
static
Filter
IdFilter
(
const
Id
id
)
{
static
inline
Filter
IdFilter
(
const
Id
id
)
{
return
[
id
](
const
Value
&
v
)
{
return
v
.
id
==
id
;
};
}
static
Filter
RecipientFilter
(
const
InfoHash
&
r
)
{
static
inline
Filter
RecipientFilter
(
const
InfoHash
&
r
)
{
return
[
r
](
const
Value
&
v
)
{
return
v
.
recipient
==
r
;
};
}
static
Filter
OwnerFilter
(
const
crypto
::
PublicKey
&
pk
)
{
static
inline
Filter
OwnerFilter
(
const
crypto
::
PublicKey
&
pk
)
{
return
OwnerFilter
(
pk
.
getId
());
}
static
Filter
OwnerFilter
(
const
InfoHash
&
pkh
)
{
static
inline
Filter
OwnerFilter
(
const
InfoHash
&
pkh
)
{
return
[
pkh
](
const
Value
&
v
)
{
return
v
.
owner
and
v
.
owner
->
getId
()
==
pkh
;
};
}
static
Filter
SeqNumFilter
(
uint16_t
seq_no
)
{
static
inline
Filter
SeqNumFilter
(
uint16_t
seq_no
)
{
return
[
seq_no
](
const
Value
&
v
)
{
return
v
.
seq
==
seq_no
;
};
}
static
Filter
UserTypeFilter
(
std
::
string
ut
)
{
static
inline
Filter
UserTypeFilter
(
std
::
string
ut
)
{
return
[
ut
=
std
::
move
(
ut
)](
const
Value
&
v
)
{
return
v
.
user_type
==
ut
;
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment