↰ Return to documentation for file (morpheus/_lib/include/morpheus/stages/write_to_file.hpp
)
#pragma once
#include "morpheus/messages/meta.hpp"
#include "morpheus/objects/file_types.hpp"
#include <mrc/channel/status.hpp>// for Status
#include <mrc/node/sink_properties.hpp>// for SinkProperties<>::sink_type_t
#include <mrc/node/source_properties.hpp>// for SourceProperties<>::source_type_t
#include <mrc/segment/builder.hpp>
#include <mrc/segment/object.hpp>// for Object
#include <pymrc/node.hpp>
#include <rxcpp/rx.hpp>
#include <fstream>
#include <functional>// for function
#include <memory>
#include <string>
#include <vector>
namespace morpheus {
/****** Component public implementations *******************/
/****** WriteToFileStage********************************/
#pragma GCC visibility push(default)
class WriteToFileStage : public mrc::pymrc::PythonNode<std::shared_ptr<MessageMeta>, std::shared_ptr<MessageMeta>>
{
public:
using base_t = mrc::pymrc::PythonNode<std::shared_ptr<MessageMeta>, std::shared_ptr<MessageMeta>>;
using typename base_t::sink_type_t;
using typename base_t::source_type_t;
using typename base_t::subscribe_fn_t;
WriteToFileStage(const std::string &filename,
std::ios::openmode mode = std::ios::out,
FileTypes file_type = FileTypes::Auto,
bool include_index_col = true);
private:
void close();
void write_json(sink_type_t &msg);
void write_csv(sink_type_t &msg);
subscribe_fn_t build_operator();
bool m_is_first{};
bool m_include_index_col;
std::ofstream m_fstream;
std::function<void(sink_type_t &)> m_write_func;
};
/****** WriteToFileStageInterfaceProxy******************/
struct WriteToFileStageInterfaceProxy
{
static std::shared_ptr<mrc::segment::Object<WriteToFileStage>> init(mrc::segment::Builder& builder,
const std::string& name,
const std::string& filename,
const std::string& mode = "w",
FileTypes file_type = FileTypes::Auto,
bool include_index_col = true);
};
#pragma GCC visibility pop// end of group
} // namespace morpheus