View on GitHub

Vistle

Distributed Data-parallel Scientific Visualization in VR

parametermanager_impl.h
Go to the documentation of this file.
1#ifndef VISTLE_PARAMETER_MANAGER_IMPL_H
2#define VISTLE_PARAMETER_MANAGER_IMPL_H
3
4#include <cassert>
5
6namespace vistle {
7
8template<class T>
9bool ParameterManager::setParameter(const std::string &name, const T &value, const message::SetParameter *inResponseTo)
10{
11 auto param = findParameter(name);
12 if (!param) {
13 std::cerr << "ParameterManager: parameter " << name << " not found" << std::endl;
14 return false;
15 }
16 auto p = std::dynamic_pointer_cast<ParameterBase<T>>(param);
17 if (!p) {
18 std::cerr << "ParameterManager: parameter " << name << " not of requested type" << std::endl;
19 return false;
20 }
21
22 return setParameter(p.get(), value, inResponseTo);
23}
24
25template<class T>
26bool ParameterManager::setParameter(ParameterBase<T> *param, const T &value, const message::SetParameter *inResponseTo)
27{
28 bool delayed = false;
29 if (inResponseTo && inResponseTo->isDelayed())
30 delayed = true;
31 param->setValue(value, false, delayed);
32 if (!inResponseTo || !inResponseTo->isDelayed())
33 parameterChangedWrapper(param);
34 else
35 m_delayedChanges.push_back(param);
36 return updateParameter(param->getName(), param, inResponseTo);
37}
38
39template<class T>
41{
42 return ParameterManager::setParameterRange(param, minimum, param->maximum());
43}
44
45template<class T>
47{
48 return ParameterManager::setParameterRange(param, param->minimum(), maximum);
49}
50
51template<class T>
52bool ParameterManager::setParameterRange(const std::string &name, const T &minimum, const T &maximum)
53{
54 auto p = std::dynamic_pointer_cast<ParameterBase<T>>(findParameter(name));
55 if (!p)
56 return false;
57
58 return setParameterRange(p.get(), minimum, maximum);
59}
60
61template<class T>
62bool ParameterManager::setParameterRange(ParameterBase<T> *param, const T &minimum, const T &maximum)
63{
64 bool ok = true;
65
66 if (minimum > maximum) {
67 std::cerr << "range for parameter " << param->getName() << " swapped: min " << minimum << " > max " << maximum
68 << std::endl;
69 param->setMinimum(maximum);
70 param->setMaximum(minimum);
71 } else {
72 param->setMinimum(minimum);
73 param->setMaximum(maximum);
74 }
75 T value = param->getValue();
76 if (value < param->minimum()) {
77 std::cerr << "value " << value << " for parameter " << param->getName()
78 << " increased to minimum: " << param->minimum() << std::endl;
79 param->setValue(param->minimum());
80 ok &= updateParameter(param->getName(), param, nullptr);
81 }
82 if (value > param->maximum()) {
83 std::cerr << "value " << value << " for parameter " << param->getName()
84 << " decreased to maximum: " << param->maximum() << std::endl;
85 param->setValue(param->maximum());
86 ok &= updateParameter(param->getName(), param, nullptr);
87 }
88 ok &= updateParameter(param->getName(), param, nullptr, Parameter::Minimum);
89 ok &= updateParameter(param->getName(), param, nullptr, Parameter::Maximum);
90 return ok;
91}
92
93template<class T>
94bool ParameterManager::getParameter(const std::string &name, T &value) const
95{
96 if (auto p = std::dynamic_pointer_cast<ParameterBase<T>>(findParameter(name))) {
97 value = p->getValue();
98 } else {
99 std::cerr << "ParameterManager::getParameter(" << name << "): type failure" << std::endl;
100 assert("dynamic_cast failed" == 0);
101 return false;
102 }
103
104 return true;
105}
106
107} // namespace vistle
108#endif
Definition: parameter.h:100
const T getValue() const
Definition: parameter.h:144
virtual T minimum() const
Definition: parameter.h:174
virtual T maximum() const
Definition: parameter.h:175
bool setParameterMinimum(ParameterBase< T > *param, const T &minimum)
Definition: parametermanager_impl.h:40
bool setParameter(const std::string &name, const T &value, const message::SetParameter *inResponseTo=nullptr)
Definition: parametermanager_impl.h:9
bool getParameter(const std::string &name, T &value) const
Definition: parametermanager_impl.h:94
bool setParameterMaximum(ParameterBase< T > *param, const T &maximum)
Definition: parametermanager_impl.h:46
bool updateParameter(const std::string &name, const Parameter *parameter, const message::SetParameter *inResponseTo, Parameter::RangeType rt=Parameter::Value)
Definition: parametermanager.cpp:157
std::shared_ptr< Parameter > findParameter(const std::string &name) const
Definition: parametermanager.cpp:233
bool setParameterRange(const std::string &name, const T &minimum, const T &maximum)
Definition: parametermanager_impl.h:52
const std::string & getName() const
Definition: parameter.cpp:49
request parameter value update or notify that a parameter value has been changed
Definition: messages.h:501
bool isDelayed() const
Definition: messages.cpp:1124
Definition: allobjects.cpp:30