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 
12 #if __cplusplus >= 201103L
13 
14 # include <memory>
15 # include "../internal/helpers.h"
16 
17 
18 namespace ariles2
19 {
20  template <class t_Value>
21  class ARILES2_VISIBILITY_ATTRIBUTE PointerHandler<std::shared_ptr<t_Value> >
22  {
23  public:
24  typedef std::shared_ptr<t_Value> Pointer;
25  typedef t_Value Value;
26 
27 
28  public:
29  static void allocate(Pointer &ptr)
30  {
31  ptr = std::make_shared<t_Value>();
32  }
33 
34  static void reset(Pointer &ptr)
35  {
36  ptr.reset();
37  }
38 
39  static bool isNull(const Pointer &ptr)
40  {
41  return (NULL == ptr);
42  }
43  };
44 
45 
46  template <class t_Value>
47  class ARILES2_VISIBILITY_ATTRIBUTE PointerHandler<std::unique_ptr<t_Value> >
48  {
49  public:
50  typedef std::unique_ptr<t_Value> Pointer;
51  typedef t_Value Value;
52 
53 
54  public:
55  static void allocate(Pointer &ptr)
56  {
57  ptr.reset(new t_Value);
58  }
59 
60  static void reset(Pointer &ptr)
61  {
62  ptr.reset();
63  }
64 
65  static bool isNull(const Pointer &ptr)
66  {
67  return (NULL == ptr);
68  }
69  };
70 } // namespace ariles2
71 
72 # define ARILES2_POINTER_TYPE std::shared_ptr
74 
75 
76 # define ARILES2_POINTER_TYPE std::unique_ptr
78 
79 #endif
ariles2
Definition: basic.h:16
ariles2::PointerHandler
class ARILES2_VISIBILITY_ATTRIBUTE PointerHandler
Definition: helpers.h:150
ARILES2_VISIBILITY_ATTRIBUTE
#define ARILES2_VISIBILITY_ATTRIBUTE
Definition: helpers.h:138
generic_pointer.h