Rumba C++ SDK
Ptr.h
Go to the documentation of this file.
1 /*
2 
3  *
4  ***
5  *****
6  ********************* Mercenaries Engineering SARL
7  ***************** Copyright (C) 2018
8  *************
9  ********* http://www.mercenaries-engineering.com
10  ***********
11  **** ****
12  ** **
13 
14 */
15 #pragma once
16 
17 #include <assert.h>
18 #include <memory>
19 
20 namespace maquina
21 {
22 
23 template<class T>
24 using Ptr = std::shared_ptr<T>;
25 
26 #ifdef NDEBUG
27 
28 // Fast alternative, no check
29 template<class To, class From>
30 inline Ptr<To> static_assert_cast(const Ptr<From>& p)
31 {
32  return std::static_pointer_cast<To>(p);
33 }
34 
35 #else
36 
37 // Safe alternative, checks
38 template<class To, class From>
40 {
41  if(p == nullptr)
42  return nullptr;
43  Ptr<To> _p = std::dynamic_pointer_cast<To>(p);
44  assert(_p);
45  return std::move(_p);
46 }
47 
48 #endif
49 
50 }
std::shared_ptr< T > Ptr
Definition: Ptr.h:24
This version of the SDK is unstable, i-e, it may change with no warning.
Definition: AddCurveAction.h:20
Ptr< To > static_assert_cast(const Ptr< From > &p)
Definition: Ptr.h:39