Leviathan  0.8.0.0
Leviathan game engine
ScriptCallingHelpers.h
Go to the documentation of this file.
1 // Leviathan Game Engine
2 // Copyright (c) 2012-2018 Henri Hyyryläinen
3 #pragma once
4 // ------------------------------------ //
6 
7 #include "angelscript.h"
8 
9 #include <type_traits>
10 
11 namespace Leviathan {
12 
14 template<class T>
15 static inline constexpr bool IsTypeReferenceCounted()
16 {
17  using CheckType = std::remove_pointer_t<std::remove_cv_t<T>>;
18  return std::is_base_of_v<ReferenceCounted, CheckType> ||
19  std::is_same_v<asIScriptFunction, CheckType> ||
20  std::is_same_v<asIScriptObject, CheckType>;
21 }
22 
25 template<class T>
26 static inline void IncrementRefCountIfRefCountedType(T* current)
27 {
28  if constexpr(IsTypeReferenceCounted<T>()) {
29  if(current)
30  current->AddRef();
31  }
32 }
33 
36 template<class T>
37 static inline void DecrementRefCountIfRefCountedType(T* current)
38 {
39  if constexpr(IsTypeReferenceCounted<T>()) {
40  if(current)
41  current->Release();
42  }
43 }
44 
47 template<class T>
48 static inline constexpr bool CanTypeRepresentAngelScriptTypes()
49 {
50  using CheckType = std::remove_pointer_t<std::remove_cv_t<T>>;
51  return std::is_same_v<asIScriptFunction, CheckType> ||
52  std::is_same_v<asIScriptObject, CheckType>;
53 }
54 
55 
56 } // namespace Leviathan
static constexpr bool IsTypeReferenceCounted()
Returns true of object type is reference counted.
static constexpr bool CanTypeRepresentAngelScriptTypes()
Returns true if type is an angelscript type that can represent different types of objects.
static void DecrementRefCountIfRefCountedType(T *current)
Increments refcount of obj if it is derived from ReferenceCounted or an angelscript type.
The access mask controls which registered functions and classes a script sees.
Definition: GameModule.h:12
static void IncrementRefCountIfRefCountedType(T *current)
Increments refcount of obj if it is derived from ReferenceCounted or an angelscript type.