Commit 45fa26fb authored by Paul's avatar Paul
Browse files

Make stream op optional

parent e788222e
......@@ -11,6 +11,16 @@
namespace rtg {
namespace operation_stream {
template <class T>
auto operator<<(std::ostream& os, const T& x) -> decltype(os << x.name())
{
return os << x.name();
}
} // namespace operation_stream
/*
* Type-erased interface for:
*
......@@ -142,16 +152,19 @@ struct operation
shape compute_shape(std::vector<shape> input) const override
{
return private_detail_te_value.compute_shape(std::move(input));
}
argument compute(std::vector<argument> input) const override
{
return private_detail_te_value.compute(std::move(input));
}
std::ostream& operator_shift_left(std::ostream& os) const override
{
using rtg::operation_stream::operator<<;
return os << private_detail_te_value;
}
......
......@@ -31,12 +31,6 @@ struct sum_op
RTG_THROW("Wrong inputs");
return inputs.front();
}
friend std::ostream& operator<<(std::ostream& os, const sum_op& op)
{
os << op.name();
return os;
}
};
struct minus_op
......@@ -66,12 +60,6 @@ struct minus_op
RTG_THROW("Wrong inputs");
return inputs.front();
}
friend std::ostream& operator<<(std::ostream& os, const minus_op& op)
{
os << op.name();
return os;
}
};
struct id_target
......
......@@ -11,12 +11,23 @@
namespace rtg {
namespace operation_stream {
template<class T>
std::ostream& operator<<(std::ostream& os, const T& x)
{
os << x.name();
return os;
}
}
<%
interface('operation',
virtual('name', returns='std::string', const=True),
virtual('compute_shape', returns='shape', input='std::vector<shape>', const=True),
virtual('compute', returns='argument', input='std::vector<argument>', const=True),
friend('operator<<', returns='std::ostream &', os='std::ostream &', op='const operation &')
friend('operator<<', returns='std::ostream &', os='std::ostream &', op='const operation &', using='rtg::operation_stream::operator<<')
)
%>
......
......@@ -173,6 +173,7 @@ pure_virtual_member = string.Template("virtual ${return_type} ${internal_name}($
virtual_member = string.Template('''
${return_type} ${internal_name}(${member_params}) ${member_const} override
{
${using}
return ${call};
}
''')
......@@ -217,7 +218,8 @@ def convert_member(d, struct_name):
'const': '',
'member_const': '',
'friend': '',
'this': '(*this)'
'this': '(*this)',
'using': ''
}
args = []
params = []
......@@ -237,6 +239,8 @@ def convert_member(d, struct_name):
member['member_const'] = 'const'
elif x == 'friend':
member['friend'] = 'friend'
elif x == 'using':
member['using'] = 'using {};'.format(d[name]['using'])
else:
use_member = not(skip and struct_name == trim_type_name(t))
arg_name = x
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment