#include #include #include #include #include "visualdl/logic/sdk.h" #include "visualdl/storage/storage.h" #include "visualdl/storage/tablet.h" namespace vs = visualdl; namespace cp = visualdl::components; struct WrapScalar { template void operator()(TypeWrapperT&& wrapped) { typedef typename TypeWrapperT::type WrappedT; wrapped.template constructor(); wrapped.method("set_caption", &WrappedT::SetCaption); wrapped.method("add_record", &WrappedT::AddRecord); } }; struct WrapHistogram { template void operator()(TypeWrapperT&& wrapped) { typedef typename TypeWrapperT::type WrappedT; typedef typename WrappedT::data_type T; wrapped.template constructor(); wrapped.method("add_record", [](WrappedT h, int step, jlcxx::ArrayRef data) { std::vector d(data.begin(), data.end()); return h.AddRecord(step, d); }); } }; JLCXX_MODULE define_julia_module(jlcxx::Module& vdl) { vdl.add_type("Tablet"); vdl.add_type("TabletReader"); vdl.add_type("Storage"); vdl.add_type("StorageReader"); vdl.add_type("LogWriter") .constructor() .constructor() .method("set_mode", &vs::LogWriter::SetMode) .method("save", &vs::LogWriter::Save) .method("as_mode", &vs::LogWriter::AsMode) .method("add_tablet", &vs::LogWriter::AddTablet) .method("storage", &vs::LogWriter::storage); vdl.add_type("LogReader") .constructor() .method("set_mode", &vs::LogReader::SetMode) .method("as_mode", &vs::LogReader::AsMode) .method("mode", &vs::LogReader::mode) .method("tablet", &vs::LogReader::tablet) .method("storage", &vs::LogReader::storage) .method("alltags", [](vs::LogReader& lr) { auto alltags = lr.all_tags(); return jlcxx::ArrayRef(alltags.data(), alltags.size()); }) .method("tags", [](vs::LogReader& lr, const std::string& x) { auto tags = lr.tags(x); return jlcxx::ArrayRef(tags.data(), tags.size()); }); // components vdl.add_type>>("Scalar") .apply, cp::Scalar, cp::Scalar, cp::Scalar>(WrapScalar()); vdl.add_type>>("Histogram") .apply, cp::Histogram, cp::Histogram, cp::Histogram>(WrapHistogram()); vdl.add_type("Image") .constructor() .method("set_caption", &cp::Image::SetCaption) .method("start_sampling", &cp::Image::StartSampling) .method("finish_sampling", &cp::Image::FinishSampling) .method("add_sample", [](cp::Image& img, jlcxx::ArrayRef shape, jlcxx::ArrayRef data) { std::vector s(shape.begin(), shape.end()); std::vector d(data.begin(), data.end()); return img.AddSample(s, d); }) .method("index_of_sample_taken", &cp::Image::IndexOfSampleTaken) .method("set_sample", [](cp::Image& img, int index, jlcxx::ArrayRef shape, jlcxx::ArrayRef data) { std::vector s(shape.begin(), shape.end()); std::vector d(data.begin(), data.end()); return img.SetSample(index, s, d); }); vdl.add_type("Text") .constructor() .method("set_caption", &cp::Text::SetCaption) .method("add_record", &cp::Text::AddRecord); vdl.add_type("Audio") .constructor() .method("set_caption", &cp::Audio::SetCaption) .method("start_sampling", &cp::Audio::StartSampling) .method("finish_sampling", &cp::Audio::FinishSampling) .method("add_sample", [](cp::Audio& img, jlcxx::ArrayRef shape, jlcxx::ArrayRef data) { std::vector s(shape.begin(), shape.end()); std::vector d(data.begin(), data.end()); return img.AddSample(s, d); }) .method("index_of_sample_taken", &cp::Audio::IndexOfSampleTaken) .method("set_sample", [](cp::Audio& img, int index, jlcxx::ArrayRef shape, jlcxx::ArrayRef data) { std::vector s(shape.begin(), shape.end()); std::vector d(data.begin(), data.end()); return img.SetSample(index, s, d); }); }