Kiwano Engine  v1.2.x
NativeObject.h
1 // Copyright (c) 2016-2018 Kiwano - Nomango
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to deal
5 // in the Software without restriction, including without limitation the rights
6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 // copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 // THE SOFTWARE.
20 
21 #pragma once
22 #include <kiwano/base/ObjectBase.h>
23 
24 #if KGE_RENDER_ENGINE == KGE_RENDER_ENGINE_DIRECTX
25 #include <kiwano/render/DirectX/D2DDeviceResources.h>
26 #endif
27 
28 namespace kiwano
29 {
30 
31 KGE_DECLARE_SMART_PTR(NativeObject);
32 
42 class KGE_API NativeObjectBase : public ObjectBase
43 {
44 public:
46 
47  bool IsValid() const override;
48 
49  void* GetNativePointer() const;
50 
51  template <typename _NativeTy>
52  _NativeTy* GetNativePointer() const;
53 
54  virtual void ResetNativePointer(void* native_pointer = nullptr);
55 
56 protected:
57  void* native_pointer_;
58 };
59 
60 #if defined(KGE_PLATFORM_WINDOWS)
61 
62 class KGE_API NativeObject : public NativeObjectBase
63 {
64 public:
65  virtual ~NativeObject();
66 
67  void ResetNativePointer(void* native_pointer = nullptr) override;
68 };
69 
70 #else
71 
72 typedef NativeObjectBase NativeObject;
73 
74 #endif
75 
78 inline void* NativeObjectBase::GetNativePointer() const
79 {
80  return native_pointer_;
81 }
82 
83 template <typename _NativeTy>
84 inline _NativeTy* NativeObjectBase::GetNativePointer() const
85 {
86  if (native_pointer_ != nullptr)
87  {
88  return static_cast<_NativeTy*>(native_pointer_);
89  }
90  return nullptr;
91 }
92 
93 } // namespace kiwano
含有本地指针的对象
Definition: NativeObject.h:42
Definition: Actor.cpp:26
基础对象
Definition: ObjectBase.h:134