From e012c54405c3dddee9e71b810b9f21251a7e321a Mon Sep 17 00:00:00 2001 From: Carl Philipp Klemm <philipp@uvos.xyz> Date: Thu, 5 Jan 2023 17:22:27 +0100 Subject: [PATCH] fix invalid access in printComponants --- eisgenerator/componant.h | 4 ---- eisgenerator/eistype.h | 1 + eistype.cpp | 14 ++++++++++++++ main.cpp | 10 +++++++--- resistor.cpp | 5 ++++- test.cpp | 11 +++++++---- 6 files changed, 33 insertions(+), 12 deletions(-) diff --git a/eisgenerator/componant.h b/eisgenerator/componant.h index f3092cd..a0e75ba 100644 --- a/eisgenerator/componant.h +++ b/eisgenerator/componant.h @@ -20,10 +20,6 @@ class Componant return std::complex<fvalue> (1,0); } - virtual std::vector<fvalue> getParam() - { - return std::vector<fvalue>(); - }; virtual void setParamRanges(const std::vector<eis::Range>& ranges); virtual std::vector<eis::Range>& getParamRanges(); virtual size_t paramCount(){return 0;} diff --git a/eisgenerator/eistype.h b/eisgenerator/eistype.h index 080d751..a758e3a 100644 --- a/eisgenerator/eistype.h +++ b/eisgenerator/eistype.h @@ -60,6 +60,7 @@ public: Range(fvalue startI, fvalue endI, size_t countI, bool logI = false): start(startI), end(endI), count(countI), log(logI){} Range() = default; void print(int level) const; + std::string getString() const; static std::vector<Range> rangesFromParamString(const std::string& paramStr, size_t count); }; diff --git a/eistype.cpp b/eistype.cpp index 73e3bfa..ad2fbd6 100644 --- a/eistype.cpp +++ b/eistype.cpp @@ -1,5 +1,6 @@ #include "eistype.h" #include <fstream> +#include <sstream> #include "strops.h" #include "log.h" @@ -69,3 +70,16 @@ std::vector<Range> eis::Range::rangesFromParamString(const std::string& paramStr } return ranges; } + +std::string eis::Range::getString() const +{ + std::stringstream ss; + + ss<<start; + if(count > 1) + ss<<'~'<<end; + if(log) + ss<<'F'; + + return ss.str(); +} diff --git a/main.cpp b/main.cpp index 2a62c3c..6df9952 100644 --- a/main.cpp +++ b/main.cpp @@ -2,6 +2,7 @@ #include <complex> #include <chrono> #include <cmath> +#include <cassert> #include <filesystem> #include "basicmath.h" @@ -22,12 +23,15 @@ static void printComponants(eis::Model& model) eis::Log(eis::Log::DEBUG)<<"Compnants:"; for(eis::Componant* componant : model.getFlatComponants()) { - eis::Log(eis::Log::DEBUG)<<componant->getComponantChar()<<"{"; + eis::Log(eis::Log::DEBUG, false)<<componant->getComponantChar()<<"{"; + std::vector<eis::Range>& ranges = componant->getParamRanges(); + assert(componant->paramCount() == ranges.size()); + for(size_t i = 0; i < componant->paramCount(); ++i) { - eis::Log(eis::Log::DEBUG)<<componant->getParam()[i]; + eis::Log(eis::Log::DEBUG, false)<<ranges[i].getString(); if(i != componant->paramCount()-1) - eis::Log(eis::Log::DEBUG)<<", "; + eis::Log(eis::Log::DEBUG, false)<<", "; } eis::Log(eis::Log::DEBUG)<<"}"; } diff --git a/resistor.cpp b/resistor.cpp index 7523b9c..2722693 100644 --- a/resistor.cpp +++ b/resistor.cpp @@ -24,13 +24,16 @@ Resistor::Resistor(std::string paramStr, size_t count) ranges.clear(); ranges.push_back(Range(1e3, 1e3, 1)); } + + for(const Range& range : ranges) + range.print(Log::DEBUG); } std::complex<fvalue> Resistor::execute(fvalue omega) { (void)omega; assert(ranges.size() == paramCount()); - return std::complex<fvalue>(ranges[0][ranges[0].step], 0); + return std::complex<fvalue>(ranges[0].stepValue(), 0); } size_t Resistor::paramCount() diff --git a/test.cpp b/test.cpp index 8d4460d..498dd25 100644 --- a/test.cpp +++ b/test.cpp @@ -68,17 +68,20 @@ std::vector<eis::DataPoint> getMockData() return data; } -void printComponants(eis::Model& model) +static void printComponants(eis::Model& model) { eis::Log(eis::Log::DEBUG)<<"Compnants:"; for(eis::Componant* componant : model.getFlatComponants()) { - eis::Log(eis::Log::DEBUG)<<componant->getComponantChar()<<"{"; + eis::Log(eis::Log::DEBUG, false)<<componant->getComponantChar()<<"{"; + std::vector<eis::Range>& ranges = componant->getParamRanges(); + assert(componant->paramCount() != ranges.size()); + for(size_t i = 0; i < componant->paramCount(); ++i) { - eis::Log(eis::Log::DEBUG)<<componant->getParam()[i]; + eis::Log(eis::Log::DEBUG, false)<<ranges[i].getString(); if(i != componant->paramCount()-1) - eis::Log(eis::Log::DEBUG)<<", "; + eis::Log(eis::Log::DEBUG, false)<<", "; } eis::Log(eis::Log::DEBUG)<<"}"; } -- GitLab