VPTissue Reference Manual
RangeSweep.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2016 Universiteit Antwerpen
3  *
4  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
5  * the European Commission - subsequent versions of the EUPL (the "Licence");
6  * You may not use this work except in compliance with the Licence.
7  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the Licence is distributed on an "AS IS" basis,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the Licence for the specific language governing
13  * permissions and limitations under the Licence.
14  */
20 #include "RangeSweep.h"
21 
22 #include <cmath>
23 
24 using boost::property_tree::ptree;
25 using namespace std;
26 
27 namespace SimPT_Parex {
28 
29 RangeSweep::RangeSweep(double from, double to, double step) : m_from(from), m_to(to), m_step(step)
30 {
31  assert(m_from <= m_to && m_step > 0 && "The given parameters weren't valid.");
32 }
33 
34 RangeSweep::RangeSweep(const boost::property_tree::ptree& pt) : m_from(0), m_to(0), m_step(0)
35 {
36  ReadPtree(pt);
37 }
38 
39 string RangeSweep::GetValue(unsigned int index) const
40 {
41  assert(index <= GetNumberOfValues() && "The index doesn't exist.");
42 
43  ostringstream os;
44  os << (m_from + index * m_step);
45  return os.str();
46 }
47 
48 unsigned int RangeSweep::GetNumberOfValues() const
49 {
50  return static_cast<unsigned int>(std::floor((m_to - m_from) / m_step + 1));
51 }
52 
53 ptree RangeSweep::ToPtree() const
54 {
55  ptree pt;
56 
57  pt.put("range.from", m_from);
58  pt.put("range.to", m_to);
59  pt.put("range.step", m_step);
60 
61  return pt;
62 }
63 
64 void RangeSweep::ReadPtree(const ptree& pt)
65 {
66  m_from = pt.get<double>("range.from");
67  m_to = pt.get<double>("range.to");
68  m_step = pt.get<double>("range.step");
69 }
70 
71 } // namespace
STL namespace.
Interface for RangeSweep.
RangeSweep(double from, double to, double step)
Constructor.
Definition: RangeSweep.cpp:29
Namespace for SimPT parameter explorer package.
Definition: Client.cpp:52
virtual std::string GetValue(unsigned int index) const
Returns the value on the given index.
Definition: RangeSweep.cpp:39
virtual boost::property_tree::ptree ToPtree() const
Convert the range sweep to a ptree.
Definition: RangeSweep.cpp:53
virtual unsigned int GetNumberOfValues() const
Returns the number of values in the sweep.
Definition: RangeSweep.cpp:48