aboutsummaryrefslogtreecommitdiffstats
path: root/src/cert/cvc/freestore.h
blob: 3049dbd13bd2b89b0dac875bf072a04758e57d9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
* (C) 2007 Christoph Ludwig
*
* Distributed under the terms of the Botan license
*/

#ifndef BOTAN_FREESTORE_H__
#define BOTAN_FREESTORE_H__

#include <botan/build.h>
#include <memory>

namespace Botan {

/**
* This class is intended as an function call parameter type and
* enables convenient automatic conversions between plain and smart
* pointer types. It internally stores a SharedPointer which can be
* accessed.
*/
template<typename T>
class BOTAN_DLL SharedPtrConverter
   {
   public:
      typedef std::shared_ptr<T> SharedPtr;

      /**
      * Construct a null pointer equivalent object.
      */
      SharedPtrConverter() : ptr() {}

      /**
      * Copy constructor.
      */
      SharedPtrConverter(SharedPtrConverter const& other) :
         ptr(other.ptr) {}

      /**
      * Construct a converter object from another pointer type.
      * @param p the pointer which shall be set as the internally stored
      * pointer value of this converter.
      */
      template<typename Ptr>
      SharedPtrConverter(Ptr p)
         : ptr(p) {}

      /**
      * Get the internally stored shared pointer.
      * @return the internally stored shared pointer
      */
      SharedPtr const& get_ptr() const { return this->ptr; }

      /**
      * Get the internally stored shared pointer.
      * @return the internally stored shared pointer
      */
      SharedPtr get_ptr() { return this->ptr; }

      /**
      * Get the internally stored shared pointer.
      * @return the internally stored shared pointer
      */
      SharedPtr const& get_shared() const { return this->ptr; }

      /**
      * Get the internally stored shared pointer.
      * @return the internally stored shared pointer
      */
      SharedPtr get_shared() { return this->ptr; }

   private:
      SharedPtr ptr;
   };

}

#endif