various c++11/c++14 cleanups
This commit is contained in:
@@ -44,9 +44,7 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Dynamic_Object() : m_type_name(""), m_option_explicit(false)
|
Dynamic_Object() = default;
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool is_explicit() const
|
bool is_explicit() const
|
||||||
{
|
{
|
||||||
@@ -114,8 +112,8 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_type_name;
|
const std::string m_type_name = "";
|
||||||
bool m_option_explicit;
|
bool m_option_explicit = false;
|
||||||
|
|
||||||
std::map<std::string, Boxed_Value> m_attrs;
|
std::map<std::string, Boxed_Value> m_attrs;
|
||||||
};
|
};
|
||||||
|
@@ -211,15 +211,15 @@ namespace chaiscript
|
|||||||
return dc && dc->m_type_name == m_type_name && (*dc->m_func) == (*m_func);
|
return dc && dc->m_type_name == m_type_name && (*dc->m_func) == (*m_func);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool call_match(const std::vector<Boxed_Value> &vals, const Type_Conversions_State &t_conversions) const override
|
bool call_match(const std::vector<Boxed_Value> &vals, const Type_Conversions_State &t_conversions) const override
|
||||||
{
|
{
|
||||||
std::vector<Boxed_Value> new_vals{Boxed_Value(Dynamic_Object(m_type_name))};
|
std::vector<Boxed_Value> new_vals{Boxed_Value(Dynamic_Object(m_type_name))};
|
||||||
new_vals.insert(new_vals.end(), vals.begin(), vals.end());
|
new_vals.insert(new_vals.end(), vals.begin(), vals.end());
|
||||||
|
|
||||||
return m_func->call_match(new_vals, t_conversions);
|
return m_func->call_match(new_vals, t_conversions);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual std::string annotation() const override
|
std::string annotation() const override
|
||||||
{
|
{
|
||||||
return m_func->annotation();
|
return m_func->annotation();
|
||||||
}
|
}
|
||||||
@@ -237,8 +237,8 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_type_name;
|
const std::string m_type_name;
|
||||||
Proxy_Function m_func;
|
const Proxy_Function m_func;
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -46,7 +46,7 @@ namespace chaiscript
|
|||||||
|
|
||||||
bad_boxed_dynamic_cast(const bad_boxed_dynamic_cast &) = default;
|
bad_boxed_dynamic_cast(const bad_boxed_dynamic_cast &) = default;
|
||||||
|
|
||||||
virtual ~bad_boxed_dynamic_cast() noexcept {}
|
virtual ~bad_boxed_dynamic_cast() noexcept = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
class bad_boxed_type_cast : public bad_boxed_cast
|
class bad_boxed_type_cast : public bad_boxed_cast
|
||||||
@@ -70,7 +70,7 @@ namespace chaiscript
|
|||||||
|
|
||||||
bad_boxed_type_cast(const bad_boxed_type_cast &) = default;
|
bad_boxed_type_cast(const bad_boxed_type_cast &) = default;
|
||||||
|
|
||||||
virtual ~bad_boxed_type_cast() noexcept {}
|
virtual ~bad_boxed_type_cast() noexcept = default;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ namespace chaiscript
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~Type_Conversion_Base() {}
|
virtual ~Type_Conversion_Base() = default;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Type_Conversion_Base(const Type_Info &t_to, const Type_Info &t_from)
|
Type_Conversion_Base(const Type_Info &t_to, const Type_Info &t_from)
|
||||||
@@ -107,8 +107,8 @@ namespace chaiscript
|
|||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Type_Info m_to;
|
const Type_Info m_to;
|
||||||
Type_Info m_from;
|
const Type_Info m_from;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -126,7 +126,7 @@ namespace chaiscript
|
|||||||
if (t_from.is_const())
|
if (t_from.is_const())
|
||||||
{
|
{
|
||||||
return Boxed_Value(
|
return Boxed_Value(
|
||||||
[&]()->std::shared_ptr<const To>{
|
[&](){
|
||||||
if (auto data = std::static_pointer_cast<const To>(detail::Cast_Helper<std::shared_ptr<const From> >::cast(t_from, nullptr)))
|
if (auto data = std::static_pointer_cast<const To>(detail::Cast_Helper<std::shared_ptr<const From> >::cast(t_from, nullptr)))
|
||||||
{
|
{
|
||||||
return data;
|
return data;
|
||||||
@@ -137,7 +137,7 @@ namespace chaiscript
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return Boxed_Value(
|
return Boxed_Value(
|
||||||
[&]()->std::shared_ptr<To>{
|
[&](){
|
||||||
if (auto data = std::static_pointer_cast<To>(detail::Cast_Helper<std::shared_ptr<From> >::cast(t_from, nullptr)))
|
if (auto data = std::static_pointer_cast<To>(detail::Cast_Helper<std::shared_ptr<From> >::cast(t_from, nullptr)))
|
||||||
{
|
{
|
||||||
return data;
|
return data;
|
||||||
@@ -182,7 +182,7 @@ namespace chaiscript
|
|||||||
if (t_from.is_const())
|
if (t_from.is_const())
|
||||||
{
|
{
|
||||||
return Boxed_Value(
|
return Boxed_Value(
|
||||||
[&]()->std::shared_ptr<const To>{
|
[&](){
|
||||||
if (auto data = std::dynamic_pointer_cast<const To>(detail::Cast_Helper<std::shared_ptr<const From> >::cast(t_from, nullptr)))
|
if (auto data = std::dynamic_pointer_cast<const To>(detail::Cast_Helper<std::shared_ptr<const From> >::cast(t_from, nullptr)))
|
||||||
{
|
{
|
||||||
return data;
|
return data;
|
||||||
@@ -193,7 +193,7 @@ namespace chaiscript
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return Boxed_Value(
|
return Boxed_Value(
|
||||||
[&]()->std::shared_ptr<To>{
|
[&](){
|
||||||
if (auto data = std::dynamic_pointer_cast<To>(detail::Cast_Helper<std::shared_ptr<From> >::cast(t_from, nullptr)))
|
if (auto data = std::dynamic_pointer_cast<To>(detail::Cast_Helper<std::shared_ptr<From> >::cast(t_from, nullptr)))
|
||||||
{
|
{
|
||||||
return data;
|
return data;
|
||||||
@@ -242,12 +242,12 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Boxed_Value convert_down(const Boxed_Value &t_base) const override
|
Boxed_Value convert_down(const Boxed_Value &t_base) const override
|
||||||
{
|
{
|
||||||
return Dynamic_Caster<Base, Derived>::cast(t_base);
|
return Dynamic_Caster<Base, Derived>::cast(t_base);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Boxed_Value convert(const Boxed_Value &t_derived) const override
|
Boxed_Value convert(const Boxed_Value &t_derived) const override
|
||||||
{
|
{
|
||||||
return Static_Caster<Derived, Base>::cast(t_derived);
|
return Static_Caster<Derived, Base>::cast(t_derived);
|
||||||
}
|
}
|
||||||
@@ -262,17 +262,18 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Boxed_Value convert_down(const Boxed_Value &t_base) const override
|
Boxed_Value convert_down(const Boxed_Value &t_base) const override
|
||||||
{
|
{
|
||||||
throw chaiscript::exception::bad_boxed_dynamic_cast(t_base.get_type_info(), typeid(Derived), "Unable to cast down inheritance hierarchy with non-polymorphic types");
|
throw chaiscript::exception::bad_boxed_dynamic_cast(t_base.get_type_info(), typeid(Derived),
|
||||||
|
"Unable to cast down inheritance hierarchy with non-polymorphic types");
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool bidir() const override
|
bool bidir() const override
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Boxed_Value convert(const Boxed_Value &t_derived) const override
|
Boxed_Value convert(const Boxed_Value &t_derived) const override
|
||||||
{
|
{
|
||||||
return Static_Caster<Derived, Base>::cast(t_derived);
|
return Static_Caster<Derived, Base>::cast(t_derived);
|
||||||
}
|
}
|
||||||
@@ -290,12 +291,12 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Boxed_Value convert_down(const Boxed_Value &) const override
|
Boxed_Value convert_down(const Boxed_Value &) const override
|
||||||
{
|
{
|
||||||
throw chaiscript::exception::bad_boxed_type_cast("No conversion exists");
|
throw chaiscript::exception::bad_boxed_type_cast("No conversion exists");
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Boxed_Value convert(const Boxed_Value &t_from) const override
|
Boxed_Value convert(const Boxed_Value &t_from) const override
|
||||||
{
|
{
|
||||||
/// \todo better handling of errors from the conversion function
|
/// \todo better handling of errors from the conversion function
|
||||||
return m_func(t_from);
|
return m_func(t_from);
|
||||||
@@ -317,11 +318,7 @@ namespace chaiscript
|
|||||||
public:
|
public:
|
||||||
struct Conversion_Saves
|
struct Conversion_Saves
|
||||||
{
|
{
|
||||||
Conversion_Saves()
|
bool enabled = false;
|
||||||
: enabled(false)
|
|
||||||
{}
|
|
||||||
|
|
||||||
bool enabled;
|
|
||||||
std::vector<Boxed_Value> saves;
|
std::vector<Boxed_Value> saves;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -350,7 +347,6 @@ namespace chaiscript
|
|||||||
m_num_types(m_conversions.size()),
|
m_num_types(m_conversions.size()),
|
||||||
m_thread_cache(this),
|
m_thread_cache(this),
|
||||||
m_conversion_saves(this)
|
m_conversion_saves(this)
|
||||||
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -448,7 +444,7 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
chaiscript::detail::threading::shared_lock<chaiscript::detail::threading::shared_mutex> l(m_mutex);
|
chaiscript::detail::threading::shared_lock<chaiscript::detail::threading::shared_mutex> l(m_mutex);
|
||||||
|
|
||||||
auto itr = find(to, from);
|
const auto itr = find(to, from);
|
||||||
|
|
||||||
if (itr != m_conversions.end())
|
if (itr != m_conversions.end())
|
||||||
{
|
{
|
||||||
|
@@ -40,17 +40,7 @@ namespace chaiscript
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr Type_Info()
|
constexpr Type_Info() = default;
|
||||||
: m_type_info(nullptr), m_bare_type_info(nullptr),
|
|
||||||
m_flags(1 << is_undef_flag)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Type_Info(Type_Info&&) = default;
|
|
||||||
Type_Info& operator=(Type_Info&&) = default;
|
|
||||||
Type_Info(const Type_Info&) = default;
|
|
||||||
Type_Info& operator=(const Type_Info&) = default;
|
|
||||||
|
|
||||||
|
|
||||||
constexpr bool operator<(const Type_Info &ti) const noexcept
|
constexpr bool operator<(const Type_Info &ti) const noexcept
|
||||||
{
|
{
|
||||||
@@ -113,15 +103,15 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const std::type_info *m_type_info;
|
const std::type_info *m_type_info = nullptr;
|
||||||
const std::type_info *m_bare_type_info;
|
const std::type_info *m_bare_type_info = nullptr;
|
||||||
unsigned int m_flags;
|
|
||||||
static const int is_const_flag = 0;
|
static const int is_const_flag = 0;
|
||||||
static const int is_reference_flag = 1;
|
static const int is_reference_flag = 1;
|
||||||
static const int is_pointer_flag = 2;
|
static const int is_pointer_flag = 2;
|
||||||
static const int is_void_flag = 3;
|
static const int is_void_flag = 3;
|
||||||
static const int is_arithmetic_flag = 4;
|
static const int is_arithmetic_flag = 4;
|
||||||
static const int is_undef_flag = 5;
|
static const int is_undef_flag = 5;
|
||||||
|
unsigned int m_flags = (1 << is_undef_flag);
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace detail
|
namespace detail
|
||||||
|
Reference in New Issue
Block a user