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

Make stream op optional

parent e788222e
...@@ -11,6 +11,16 @@ ...@@ -11,6 +11,16 @@
namespace rtg { 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: * Type-erased interface for:
* *
...@@ -142,16 +152,19 @@ struct operation ...@@ -142,16 +152,19 @@ struct operation
shape compute_shape(std::vector<shape> input) const override shape compute_shape(std::vector<shape> input) const override
{ {
return private_detail_te_value.compute_shape(std::move(input)); return private_detail_te_value.compute_shape(std::move(input));
} }
argument compute(std::vector<argument> input) const override argument compute(std::vector<argument> input) const override
{ {
return private_detail_te_value.compute(std::move(input)); return private_detail_te_value.compute(std::move(input));
} }
std::ostream& operator_shift_left(std::ostream& os) const override std::ostream& operator_shift_left(std::ostream& os) const override
{ {
using rtg::operation_stream::operator<<;
return os << private_detail_te_value; return os << private_detail_te_value;
} }
......
...@@ -31,12 +31,6 @@ struct sum_op ...@@ -31,12 +31,6 @@ struct sum_op
RTG_THROW("Wrong inputs"); RTG_THROW("Wrong inputs");
return inputs.front(); return inputs.front();
} }
friend std::ostream& operator<<(std::ostream& os, const sum_op& op)
{
os << op.name();
return os;
}
}; };
struct minus_op struct minus_op
...@@ -66,12 +60,6 @@ struct minus_op ...@@ -66,12 +60,6 @@ struct minus_op
RTG_THROW("Wrong inputs"); RTG_THROW("Wrong inputs");
return inputs.front(); return inputs.front();
} }
friend std::ostream& operator<<(std::ostream& os, const minus_op& op)
{
os << op.name();
return os;
}
}; };
struct id_target struct id_target
......
...@@ -11,12 +11,23 @@ ...@@ -11,12 +11,23 @@
namespace rtg { namespace rtg {
namespace operation_stream {
template<class T>
std::ostream& operator<<(std::ostream& os, const T& x)
{
os << x.name();
return os;
}
}
<% <%
interface('operation', interface('operation',
virtual('name', returns='std::string', const=True), virtual('name', returns='std::string', const=True),
virtual('compute_shape', returns='shape', input='std::vector<shape>', const=True), virtual('compute_shape', returns='shape', input='std::vector<shape>', const=True),
virtual('compute', returns='argument', input='std::vector<argument>', 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}($ ...@@ -173,6 +173,7 @@ pure_virtual_member = string.Template("virtual ${return_type} ${internal_name}($
virtual_member = string.Template(''' virtual_member = string.Template('''
${return_type} ${internal_name}(${member_params}) ${member_const} override ${return_type} ${internal_name}(${member_params}) ${member_const} override
{ {
${using}
return ${call}; return ${call};
} }
''') ''')
...@@ -217,7 +218,8 @@ def convert_member(d, struct_name): ...@@ -217,7 +218,8 @@ def convert_member(d, struct_name):
'const': '', 'const': '',
'member_const': '', 'member_const': '',
'friend': '', 'friend': '',
'this': '(*this)' 'this': '(*this)',
'using': ''
} }
args = [] args = []
params = [] params = []
...@@ -237,6 +239,8 @@ def convert_member(d, struct_name): ...@@ -237,6 +239,8 @@ def convert_member(d, struct_name):
member['member_const'] = 'const' member['member_const'] = 'const'
elif x == 'friend': elif x == 'friend':
member['friend'] = 'friend' member['friend'] = 'friend'
elif x == 'using':
member['using'] = 'using {};'.format(d[name]['using'])
else: else:
use_member = not(skip and struct_name == trim_type_name(t)) use_member = not(skip and struct_name == trim_type_name(t))
arg_name = x 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