hpp-util 6.0.0
Debugging tools for the HPP project.
Loading...
Searching...
No Matches
pointer.hh
Go to the documentation of this file.
1// Copyright (C) 2013 by Antonio El Khoury, CNRS.
2//
3
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are
6// met:
7//
8// 1. Redistributions of source code must retain the above copyright
9// notice, this list of conditions and the following disclaimer.
10//
11// 2. Redistributions in binary form must reproduce the above copyright
12// notice, this list of conditions and the following disclaimer in the
13// documentation and/or other materials provided with the distribution.
14//
15// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19// HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
26// DAMAGE.
27//
28// This software is provided "as is" without warranty of any kind,
29// either expressed or implied, including but not limited to the
30// implied warranties of fitness for a particular purpose.
31//
32// See the COPYING file for more information.
33
34#ifndef HPP_UTIL_POINTER_HH
35#define HPP_UTIL_POINTER_HH
36
37#include <memory>
38
39namespace hpp {
40using std::shared_ptr;
41using std::weak_ptr;
42
43using std::const_pointer_cast;
44using std::dynamic_pointer_cast;
45using std::static_pointer_cast;
46
47using std::make_shared;
48} // namespace hpp
49
58
59#define HPP_POINTER_DEFS(t) \
60 typedef hpp::weak_ptr<t> t##WkPtr_t; \
61 typedef hpp::weak_ptr<const t> t##ConstWkPtr_t; \
62 struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n
63
67#define HPP_PREDEF_CLASS(t) \
68 class t; \
69 HPP_POINTER_DEFS(t); \
70 struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n
71
72#define HPP_STATIC_PTR_CAST(t, x) hpp::static_pointer_cast<t>(x)
73#define HPP_DYNAMIC_PTR_CAST(t, x) hpp::dynamic_pointer_cast<t>(x)
74#ifndef NDEBUG
75#define HPP_STATIC_CAST_REF_CHECK(t, x) \
76 try { \
77 dynamic_cast<t&>(x); \
78 } catch (const std::exception& exc) { \
79 assert("Cast in #t failed" && 0); \
80 }
81#else
82#define HPP_STATIC_CAST_REF_CHECK(t, x)
83#endif // defined NDEBUG
84#endif
Definition assertion.hh:45