From ef8cd1f5910d85d0cf9651fd1d47291b624cae2a Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Sat, 5 Sep 2009 23:46:21 +0000 Subject: [PATCH] Add more robust support for handling of const ptr values --- .../chaiscript/dispatchkit/boxed_value.hpp | 61 +++++++++++++++++-- 1 file changed, 57 insertions(+), 4 deletions(-) diff --git a/include/chaiscript/dispatchkit/boxed_value.hpp b/include/chaiscript/dispatchkit/boxed_value.hpp index 4399809..e003fc5 100644 --- a/include/chaiscript/dispatchkit/boxed_value.hpp +++ b/include/chaiscript/dispatchkit/boxed_value.hpp @@ -355,7 +355,12 @@ namespace chaiscript return boost::any_cast >(ob.get()); } } else { - return boost::cref(*(boost::any_cast >(ob.get()))); + if (!ob.get_type_info().m_is_const) + { + return boost::cref(*(boost::any_cast >(ob.get()))); + } else { + return boost::cref(*(boost::any_cast >(ob.get()))); + } } } }; @@ -379,7 +384,12 @@ namespace chaiscript return boost::any_cast >(ob.get()); } } else { - return boost::cref(*(boost::any_cast >(ob.get()))); + if (!ob.get_type_info().m_is_const) + { + return boost::cref(*(boost::any_cast >(ob.get()))); + } else { + return boost::cref(*(boost::any_cast >(ob.get()))); + } } } }; @@ -403,7 +413,12 @@ namespace chaiscript return (boost::any_cast >(ob.get())).get_pointer(); } } else { - return (boost::any_cast >(ob.get())).get(); + if (!ob.get_type_info().m_is_const) + { + return (boost::any_cast >(ob.get())).get(); + } else { + return (boost::any_cast >(ob.get())).get(); + } } } }; @@ -461,7 +476,26 @@ namespace chaiscript }; /** - * Cast_Helper for casting to a boost::shared_ptr<> type + * Cast_Helper for casting to a boost::shared_ptr type + */ + template + struct Cast_Helper > + { + typedef typename boost::shared_ptr Result_Type; + + static Result_Type cast(const Boxed_Value &ob) + { + if (!ob.get_type_info().m_is_const) + { + return boost::const_pointer_cast(boost::any_cast >(ob.get())); + } else { + return boost::any_cast >(ob.get()); + } + } + }; + + /** + * Cast_Helper for casting to a const boost::shared_ptr<> & type */ template struct Cast_Helper &> @@ -474,6 +508,25 @@ namespace chaiscript } }; + /** + * Cast_Helper for casting to a const boost::shared_ptr & type + */ + template + struct Cast_Helper &> + { + typedef typename boost::shared_ptr Result_Type; + + static Result_Type cast(const Boxed_Value &ob) + { + if (!ob.get_type_info().m_is_const) + { + return boost::const_pointer_cast(boost::any_cast >(ob.get())); + } else { + return boost::any_cast >(ob.get()); + } + } + }; + /**