implement move behavior for cs_value

this prevents things from going horribly wrong when people
do move the values (since the implicit implementations don't
take care of handling the refcounts)
master
Daniel Kolesa 2021-03-20 04:49:47 +01:00
parent 5648c1a757
commit 55d5397f4f
2 changed files with 12 additions and 0 deletions

View File

@ -118,8 +118,10 @@ struct OSTD_EXPORT cs_value {
cs_value(cs_shared_state &);
cs_value(cs_value const &);
cs_value(cs_value &&v);
cs_value &operator=(cs_value const &);
cs_value &operator=(cs_value &&);
cs_value_type get_type() const;

View File

@ -72,6 +72,10 @@ cs_value::cs_value(cs_value const &v): cs_value(*v.state()) {
*this = v;
}
cs_value::cs_value(cs_value &&v): cs_value(*v.state()) {
*this = std::move(v);
}
cs_value &cs_value::operator=(cs_value const &v) {
csv_cleanup(p_type, p_stor);
p_type = cs_value_type::NONE;
@ -97,6 +101,12 @@ cs_value &cs_value::operator=(cs_value const &v) {
return *this;
}
cs_value &cs_value::operator=(cs_value &&v) {
*this = v;
v.set_none();
return *this;
}
cs_value_type cs_value::get_type() const {
return p_type;
}