Skip to content

Commit

Permalink
Merge pull request #21 from iritkatriel/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
iritkatriel committed Feb 2, 2016
2 parents d31870e + 8e252ec commit 6c176e8
Show file tree
Hide file tree
Showing 12 changed files with 251 additions and 402 deletions.
2 changes: 1 addition & 1 deletion examples/B_common_subexpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ void common_subexpressions()
// print it
// emit it into the output stream
//
// the output is assined to the 'greeting' variable,
// the output is assigned to the 'greeting' variable,
// which can be used in other streamulus expressions.
//
Subscription<std::string>::type greeting =
Expand Down
22 changes: 12 additions & 10 deletions src/cpp14_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,19 @@ namespace streamulus {
* remove-optional (where should this live?)
*/

template<typename T>
struct remove_optional {
using type = T;
};

template<typename T>
struct remove_optional<boost::optional<T>> {
using type = T;
};
namespace detail {
template<typename T>
struct remove_optional_impl {
using type = T;
};

template<typename T>
struct remove_optional_impl<boost::optional<T>> {
using type = T;
};
}

template<typename T>
using remove_optional_t = typename remove_optional<remove_reference_t<remove_const_t<T>>>::type;
using remove_optional = typename detail::remove_optional_impl<remove_reference_t<remove_const_t<T>>>::type;

}
2 changes: 1 addition & 1 deletion src/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ namespace streamulus
// Get the type of the strop created by the expression
using result_strop_type = typename std::result_of<smls_grammar(const Expr&, Engine*)>::type;
// Extract the output type
using type = strop_return_type_t<remove_reference_t<result_strop_type>>;
using type = strop_return_type<remove_reference_t<result_strop_type>>;
};

template<typename Expr>
Expand Down
8 changes: 1 addition & 7 deletions src/funcs.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,7 @@ namespace streamulus
{
}

template<class Sig>
struct result
{
using type = remove_const_t<remove_reference_t<T>>;
};

typename result<ConstFunc(T)>::type
remove_const_t<remove_reference_t<T>>
operator()() const
{
return mValue;
Expand Down
62 changes: 34 additions & 28 deletions src/grammar.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,23 +154,29 @@ namespace streamulus
struct case_
: proto::or_<
proto::when<unary_op_rule,
generic_func(functor_of<TAG>(), smls_grammar(proto::_child), proto::_state)>
generic_func(proto::_state,
functor_of<TAG>(),
smls_grammar(proto::_child))>

, proto::when<binary_op_rule,
generic_func(functor_of<TAG>(), smls_grammar(proto::_left),
smls_grammar(proto::_right), proto::_state)>
generic_func(proto::_state,
functor_of<TAG>(),
smls_grammar(proto::_left),
smls_grammar(proto::_right))>
, proto::when<ternary_op_rule,
generic_func(functor_of<TAG>(), smls_grammar(proto::_child0),
smls_grammar(proto::_child1),
smls_grammar(proto::_child2), proto::_state)>
generic_func(proto::_state,
functor_of<TAG>(),
smls_grammar(proto::_child0),
smls_grammar(proto::_child1),
smls_grammar(proto::_child2))>
>
{};
};

// Terminal expressions
template<>
struct smls_grammar_cases::case_<proto::tag::terminal>
: proto::when<proto::_, HandleTerminal(proto::_value,proto::_state)>
: proto::when<proto::_, HandleTerminal(proto::_state, proto::_value)>
{};


Expand All @@ -181,45 +187,45 @@ namespace streamulus
struct smls_grammar_cases::case_<proto::tag::function>
: proto::or_<
proto::when<window_rule,
SlidingWindow(get_terminal_value(proto::_child1), smls_grammar(proto::_child2), proto::_state)
SlidingWindow(proto::_state, get_terminal_value(proto::_child1), smls_grammar(proto::_child2))
>
, proto::when<function_0_rule,
generic_func(get_terminal_value(proto::_child0), proto::_state)
generic_func(proto::_state, get_terminal_value(proto::_child0))
>
, proto::when<function_1_rule,
generic_func(get_terminal_value(proto::_child0),
smls_grammar(proto::_child1),
proto::_state)
generic_func(proto::_state,
get_terminal_value(proto::_child0),
smls_grammar(proto::_child1))
>
, proto::when<function_2_rule,
generic_func(get_terminal_value(proto::_child0),
smls_grammar(proto::_child1),
smls_grammar(proto::_child2),
proto::_state)
generic_func(proto::_state,
get_terminal_value(proto::_child0),
smls_grammar(proto::_child1),
smls_grammar(proto::_child2))
>
, proto::when<function_3_rule,
generic_func(get_terminal_value(proto::_child0),
smls_grammar(proto::_child1),
smls_grammar(proto::_child2),
smls_grammar(proto::_child3),
proto::_state)
, proto::when<function_3_rule,
generic_func(proto::_state,
get_terminal_value(proto::_child0),
smls_grammar(proto::_child1),
smls_grammar(proto::_child2),
smls_grammar(proto::_child3))
>
, proto::when<function_4_rule,
generic_func(get_terminal_value(proto::_child0),
generic_func(proto::_state,
get_terminal_value(proto::_child0),
smls_grammar(proto::_child1),
smls_grammar(proto::_child2),
smls_grammar(proto::_child3),
smls_grammar(proto::_child4),
proto::_state)
smls_grammar(proto::_child4))
>
, proto::when<function_5_rule,
generic_func(get_terminal_value(proto::_child0),
generic_func(proto::_state,
get_terminal_value(proto::_child0),
smls_grammar(proto::_child1),
smls_grammar(proto::_child2),
smls_grammar(proto::_child3),
smls_grammar(proto::_child4),
smls_grammar(proto::_child5),
proto::_state)
smls_grammar(proto::_child5))
>
>
{};
Expand Down
10 changes: 1 addition & 9 deletions src/sliding_window_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,9 @@ namespace streamulus
: mFunction(f)
{
}

template<class Sig> struct result;

template<class This,typename WA>
struct result<This(WA)>
{
using type = typename F::template value_type<F(typename WindowBaseType<WA>::type)>::type;
};

template<typename WA>
boost::optional<typename result<WindowFunc(WA)>::type>
boost::optional<typename F::template value_type<F(typename WindowBaseType<WA>::type)>::type>
operator()(const WA& window_update)
{
if (window_update.first == DATA_OUT)
Expand Down
41 changes: 36 additions & 5 deletions src/strop.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@

#include <boost/function_types/parameter_types.hpp>
#include <boost/function_types/result_type.hpp>
#include <boost/fusion/functional/invocation/invoke.hpp>
#include <boost/fusion/include/vector.hpp>
#include <boost/fusion/include/transform.hpp>
#include <boost/fusion/include/make_vector.hpp>
#include <boost/proto/proto.hpp>


Expand All @@ -40,6 +43,8 @@ namespace streamulus {
struct MakeStreamPtrType {
using type = std::shared_ptr<Stream<T>>;
};

using R = typename boost::function_types::result_type<F>::type;
using param_types = boost::function_types::parameter_types<F>;
using input_types = typename boost::mpl::transform<param_types, MakeStreamPtrType<boost::mpl::_1> >::type;

Expand All @@ -48,17 +53,38 @@ namespace streamulus {
virtual ~Strop() {
}

template<typename Inputs>
// a fusion sequence of the inputs
void SetInputs(const Inputs &inputs) {
mInputs = inputs;
template<typename... Inputs>
void SetInputs(Inputs... inputs) {
mInputs = boost::fusion::make_vector(inputs...);
}

template<int I>
Stream<typename boost::mpl::at_c<param_types, I>::type> *const Input() {
return boost::fusion::at_c<I>(mInputs).get();
}

struct extract_input_value {
template<typename Sig>
struct result;

template<typename This, typename T>
struct result<This(std::shared_ptr<Stream<T>>)> {
typedef T type;
};

template<typename T>
T operator()(std::shared_ptr<Stream<T>> input) const {
return input.get()->Current();
}
};

R Invoke(std::function<F> &f) {
return boost::fusion::invoke(
std::reference_wrapper<std::function<F>>(f),
boost::fusion::transform(mInputs, extract_input_value())
);
}

/**
* HasMore() returns true if any of the inputs has more data, false otherwise
*/
Expand All @@ -84,10 +110,15 @@ namespace streamulus {
};

bool IsValid() {
return boost::fusion::fold(mInputs, true, is_valid_fold_function());
return NoInputs() || boost::fusion::fold(mInputs, true, is_valid_fold_function());
}

bool NoInputs() {
return boost::fusion::empty(mInputs);
}

private:

typename boost::fusion::result_of::as_vector<typename input_types::type>::type mInputs;

};
Expand Down
2 changes: 0 additions & 2 deletions src/strop_data_source.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ namespace streamulus
class DataSource : public StropStreamProducer<R>
{
public:

using result_type = R;

DataSource(const std::string& name, bool verbose)
: mIsValid(false)
Expand Down
Loading

0 comments on commit 6c176e8

Please sign in to comment.