Migrate libasyncio from boost.signal to signals2 (#8756)
[libasyncio] / utils / asyncio_pointer_func.hpp
CommitLineData
8c15b8c7
TJ
1/*
2The software in this package is distributed under the GNU General
3Public License version 2 (with a special exception described below).
4
5A copy of GNU General Public License (GPL) is included in this distribution,
6in the file COPYING.GPL.
7
8As a special exception, if other files instantiate templates or use macros
9or inline functions from this file, or you compile this file and link it
10with other works to produce a work based on this file, this file
11does not by itself cause the resulting work to be covered
12by the GNU General Public License.
13
14However the source code for this file must still be made available
15in accordance with section (3) of the GNU General Public License.
16
17This exception does not invalidate any other reasons why a work based
18on this file might be covered by the GNU General Public License.
19*/
32c42058
RP
20/**
21 * @file
22 * @brief some functions to deal with (smart) pointer
23 *
24 * @author Reinhard Pfau \<Reinhard.Pfau@gmx.de\>
25 * @copyright &copy; Copyright 2009 by Intra2net AG
32c42058
RP
26 */
27
28#ifndef _ASYNCIO_POINTER_FUNC_HPP_
29#define _ASYNCIO_POINTER_FUNC_HPP_
30
31#include <asyncio_config.hpp>
32#include <boost/shared_ptr.hpp>
33#include <boost/enable_shared_from_this.hpp>
34#ifdef HAVE_LIBI2NCOMMON
35# include <pointer_func.hpp>
36#endif
37
38namespace AsyncIo
39{
40namespace Utils
41{
42
43#ifdef HAVE_LIBI2NCOMMON
44
45// NOTE: this typedef is needed by I2N code; please keep it!
46
3d0fe434
TJ
47typedef I2n::SharedBase SharedBase;
48
32c42058
RP
49#else
50
51class SharedBase
52: public boost::enable_shared_from_this< SharedBase >
53{
54 public:
55 typedef boost::shared_ptr< SharedBase > PtrType;
56
57 public:
58 SharedBase() {}
59 virtual ~SharedBase() {}
60
61 template< class D >
62 boost::shared_ptr< D > get_ptr_as()
63 {
64 try
65 {
d0290d78 66 return boost::dynamic_pointer_cast< D >( shared_from_this() );
32c42058
RP
67 }
68 catch( boost::bad_weak_ptr& e )
69 {
70 // we ignore this error.
71 }
72 return boost::shared_ptr< D >();
73 }
74
75}; // end of SharedBase
76
77#endif
78
79
80} // end of namespace Utils
81} // end of namespace AsyncIo
82
83
84#endif