From 5861c45fc1ae4346877db24eda6098019765f4d0 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Mon, 15 Sep 2014 21:16:44 -0600 Subject: [PATCH] C++11 related cleanup and improvments --- include/chaiscript/dispatchkit/bootstrap.hpp | 8 ++--- .../chaiscript/dispatchkit/boxed_number.hpp | 4 +-- .../chaiscript/dispatchkit/boxed_value.hpp | 2 +- .../chaiscript/dispatchkit/dispatchkit.hpp | 36 +++++++------------ .../dispatchkit/proxy_constructors.hpp | 2 +- 5 files changed, 18 insertions(+), 34 deletions(-) diff --git a/include/chaiscript/dispatchkit/bootstrap.hpp b/include/chaiscript/dispatchkit/bootstrap.hpp index 76058d4..9384920 100644 --- a/include/chaiscript/dispatchkit/bootstrap.hpp +++ b/include/chaiscript/dispatchkit/bootstrap.hpp @@ -46,13 +46,9 @@ namespace chaiscript /// \param[in] v Boxed_Number to copy into the new object /// \returns The newly created object. template - std::shared_ptr construct_pod(Boxed_Number v) + std::shared_ptr construct_pod(const Boxed_Number &v) { - std::shared_ptr p(new P1()); - Boxed_Value bv(p); - Boxed_Number nb(bv); - nb = v; - return p; + return std::make_shared(v.get_as()); } } diff --git a/include/chaiscript/dispatchkit/boxed_number.hpp b/include/chaiscript/dispatchkit/boxed_number.hpp index f3d2838..3541bfb 100644 --- a/include/chaiscript/dispatchkit/boxed_number.hpp +++ b/include/chaiscript/dispatchkit/boxed_number.hpp @@ -334,8 +334,8 @@ namespace chaiscript { } - Boxed_Number(const Boxed_Value &v) - : bv(v) + Boxed_Number(Boxed_Value v) + : bv(std::move(v)) { validate_boxed_number(v); } diff --git a/include/chaiscript/dispatchkit/boxed_value.hpp b/include/chaiscript/dispatchkit/boxed_value.hpp index 861a2f7..3fe48b0 100644 --- a/include/chaiscript/dispatchkit/boxed_value.hpp +++ b/include/chaiscript/dispatchkit/boxed_value.hpp @@ -297,7 +297,7 @@ namespace chaiscript template Boxed_Value const_var_impl(const T &t) { - return Boxed_Value(std::shared_ptr::type >(new T(t))); + return Boxed_Value(std::make_shared::type >(t)); } /// \brief Takes a pointer to a value, adds const to the pointed to type and returns an immutable Boxed_Value. diff --git a/include/chaiscript/dispatchkit/dispatchkit.hpp b/include/chaiscript/dispatchkit/dispatchkit.hpp index fd539de..0b1e165 100644 --- a/include/chaiscript/dispatchkit/dispatchkit.hpp +++ b/include/chaiscript/dispatchkit/dispatchkit.hpp @@ -430,7 +430,7 @@ namespace chaiscript Dispatch_Engine() : m_stack_holder(this), - m_place_holder(std::shared_ptr(new dispatch::Placeholder_Object())) + m_place_holder(std::make_shared()) { } @@ -549,8 +549,7 @@ namespace chaiscript */ void new_scope() { - StackData &stack = get_stack_data(); - stack.push_back(Scope()); + get_stack_data().emplace_back(); } /** @@ -571,9 +570,8 @@ namespace chaiscript /// Pushes a new stack on to the list of stacks void new_stack() { - Stack s(new Stack::element_type()); - s->push_back(Scope()); - m_stack_holder->stacks.push_back(s); + // add a new Stack with 1 element + m_stack_holder->stacks.emplace_back(std::make_shared(1)); } void pop_stack() @@ -836,7 +834,7 @@ namespace chaiscript { for (const auto & internal_func : function.second) { - rets.push_back(std::make_pair(function.first, internal_func)); + rets.emplace_back(function.first, internal_func); } } @@ -867,19 +865,14 @@ namespace chaiscript return call_function(t_name, std::vector()); } - Boxed_Value call_function(const std::string &t_name, const Boxed_Value &p1) const + Boxed_Value call_function(const std::string &t_name, Boxed_Value p1) const { - std::vector params; - params.push_back(p1); - return call_function(t_name, params); + return call_function(t_name, std::vector({std::move(p1)})); } - Boxed_Value call_function(const std::string &t_name, const Boxed_Value &p1, const Boxed_Value &p2) const + Boxed_Value call_function(const std::string &t_name, Boxed_Value p1, Boxed_Value p2) const { - std::vector params; - params.push_back(p1); - params.push_back(p2); - return call_function(t_name, params); + return call_function(t_name, std::vector({std::move(p1), std::move(p2)})); } /** @@ -1219,14 +1212,11 @@ namespace chaiscript // if the function is the only function but it also contains // arithmetic operators, we must wrap it in a dispatch function // to allow for automatic arithmetic type conversions - std::vector vec; - vec.push_back(t_f); + std::vector vec({t_f}); funcs.insert(std::make_pair(t_name, vec)); func_objs[t_name] = Proxy_Function(new Dispatch_Function(vec)); } else { - std::vector vec; - vec.push_back(t_f); - funcs.insert(std::make_pair(t_name, vec)); + funcs.insert(std::make_pair(t_name, std::vector({t_f}))); func_objs[t_name] = t_f; } @@ -1241,9 +1231,7 @@ namespace chaiscript Stack_Holder() : call_depth(0) { - Stack s(new StackData()); - s->push_back(Scope()); - stacks.push_back(s); + stacks.emplace_back(std::make_shared(1)); } std::deque stacks; diff --git a/include/chaiscript/dispatchkit/proxy_constructors.hpp b/include/chaiscript/dispatchkit/proxy_constructors.hpp index 0c56f95..64d2a93 100644 --- a/include/chaiscript/dispatchkit/proxy_constructors.hpp +++ b/include/chaiscript/dispatchkit/proxy_constructors.hpp @@ -21,7 +21,7 @@ namespace chaiscript template std::shared_ptr constructor_(Params ... params) { - return std::shared_ptr(new Class(params...)); + return std::make_shared(params...); } template