Skip to content

Commit a02f7a3

Browse files
committed
do not allow write-access to default value
Defaults are not supposed to be modified by accident. Instead, provide a writable reference to currentValue.
1 parent 42900f9 commit a02f7a3

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

core/include/moveit/task_constructor/properties.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,11 @@ class Property
133133
/// is a value defined?
134134
inline bool defined() const { return !(value_.empty() && default_.empty()); }
135135

136+
/// is a non-default value set?
137+
inline bool hasCurrentValue() const { return !value_.empty(); }
138+
136139
/// get current value (or default if not set)
137140
inline const boost::any& value() const { return value_.empty() ? default_ : value_; }
138-
inline boost::any& value() { return value_.empty() ? default_ : value_; }
139141

140142
/// get typed value of property. Throws bad_any_cast on type mismatch, undefined if !defined().
141143
template <typename T>
@@ -148,6 +150,8 @@ class Property
148150

149151
/// get default value
150152
const boost::any& defaultValue() const { return default_; }
153+
const boost::any& currentValue() const { return value_; }
154+
boost::any& currentValue() { return value_; };
151155

152156
/// serialize value using registered functions
153157
static std::string serialize(const boost::any& value);

core/src/properties.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ Property::Property() : Property(typeid(boost::any), "", boost::any()) {}
120120

121121
void Property::setValue(const boost::any& value) {
122122
setCurrentValue(value);
123-
default_ = value_;
123+
setDefaultValue(value_);
124124
initialized_from_ = 0;
125125
}
126126

core/src/stages/fixed_cartesian_poses.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ FixedCartesianPoses::FixedCartesianPoses(const std::string& name) : MonitoringGe
5757

5858
void FixedCartesianPoses::addPose(const geometry_msgs::PoseStamped& pose) {
5959
moveit::task_constructor::Property& poses = properties().property("poses");
60-
if (!poses.defined())
61-
poses.setValue(PosesList({ pose }));
60+
if (!poses.hasCurrentValue())
61+
poses.setCurrentValue(PosesList({ pose }));
6262
else
63-
boost::any_cast<PosesList&>(poses.value()).push_back(pose);
63+
boost::any_cast<PosesList&>(poses.currentValue()).push_back(pose);
6464
}
6565

6666
void FixedCartesianPoses::reset() {

0 commit comments

Comments
 (0)