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
5ca290af
Commit
5ca290af
authored
Mar 03, 2012
by
neverlord
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added member function to suppress type checking
parent
effba5fa
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
97 additions
and
24 deletions
+97
-24
cppa/detail/invokable.hpp
cppa/detail/invokable.hpp
+97
-24
No files found.
cppa/detail/invokable.hpp
View file @
5ca290af
...
...
@@ -36,6 +36,7 @@
#include <cstdint>
#include "cppa/match.hpp"
#include "cppa/pattern.hpp"
#include "cppa/any_tuple.hpp"
#include "cppa/tuple_cast.hpp"
#include "cppa/util/duration.hpp"
...
...
@@ -111,7 +112,17 @@ class invokable : public invokable_base
public:
virtual
intermediate
*
get_intermediate
(
any_tuple
const
&
)
=
0
;
virtual
bool
matches_values
()
const
=
0
;
// Checks whether the types of @p value match the pattern.
virtual
bool
types_match
(
any_tuple
const
&
value
)
const
=
0
;
// Checks whether this invokable could be invoked with @p value.
virtual
bool
could_invoke
(
any_tuple
const
&
value
)
const
=
0
;
// Prepare this invokable.
virtual
intermediate
*
get_intermediate
(
any_tuple
const
&
value
)
=
0
;
// Prepare this invokable and suppress type checking.
virtual
intermediate
*
get_unsafe_intermediate
(
any_tuple
const
&
value
)
=
0
;
// Suppress type checking.
virtual
bool
unsafe_invoke
(
any_tuple
const
&
value
)
const
=
0
;
};
...
...
@@ -129,11 +140,18 @@ class invokable_impl : public invokable
m_iimpl
;
std
::
unique_ptr
<
Pattern
>
m_pattern
;
template
<
typename
T
>
bool
invoke_impl
(
T
const
&
data
)
const
public:
template
<
typename
F
>
invokable_impl
(
F
&&
fun
,
std
::
unique_ptr
<
Pattern
>&&
pptr
)
:
m_iimpl
(
std
::
forward
<
F
>
(
fun
)),
m_pattern
(
std
::
move
(
pptr
))
{
}
bool
invoke
(
any_tuple
const
&
value
)
const
{
auto
tuple_option
=
tuple_cast
(
data
,
*
m_pattern
);
if
(
tuple_option
.
valid
()
)
auto
tuple_option
=
tuple_cast
(
value
,
*
m_pattern
);
if
(
tuple_option
)
{
util
::
apply_tuple
(
m_iimpl
.
m_fun
,
*
tuple_option
);
return
true
;
...
...
@@ -141,23 +159,37 @@ class invokable_impl : public invokable
return
false
;
}
public:
bool
unsafe_invoke
(
any_tuple
const
&
value
)
const
{
auto
tuple_option
=
unsafe_tuple_cast
(
value
,
*
m_pattern
);
if
(
tuple_option
)
{
util
::
apply_tuple
(
m_iimpl
.
m_fun
,
*
tuple_option
);
return
true
;
}
return
false
;
}
template
<
typename
F
>
invokable_impl
(
F
&&
fun
,
std
::
unique_ptr
<
Pattern
>&&
pptr
)
:
m_iimpl
(
std
::
forward
<
F
>
(
fun
)),
m_pattern
(
std
::
move
(
pptr
))
bool
matches_values
()
const
{
return
m_pattern
->
has_values
();
}
bool
invoke
(
any_tuple
const
&
data
)
const
bool
types_match
(
any_tuple
const
&
value
)
const
{
return
match_types
(
value
,
*
m_pattern
);
}
bool
could_invoke
(
any_tuple
const
&
value
)
const
{
return
invoke_impl
(
data
);
return
match
(
value
,
*
m_pattern
);
}
intermediate
*
get_intermediate
(
any_tuple
const
&
data
)
intermediate
*
get_intermediate
(
any_tuple
const
&
value
)
{
auto
tuple_option
=
tuple_cast
(
data
,
*
m_pattern
);
if
(
tuple_option
.
valid
()
)
auto
tuple_option
=
tuple_cast
(
value
,
*
m_pattern
);
if
(
tuple_option
)
{
m_iimpl
.
m_args
=
std
::
move
(
*
tuple_option
);
return
&
m_iimpl
;
...
...
@@ -165,6 +197,17 @@ class invokable_impl : public invokable
return
nullptr
;
}
intermediate
*
get_unsafe_intermediate
(
any_tuple
const
&
value
)
{
auto
x
=
unsafe_tuple_cast
(
value
,
*
m_pattern
);
if
(
x
)
{
m_iimpl
.
m_args
=
std
::
move
(
*
x
);
return
&
m_iimpl
;
}
return
nullptr
;
}
};
template
<
typename
Fun
,
class
Tuple
,
class
Pattern
>
...
...
@@ -180,8 +223,21 @@ class invokable_impl<0, Fun, Tuple, Pattern> : public invokable
m_iimpl
;
std
::
unique_ptr
<
Pattern
>
m_pattern
;
template
<
typename
T
>
bool
invoke_impl
(
T
const
&
data
)
const
template
<
typename
...
P
>
bool
unsafe_vmatch
(
any_tuple
const
&
t
,
pattern
<
P
...
>
const
&
p
)
const
{
return
matcher
<
Pattern
::
wildcard_pos
,
P
...
>::
vmatch
(
t
,
p
);
}
public:
template
<
typename
F
>
invokable_impl
(
F
&&
fun
,
std
::
unique_ptr
<
Pattern
>&&
pptr
)
:
m_iimpl
(
std
::
forward
<
F
>
(
fun
)),
m_pattern
(
std
::
move
(
pptr
))
{
}
bool
invoke
(
any_tuple
const
&
data
)
const
{
if
(
match
(
data
,
*
m_pattern
))
{
...
...
@@ -191,22 +247,39 @@ class invokable_impl<0, Fun, Tuple, Pattern> : public invokable
return
false
;
}
public:
bool
unsafe_invoke
(
any_tuple
const
&
value
)
const
{
if
(
unsafe_vmatch
(
value
,
*
m_pattern
))
{
m_iimpl
.
m_fun
();
return
true
;
}
return
false
;
}
template
<
typename
F
>
invokable_impl
(
F
&&
fun
,
std
::
unique_ptr
<
Pattern
>&&
pptr
)
:
m_iimpl
(
std
::
forward
<
F
>
(
fun
)),
m_pattern
(
std
::
move
(
pptr
))
bool
matches_values
()
const
{
return
m_pattern
->
has_values
();
}
bool
invoke
(
any_tuple
const
&
data
)
const
bool
types_match
(
any_tuple
const
&
value
)
const
{
return
match_types
(
value
,
*
m_pattern
);
}
bool
could_invoke
(
any_tuple
const
&
value
)
const
{
return
match
(
value
,
*
m_pattern
);
}
intermediate
*
get_intermediate
(
any_tuple
const
&
value
)
{
return
invoke_impl
(
data
)
;
return
match
(
value
,
*
m_pattern
)
?
&
m_iimpl
:
nullptr
;
}
intermediate
*
get_
intermediate
(
any_tuple
const
&
data
)
intermediate
*
get_
unsafe_intermediate
(
any_tuple
const
&
value
)
{
return
match
(
data
,
*
m_pattern
)
?
&
m_iimpl
:
nullptr
;
return
unsafe_vmatch
(
value
,
*
m_pattern
)
?
&
m_iimpl
:
nullptr
;
}
};
...
...
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