29 #ifndef DATATOOLS_HANDLE_H 30 #define DATATOOLS_HANDLE_H 35 #include <type_traits> 39 #include <boost/shared_ptr.hpp> 40 #include <boost/smart_ptr/make_shared.hpp> 41 #include <boost/serialization/nvp.hpp> 42 #include <boost/serialization/tracking.hpp> 43 #include <boost/serialization/shared_ptr.hpp> 113 template <
typename T>
163 typename = std::enable_if<
164 std::is_same<const Q, T>::value &&
165 std::is_const<T>::value &&
166 !std::is_const<Q>::value>>
168 : _sp_(const_cast<Q*>(held))
190 return _sp_.unique();
197 return _sp_.get() !=
nullptr;
201 operator bool()
const 203 return _sp_.get() !=
nullptr;
208 _sp_.swap(other_._sp_);
216 DT_THROW_IF(_sp_.get() ==
nullptr, std::logic_error,
"Handle holds no data!");
229 template<
typename Q = T>
230 typename std::enable_if<
231 std::is_same<Q, T>::value &&
232 !std::is_const<Q>::value &&
233 !std::is_const<T>::value,
236 DT_THROW_IF(_sp_.get() ==
nullptr, std::logic_error,
"Handle holds no data!");
244 DT_THROW_IF(!_sp_, std::logic_error,
"Handle holds no data!");
252 DT_THROW_IF(!_sp_, std::logic_error,
"Handle holds no data!");
261 DT_THROW_IF(!_sp_, std::logic_error,
"Handle holds no data!");
262 return *(_sp_.get());
269 DT_THROW_IF(!_sp_, std::logic_error,
"Handle holds no data!");
270 return *(_sp_.get());
281 template<
typename Q = T>
282 typename std::enable_if<
283 std::is_same<Q, T>::value &&
284 !std::is_const<Q>::value &&
285 !std::is_const<T>::value,
288 boost::shared_ptr<const T> csp = boost::const_pointer_cast<const T, T>(_sp_);
294 friend class boost::serialization::access;
295 template <
class Archive>
298 ar_ & boost::serialization::make_nvp(
"sp", _sp_);
304 boost::shared_ptr<T> _sp_;
353 template <
typename T,
typename... Args>
357 return handle<T>(boost::make_shared<T>(std::forward<Args>(args)...));
400 template <
typename T>
401 struct handle_predicate
402 :
public i_predicate<handle<T> >
407 bool no_data_means_false_ =
true)
408 : _predicate_(predicate_)
409 , _no_data_means_false_(no_data_means_false_)
419 if (_no_data_means_false_)
return false;
420 DT_THROW(std::logic_error,
"Handle has no data !");
422 return _predicate_(handle_.
get());
427 bool _no_data_means_false_;
433 #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION 435 namespace serialization{
440 typedef mpl::integral_c_tag
tag;
441 #if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3206)) 442 typedef BOOST_DEDUCED_TYPENAME mpl::int_< ::boost::serialization::track_never>
type;
444 typedef mpl::int_< ::boost::serialization::track_never>
type;
446 #if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x570)) 447 BOOST_STATIC_CONSTANT(
int, value = ::boost::serialization::track_never);
449 BOOST_STATIC_CONSTANT(
int, value = type::value);
453 #define BOOST_SERIALIZATION_DATATOOLS_HANDLE(T) 456 #define BOOST_SERIALIZATION_DATATOOLS_HANDLE(T) \ 457 BOOST_SERIALIZATION_SHARED_PTR(T) \ 458 BOOST_CLASS_TRACKING(::datatools::handle< T >, \ 459 ::boost::serialization::track_never) \ 463 #endif // DATATOOLS_HANDLE_H
#define DT_THROW(ExceptionType, Message)
Definition: exception.h:121
Serialization stuff for CLHEP 'vector_3d'.
Definition: portable_archive_exception.hpp:27
void serialize(Archive &a_ar, geomtools::vector_3d &v_, const unsigned int a_version)
Utility macros for exception handling.
#define DT_THROW_IF(Condition, ExceptionType, Message)
Definition: exception.h:76