C++11/14 updates

This commit is contained in:
Jason Turner
2016-03-11 14:45:40 -07:00
parent a3365a9c4a
commit a363ef5e0e
6 changed files with 39 additions and 52 deletions

View File

@@ -46,7 +46,7 @@ namespace chaiscript
}
bad_boxed_cast(const bad_boxed_cast &) = default;
virtual ~bad_boxed_cast() noexcept {}
virtual ~bad_boxed_cast() noexcept = default;
/// \brief Description of what error occurred
virtual const char * what() const noexcept override

View File

@@ -82,21 +82,19 @@ namespace chaiscript
if (t_conversions && (*t_conversions)->convertable_type<Type>())
{
try {
// std::cout << "trying an up conversion " << typeid(Type).name() << '\n';
// We will not catch any bad_boxed_dynamic_cast that is thrown, let the user get it
// either way, we are not responsible if it doesn't work
return detail::Cast_Helper<Type>::cast((*t_conversions)->boxed_type_conversion<Type>(t_conversions->saves(), bv), t_conversions);
} catch (...) {
try {
// std::cout << "trying a down conversion " << typeid(Type).name() << '\n';
// try going the other way - down the inheritance graph
// try going the other way
return detail::Cast_Helper<Type>::cast((*t_conversions)->boxed_type_down_conversion<Type>(t_conversions->saves(), bv), t_conversions);
} catch (const chaiscript::detail::exception::bad_any_cast &) {
throw exception::bad_boxed_cast(bv.get_type_info(), typeid(Type));
}
}
} else {
// If it's not polymorphic, just throw the error, don't waste the time on the
// If it's not convertable, just throw the error, don't waste the time on the
// attempted dynamic_cast
throw exception::bad_boxed_cast(bv.get_type_info(), typeid(Type));
}

View File

@@ -30,7 +30,7 @@ namespace chaiscript
{
arithmetic_error(const std::string& reason) : std::runtime_error("Arithmetic error: " + reason) {}
arithmetic_error(const arithmetic_error &) = default;
virtual ~arithmetic_error() noexcept {}
virtual ~arithmetic_error() noexcept = default;
};
}
}

View File

@@ -56,14 +56,14 @@ namespace chaiscript
class reserved_word_error : public std::runtime_error
{
public:
reserved_word_error(const std::string &t_word) noexcept
explicit reserved_word_error(const std::string &t_word) noexcept
: std::runtime_error("Reserved word not allowed in object name: " + t_word), m_word(t_word)
{
}
reserved_word_error(const reserved_word_error &) = default;
virtual ~reserved_word_error() noexcept {}
virtual ~reserved_word_error() noexcept = default;
std::string word() const
{
@@ -78,14 +78,14 @@ namespace chaiscript
class illegal_name_error : public std::runtime_error
{
public:
illegal_name_error(const std::string &t_name) noexcept
explicit illegal_name_error(const std::string &t_name) noexcept
: std::runtime_error("Reserved name not allowed in object name: " + t_name), m_name(t_name)
{
}
illegal_name_error(const illegal_name_error &) = default;
virtual ~illegal_name_error() noexcept {}
virtual ~illegal_name_error() noexcept = default;
std::string name() const
{
@@ -101,14 +101,14 @@ namespace chaiscript
class name_conflict_error : public std::runtime_error
{
public:
name_conflict_error(const std::string &t_name) noexcept
explicit name_conflict_error(const std::string &t_name) noexcept
: std::runtime_error("Name already exists in current context " + t_name), m_name(t_name)
{
}
name_conflict_error(const name_conflict_error &) = default;
virtual ~name_conflict_error() noexcept {}
virtual ~name_conflict_error() noexcept = default;
std::string name() const
{
@@ -131,7 +131,7 @@ namespace chaiscript
}
global_non_const(const global_non_const &) = default;
virtual ~global_non_const() noexcept {}
virtual ~global_non_const() noexcept = default;
};
}
@@ -194,30 +194,28 @@ namespace chaiscript
apply_globals(m_globals.begin(), m_globals.end(), t_engine);
}
~Module()
{
}
bool has_function(const Proxy_Function &new_f, const std::string &name)
{
return std::any_of(m_funcs.begin(), m_funcs.end(), [&](const std::pair<Proxy_Function, std::string> &existing_f) {
return existing_f.second == name && *(existing_f.first) == *(new_f);
});
return std::any_of(m_funcs.begin(), m_funcs.end(),
[&](const std::pair<Proxy_Function, std::string> &existing_f) {
return existing_f.second == name && *(existing_f.first) == *(new_f);
}
);
}
private:
std::vector<std::pair<Type_Info, std::string> > m_typeinfos;
std::vector<std::pair<Proxy_Function, std::string> > m_funcs;
std::vector<std::pair<Boxed_Value, std::string> > m_globals;
std::vector<std::pair<Type_Info, std::string>> m_typeinfos;
std::vector<std::pair<Proxy_Function, std::string>> m_funcs;
std::vector<std::pair<Boxed_Value, std::string>> m_globals;
std::vector<std::string> m_evals;
std::vector<Type_Conversion> m_conversions;
template<typename T, typename InItr>
static void apply(InItr begin, const InItr end, T &t)
{
for_each(begin, end, [&t](typename std::iterator_traits<InItr>::reference obj)
{
for_each(begin, end,
[&t](const auto &obj) {
try {
t.add(obj.first, obj.second);
} catch (const chaiscript::exception::name_conflict_error &) {
@@ -600,12 +598,10 @@ namespace chaiscript
{
t_holder.call_params.pop_back();
StackData &stack = get_stack_data(t_holder);
if (stack.size() > 1)
{
stack.pop_back();
} else {
throw std::range_error("Unable to pop global stack");
}
assert(!stack.empty());
stack.pop_back();
}
@@ -916,10 +912,8 @@ namespace chaiscript
}
for (const auto &fun : t_funs) {
if (fun->is_attribute_function()) {
if (fun->compare_first_type(t_params[0], t_conversions)) {
return true;
}
if (fun->is_attribute_function()
&& fun->compare_first_type(t_params[0], t_conversions)) {
}
}
@@ -1107,7 +1101,7 @@ namespace chaiscript
const Const_Proxy_Function &f = this->boxed_cast<Const_Proxy_Function>(params[0]);
const Type_Conversions_State convs(m_conversions, m_conversions.conversion_saves());
return Boxed_Value(f->call_match(std::vector<Boxed_Value>(params.begin() + 1, params.end()), convs));
return const_var(f->call_match(std::vector<Boxed_Value>(params.begin() + 1, params.end()), convs));
}
/// Dump all system info to stdout

View File

@@ -33,7 +33,7 @@ namespace chaiscript
option_explicit_set(const option_explicit_set &) = default;
virtual ~option_explicit_set() noexcept {}
virtual ~option_explicit_set() noexcept = default;
};
class Dynamic_Object

View File

@@ -39,7 +39,7 @@ namespace chaiscript
/// A Proxy_Function implementation designed for calling a function
/// that is automatically guarded based on the first param based on the
/// param's type name
class Dynamic_Object_Function : public Proxy_Function_Base
class Dynamic_Object_Function final : public Proxy_Function_Base
{
public:
Dynamic_Object_Function(
@@ -67,12 +67,11 @@ namespace chaiscript
&& "Programming error, Dynamic_Object_Function must have at least one parameter (this)");
}
virtual ~Dynamic_Object_Function() {}
Dynamic_Object_Function &operator=(const Dynamic_Object_Function) = delete;
Dynamic_Object_Function(Dynamic_Object_Function &) = delete;
virtual bool operator==(const Proxy_Function_Base &f) const override
bool operator==(const Proxy_Function_Base &f) const override
{
if (const auto *df = dynamic_cast<const Dynamic_Object_Function *>(&f))
{
@@ -82,9 +81,9 @@ namespace chaiscript
}
}
virtual bool is_attribute_function() const override { return m_is_attribute; }
bool is_attribute_function() const override { return m_is_attribute; }
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
{
if (dynamic_object_typename_match(vals, m_type_name, m_ti, t_conversions))
{
@@ -94,12 +93,12 @@ namespace chaiscript
}
}
virtual std::vector<Const_Proxy_Function> get_contained_functions() const override
std::vector<Const_Proxy_Function> get_contained_functions() const override
{
return {m_func};
}
virtual std::string annotation() const override
std::string annotation() const override
{
return m_func->annotation();
}
@@ -170,9 +169,7 @@ namespace chaiscript
Proxy_Function m_func;
std::unique_ptr<Type_Info> m_ti;
const Type_Info m_doti;
bool m_is_attribute;
const bool m_is_attribute;
};
@@ -182,7 +179,7 @@ namespace chaiscript
* that is automatically guarded based on the first param based on the
* param's type name
*/
class Dynamic_Object_Constructor : public Proxy_Function_Base
class Dynamic_Object_Constructor final : public Proxy_Function_Base
{
public:
Dynamic_Object_Constructor(
@@ -208,9 +205,7 @@ namespace chaiscript
return std::vector<Type_Info>(begin, end);
}
virtual ~Dynamic_Object_Constructor() {}
virtual bool operator==(const Proxy_Function_Base &f) const override
bool operator==(const Proxy_Function_Base &f) const override
{
const Dynamic_Object_Constructor *dc = dynamic_cast<const Dynamic_Object_Constructor*>(&f);
return dc && dc->m_type_name == m_type_name && (*dc->m_func) == (*m_func);
@@ -230,7 +225,7 @@ namespace chaiscript
}
protected:
virtual Boxed_Value do_call(const std::vector<Boxed_Value> &params, const Type_Conversions_State &t_conversions) const override
Boxed_Value do_call(const std::vector<Boxed_Value> &params, const Type_Conversions_State &t_conversions) const override
{
auto bv = Boxed_Value(Dynamic_Object(m_type_name), true);
std::vector<Boxed_Value> new_params{bv};