Skip to content

Commit

Permalink
Removed 'mutable' member of variant_callable
Browse files Browse the repository at this point in the history
In the old code, both this and the const version were part of a union, which meant both got intialized with a value.
Now, the mutable variable was always nullptr. Since we cannot pass a non-const callable ptr to the variant ctor, we
need to use const_cast.
  • Loading branch information
Vultraz committed Apr 2, 2017
1 parent 29f04bd commit 00a9873
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 15 deletions.
10 changes: 2 additions & 8 deletions src/formula/variant.hpp
Expand Up @@ -98,26 +98,20 @@ class variant
return value_cast<game_logic::variant_callable>()->get_callable();
}

game_logic::formula_callable_ptr mutable_callable() const
{
must_be(VARIANT_TYPE::TYPE_CALLABLE);
return value_cast<game_logic::variant_callable>()->get_callable_mutable();
}

template<typename T>
T* try_convert() const
{
if(!is_callable()) {
return nullptr;
}

return dynamic_cast<T*>(mutable_callable().get());
return dynamic_cast<T*>(const_cast<game_logic::formula_callable*>(as_callable().get()));
}

template<typename T>
T* convert_to() const
{
T* res = dynamic_cast<T*>(mutable_callable().get());
T* res = dynamic_cast<T*>(const_cast<game_logic::formula_callable*>(as_callable().get()));
if(!res) {
throw type_error("could not convert type");
}
Expand Down
1 change: 0 additions & 1 deletion src/formula/variant_private.cpp
Expand Up @@ -66,7 +66,6 @@ std::string variant_decimal::to_string_impl(const bool sign_value) const

variant_callable::variant_callable(const formula_callable* callable)
: callable_(callable)
, mutable_callable_(nullptr) // FIXME
{}

std::string variant_callable::get_serialized_string() const
Expand Down
6 changes: 0 additions & 6 deletions src/formula/variant_private.hpp
Expand Up @@ -272,11 +272,6 @@ class variant_callable : public virtual variant_value_base
return callable_;
}

formula_callable_ptr get_callable_mutable()
{
return mutable_callable_;
}

virtual std::string string_cast() const override
{
return "(object)";
Expand All @@ -296,7 +291,6 @@ class variant_callable : public virtual variant_value_base

private:
const_formula_callable_ptr callable_;
formula_callable_ptr mutable_callable_;
};


Expand Down

0 comments on commit 00a9873

Please sign in to comment.