summaryrefslogtreecommitdiff
path: root/cpp/src/Ice/VirtualShared.h
blob: de16e0d509136163b8d95767d442c82875980dfb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// **********************************************************************
//
// Copyright (c) 2003-2017 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************

#ifndef ICE_VIRTUAL_SHARED_H
#define ICE_VIRTUAL_SHARED_H

#ifdef ICE_CPP11_MAPPING

namespace IceInternal
{

class VirtualEnableSharedFromThisBase : public std::enable_shared_from_this<VirtualEnableSharedFromThisBase>
{
public:
    
    virtual ~VirtualEnableSharedFromThisBase() = default;
};

template<typename T> 
class EnableSharedFromThis : public virtual VirtualEnableSharedFromThisBase
{
public:

    std::shared_ptr<T> shared_from_this()
    {
        return std::dynamic_pointer_cast<T>(VirtualEnableSharedFromThisBase::shared_from_this());
    }

    std::shared_ptr<T const> shared_from_this() const
    {
        return std::dynamic_pointer_cast<T const>(VirtualEnableSharedFromThisBase::shared_from_this());
    }
};

}
#endif
#endif