Add more robust support for handling of const ptr values
This commit is contained in:
parent
46cdb89921
commit
ef8cd1f591
@ -355,7 +355,12 @@ namespace chaiscript
|
|||||||
return boost::any_cast<boost::reference_wrapper<const Result> >(ob.get());
|
return boost::any_cast<boost::reference_wrapper<const Result> >(ob.get());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return boost::cref(*(boost::any_cast<boost::shared_ptr<Result> >(ob.get())));
|
if (!ob.get_type_info().m_is_const)
|
||||||
|
{
|
||||||
|
return boost::cref(*(boost::any_cast<boost::shared_ptr<Result> >(ob.get())));
|
||||||
|
} else {
|
||||||
|
return boost::cref(*(boost::any_cast<boost::shared_ptr<const Result> >(ob.get())));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -379,7 +384,12 @@ namespace chaiscript
|
|||||||
return boost::any_cast<boost::reference_wrapper<const Result> >(ob.get());
|
return boost::any_cast<boost::reference_wrapper<const Result> >(ob.get());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return boost::cref(*(boost::any_cast<boost::shared_ptr<Result> >(ob.get())));
|
if (!ob.get_type_info().m_is_const)
|
||||||
|
{
|
||||||
|
return boost::cref(*(boost::any_cast<boost::shared_ptr<Result> >(ob.get())));
|
||||||
|
} else {
|
||||||
|
return boost::cref(*(boost::any_cast<boost::shared_ptr<const Result> >(ob.get())));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -403,7 +413,12 @@ namespace chaiscript
|
|||||||
return (boost::any_cast<boost::reference_wrapper<const Result> >(ob.get())).get_pointer();
|
return (boost::any_cast<boost::reference_wrapper<const Result> >(ob.get())).get_pointer();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return (boost::any_cast<boost::shared_ptr<Result> >(ob.get())).get();
|
if (!ob.get_type_info().m_is_const)
|
||||||
|
{
|
||||||
|
return (boost::any_cast<boost::shared_ptr<Result> >(ob.get())).get();
|
||||||
|
} else {
|
||||||
|
return (boost::any_cast<boost::shared_ptr<const Result> >(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<const> type
|
||||||
|
*/
|
||||||
|
template<typename Result>
|
||||||
|
struct Cast_Helper<typename boost::shared_ptr<const Result> >
|
||||||
|
{
|
||||||
|
typedef typename boost::shared_ptr<const Result> Result_Type;
|
||||||
|
|
||||||
|
static Result_Type cast(const Boxed_Value &ob)
|
||||||
|
{
|
||||||
|
if (!ob.get_type_info().m_is_const)
|
||||||
|
{
|
||||||
|
return boost::const_pointer_cast<const Result>(boost::any_cast<boost::shared_ptr<Result> >(ob.get()));
|
||||||
|
} else {
|
||||||
|
return boost::any_cast<boost::shared_ptr<const Result> >(ob.get());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cast_Helper for casting to a const boost::shared_ptr<> & type
|
||||||
*/
|
*/
|
||||||
template<typename Result>
|
template<typename Result>
|
||||||
struct Cast_Helper<const boost::shared_ptr<Result> &>
|
struct Cast_Helper<const boost::shared_ptr<Result> &>
|
||||||
@ -474,6 +508,25 @@ namespace chaiscript
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cast_Helper for casting to a const boost::shared_ptr<const> & type
|
||||||
|
*/
|
||||||
|
template<typename Result>
|
||||||
|
struct Cast_Helper<const boost::shared_ptr<const Result> &>
|
||||||
|
{
|
||||||
|
typedef typename boost::shared_ptr<const Result> Result_Type;
|
||||||
|
|
||||||
|
static Result_Type cast(const Boxed_Value &ob)
|
||||||
|
{
|
||||||
|
if (!ob.get_type_info().m_is_const)
|
||||||
|
{
|
||||||
|
return boost::const_pointer_cast<const Result>(boost::any_cast<boost::shared_ptr<Result> >(ob.get()));
|
||||||
|
} else {
|
||||||
|
return boost::any_cast<boost::shared_ptr<const Result> >(ob.get());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user