#include "backends/common/serialization.hpp"
namespace cv {
-namespace gimpl {
+namespace gapi {
namespace s11n {
namespace {
-void putData(GSerialized& s, const GModel::ConstGraph& cg, const ade::NodeHandle &nh) {
+void putData(GSerialized& s, const cv::gimpl::GModel::ConstGraph& cg, const ade::NodeHandle &nh) {
const auto gdata = cg.metadata(nh).get<gimpl::Data>();
const auto it = ade::util::find_if(s.m_datas, [&gdata](const cv::gimpl::Data &cd) {
return cd.rc == gdata.rc && cd.shape == gdata.shape;
}
}
-void putOp(GSerialized& s, const GModel::ConstGraph& cg, const ade::NodeHandle &nh) {
+void putOp(GSerialized& s, const cv::gimpl::GModel::ConstGraph& cg, const ade::NodeHandle &nh) {
const auto& op = cg.metadata(nh).get<gimpl::Op>();
for (const auto &in_nh : nh->inNodes()) { putData(s, cg, in_nh); }
for (const auto &out_nh : nh->outNodes()) { putData(s, cg, out_nh); }
}
void mkDataNode(ade::Graph& g, const cv::gimpl::Data& data) {
- GModel::Graph gm(g);
+ cv::gimpl::GModel::Graph gm(g);
auto nh = gm.createNode();
- gm.metadata(nh).set(NodeType{NodeType::DATA});
+ gm.metadata(nh).set(cv::gimpl::NodeType{cv::gimpl::NodeType::DATA});
gm.metadata(nh).set(data);
}
void mkOpNode(ade::Graph& g, const cv::gimpl::Op& op) {
- GModel::Graph gm(g);
+ cv::gimpl::GModel::Graph gm(g);
auto nh = gm.createNode();
- gm.metadata(nh).set(NodeType{NodeType::OP});
+ gm.metadata(nh).set(cv::gimpl::NodeType{cv::gimpl::NodeType::OP});
gm.metadata(nh).set(op);
}
void linkNodes(ade::Graph& g) {
std::map<cv::gimpl::RcDesc, ade::NodeHandle> dataNodes;
- GModel::Graph gm(g);
+ cv::gimpl::GModel::Graph gm(g);
for (const auto& nh : g.nodes()) {
- if (gm.metadata(nh).get<NodeType>().t == NodeType::DATA) {
+ if (gm.metadata(nh).get<cv::gimpl::NodeType>().t == cv::gimpl::NodeType::DATA) {
const auto &d = gm.metadata(nh).get<gimpl::Data>();
const auto rc = cv::gimpl::RcDesc{d.rc, d.shape, d.ctor};
dataNodes[rc] = nh;
}
for (const auto& nh : g.nodes()) {
- if (gm.metadata(nh).get<NodeType>().t == NodeType::OP) {
+ if (gm.metadata(nh).get<cv::gimpl::NodeType>().t == cv::gimpl::NodeType::OP) {
const auto& op = gm.metadata(nh).get<gimpl::Op>();
for (const auto& in : ade::util::indexed(op.args)) {
const auto& arg = ade::util::value(in);
const auto rc = arg.get<gimpl::RcDesc>();
const auto& in_nh = dataNodes.at(rc);
const auto& in_eh = g.link(in_nh, nh);
- gm.metadata(in_eh).set(Input{idx});
+ gm.metadata(in_eh).set(cv::gimpl::Input{idx});
}
}
const auto rc = ade::util::value(out);
const auto& out_nh = dataNodes.at(rc);
const auto& out_eh = g.link(nh, out_nh);
- gm.metadata(out_eh).set(Output{idx});
+ gm.metadata(out_eh).set(cv::gimpl::Output{idx});
}
}
}
using M = std::map<cv::gimpl::RcDesc, ade::NodeHandle>; // FIXME: unordered!
cv::gimpl::GModel::Graph gm(g);
- auto &proto = gm.metadata().get<Protocol>();
+ auto &proto = gm.metadata().get<cv::gimpl::Protocol>();
const S set_in(proto.inputs.begin(), proto.inputs.end());
const S set_out(proto.outputs.begin(), proto.outputs.end());
// OpenCV types ////////////////////////////////////////////////////////////////
-I::OStream& operator<< (I::OStream& os, const cv::Point &pt) {
+IOStream& operator<< (IOStream& os, const cv::Point &pt) {
return os << pt.x << pt.y;
}
-I::IStream& operator>> (I::IStream& is, cv::Point& pt) {
+IIStream& operator>> (IIStream& is, cv::Point& pt) {
return is >> pt.x >> pt.y;
}
-I::OStream& operator<< (I::OStream& os, const cv::Size &sz) {
+IOStream& operator<< (IOStream& os, const cv::Size &sz) {
return os << sz.width << sz.height;
}
-I::IStream& operator>> (I::IStream& is, cv::Size& sz) {
+IIStream& operator>> (IIStream& is, cv::Size& sz) {
return is >> sz.width >> sz.height;
}
-I::OStream& operator<< (I::OStream& os, const cv::Rect &rc) {
+IOStream& operator<< (IOStream& os, const cv::Rect &rc) {
return os << rc.x << rc.y << rc.width << rc.height;
}
-I::IStream& operator>> (I::IStream& is, cv::Rect& rc) {
+IIStream& operator>> (IIStream& is, cv::Rect& rc) {
return is >> rc.x >> rc.y >> rc.width >> rc.height;
}
-I::OStream& operator<< (I::OStream& os, const cv::Scalar &s) {
+IOStream& operator<< (IOStream& os, const cv::Scalar &s) {
return os << s.val[0] << s.val[1] << s.val[2] << s.val[3];
}
-I::IStream& operator>> (I::IStream& is, cv::Scalar& s) {
+IIStream& operator>> (IIStream& is, cv::Scalar& s) {
return is >> s.val[0] >> s.val[1] >> s.val[2] >> s.val[3];
}
#if !defined(GAPI_STANDALONE)
template<typename T>
- void write_plain(I::OStream &os, const T *arr, std::size_t sz) {
+ void write_plain(IOStream &os, const T *arr, std::size_t sz) {
for (auto &&it : ade::util::iota(sz)) os << arr[it];
}
template<typename T>
- void read_plain(I::IStream &is, T *arr, std::size_t sz) {
+ void read_plain(IIStream &is, T *arr, std::size_t sz) {
for (auto &&it : ade::util::iota(sz)) is >> arr[it];
}
template<typename T>
-void write_mat_data(I::OStream &os, const cv::Mat &m) {
+void write_mat_data(IOStream &os, const cv::Mat &m) {
// Write every row individually (handles the case when Mat is a view)
for (auto &&r : ade::util::iota(m.rows)) {
write_plain(os, m.ptr<T>(r), m.cols*m.channels());
}
}
template<typename T>
-void read_mat_data(I::IStream &is, cv::Mat &m) {
+void read_mat_data(IIStream &is, cv::Mat &m) {
// Write every row individually (handles the case when Mat is aligned)
for (auto &&r : ade::util::iota(m.rows)) {
read_plain(is, m.ptr<T>(r), m.cols*m.channels());
}
}
#else
-void write_plain(I::OStream &os, const uchar *arr, std::size_t sz) {
+void write_plain(IOStream &os, const uchar *arr, std::size_t sz) {
for (auto &&it : ade::util::iota(sz)) os << arr[it];
}
-void read_plain(I::IStream &is, uchar *arr, std::size_t sz) {
+void read_plain(IIStream &is, uchar *arr, std::size_t sz) {
for (auto &&it : ade::util::iota(sz)) is >> arr[it];
}
template<typename T>
-void write_mat_data(I::OStream &os, const cv::Mat &m) {
+void write_mat_data(IOStream &os, const cv::Mat &m) {
// Write every row individually (handles the case when Mat is a view)
for (auto &&r : ade::util::iota(m.rows)) {
write_plain(os, m.ptr(r), m.cols*m.channels()*sizeof(T));
}
}
template<typename T>
-void read_mat_data(I::IStream &is, cv::Mat &m) {
+void read_mat_data(IIStream &is, cv::Mat &m) {
// Write every row individually (handles the case when Mat is aligned)
for (auto &&r : ade::util::iota(m.rows)) {
read_plain(is, m.ptr(r), m.cols*m.channels()*sizeof(T));
#endif
} // namespace
-I::OStream& operator<< (I::OStream& os, const cv::Mat &m) {
+IOStream& operator<< (IOStream& os, const cv::Mat &m) {
#if !defined(GAPI_STANDALONE)
GAPI_Assert(m.size.dims() == 2 && "Only 2D images are supported now");
#else
}
return os;
}
-I::IStream& operator>> (I::IStream& is, cv::Mat& m) {
+IIStream& operator>> (IIStream& is, cv::Mat& m) {
int rows = -1, cols = -1, type = 0;
is >> rows >> cols >> type;
m.create(cv::Size(cols, rows), type);
return is;
}
-I::OStream& operator<< (I::OStream& os, const cv::gapi::wip::draw::Text &t) {
+IOStream& operator<< (IOStream& os, const cv::gapi::wip::draw::Text &t) {
return os << t.bottom_left_origin << t.color << t.ff << t.fs << t.lt << t.org << t.text << t.thick;
}
-I::IStream& operator>> (I::IStream& is, cv::gapi::wip::draw::Text &t) {
+IIStream& operator>> (IIStream& is, cv::gapi::wip::draw::Text &t) {
return is >> t.bottom_left_origin >> t.color >> t.ff >> t.fs >> t.lt >> t.org >> t.text >> t.thick;
}
-I::OStream& operator<< (I::OStream&, const cv::gapi::wip::draw::FText &) {
+IOStream& operator<< (IOStream&, const cv::gapi::wip::draw::FText &) {
GAPI_Assert(false && "Serialization: Unsupported << for FText");
}
-I::IStream& operator>> (I::IStream&, cv::gapi::wip::draw::FText &) {
+IIStream& operator>> (IIStream&, cv::gapi::wip::draw::FText &) {
GAPI_Assert(false && "Serialization: Unsupported >> for FText");
}
-I::OStream& operator<< (I::OStream& os, const cv::gapi::wip::draw::Circle &c) {
+IOStream& operator<< (IOStream& os, const cv::gapi::wip::draw::Circle &c) {
return os << c.center << c.color << c.lt << c.radius << c.shift << c.thick;
}
-I::IStream& operator>> (I::IStream& is, cv::gapi::wip::draw::Circle &c) {
+IIStream& operator>> (IIStream& is, cv::gapi::wip::draw::Circle &c) {
return is >> c.center >> c.color >> c.lt >> c.radius >> c.shift >> c.thick;
}
-I::OStream& operator<< (I::OStream& os, const cv::gapi::wip::draw::Rect &r) {
+IOStream& operator<< (IOStream& os, const cv::gapi::wip::draw::Rect &r) {
return os << r.color << r.lt << r.rect << r.shift << r.thick;
}
-I::IStream& operator>> (I::IStream& is, cv::gapi::wip::draw::Rect &r) {
+IIStream& operator>> (IIStream& is, cv::gapi::wip::draw::Rect &r) {
return is >> r.color >> r.lt >> r.rect >> r.shift >> r.thick;
}
-I::OStream& operator<< (I::OStream& os, const cv::gapi::wip::draw::Image &i) {
+IOStream& operator<< (IOStream& os, const cv::gapi::wip::draw::Image &i) {
return os << i.org << i.alpha << i.img;
}
-I::IStream& operator>> (I::IStream& is, cv::gapi::wip::draw::Image &i) {
+IIStream& operator>> (IIStream& is, cv::gapi::wip::draw::Image &i) {
return is >> i.org >> i.alpha >> i.img;
}
-I::OStream& operator<< (I::OStream& os, const cv::gapi::wip::draw::Mosaic &m) {
+IOStream& operator<< (IOStream& os, const cv::gapi::wip::draw::Mosaic &m) {
return os << m.cellSz << m.decim << m.mos;
}
-I::IStream& operator>> (I::IStream& is, cv::gapi::wip::draw::Mosaic &m) {
+IIStream& operator>> (IIStream& is, cv::gapi::wip::draw::Mosaic &m) {
return is >> m.cellSz >> m.decim >> m.mos;
}
-I::OStream& operator<< (I::OStream& os, const cv::gapi::wip::draw::Poly &p) {
+IOStream& operator<< (IOStream& os, const cv::gapi::wip::draw::Poly &p) {
return os << p.color << p.lt << p.points << p.shift << p.thick;
}
-I::IStream& operator>> (I::IStream& is, cv::gapi::wip::draw::Poly &p) {
+IIStream& operator>> (IIStream& is, cv::gapi::wip::draw::Poly &p) {
return is >> p.color >> p.lt >> p.points >> p.shift >> p.thick;
}
-I::OStream& operator<< (I::OStream& os, const cv::gapi::wip::draw::Line &l) {
+IOStream& operator<< (IOStream& os, const cv::gapi::wip::draw::Line &l) {
return os << l.color << l.lt << l.pt1 << l.pt2 << l.shift << l.thick;
}
-I::IStream& operator>> (I::IStream& is, cv::gapi::wip::draw::Line &l) {
+IIStream& operator>> (IIStream& is, cv::gapi::wip::draw::Line &l) {
return is >> l.color >> l.lt >> l.pt1 >> l.pt2 >> l.shift >> l.thick;
}
// Stubs (empty types)
-I::OStream& operator<< (I::OStream& os, cv::util::monostate ) {return os;}
-I::IStream& operator>> (I::IStream& is, cv::util::monostate &) {return is;}
+IOStream& operator<< (IOStream& os, cv::util::monostate ) {return os;}
+IIStream& operator>> (IIStream& is, cv::util::monostate &) {return is;}
-I::OStream& operator<< (I::OStream& os, const cv::GScalarDesc &) {return os;}
-I::IStream& operator>> (I::IStream& is, cv::GScalarDesc &) {return is;}
+IOStream& operator<< (IOStream& os, const cv::GScalarDesc &) {return os;}
+IIStream& operator>> (IIStream& is, cv::GScalarDesc &) {return is;}
-I::OStream& operator<< (I::OStream& os, const cv::GOpaqueDesc &) {return os;}
-I::IStream& operator>> (I::IStream& is, cv::GOpaqueDesc &) {return is;}
+IOStream& operator<< (IOStream& os, const cv::GOpaqueDesc &) {return os;}
+IIStream& operator>> (IIStream& is, cv::GOpaqueDesc &) {return is;}
-I::OStream& operator<< (I::OStream& os, const cv::GArrayDesc &) {return os;}
-I::IStream& operator>> (I::IStream& is, cv::GArrayDesc &) {return is;}
+IOStream& operator<< (IOStream& os, const cv::GArrayDesc &) {return os;}
+IIStream& operator>> (IIStream& is, cv::GArrayDesc &) {return is;}
#if !defined(GAPI_STANDALONE)
-I::OStream& operator<< (I::OStream& os, const cv::UMat &)
+IOStream& operator<< (IOStream& os, const cv::UMat &)
{
GAPI_Assert(false && "Serialization: Unsupported << for UMat");
return os;
}
-I::IStream& operator >> (I::IStream& is, cv::UMat &)
+IIStream& operator >> (IIStream& is, cv::UMat &)
{
GAPI_Assert(false && "Serialization: Unsupported >> for UMat");
return is;
}
#endif // !defined(GAPI_STANDALONE)
-I::OStream& operator<< (I::OStream& os, const cv::gapi::wip::IStreamSource::Ptr &)
+IOStream& operator<< (IOStream& os, const cv::gapi::wip::IStreamSource::Ptr &)
{
GAPI_Assert(false && "Serialization: Unsupported << for IStreamSource::Ptr");
return os;
}
-I::IStream& operator >> (I::IStream& is, cv::gapi::wip::IStreamSource::Ptr &)
+IIStream& operator >> (IIStream& is, cv::gapi::wip::IStreamSource::Ptr &)
{
GAPI_Assert("Serialization: Unsupported >> for IStreamSource::Ptr");
return is;
template<typename Ref>
struct putToStream<Ref, std::tuple<>>
{
- static void put(I::OStream&, const Ref &)
+ static void put(IOStream&, const Ref &)
{
GAPI_Assert(false && "Unsupported type for GArray/GOpaque serialization");
}
template<typename Ref, typename T, typename... Ts>
struct putToStream<Ref, std::tuple<T, Ts...>>
{
- static void put(I::OStream& os, const Ref &r)
+ static void put(IOStream& os, const Ref &r)
{
if (r.getKind() == cv::detail::GOpaqueTraits<T>::kind) {
os << r.template rref<T>();
template<typename Ref>
struct getFromStream<Ref, std::tuple<>>
{
- static void get(I::IStream&, Ref &, cv::detail::OpaqueKind)
+ static void get(IIStream&, Ref &, cv::detail::OpaqueKind)
{
GAPI_Assert(false && "Unsupported type for GArray/GOpaque deserialization");
}
template<typename Ref, typename T, typename... Ts>
struct getFromStream<Ref, std::tuple<T, Ts...>>
{
- static void get(I::IStream& is, Ref &r, cv::detail::OpaqueKind kind) {
+ static void get(IIStream& is, Ref &r, cv::detail::OpaqueKind kind) {
if (kind == cv::detail::GOpaqueTraits<T>::kind) {
r.template reset<T>();
auto& val = r.template wref<T>();
};
}
-I::OStream& operator<< (I::OStream& os, const cv::detail::VectorRef& ref)
+IOStream& operator<< (IOStream& os, const cv::detail::VectorRef& ref)
{
os << ref.getKind();
putToStream<cv::detail::VectorRef, cv::detail::GOpaqueTraitsArrayTypes>::put(os, ref);
return os;
}
-I::IStream& operator >> (I::IStream& is, cv::detail::VectorRef& ref)
+IIStream& operator >> (IIStream& is, cv::detail::VectorRef& ref)
{
cv::detail::OpaqueKind kind;
is >> kind;
return is;
}
-I::OStream& operator<< (I::OStream& os, const cv::detail::OpaqueRef& ref)
+IOStream& operator<< (IOStream& os, const cv::detail::OpaqueRef& ref)
{
os << ref.getKind();
putToStream<cv::detail::OpaqueRef, cv::detail::GOpaqueTraitsOpaqueTypes>::put(os, ref);
return os;
}
-I::IStream& operator >> (I::IStream& is, cv::detail::OpaqueRef& ref)
+IIStream& operator >> (IIStream& is, cv::detail::OpaqueRef& ref)
{
cv::detail::OpaqueKind kind;
is >> kind;
// Enums and structures
namespace {
-template<typename E> I::OStream& put_enum(I::OStream& os, E e) {
+template<typename E> IOStream& put_enum(IOStream& os, E e) {
return os << static_cast<int>(e);
}
-template<typename E> I::IStream& get_enum(I::IStream& is, E &e) {
+template<typename E> IIStream& get_enum(IIStream& is, E &e) {
int x{}; is >> x; e = static_cast<E>(x);
return is;
}
} // anonymous namespace
-I::OStream& operator<< (I::OStream& os, cv::GShape sh) {
+IOStream& operator<< (IOStream& os, cv::GShape sh) {
return put_enum(os, sh);
}
-I::IStream& operator>> (I::IStream& is, cv::GShape &sh) {
+IIStream& operator>> (IIStream& is, cv::GShape &sh) {
return get_enum<cv::GShape>(is, sh);
}
-I::OStream& operator<< (I::OStream& os, cv::detail::ArgKind k) {
+IOStream& operator<< (IOStream& os, cv::detail::ArgKind k) {
return put_enum(os, k);
}
-I::IStream& operator>> (I::IStream& is, cv::detail::ArgKind &k) {
+IIStream& operator>> (IIStream& is, cv::detail::ArgKind &k) {
return get_enum<cv::detail::ArgKind>(is, k);
}
-I::OStream& operator<< (I::OStream& os, cv::detail::OpaqueKind k) {
+IOStream& operator<< (IOStream& os, cv::detail::OpaqueKind k) {
return put_enum(os, k);
}
-I::IStream& operator>> (I::IStream& is, cv::detail::OpaqueKind &k) {
+IIStream& operator>> (IIStream& is, cv::detail::OpaqueKind &k) {
return get_enum<cv::detail::OpaqueKind>(is, k);
}
-I::OStream& operator<< (I::OStream& os, cv::gimpl::Data::Storage s) {
+IOStream& operator<< (IOStream& os, cv::gimpl::Data::Storage s) {
return put_enum(os, s);
}
-I::IStream& operator>> (I::IStream& is, cv::gimpl::Data::Storage &s) {
+IIStream& operator>> (IIStream& is, cv::gimpl::Data::Storage &s) {
return get_enum<cv::gimpl::Data::Storage>(is, s);
}
-I::OStream& operator<< (I::OStream& os, const cv::GArg &arg) {
+IOStream& operator<< (IOStream& os, const cv::GArg &arg) {
// Only GOBJREF and OPAQUE_VAL kinds can be serialized/deserialized
GAPI_Assert( arg.kind == cv::detail::ArgKind::OPAQUE_VAL
|| arg.kind == cv::detail::ArgKind::GOBJREF);
return os;
}
-I::IStream& operator>> (I::IStream& is, cv::GArg &arg) {
+IIStream& operator>> (IIStream& is, cv::GArg &arg) {
is >> arg.kind >> arg.opaque_kind;
// Only GOBJREF and OPAQUE_VAL kinds can be serialized/deserialized
return is;
}
-I::OStream& operator<< (I::OStream& os, const cv::GKernel &k) {
+IOStream& operator<< (IOStream& os, const cv::GKernel &k) {
return os << k.name << k.tag << k.outShapes;
}
-I::IStream& operator>> (I::IStream& is, cv::GKernel &k) {
+IIStream& operator>> (IIStream& is, cv::GKernel &k) {
return is >> const_cast<std::string&>(k.name)
>> const_cast<std::string&>(k.tag)
>> const_cast<cv::GShapes&>(k.outShapes);
}
-I::OStream& operator<< (I::OStream& os, const cv::GMatDesc &d) {
+IOStream& operator<< (IOStream& os, const cv::GMatDesc &d) {
return os << d.depth << d.chan << d.size << d.planar << d.dims;
}
-I::IStream& operator>> (I::IStream& is, cv::GMatDesc &d) {
+IIStream& operator>> (IIStream& is, cv::GMatDesc &d) {
return is >> d.depth >> d.chan >> d.size >> d.planar >> d.dims;
}
-I::OStream& operator<< (I::OStream& os, const cv::gimpl::RcDesc &rc) {
+IOStream& operator<< (IOStream& os, const cv::gimpl::RcDesc &rc) {
// FIXME: HostCtor is not serialized!
return os << rc.id << rc.shape;
}
-I::IStream& operator>> (I::IStream& is, cv::gimpl::RcDesc &rc) {
+IIStream& operator>> (IIStream& is, cv::gimpl::RcDesc &rc) {
// FIXME: HostCtor is not deserialized!
return is >> rc.id >> rc.shape;
}
-I::OStream& operator<< (I::OStream& os, const cv::gimpl::Op &op) {
+IOStream& operator<< (IOStream& os, const cv::gimpl::Op &op) {
return os << op.k << op.args << op.outs;
}
-I::IStream& operator>> (I::IStream& is, cv::gimpl::Op &op) {
+IIStream& operator>> (IIStream& is, cv::gimpl::Op &op) {
return is >> op.k >> op.args >> op.outs;
}
-I::OStream& operator<< (I::OStream& os, const cv::gimpl::Data &d) {
+IOStream& operator<< (IOStream& os, const cv::gimpl::Data &d) {
// FIXME: HostCtor is not stored here!!
// FIXME: Storage may be incorrect for subgraph-to-graph process
return os << d.shape << d.rc << d.meta << d.storage << d.kind;
};
} // anonymous namespace
-I::IStream& operator>> (I::IStream& is, cv::gimpl::Data &d) {
+IIStream& operator>> (IIStream& is, cv::gimpl::Data &d) {
// FIXME: HostCtor is not stored here!!
// FIXME: Storage may be incorrect for subgraph-to-graph process
is >> d.shape >> d.rc >> d.meta >> d.storage >> d.kind;
}
-I::OStream& operator<< (I::OStream& os, const cv::gimpl::DataObjectCounter &c) {
+IOStream& operator<< (IOStream& os, const cv::gimpl::DataObjectCounter &c) {
return os << c.m_next_data_id;
}
-I::IStream& operator>> (I::IStream& is, cv::gimpl::DataObjectCounter &c) {
+IIStream& operator>> (IIStream& is, cv::gimpl::DataObjectCounter &c) {
return is >> c.m_next_data_id;
}
-I::OStream& operator<< (I::OStream& os, const cv::gimpl::Protocol &p) {
+IOStream& operator<< (IOStream& os, const cv::gimpl::Protocol &p) {
// NB: in_nhs/out_nhs are not written!
return os << p.inputs << p.outputs;
}
-I::IStream& operator>> (I::IStream& is, cv::gimpl::Protocol &p) {
+IIStream& operator>> (IIStream& is, cv::gimpl::Protocol &p) {
// NB: in_nhs/out_nhs are reconstructed at a later phase
return is >> p.inputs >> p.outputs;
}
-void serialize( I::OStream& os
+void serialize( IOStream& os
, const ade::Graph &g
, const std::vector<ade::NodeHandle> &nodes) {
cv::gimpl::GModel::ConstGraph cg(g);
serialize(os, g, cg.metadata().get<cv::gimpl::Protocol>(), nodes);
}
-void serialize( I::OStream& os
+void serialize( IOStream& os
, const ade::Graph &g
, const cv::gimpl::Protocol &p
, const std::vector<ade::NodeHandle> &nodes) {
cv::gimpl::GModel::ConstGraph cg(g);
GSerialized s;
for (auto &nh : nodes) {
- switch (cg.metadata(nh).get<NodeType>().t)
+ switch (cg.metadata(nh).get<cv::gimpl::NodeType>().t)
{
- case NodeType::OP: putOp (s, cg, nh); break;
- case NodeType::DATA: putData(s, cg, nh); break;
+ case cv::gimpl::NodeType::OP: putOp (s, cg, nh); break;
+ case cv::gimpl::NodeType::DATA: putData(s, cg, nh); break;
default: util::throw_error(std::logic_error("Unknown NodeType"));
}
}
os << s.m_ops << s.m_datas << s.m_counter << s.m_proto;
}
-GSerialized deserialize(I::IStream &is) {
+GSerialized deserialize(IIStream &is) {
GSerialized s;
is >> s.m_ops >> s.m_datas >> s.m_counter >> s.m_proto;
return s;
void reconstruct(const GSerialized &s, ade::Graph &g) {
GAPI_Assert(g.nodes().empty());
- for (const auto& d : s.m_datas) cv::gimpl::s11n::mkDataNode(g, d);
- for (const auto& op : s.m_ops) cv::gimpl::s11n::mkOpNode(g, op);
- cv::gimpl::s11n::linkNodes(g);
+ for (const auto& d : s.m_datas) cv::gapi::s11n::mkDataNode(g, d);
+ for (const auto& op : s.m_ops) cv::gapi::s11n::mkOpNode(g, op);
+ cv::gapi::s11n::linkNodes(g);
cv::gimpl::GModel::Graph gm(g);
gm.metadata().set(s.m_counter);
gm.metadata().set(s.m_proto);
- cv::gimpl::s11n::relinkProto(g);
+ cv::gapi::s11n::relinkProto(g);
gm.metadata().set(cv::gimpl::Deserialized{});
}
const std::vector<char>& ByteMemoryOutStream::data() const {
return m_storage;
}
-I::OStream& ByteMemoryOutStream::operator<< (uint32_t atom) {
+IOStream& ByteMemoryOutStream::operator<< (uint32_t atom) {
m_storage.push_back(0xFF & (atom));
m_storage.push_back(0xFF & (atom >> 8));
m_storage.push_back(0xFF & (atom >> 16));
m_storage.push_back(0xFF & (atom >> 24));
return *this;
}
-I::OStream& ByteMemoryOutStream::operator<< (uint64_t atom) {
+IOStream& ByteMemoryOutStream::operator<< (uint64_t atom) {
for (int i = 0; i < 8; ++i) {
m_storage.push_back(0xFF & (atom >> (i * 8)));;
}
return *this;
}
-I::OStream& ByteMemoryOutStream::operator<< (bool atom) {
+IOStream& ByteMemoryOutStream::operator<< (bool atom) {
m_storage.push_back(atom ? 1 : 0);
return *this;
}
-I::OStream& ByteMemoryOutStream::operator<< (char atom) {
+IOStream& ByteMemoryOutStream::operator<< (char atom) {
m_storage.push_back(atom);
return *this;
}
-I::OStream& ByteMemoryOutStream::operator<< (unsigned char atom) {
+IOStream& ByteMemoryOutStream::operator<< (unsigned char atom) {
return *this << static_cast<char>(atom);
}
-I::OStream& ByteMemoryOutStream::operator<< (short atom) {
+IOStream& ByteMemoryOutStream::operator<< (short atom) {
static_assert(sizeof(short) == 2, "Expecting sizeof(short) == 2");
m_storage.push_back(0xFF & (atom));
m_storage.push_back(0xFF & (atom >> 8));
return *this;
}
-I::OStream& ByteMemoryOutStream::operator<< (unsigned short atom) {
+IOStream& ByteMemoryOutStream::operator<< (unsigned short atom) {
return *this << static_cast<short>(atom);
}
-I::OStream& ByteMemoryOutStream::operator<< (int atom) {
+IOStream& ByteMemoryOutStream::operator<< (int atom) {
static_assert(sizeof(int) == 4, "Expecting sizeof(int) == 4");
return *this << static_cast<uint32_t>(atom);
}
-//I::OStream& ByteMemoryOutStream::operator<< (std::size_t atom) {
+//IOStream& ByteMemoryOutStream::operator<< (std::size_t atom) {
// // NB: type truncated!
// return *this << static_cast<uint32_t>(atom);
//}
-I::OStream& ByteMemoryOutStream::operator<< (float atom) {
+IOStream& ByteMemoryOutStream::operator<< (float atom) {
static_assert(sizeof(float) == 4, "Expecting sizeof(float) == 4");
uint32_t tmp = 0u;
memcpy(&tmp, &atom, sizeof(float));
return *this << static_cast<uint32_t>(htonl(tmp));
}
-I::OStream& ByteMemoryOutStream::operator<< (double atom) {
+IOStream& ByteMemoryOutStream::operator<< (double atom) {
static_assert(sizeof(double) == 8, "Expecting sizeof(double) == 8");
uint32_t tmp[2] = {0u};
memcpy(tmp, &atom, sizeof(double));
*this << static_cast<uint32_t>(htonl(tmp[1]));
return *this;
}
-I::OStream& ByteMemoryOutStream::operator<< (const std::string &str) {
+IOStream& ByteMemoryOutStream::operator<< (const std::string &str) {
//*this << static_cast<std::size_t>(str.size()); // N.B. Put type explicitly
*this << static_cast<uint32_t>(str.size()); // N.B. Put type explicitly
for (auto c : str) *this << c;
ByteMemoryInStream::ByteMemoryInStream(const std::vector<char> &data)
: m_storage(data) {
}
-I::IStream& ByteMemoryInStream::operator>> (uint32_t &atom) {
+IIStream& ByteMemoryInStream::operator>> (uint32_t &atom) {
check(sizeof(uint32_t));
uint8_t x[4];
x[0] = static_cast<uint8_t>(m_storage[m_idx++]);
atom = ((x[0]) | (x[1] << 8) | (x[2] << 16) | (x[3] << 24));
return *this;
}
-I::IStream& ByteMemoryInStream::operator>> (bool& atom) {
+IIStream& ByteMemoryInStream::operator>> (bool& atom) {
check(sizeof(char));
atom = (m_storage[m_idx++] == 0) ? false : true;
return *this;
}
-I::IStream& ByteMemoryInStream::operator>> (std::vector<bool>::reference atom) {
+IIStream& ByteMemoryInStream::operator>> (std::vector<bool>::reference atom) {
check(sizeof(char));
atom = (m_storage[m_idx++] == 0) ? false : true;
return *this;
}
-I::IStream& ByteMemoryInStream::operator>> (char &atom) {
+IIStream& ByteMemoryInStream::operator>> (char &atom) {
check(sizeof(char));
atom = m_storage[m_idx++];
return *this;
}
-I::IStream& ByteMemoryInStream::operator>> (uint64_t &atom) {
+IIStream& ByteMemoryInStream::operator>> (uint64_t &atom) {
check(sizeof(uint64_t));
uint8_t x[8];
atom = 0;
}
return *this;
}
-I::IStream& ByteMemoryInStream::operator>> (unsigned char &atom) {
+IIStream& ByteMemoryInStream::operator>> (unsigned char &atom) {
char c{};
*this >> c;
atom = static_cast<unsigned char>(c);
return *this;
}
-I::IStream& ByteMemoryInStream::operator>> (short &atom) {
+IIStream& ByteMemoryInStream::operator>> (short &atom) {
static_assert(sizeof(short) == 2, "Expecting sizeof(short) == 2");
check(sizeof(short));
uint8_t x[2];
atom = ((x[0]) | (x[1] << 8));
return *this;
}
-I::IStream& ByteMemoryInStream::operator>> (unsigned short &atom) {
+IIStream& ByteMemoryInStream::operator>> (unsigned short &atom) {
short s{};
*this >> s;
atom = static_cast<unsigned short>(s);
return *this;
}
-I::IStream& ByteMemoryInStream::operator>> (int& atom) {
+IIStream& ByteMemoryInStream::operator>> (int& atom) {
static_assert(sizeof(int) == 4, "Expecting sizeof(int) == 4");
atom = static_cast<int>(getU32());
return *this;
}
-//I::IStream& ByteMemoryInStream::operator>> (std::size_t& atom) {
+//IIStream& ByteMemoryInStream::operator>> (std::size_t& atom) {
// // NB. Type was truncated!
// atom = static_cast<std::size_t>(getU32());
// return *this;
//}
-I::IStream& ByteMemoryInStream::operator>> (float& atom) {
+IIStream& ByteMemoryInStream::operator>> (float& atom) {
static_assert(sizeof(float) == 4, "Expecting sizeof(float) == 4");
uint32_t tmp = ntohl(getU32());
memcpy(&atom, &tmp, sizeof(float));
return *this;
}
-I::IStream& ByteMemoryInStream::operator>> (double& atom) {
+IIStream& ByteMemoryInStream::operator>> (double& atom) {
static_assert(sizeof(double) == 8, "Expecting sizeof(double) == 8");
uint32_t tmp[2] = {ntohl(getU32()), ntohl(getU32())};
memcpy(&atom, tmp, sizeof(double));
return *this;
}
-I::IStream& ByteMemoryInStream::operator>> (std::string& str) {
+IIStream& ByteMemoryInStream::operator>> (std::string& str) {
//std::size_t sz = 0u;
uint32_t sz = 0u;
*this >> sz;
return *this;
}
-GAPI_EXPORTS void serialize(I::OStream& os, const cv::GMetaArgs &ma) {
+GAPI_EXPORTS void serialize(IOStream& os, const cv::GMetaArgs &ma) {
os << ma;
}
-GAPI_EXPORTS void serialize(I::OStream& os, const cv::GRunArgs &ra) {
+GAPI_EXPORTS void serialize(IOStream& os, const cv::GRunArgs &ra) {
os << ra;
}
-GAPI_EXPORTS GMetaArgs meta_args_deserialize(I::IStream& is) {
+GAPI_EXPORTS GMetaArgs meta_args_deserialize(IIStream& is) {
GMetaArgs s;
is >> s;
return s;
}
-GAPI_EXPORTS GRunArgs run_args_deserialize(I::IStream& is) {
+GAPI_EXPORTS GRunArgs run_args_deserialize(IIStream& is) {
GRunArgs s;
is >> s;
return s;
} // namespace s11n
-} // namespace gimpl
+} // namespace gapi
} // namespace cv
#include "compiler/gmodel.hpp"
#include "opencv2/gapi/render/render_types.hpp"
+#include "opencv2/gapi/s11n.hpp" // basic interfaces
#if (defined _WIN32 || defined _WIN64) && defined _MSC_VER
#pragma warning(disable: 4702)
#endif
namespace cv {
-namespace gimpl {
+namespace gapi {
namespace s11n {
struct GSerialized {
};
////////////////////////////////////////////////////////////////////////////////
-// Stream interfaces, so far temporary
-namespace I {
- struct GAPI_EXPORTS OStream {
- virtual ~OStream() = default;
-
- // Define the native support for basic C++ types at the API level:
- virtual OStream& operator<< (bool) = 0;
- virtual OStream& operator<< (char) = 0;
- virtual OStream& operator<< (unsigned char) = 0;
- virtual OStream& operator<< (short) = 0;
- virtual OStream& operator<< (unsigned short) = 0;
- virtual OStream& operator<< (int) = 0;
- //virtual OStream& operator<< (std::size_t) = 0;
- virtual OStream& operator<< (uint32_t) = 0;
- virtual OStream& operator<< (uint64_t) = 0;
- virtual OStream& operator<< (float) = 0;
- virtual OStream& operator<< (double) = 0;
- virtual OStream& operator<< (const std::string&) = 0;
- };
-
- struct GAPI_EXPORTS IStream {
- virtual ~IStream() = default;
-
- virtual IStream& operator>> (bool &) = 0;
- virtual IStream& operator>> (std::vector<bool>::reference) = 0;
- virtual IStream& operator>> (char &) = 0;
- virtual IStream& operator>> (unsigned char &) = 0;
- virtual IStream& operator>> (short &) = 0;
- virtual IStream& operator>> (unsigned short &) = 0;
- virtual IStream& operator>> (int &) = 0;
- virtual IStream& operator>> (float &) = 0;
- virtual IStream& operator>> (double &) = 0;
- //virtual IStream& operator>> (std::size_t &) = 0;
- virtual IStream& operator >> (uint32_t &) = 0;
- virtual IStream& operator >> (uint64_t &) = 0;
- virtual IStream& operator>> (std::string &) = 0;
- };
-} // namespace I
-
-////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// S11N operators
-// Note: operators for basic types are defined in IStream/OStream
-
-// OpenCV types ////////////////////////////////////////////////////////////////
-
-GAPI_EXPORTS I::OStream& operator<< (I::OStream& os, const cv::Point &pt);
-GAPI_EXPORTS I::IStream& operator>> (I::IStream& is, cv::Point &pt);
-
-GAPI_EXPORTS I::OStream& operator<< (I::OStream& os, const cv::Size &sz);
-GAPI_EXPORTS I::IStream& operator>> (I::IStream& is, cv::Size &sz);
-
-GAPI_EXPORTS I::OStream& operator<< (I::OStream& os, const cv::Rect &rc);
-GAPI_EXPORTS I::IStream& operator>> (I::IStream& is, cv::Rect &rc);
+// Note: operators for basic types are defined in IIStream/IOStream
-GAPI_EXPORTS I::OStream& operator<< (I::OStream& os, const cv::Scalar &s);
-GAPI_EXPORTS I::IStream& operator>> (I::IStream& is, cv::Scalar &s);
-
-GAPI_EXPORTS I::OStream& operator<< (I::OStream& os, const cv::Mat &m);
-GAPI_EXPORTS I::IStream& operator>> (I::IStream& is, cv::Mat &m);
+// G-API types /////////////////////////////////////////////////////////////////
-GAPI_EXPORTS I::OStream& operator<< (I::OStream& os, const cv::gapi::wip::draw::Text &t);
-GAPI_EXPORTS I::IStream& operator>> (I::IStream& is, cv::gapi::wip::draw::Text &t);
+GAPI_EXPORTS IOStream& operator<< (IOStream& os, cv::util::monostate );
+GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::util::monostate &);
-GAPI_EXPORTS I::OStream& operator<< (I::OStream&, const cv::gapi::wip::draw::FText &);
-GAPI_EXPORTS I::IStream& operator>> (I::IStream&, cv::gapi::wip::draw::FText &);
+GAPI_EXPORTS IOStream& operator<< (IOStream& os, cv::GShape shape);
+GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::GShape &shape);
-GAPI_EXPORTS I::OStream& operator<< (I::OStream& os, const cv::gapi::wip::draw::Circle &c);
-GAPI_EXPORTS I::IStream& operator>> (I::IStream& is, cv::gapi::wip::draw::Circle &c);
+GAPI_EXPORTS IOStream& operator<< (IOStream& os, cv::detail::ArgKind k);
+GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::detail::ArgKind &k);
-GAPI_EXPORTS I::OStream& operator<< (I::OStream& os, const cv::gapi::wip::draw::Rect &r);
-GAPI_EXPORTS I::IStream& operator>> (I::IStream& is, cv::gapi::wip::draw::Rect &r);
+GAPI_EXPORTS IOStream& operator<< (IOStream& os, cv::detail::OpaqueKind k);
+GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::detail::OpaqueKind &k);
-GAPI_EXPORTS I::OStream& operator<< (I::OStream& os, const cv::gapi::wip::draw::Image &i);
-GAPI_EXPORTS I::IStream& operator>> (I::IStream& is, cv::gapi::wip::draw::Image &i);
+GAPI_EXPORTS IOStream& operator<< (IOStream& os, cv::gimpl::Data::Storage s);
+GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::gimpl::Data::Storage &s);
-GAPI_EXPORTS I::OStream& operator<< (I::OStream& os, const cv::gapi::wip::draw::Mosaic &m);
-GAPI_EXPORTS I::IStream& operator>> (I::IStream& is, cv::gapi::wip::draw::Mosaic &m);
+GAPI_EXPORTS IOStream& operator<< (IOStream& os, const cv::gimpl::DataObjectCounter &c);
+GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::gimpl::DataObjectCounter &c);
-GAPI_EXPORTS I::OStream& operator<< (I::OStream& os, const cv::gapi::wip::draw::Poly &p);
-GAPI_EXPORTS I::IStream& operator>> (I::IStream& is, cv::gapi::wip::draw::Poly &p);
+GAPI_EXPORTS IOStream& operator<< (IOStream& os, const cv::gimpl::Protocol &p);
+GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::gimpl::Protocol &p);
-GAPI_EXPORTS I::OStream& operator<< (I::OStream& os, const cv::gapi::wip::draw::Line &l);
-GAPI_EXPORTS I::IStream& operator>> (I::IStream& is, cv::gapi::wip::draw::Line &l);
+GAPI_EXPORTS IOStream& operator<< (IOStream& os, const cv::GArg &arg);
+GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::GArg &arg);
-// G-API types /////////////////////////////////////////////////////////////////
+//Forward declaration
+//IOStream& operator<< (IOStream& os, const cv::GRunArg &arg);
+//IIStream& operator>> (IIStream& is, cv::GRunArg &arg);
-GAPI_EXPORTS I::OStream& operator<< (I::OStream& os, cv::util::monostate );
-GAPI_EXPORTS I::IStream& operator>> (I::IStream& is, cv::util::monostate &);
+GAPI_EXPORTS IOStream& operator<< (IOStream& os, const cv::GKernel &k);
+GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::GKernel &k);
-GAPI_EXPORTS I::OStream& operator<< (I::OStream& os, cv::GShape shape);
-GAPI_EXPORTS I::IStream& operator>> (I::IStream& is, cv::GShape &shape);
+GAPI_EXPORTS IOStream& operator<< (IOStream& os, const cv::GMatDesc &d);
+GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::GMatDesc &d);
-GAPI_EXPORTS I::OStream& operator<< (I::OStream& os, cv::detail::ArgKind k);
-GAPI_EXPORTS I::IStream& operator>> (I::IStream& is, cv::detail::ArgKind &k);
+GAPI_EXPORTS IOStream& operator<< (IOStream& os, const cv::GScalarDesc &);
+GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::GScalarDesc &);
-GAPI_EXPORTS I::OStream& operator<< (I::OStream& os, cv::detail::OpaqueKind k);
-GAPI_EXPORTS I::IStream& operator>> (I::IStream& is, cv::detail::OpaqueKind &k);
+GAPI_EXPORTS IOStream& operator<< (IOStream& os, const cv::GOpaqueDesc &);
+GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::GOpaqueDesc &);
-GAPI_EXPORTS I::OStream& operator<< (I::OStream& os, cv::gimpl::Data::Storage s);
-GAPI_EXPORTS I::IStream& operator>> (I::IStream& is, cv::gimpl::Data::Storage &s);
+GAPI_EXPORTS IOStream& operator<< (IOStream& os, const cv::GArrayDesc &);
+GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::GArrayDesc &);
-GAPI_EXPORTS I::OStream& operator<< (I::OStream& os, const cv::gimpl::DataObjectCounter &c);
-GAPI_EXPORTS I::IStream& operator>> (I::IStream& is, cv::gimpl::DataObjectCounter &c);
+#if !defined(GAPI_STANDALONE)
+GAPI_EXPORTS IOStream& operator<< (IOStream& os, const cv::UMat &);
+GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::UMat &);
+#endif // !defined(GAPI_STANDALONE)
-GAPI_EXPORTS I::OStream& operator<< (I::OStream& os, const cv::gimpl::Protocol &p);
-GAPI_EXPORTS I::IStream& operator>> (I::IStream& is, cv::gimpl::Protocol &p);
+GAPI_EXPORTS IOStream& operator<< (IOStream& os, const cv::gapi::wip::IStreamSource::Ptr &);
+GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::gapi::wip::IStreamSource::Ptr &);
-GAPI_EXPORTS I::OStream& operator<< (I::OStream& os, const cv::GArg &arg);
-GAPI_EXPORTS I::IStream& operator>> (I::IStream& is, cv::GArg &arg);
+GAPI_EXPORTS IOStream& operator<< (IOStream& os, const cv::detail::VectorRef &);
+GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::detail::VectorRef &);
-//Forward declaration
-//I::OStream& operator<< (I::OStream& os, const cv::GRunArg &arg);
-//I::IStream& operator>> (I::IStream& is, cv::GRunArg &arg);
+GAPI_EXPORTS IOStream& operator<< (IOStream& os, const cv::detail::OpaqueRef &);
+GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::detail::OpaqueRef &);
-GAPI_EXPORTS I::OStream& operator<< (I::OStream& os, const cv::GKernel &k);
-GAPI_EXPORTS I::IStream& operator>> (I::IStream& is, cv::GKernel &k);
+GAPI_EXPORTS IOStream& operator<< (IOStream& os, const cv::gimpl::RcDesc &rc);
+GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::gimpl::RcDesc &rc);
-GAPI_EXPORTS I::OStream& operator<< (I::OStream& os, const cv::GMatDesc &d);
-GAPI_EXPORTS I::IStream& operator>> (I::IStream& is, cv::GMatDesc &d);
+GAPI_EXPORTS IOStream& operator<< (IOStream& os, const cv::gimpl::Op &op);
+GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::gimpl::Op &op);
-GAPI_EXPORTS I::OStream& operator<< (I::OStream& os, const cv::GScalarDesc &);
-GAPI_EXPORTS I::IStream& operator>> (I::IStream& is, cv::GScalarDesc &);
+GAPI_EXPORTS IOStream& operator<< (IOStream& os, const cv::gimpl::Data &op);
+GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::gimpl::Data &op);
-GAPI_EXPORTS I::OStream& operator<< (I::OStream& os, const cv::GOpaqueDesc &);
-GAPI_EXPORTS I::IStream& operator>> (I::IStream& is, cv::GOpaqueDesc &);
+// Render types ////////////////////////////////////////////////////////////////
-GAPI_EXPORTS I::OStream& operator<< (I::OStream& os, const cv::GArrayDesc &);
-GAPI_EXPORTS I::IStream& operator>> (I::IStream& is, cv::GArrayDesc &);
+GAPI_EXPORTS IOStream& operator<< (IOStream& os, const cv::gapi::wip::draw::Text &t);
+GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::gapi::wip::draw::Text &t);
-#if !defined(GAPI_STANDALONE)
-GAPI_EXPORTS I::OStream& operator<< (I::OStream& os, const cv::UMat &);
-GAPI_EXPORTS I::IStream& operator>> (I::IStream& is, cv::UMat &);
-#endif // !defined(GAPI_STANDALONE)
+GAPI_EXPORTS IOStream& operator<< (IOStream&, const cv::gapi::wip::draw::FText &);
+GAPI_EXPORTS IIStream& operator>> (IIStream&, cv::gapi::wip::draw::FText &);
-GAPI_EXPORTS I::OStream& operator<< (I::OStream& os, const cv::gapi::wip::IStreamSource::Ptr &);
-GAPI_EXPORTS I::IStream& operator>> (I::IStream& is, cv::gapi::wip::IStreamSource::Ptr &);
+GAPI_EXPORTS IOStream& operator<< (IOStream& os, const cv::gapi::wip::draw::Circle &c);
+GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::gapi::wip::draw::Circle &c);
-GAPI_EXPORTS I::OStream& operator<< (I::OStream& os, const cv::detail::VectorRef &);
-GAPI_EXPORTS I::IStream& operator>> (I::IStream& is, cv::detail::VectorRef &);
+GAPI_EXPORTS IOStream& operator<< (IOStream& os, const cv::gapi::wip::draw::Rect &r);
+GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::gapi::wip::draw::Rect &r);
-GAPI_EXPORTS I::OStream& operator<< (I::OStream& os, const cv::detail::OpaqueRef &);
-GAPI_EXPORTS I::IStream& operator>> (I::IStream& is, cv::detail::OpaqueRef &);
+GAPI_EXPORTS IOStream& operator<< (IOStream& os, const cv::gapi::wip::draw::Image &i);
+GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::gapi::wip::draw::Image &i);
-GAPI_EXPORTS I::OStream& operator<< (I::OStream& os, const cv::gimpl::RcDesc &rc);
-GAPI_EXPORTS I::IStream& operator>> (I::IStream& is, cv::gimpl::RcDesc &rc);
+GAPI_EXPORTS IOStream& operator<< (IOStream& os, const cv::gapi::wip::draw::Mosaic &m);
+GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::gapi::wip::draw::Mosaic &m);
-GAPI_EXPORTS I::OStream& operator<< (I::OStream& os, const cv::gimpl::Op &op);
-GAPI_EXPORTS I::IStream& operator>> (I::IStream& is, cv::gimpl::Op &op);
+GAPI_EXPORTS IOStream& operator<< (IOStream& os, const cv::gapi::wip::draw::Poly &p);
+GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::gapi::wip::draw::Poly &p);
-GAPI_EXPORTS I::OStream& operator<< (I::OStream& os, const cv::gimpl::Data &op);
-GAPI_EXPORTS I::IStream& operator>> (I::IStream& is, cv::gimpl::Data &op);
+GAPI_EXPORTS IOStream& operator<< (IOStream& os, const cv::gapi::wip::draw::Line &l);
+GAPI_EXPORTS IIStream& operator>> (IIStream& is, cv::gapi::wip::draw::Line &l);
// The top-level serialization routine.
// Note it is just a single function which takes a GModel and a list of nodes
// and writes the data to the stream (recursively)
-GAPI_EXPORTS void serialize( I::OStream& os
+GAPI_EXPORTS void serialize( IOStream& os
, const ade::Graph &g
, const std::vector<ade::NodeHandle> &nodes);
// The top-level serialization routine.
// Note it is just a single function which takes a GModel and a list of nodes
// and writes the data to the stream (recursively)
-GAPI_EXPORTS void serialize( I::OStream& os
+GAPI_EXPORTS void serialize( IOStream& os
, const ade::Graph &g
, const cv::gimpl::Protocol &p
, const std::vector<ade::NodeHandle> &nodes);
// Summarizing, the `deserialize()` happens *once per GComputation* immediately
// during the cv::gapi::deserialize<GComputation>(), and `reconstruct()` happens
// on every compilation process issued for this GComputation.
-GAPI_EXPORTS GSerialized deserialize(I::IStream& is);
+GAPI_EXPORTS GSerialized deserialize(IIStream& is);
GAPI_EXPORTS void reconstruct(const GSerialized &s, ade::Graph &g);
-// Generic: map serialization ////////////////////////////////////////
-template<typename K, typename V>
-I::OStream& operator<< (I::OStream& os, const std::map<K, V> &m) {
- const uint32_t sz = static_cast<uint32_t>(m.size()); // explicitly specify type
- os << sz;
- for (const auto& it : m) os << it.first << it.second;
- return os;
-}
-template<typename K, typename V>
-I::IStream& operator>> (I::IStream& is, std::map<K, V> &m) {
- m.clear();
- uint32_t sz = 0u;
- is >> sz;
- for (std::size_t i = 0; i < sz; ++i) {
- K k{};
- V v{};
- is >> k >> v;
- m[k] = v;
- }
- return is;
-}
-
-// Legacy //////////////////////////////////////////////////////////////////////
-// Generic: unordered_map serialization ////////////////////////////////////////
-template<typename K, typename V>
-I::OStream& operator<< (I::OStream& os, const std::unordered_map<K, V> &m) {
- //const std::size_t sz = m.size(); // explicitly specify type
- const uint32_t sz = (uint32_t)m.size(); // explicitly specify type
- os << sz;
- for (auto &&it : m) os << it.first << it.second;
- return os;
-}
-template<typename K, typename V>
-I::IStream& operator>> (I::IStream& is, std::unordered_map<K, V> &m) {
- m.clear();
- //std::size_t sz = 0u;
- uint32_t sz = 0u;
- is >> sz;
- if (sz != 0u) {
- for (auto &&i : ade::util::iota(sz)) {
- (void) i;
- K k{};
- V v{};
- is >> k >> v;
- m.insert({k,v});
- }
- GAPI_Assert(sz == m.size());
- }
- return is;
-}
-
// Generic: variant serialization //////////////////////////////////////////////
namespace detail { // FIXME: breaks old code
template<typename V>
-I::OStream& put_v(I::OStream&, const V&, std::size_t) {
+IOStream& put_v(IOStream&, const V&, std::size_t) {
GAPI_Assert(false && "variant>>: requested index is invalid");
};
template<typename V, typename X, typename... Xs>
-I::OStream& put_v(I::OStream& os, const V& v, std::size_t x) {
+IOStream& put_v(IOStream& os, const V& v, std::size_t x) {
return (x == 0u)
? os << cv::util::get<X>(v)
: put_v<V, Xs...>(os, v, x-1);
}
template<typename V>
-I::IStream& get_v(I::IStream&, V&, std::size_t, std::size_t) {
+IIStream& get_v(IIStream&, V&, std::size_t, std::size_t) {
GAPI_Assert(false && "variant<<: requested index is invalid");
}
template<typename V, typename X, typename... Xs>
-I::IStream& get_v(I::IStream& is, V& v, std::size_t i, std::size_t gi) {
+IIStream& get_v(IIStream& is, V& v, std::size_t i, std::size_t gi) {
if (i == gi) {
X x{};
is >> x;
} // namespace detail FIXME: breaks old code
template<typename... Ts>
-I::OStream& operator<< (I::OStream& os, const cv::util::variant<Ts...> &v) {
+IOStream& operator<< (IOStream& os, const cv::util::variant<Ts...> &v) {
os << (uint32_t)v.index();
return detail::put_v<cv::util::variant<Ts...>, Ts...>(os, v, v.index());
}
template<typename... Ts>
-I::IStream& operator>> (I::IStream& is, cv::util::variant<Ts...> &v) {
+IIStream& operator>> (IIStream& is, cv::util::variant<Ts...> &v) {
int idx = -1;
is >> idx;
GAPI_Assert(idx >= 0 && idx < (int)sizeof...(Ts));
return detail::get_v<cv::util::variant<Ts...>, Ts...>(is, v, 0u, idx);
}
-// Generic: vector serialization ///////////////////////////////////////////////
-// Moved here to fix CLang issues https://clang.llvm.org/compatibility.html
-// Unqualified lookup in templates
-template<typename T>
-I::OStream& operator<< (I::OStream& os, const std::vector<T> &ts) {
- //const std::size_t sz = ts.size(); // explicitly specify type
- const uint32_t sz = (uint32_t)ts.size(); // explicitly specify type
- os << sz;
- for (auto &&v : ts) os << v;
- return os;
-}
-template<typename T>
-I::IStream& operator >> (I::IStream& is, std::vector<T> &ts) {
- //std::size_t sz = 0u;
- uint32_t sz = 0u;
- is >> sz;
- if (sz == 0u) {
- ts.clear();
- }
- else {
- ts.resize(sz);
- for (auto &&i : ade::util::iota(sz)) is >> ts[i];
- }
- return is;
-}
-
// FIXME: Basic Stream implementaions //////////////////////////////////////////
// Basic in-memory stream implementations.
-class GAPI_EXPORTS ByteMemoryOutStream final: public I::OStream {
+class GAPI_EXPORTS ByteMemoryOutStream final: public IOStream {
std::vector<char> m_storage;
- //virtual I::OStream& operator << (uint32_t) override;
- //virtual I::OStream& operator<< (uint32_t) final;
+ //virtual IOStream& operator << (uint32_t) override;
+ //virtual IOStream& operator<< (uint32_t) final;
public:
const std::vector<char>& data() const;
- virtual I::OStream& operator<< (bool) override;
- virtual I::OStream& operator<< (char) override;
- virtual I::OStream& operator<< (unsigned char) override;
- virtual I::OStream& operator<< (short) override;
- virtual I::OStream& operator<< (unsigned short) override;
- virtual I::OStream& operator<< (int) override;
- //virtual I::OStream& operator<< (std::size_t) override;
- virtual I::OStream& operator<< (float) override;
- virtual I::OStream& operator<< (double) override;
- virtual I::OStream& operator<< (const std::string&) override;
- virtual I::OStream& operator<< (uint32_t) override;
- virtual I::OStream& operator<< (uint64_t) override;
+ virtual IOStream& operator<< (bool) override;
+ virtual IOStream& operator<< (char) override;
+ virtual IOStream& operator<< (unsigned char) override;
+ virtual IOStream& operator<< (short) override;
+ virtual IOStream& operator<< (unsigned short) override;
+ virtual IOStream& operator<< (int) override;
+ //virtual IOStream& operator<< (std::size_t) override;
+ virtual IOStream& operator<< (float) override;
+ virtual IOStream& operator<< (double) override;
+ virtual IOStream& operator<< (const std::string&) override;
+ virtual IOStream& operator<< (uint32_t) override;
+ virtual IOStream& operator<< (uint64_t) override;
};
-class GAPI_EXPORTS ByteMemoryInStream final: public I::IStream {
+class GAPI_EXPORTS ByteMemoryInStream final: public IIStream {
const std::vector<char>& m_storage;
size_t m_idx = 0u;
void check(std::size_t n) { (void) n; GAPI_DbgAssert(m_idx+n-1 < m_storage.size()); }
uint32_t getU32() { uint32_t v{}; *this >> v; return v; };
- //virtual I::IStream& operator>> (uint32_t &) final;
+ //virtual IIStream& operator>> (uint32_t &) final;
public:
explicit ByteMemoryInStream(const std::vector<char> &data);
- virtual I::IStream& operator>> (bool &) override;
- virtual I::IStream& operator>> (std::vector<bool>::reference) override;
- virtual I::IStream& operator>> (char &) override;
- virtual I::IStream& operator>> (unsigned char &) override;
- virtual I::IStream& operator>> (short &) override;
- virtual I::IStream& operator>> (unsigned short &) override;
- virtual I::IStream& operator>> (int &) override;
- virtual I::IStream& operator>> (float &) override;
- virtual I::IStream& operator>> (double &) override;
- //virtual I::IStream& operator>> (std::size_t &) override;
- virtual I::IStream& operator >> (uint32_t &) override;
- virtual I::IStream& operator >> (uint64_t &) override;
- virtual I::IStream& operator>> (std::string &) override;
+ virtual IIStream& operator>> (bool &) override;
+ virtual IIStream& operator>> (std::vector<bool>::reference) override;
+ virtual IIStream& operator>> (char &) override;
+ virtual IIStream& operator>> (unsigned char &) override;
+ virtual IIStream& operator>> (short &) override;
+ virtual IIStream& operator>> (unsigned short &) override;
+ virtual IIStream& operator>> (int &) override;
+ virtual IIStream& operator>> (float &) override;
+ virtual IIStream& operator>> (double &) override;
+ //virtual IIStream& operator>> (std::size_t &) override;
+ virtual IIStream& operator >> (uint32_t &) override;
+ virtual IIStream& operator >> (uint64_t &) override;
+ virtual IIStream& operator>> (std::string &) override;
};
-GAPI_EXPORTS void serialize(I::OStream& os, const cv::GMetaArgs &ma);
-GAPI_EXPORTS void serialize(I::OStream& os, const cv::GRunArgs &ra);
-GAPI_EXPORTS GMetaArgs meta_args_deserialize(I::IStream& is);
-GAPI_EXPORTS GRunArgs run_args_deserialize(I::IStream& is);
+GAPI_EXPORTS void serialize(IOStream& os, const cv::GMetaArgs &ma);
+GAPI_EXPORTS void serialize(IOStream& os, const cv::GRunArgs &ra);
+GAPI_EXPORTS GMetaArgs meta_args_deserialize(IIStream& is);
+GAPI_EXPORTS GRunArgs run_args_deserialize(IIStream& is);
} // namespace s11n
-} // namespace gimpl
+} // namespace gapi
} // namespace cv
#endif // OPENCV_GAPI_COMMON_SERIALIZATION_HPP