ASPiK SDK
interface.h
1 // This file is part of VSTGUI. It is subject to the license terms
2 // in the LICENSE file found in the top-level directory of this
3 // distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
4 
5 #pragma once
6 
7 #include <memory>
8 
9 //------------------------------------------------------------------------
10 namespace VSTGUI {
11 
12 //------------------------------------------------------------------------
13 class Interface
14 {
15 public:
16  virtual ~Interface () noexcept {}
17 
18  Interface () = default;
19  Interface (const Interface&) = delete;
20  Interface (Interface&&) = delete;
21  Interface& operator= (const Interface&) = delete;
22  Interface& operator= (Interface&&) = delete;
23 
24  template <typename T>
25  const auto dynamicCast () const
26  {
27  return dynamic_cast<const T*> (this);
28  }
29 
30  template <typename T>
31  auto dynamicCast ()
32  {
33  return dynamic_cast<T*> (this);
34  }
35 };
36 
37 //------------------------------------------------------------------------
38 using InterfacePtr = std::shared_ptr<Interface>;
39 
40 //------------------------------------------------------------------------
41 template <typename Iface, typename T>
42 inline auto dynamicPtrCast (std::shared_ptr<T>& obj)
43 {
44  return std::dynamic_pointer_cast<Iface> (obj);
45 }
46 
47 //------------------------------------------------------------------------
48 template <typename Iface, typename T>
49 inline const auto dynamicPtrCast (const std::shared_ptr<T>& obj)
50 {
51  return std::dynamic_pointer_cast<Iface> (obj);
52 }
53 
54 //------------------------------------------------------------------------
55 template <typename Iface, typename T>
56 inline auto staticPtrCast (std::shared_ptr<T>& obj)
57 {
58  return std::static_pointer_cast<Iface> (obj);
59 }
60 
61 //------------------------------------------------------------------------
62 template <typename Iface, typename T>
63 inline const auto staticPtrCast (const std::shared_ptr<T>& obj)
64 {
65  return std::static_pointer_cast<Iface> (obj);
66 }
67 
68 //------------------------------------------------------------------------
69 template <typename Iface, typename T>
70 inline const auto& asInterface (const T& obj)
71 {
72  return static_cast<const Iface&> (obj);
73 }
74 
75 //------------------------------------------------------------------------
76 } // VSTGUI
Definition: interface.h:13
Definition: customcontrols.cpp:8