From: Soeren Apel Date: Sun, 23 Aug 2020 18:05:36 +0000 (+0200) Subject: MathSignal: Rename sig_sample() to sample() X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=36e62b1700d580adde53c8f4489037f0071fa6a0;p=pulseview.git MathSignal: Rename sig_sample() to sample() --- diff --git a/pv/data/mathsignal.cpp b/pv/data/mathsignal.cpp index 86043913..2217bffd 100644 --- a/pv/data/mathsignal.cpp +++ b/pv/data/mathsignal.cpp @@ -47,14 +47,14 @@ const int64_t MathSignal::ChunkLength = 256 * 1024; template -struct sig_sample : public exprtk::igeneric_function +struct fnc_sample : public exprtk::igeneric_function { typedef typename exprtk::igeneric_function::parameter_list_t parameter_list_t; typedef typename exprtk::igeneric_function::generic_type generic_type; typedef typename generic_type::scalar_view scalar_t; typedef typename generic_type::string_view string_t; - sig_sample(MathSignal& owner) : + fnc_sample(MathSignal& owner) : exprtk::igeneric_function("ST"), // Require channel name and sample number owner_(owner), sig_data(nullptr) @@ -67,7 +67,7 @@ struct sig_sample : public exprtk::igeneric_function const scalar_t exprtk_sample_num = scalar_t(parameters[1]); const std::string str_sig_name = to_str(exprtk_sig_name); - const double sample_num = exprtk_sample_num(); + const double sample_num = std::max(exprtk_sample_num(), (double)0); if (!sig_data) sig_data = owner_.signal_from_name(str_sig_name); @@ -95,7 +95,7 @@ MathSignal::MathSignal(pv::Session &session) : exprtk_symbol_table_(nullptr), exprtk_expression_(nullptr), exprtk_parser_(nullptr), - fnc_sig_sample_(nullptr) + fnc_sample_(nullptr) { uint32_t sig_idx = session_.get_next_signal_index(MathChannel); set_name(QString(tr("Math%1")).arg(sig_idx)); @@ -110,9 +110,6 @@ MathSignal::MathSignal(pv::Session &session) : MathSignal::~MathSignal() { reset_generation(); - - if (fnc_sig_sample_) - delete fnc_sig_sample_; } void MathSignal::save_settings(QSettings &settings) const @@ -280,9 +277,9 @@ void MathSignal::reset_generation() exprtk_unknown_symbol_table_ = nullptr; } - if (fnc_sig_sample_) { - delete fnc_sig_sample_; - fnc_sig_sample_ = nullptr; + if (fnc_sample_) { + delete fnc_sample_; + fnc_sample_ = nullptr; } if (!error_message_.isEmpty()) { @@ -305,12 +302,12 @@ void MathSignal::begin_generation() disconnect(this, SLOT(on_data_received())); disconnect(this, SLOT(on_enabled_changed())); - fnc_sig_sample_ = new sig_sample(*this); + fnc_sample_ = new fnc_sample(*this); exprtk_unknown_symbol_table_ = new exprtk::symbol_table(); exprtk_symbol_table_ = new exprtk::symbol_table(); - exprtk_symbol_table_->add_function("sig_sample", *fnc_sig_sample_); + exprtk_symbol_table_->add_function("sample", *fnc_sample_); exprtk_symbol_table_->add_variable("t", exprtk_current_time_); exprtk_symbol_table_->add_variable("s", exprtk_current_sample_); exprtk_symbol_table_->add_constants(); @@ -380,7 +377,7 @@ void MathSignal::generate_samples(uint32_t segment_id, const uint64_t start_samp shared_ptr segment = analog->analog_segments().at(segment_id); // Keep the math functions segment IDs in sync - fnc_sig_sample_->current_segment = segment_id; + fnc_sample_->current_segment = segment_id; const double sample_rate = data_->get_samplerate(); diff --git a/pv/data/mathsignal.hpp b/pv/data/mathsignal.hpp index e452215b..76427c56 100644 --- a/pv/data/mathsignal.hpp +++ b/pv/data/mathsignal.hpp @@ -43,7 +43,7 @@ namespace data { class SignalBase; template -struct sig_sample; +struct fnc_sample; struct signal_data { signal_data(const shared_ptr _sb) : @@ -139,10 +139,10 @@ private: exprtk::parser *exprtk_parser_; double exprtk_current_time_, exprtk_current_sample_; - sig_sample* fnc_sig_sample_; + fnc_sample* fnc_sample_; // Give sig_sample access to the private helper functions - friend struct sig_sample; + friend struct fnc_sample; }; } // namespace data