.. _program_listing_file__tmp_ws_src_data_tamer_data_tamer_cpp_include_data_tamer_channel.hpp: Program Listing for File channel.hpp ==================================== |exhale_lsh| :ref:`Return to documentation for file ` (``/tmp/ws/src/data_tamer/data_tamer_cpp/include/data_tamer/channel.hpp``) .. |exhale_lsh| unicode:: U+021B0 .. UPWARDS ARROW WITH TIP LEFTWARDS .. code-block:: cpp #pragma once #include "data_tamer/values.hpp" #include "data_tamer/data_sink.hpp" #include "data_tamer/details/mutex.hpp" #include "data_tamer/details/locked_reference.hpp" #include #include namespace DataTamer { // Utility inline std::chrono::nanoseconds NsecSinceEpoch() { auto since_epoch = std::chrono::system_clock::now().time_since_epoch(); return std::chrono::duration_cast(since_epoch); } class DataSinkBase; class LogChannel; class ChannelsRegistry; template class LoggedValue { protected: LoggedValue(const std::shared_ptr& channel, const std::string& name, T initial_value); friend LogChannel; public: LoggedValue() {} ~LoggedValue(); LoggedValue(LoggedValue const& other) = delete; LoggedValue& operator=(LoggedValue const& other) = delete; LoggedValue(LoggedValue&& other) = default; LoggedValue& operator=(LoggedValue&& other) = default; void set(const T& value, bool auto_enable = true); [[nodiscard]] T get(); [[nodiscard]] LockedRef getLockedReference(); void setEnabled(bool enabled); [[nodiscard]] bool isEnabled() const { return enabled_; } private: std::weak_ptr channel_; T value_ = {}; RegistrationID id_; bool enabled_ = true; }; //--------------------------------------------------------- class LogChannel : public std::enable_shared_from_this { protected: // We make this private because the object must be wrapped // inside a std::shared_ptr. // This allows us to use std::weak_ptr in LoggedValue LogChannel(std::string name); public: static std::shared_ptr create(std::string name); ~LogChannel(); LogChannel(const LogChannel&) = delete; LogChannel& operator=(const LogChannel&) = delete; LogChannel(LogChannel&&) = delete; LogChannel& operator=(LogChannel&&) = delete; template RegistrationID registerValue(const std::string& name, const T* value); template