Add operator<< for Coordinate, Fraction, Point

This commit is contained in:
FeRD (Frank Dana)
2020-11-27 00:33:52 -05:00
parent 70ea2659d8
commit bf80251a49
3 changed files with 48 additions and 2 deletions

View File

@@ -75,6 +75,18 @@ namespace openshot {
void SetJsonValue(const Json::Value root); ///< Load Json::Value into this object
};
/// Stream output operator for openshot::Coordinate
template<class charT, class traits>
std::basic_ostream<charT, traits>&
operator<<(std::basic_ostream<charT, traits>& o, const openshot::Coordinate& co) {
std::basic_ostringstream<charT, traits> s;
s.flags(o.flags());
s.imbue(o.getloc());
s.precision(o.precision());
s << "(" << co.X << ", " << co.Y << ")";
return o << s.str();
};
}
#endif

View File

@@ -84,7 +84,16 @@ namespace openshot {
Fraction Reciprocal() const;
};
// Stream output operator for openshot::Fraction
template<class charT, class traits>
std::basic_ostream<charT, traits>&
operator<<(std::basic_ostream<charT, traits>& o, const openshot::Fraction& frac) {
std::basic_ostringstream<charT, traits> s;
s.flags(o.flags());
s.imbue(o.getloc());
s.precision(o.precision());
s << "Fraction(" << frac.num << ", " << frac.den << ")";
return o << s.str();
};
}
#endif

View File

@@ -126,6 +126,31 @@ namespace openshot
};
// Stream output operator for openshot::Point
template<class charT, class traits>
std::basic_ostream<charT, traits>&
operator<<(std::basic_ostream<charT, traits>& o, const openshot::Point& p) {
std::basic_ostringstream<charT, traits> s;
s.flags(o.flags());
s.imbue(o.getloc());
s.precision(o.precision());
s << "co" << p.co;
switch(p.interpolation) {
case(openshot::LINEAR):
s << " interpolation(LINEAR)";
break;
case(openshot::CONSTANT):
s << " interpolation(CONSTANT)";
break;
case(openshot::BEZIER):
s << " interpolation(BEZIER)"
<< " handle_left" << p.handle_left
<< " handle_right" << p.handle_right;
break;
}
return o << s.str();
};
}
#endif