.. _program_listing_file__tmp_ws_src_data_tamer_data_tamer_cpp_include_data_tamer_data_sink.hpp: Program Listing for File data_sink.hpp ====================================== |exhale_lsh| :ref:`Return to documentation for file ` (``/tmp/ws/src/data_tamer/data_tamer_cpp/include/data_tamer/data_sink.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #pragma once #include "data_tamer/types.hpp" #include #include #include #include #include #include namespace DataTamer { using ActiveMask = std::vector; using PayloadVector = std::vector; bool GetBit(const ActiveMask& mask, size_t index); void SetBit(ActiveMask& mask, size_t index, bool val); struct Snapshot { std::string_view channel_name; std::size_t schema_hash; std::chrono::nanoseconds timestamp; ActiveMask active_mask; PayloadVector payload; }; using DataSnapshot = std::vector; class DataSinkBase { public: DataSinkBase(); DataSinkBase(const DataSinkBase& other) = delete; DataSinkBase& operator=(const DataSinkBase& other) = delete; DataSinkBase(DataSinkBase&& other) = delete; DataSinkBase& operator=(DataSinkBase&& other) = delete; virtual ~DataSinkBase(); virtual void addChannel(const std::string& name, const Schema& schema) = 0; virtual bool pushSnapshot(const Snapshot& snapshot); protected: virtual bool storeSnapshot(const Snapshot& snapshot) = 0; void stopThread(); private: struct Pimpl; std::unique_ptr _p; }; //-------------------------------------------------- inline bool GetBit(const ActiveMask& mask, size_t index) { const uint8_t& byte = mask[index >> 3]; return 0 != (byte & uint8_t(1 << (index % 8))); } inline void SetBit(ActiveMask& mask, size_t index, bool value) { if (!value) { mask[index >> 3] &= uint8_t(~(1 << (index % 8))); } else { mask[index >> 3] |= uint8_t(1 << (index % 8)); } } } // namespace DataTamer