Ariles
pointer.h
Go to the documentation of this file.
1 /**
2  @file
3  @author Alexander Sherikov
4  @copyright 2018 Alexander Sherikov, Licensed under the Apache License, Version 2.0.
5  (see @ref LICENSE or http://www.apache.org/licenses/LICENSE-2.0)
6 
7  @brief
8 */
9 
10 #pragma once
11 #if __cplusplus >= 201103L
12 
13 # include <memory>
14 
15 namespace ariles
16 {
17  template <class t_Value>
18  class ARILES_VISIBILITY_ATTRIBUTE PointerHandler<std::shared_ptr<t_Value> >
19  {
20  public:
21  typedef std::shared_ptr<t_Value> Pointer;
22  typedef t_Value Value;
23 
24 
25  public:
26  static void allocate(Pointer &ptr)
27  {
28  ptr = std::make_shared<t_Value>();
29  }
30 
31  static void reset(Pointer &ptr)
32  {
33  ptr.reset();
34  }
35 
36  static bool isNull(const Pointer &ptr)
37  {
38  return (NULL == ptr);
39  }
40  };
41 
42 
43  template <class t_Value>
44  class ARILES_VISIBILITY_ATTRIBUTE PointerHandler<std::unique_ptr<t_Value> >
45  {
46  public:
47  typedef std::unique_ptr<t_Value> Pointer;
48  typedef t_Value Value;
49 
50 
51  public:
52  static void allocate(Pointer &ptr)
53  {
54  ptr.reset(new t_Value);
55  }
56 
57  static void reset(Pointer &ptr)
58  {
59  ptr.reset();
60  }
61 
62  static bool isNull(const Pointer &ptr)
63  {
64  return (NULL == ptr);
65  }
66  };
67 } // namespace ariles
68 
69 # define ARILES_POINTER_TYPE std::shared_ptr
71 
72 
73 # define ARILES_POINTER_TYPE std::unique_ptr
75 
76 #endif
class ARILES_VISIBILITY_ATTRIBUTE PointerHandler
Definition: helpers.h:114
#define ARILES_VISIBILITY_ATTRIBUTE
Definition: helpers.h:69
Definition: basic.h:17