hpp-util  4.11.0
Debugging tools for the HPP project.
pointer.hh
Go to the documentation of this file.
1 // Copyright (C) 2013 by Antonio El Khoury, CNRS.
2 //
3 // This file is part of the hpp-util.
4 //
5 // This software is provided "as is" without warranty of any kind,
6 // either expressed or implied, including but not limited to the
7 // implied warranties of fitness for a particular purpose.
8 //
9 // See the COPYING file for more information.
10 
11 #ifndef HPP_UTIL_POINTER_HH
12 # define HPP_UTIL_POINTER_HH
13 
14 # include <memory>
15 
16 namespace hpp {
17  using std::shared_ptr;
18  using std::weak_ptr;
19 
20  using std::static_pointer_cast;
21  using std::dynamic_pointer_cast;
22  using std::const_pointer_cast;
23 
24  using std::make_shared;
25 } // namespace hpp
26 
35 
36 # define HPP_POINTER_DEFS(t) \
37  typedef hpp::weak_ptr <t> t##WkPtr_t; \
38  typedef hpp::weak_ptr <const t> t##ConstWkPtr_t; \
39  struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n
40 
44 # define HPP_PREDEF_CLASS(t) \
45  class t; \
46  HPP_POINTER_DEFS(t); \
47  struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n
48 
49 # define HPP_STATIC_PTR_CAST(t, x) hpp::static_pointer_cast < t > (x)
50 # define HPP_DYNAMIC_PTR_CAST(t, x) hpp::dynamic_pointer_cast < t > (x)
51 # ifndef NDEBUG
52 # define HPP_STATIC_CAST_REF_CHECK(t, x)\
53  try {\
54  dynamic_cast < t& > (x);\
55  } catch (const std::exception& exc) {\
56  assert ("Cast in #t failed" && 0);\
57  }
58 # else
59 # define HPP_STATIC_CAST_REF_CHECK(t, x)
60 # endif // defined NDEBUG
61 #endif
Definition: assertion.hh:22