Skip to content
Snippets Groups Projects
Commit 3f7c1ef0 authored by Carl Philipp Klemm's avatar Carl Philipp Klemm
Browse files

Range: add a function to get a range as a vector of fvalues

parent ac20588d
No related branches found
No related tags found
No related merge requests found
...@@ -61,7 +61,7 @@ class Range ...@@ -61,7 +61,7 @@ class Range
public: public:
fvalue start; fvalue start;
fvalue end; fvalue end;
size_t count; size_t count = 0;
size_t step = 0; size_t step = 0;
bool log = false; bool log = false;
...@@ -77,7 +77,7 @@ public: ...@@ -77,7 +77,7 @@ public:
} }
fvalue at(size_t index) const fvalue at(size_t index) const
{ {
assert(index < count); assert(index < count || (index == 0 && count == 0));
if(count < 2) if(count < 2)
return start; return start;
return log ? pow(10, stepSize()*index+log10(start)) : stepSize()*index+start; return log ? pow(10, stepSize()*index+log10(start)) : stepSize()*index+start;
...@@ -107,6 +107,7 @@ public: ...@@ -107,6 +107,7 @@ public:
void print(int level) const; void print(int level) const;
std::string getString() const; std::string getString() const;
bool isSane() const; bool isSane() const;
std::vector<fvalue> getRangeVector() const;
static std::vector<Range> rangesFromParamString(const std::string& paramStr, size_t count); static std::vector<Range> rangesFromParamString(const std::string& paramStr, size_t count);
}; };
......
...@@ -65,6 +65,14 @@ void eis::Range::print(int level) const ...@@ -65,6 +65,14 @@ void eis::Range::print(int level) const
Log(static_cast<Log::Level>(level))<<"Range "<<start<<'-'<<end<<' '<<count<<" steps"<<(log ? " Log" : ""); Log(static_cast<Log::Level>(level))<<"Range "<<start<<'-'<<end<<' '<<count<<" steps"<<(log ? " Log" : "");
} }
std::vector<fvalue> eis::Range::getRangeVector() const
{
std::vector<fvalue> out(count, 0);
for(size_t i = 0; i < count; ++i)
out[i] = at(i);
return out;
}
std::vector<Range> eis::Range::rangesFromParamString(const std::string& paramStr, size_t count) std::vector<Range> eis::Range::rangesFromParamString(const std::string& paramStr, size_t count)
{ {
std::vector<std::string> tokens = tokenize(paramStr, ','); std::vector<std::string> tokens = tokenize(paramStr, ',');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment