Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
1629ebc4
Commit
1629ebc4
authored
Mar 13, 2018
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support finalize callbacks with 1 and 2 args
parent
673c0fd3
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
96 additions
and
17 deletions
+96
-17
libcaf_core/caf/detail/stream_sink_driver_impl.hpp
libcaf_core/caf/detail/stream_sink_driver_impl.hpp
+4
-3
libcaf_core/caf/detail/stream_sink_impl.hpp
libcaf_core/caf/detail/stream_sink_impl.hpp
+1
-9
libcaf_core/caf/detail/stream_source_driver_impl.hpp
libcaf_core/caf/detail/stream_source_driver_impl.hpp
+4
-3
libcaf_core/caf/detail/stream_stage_driver_impl.hpp
libcaf_core/caf/detail/stream_stage_driver_impl.hpp
+2
-1
libcaf_core/caf/detail/type_traits.hpp
libcaf_core/caf/detail/type_traits.hpp
+14
-0
libcaf_core/caf/stream_finalize_trait.hpp
libcaf_core/caf/stream_finalize_trait.hpp
+58
-0
libcaf_core/caf/stream_sink.hpp
libcaf_core/caf/stream_sink.hpp
+9
-1
libcaf_core/caf/stream_stage.hpp
libcaf_core/caf/stream_stage.hpp
+4
-0
No files found.
libcaf_core/caf/detail/stream_sink_driver_impl.hpp
View file @
1629ebc4
...
@@ -21,6 +21,7 @@
...
@@ -21,6 +21,7 @@
#define CAF_STREAM_SINK_DRIVER_IMPL_HPP
#define CAF_STREAM_SINK_DRIVER_IMPL_HPP
#include "caf/none.hpp"
#include "caf/none.hpp"
#include "caf/stream_finalize_trait.hpp"
#include "caf/stream_sink_driver.hpp"
#include "caf/stream_sink_driver.hpp"
#include "caf/stream_sink_trait.hpp"
#include "caf/stream_sink_trait.hpp"
...
@@ -44,7 +45,7 @@ public:
...
@@ -44,7 +45,7 @@ public:
template
<
class
Init
>
template
<
class
Init
>
stream_sink_driver_impl
(
Init
init
,
Process
f
,
Finalize
fin
)
stream_sink_driver_impl
(
Init
init
,
Process
f
,
Finalize
fin
)
:
process_
(
std
::
move
(
f
)),
:
process_
(
std
::
move
(
f
)),
fin
alize
_
(
std
::
move
(
fin
))
{
fin_
(
std
::
move
(
fin
))
{
init
(
state_
);
init
(
state_
);
}
}
...
@@ -53,12 +54,12 @@ public:
...
@@ -53,12 +54,12 @@ public:
}
}
void
finalize
(
const
error
&
err
)
override
{
void
finalize
(
const
error
&
err
)
override
{
finalize_
(
state_
,
err
);
stream_finalize_trait
<
Finalize
,
state_type
>::
invoke
(
fin_
,
state_
,
err
);
}
}
private:
private:
Process
process_
;
Process
process_
;
Finalize
fin
alize
_
;
Finalize
fin_
;
state_type
state_
;
state_type
state_
;
};
};
...
...
libcaf_core/caf/detail/stream_sink_impl.hpp
View file @
1629ebc4
...
@@ -26,8 +26,6 @@
...
@@ -26,8 +26,6 @@
#include "caf/sec.hpp"
#include "caf/sec.hpp"
#include "caf/stream_manager.hpp"
#include "caf/stream_manager.hpp"
#include "caf/stream_sink.hpp"
#include "caf/stream_sink.hpp"
#include "caf/stream_sink_trait.hpp"
#include "caf/terminal_stream_scatterer.hpp"
#include "caf/policy/arg.hpp"
#include "caf/policy/arg.hpp"
...
@@ -47,15 +45,10 @@ public:
...
@@ -47,15 +45,10 @@ public:
stream_sink_impl
(
scheduled_actor
*
self
,
Ts
&&
...
xs
)
stream_sink_impl
(
scheduled_actor
*
self
,
Ts
&&
...
xs
)
:
stream_manager
(
self
),
:
stream_manager
(
self
),
super
(
self
),
super
(
self
),
driver_
(
std
::
forward
<
Ts
>
(
xs
)...),
driver_
(
std
::
forward
<
Ts
>
(
xs
)...)
{
out_
(
self
)
{
// nop
// nop
}
}
terminal_stream_scatterer
&
out
()
override
{
return
out_
;
}
void
handle
(
inbound_path
*
,
downstream_msg
::
batch
&
x
)
override
{
void
handle
(
inbound_path
*
,
downstream_msg
::
batch
&
x
)
override
{
CAF_LOG_TRACE
(
CAF_ARG
(
x
));
CAF_LOG_TRACE
(
CAF_ARG
(
x
));
using
vec_type
=
std
::
vector
<
input_type
>
;
using
vec_type
=
std
::
vector
<
input_type
>
;
...
@@ -73,7 +66,6 @@ protected:
...
@@ -73,7 +66,6 @@ protected:
private:
private:
driver_type
driver_
;
driver_type
driver_
;
terminal_stream_scatterer
out_
;
};
};
template
<
class
Driver
,
class
...
Ts
>
template
<
class
Driver
,
class
...
Ts
>
...
...
libcaf_core/caf/detail/stream_source_driver_impl.hpp
View file @
1629ebc4
...
@@ -21,6 +21,7 @@
...
@@ -21,6 +21,7 @@
#define CAF_STREAM_SOURCE_DRIVER_IMPL_HPP
#define CAF_STREAM_SOURCE_DRIVER_IMPL_HPP
#include "caf/none.hpp"
#include "caf/none.hpp"
#include "caf/stream_finalize_trait.hpp"
#include "caf/stream_source_driver.hpp"
#include "caf/stream_source_driver.hpp"
#include "caf/stream_source_trait.hpp"
#include "caf/stream_source_trait.hpp"
...
@@ -45,7 +46,7 @@ public:
...
@@ -45,7 +46,7 @@ public:
stream_source_driver_impl
(
Init
init
,
Pull
f
,
Done
pred
,
Finalize
fin
)
stream_source_driver_impl
(
Init
init
,
Pull
f
,
Done
pred
,
Finalize
fin
)
:
pull_
(
std
::
move
(
f
)),
:
pull_
(
std
::
move
(
f
)),
done_
(
std
::
move
(
pred
)),
done_
(
std
::
move
(
pred
)),
fin
alize
_
(
std
::
move
(
fin
))
{
fin_
(
std
::
move
(
fin
))
{
init
(
state_
);
init
(
state_
);
}
}
...
@@ -58,14 +59,14 @@ public:
...
@@ -58,14 +59,14 @@ public:
}
}
void
finalize
(
const
error
&
err
)
override
{
void
finalize
(
const
error
&
err
)
override
{
finalize_
(
state_
,
err
);
stream_finalize_trait
<
Finalize
,
state_type
>::
invoke
(
fin_
,
state_
,
err
);
}
}
private:
private:
state_type
state_
;
state_type
state_
;
Pull
pull_
;
Pull
pull_
;
Done
done_
;
Done
done_
;
Finalize
fin
alize
_
;
Finalize
fin_
;
};
};
}
// namespace detail
}
// namespace detail
...
...
libcaf_core/caf/detail/stream_stage_driver_impl.hpp
View file @
1629ebc4
...
@@ -20,6 +20,7 @@
...
@@ -20,6 +20,7 @@
#ifndef CAF_STREAM_STAGE_DRIVER_IMPL_HPP
#ifndef CAF_STREAM_STAGE_DRIVER_IMPL_HPP
#define CAF_STREAM_STAGE_DRIVER_IMPL_HPP
#define CAF_STREAM_STAGE_DRIVER_IMPL_HPP
#include "caf/stream_finalize_trait.hpp"
#include "caf/stream_slot.hpp"
#include "caf/stream_slot.hpp"
#include "caf/stream_stage_driver.hpp"
#include "caf/stream_stage_driver.hpp"
#include "caf/stream_stage_trait.hpp"
#include "caf/stream_stage_trait.hpp"
...
@@ -61,7 +62,7 @@ public:
...
@@ -61,7 +62,7 @@ public:
}
}
void
finalize
(
const
error
&
err
)
override
{
void
finalize
(
const
error
&
err
)
override
{
return
fin_
(
state_
,
err
);
stream_finalize_trait
<
Finalize
,
state_type
>::
invoke
(
fin_
,
state_
,
err
);
}
}
private:
private:
...
...
libcaf_core/caf/detail/type_traits.hpp
View file @
1629ebc4
...
@@ -490,6 +490,20 @@ public:
...
@@ -490,6 +490,20 @@ public:
static
constexpr
bool
value
=
std
::
is_same
<
bool
,
result_type
>::
value
;
static
constexpr
bool
value
=
std
::
is_same
<
bool
,
result_type
>::
value
;
};
};
/// Checks wheter `F` is callable with arguments of types `Ts...`.
template
<
class
F
,
class
...
Ts
>
struct
is_callable_with
{
template
<
class
U
>
static
auto
sfinae
(
U
*
)
->
decltype
((
std
::
declval
<
U
&>
())(
std
::
declval
<
Ts
>
()...),
std
::
true_type
());
template
<
class
U
>
static
auto
sfinae
(...)
->
std
::
false_type
;
using
type
=
decltype
(
sfinae
<
F
>
(
nullptr
));
static
constexpr
bool
value
=
type
::
value
;
};
/// Checks wheter `F` takes mutable references.
/// Checks wheter `F` takes mutable references.
///
///
/// A manipulator is a functor that manipulates its arguments via
/// A manipulator is a functor that manipulates its arguments via
...
...
libcaf_core/caf/stream_finalize_trait.hpp
0 → 100644
View file @
1629ebc4
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2018 Dominik Charousset *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#ifndef CAF_STREAM_FINALIZE_TRAIT_HPP
#define CAF_STREAM_FINALIZE_TRAIT_HPP
#include "caf/make_message.hpp"
#include "caf/message.hpp"
#include "caf/stream_sink.hpp"
#include "caf/detail/type_traits.hpp"
namespace
caf
{
/// Dispatches a finalize call to a function taking either one or two arguments.
template
<
class
Fun
,
class
State
,
bool
AcceptsTwoArgs
=
detail
::
is_callable_with
<
Fun
,
State
&
,
const
error
&
>
::
value
>
struct
stream_finalize_trait
;
/// Specializes the trait for callbacks that only take the state.
template
<
class
Fun
,
class
State
>
struct
stream_finalize_trait
<
Fun
,
State
,
false
>
{
static
void
invoke
(
Fun
&
f
,
State
&
st
,
const
error
&
)
{
static_assert
(
detail
::
is_callable_with
<
Fun
,
State
&>::
value
,
"Finalize function neither accepts (State&, const error&) "
"nor (State&)"
);
f
(
st
);
}
};
/// Specializes the trait for callbacks that take state and error.
template
<
class
Fun
,
class
State
>
struct
stream_finalize_trait
<
Fun
,
State
,
true
>
{
static
void
invoke
(
Fun
&
f
,
State
&
st
,
const
error
&
err
)
{
f
(
st
,
err
);
}
};
}
// namespace caf
#endif // CAF_STREAM_FINALIZE_TRAIT_HPP
libcaf_core/caf/stream_sink.hpp
View file @
1629ebc4
...
@@ -24,6 +24,7 @@
...
@@ -24,6 +24,7 @@
#include "caf/intrusive_ptr.hpp"
#include "caf/intrusive_ptr.hpp"
#include "caf/stream_manager.hpp"
#include "caf/stream_manager.hpp"
#include "caf/stream_result.hpp"
#include "caf/stream_result.hpp"
#include "caf/terminal_stream_scatterer.hpp"
#include "caf/detail/type_traits.hpp"
#include "caf/detail/type_traits.hpp"
...
@@ -38,7 +39,7 @@ public:
...
@@ -38,7 +39,7 @@ public:
// -- constructors, destructors, and assignment operators --------------------
// -- constructors, destructors, and assignment operators --------------------
stream_sink
(
scheduled_actor
*
self
)
:
stream_manager
(
self
)
{
stream_sink
(
scheduled_actor
*
self
)
:
stream_manager
(
self
)
,
dummy_out_
(
self
)
{
// nop
// nop
}
}
...
@@ -48,6 +49,10 @@ public:
...
@@ -48,6 +49,10 @@ public:
return
!
this
->
continuous
()
&&
this
->
inbound_paths_
.
empty
();
return
!
this
->
continuous
()
&&
this
->
inbound_paths_
.
empty
();
}
}
stream_scatterer
&
out
()
override
{
return
dummy_out_
;
}
// -- properties -------------------------------------------------------------
// -- properties -------------------------------------------------------------
/// Creates a new input path to the current sender.
/// Creates a new input path to the current sender.
...
@@ -55,6 +60,9 @@ public:
...
@@ -55,6 +60,9 @@ public:
add_inbound_path
(
const
stream
<
input_type
>&
)
{
add_inbound_path
(
const
stream
<
input_type
>&
)
{
return
{
add_unchecked_inbound_path_impl
(),
this
};
return
{
add_unchecked_inbound_path_impl
(),
this
};
}
}
private:
terminal_stream_scatterer
dummy_out_
;
};
};
template
<
class
In
>
template
<
class
In
>
...
...
libcaf_core/caf/stream_stage.hpp
View file @
1629ebc4
...
@@ -46,6 +46,10 @@ public:
...
@@ -46,6 +46,10 @@ public:
right_super
(
self
)
{
right_super
(
self
)
{
// nop
// nop
}
}
Scatterer
&
out
()
override
{
return
left_super
::
out
();
}
};
};
template
<
class
In
,
class
Out
,
class
Scatterer
>
template
<
class
In
,
class
Out
,
class
Scatterer
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment