helper-osx.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #ifndef NDN_SECURITY_TPM_HELPER_OSX_HPP
23 #define NDN_SECURITY_TPM_HELPER_OSX_HPP
24 
25 #include "../../common.hpp"
26 
27 #ifndef NDN_CXX_HAVE_OSX_SECURITY
28 #error "This file should not be included ..."
29 #endif
30 
31 #include <CoreFoundation/CoreFoundation.h>
32 #include <Security/Security.h>
33 
34 namespace ndn {
35 namespace security {
36 namespace tpm {
37 
47 template<class T>
49 {
50 public: // Construction/destruction
52  : m_typeRef(nullptr)
53  {
54  }
55 
56  CFReleaser(const T& typeRef)
57  : m_typeRef(typeRef)
58  {
59  }
60 
61  CFReleaser(const CFReleaser& inReleaser)
62  : m_typeRef(nullptr)
63  {
64  retain(inReleaser.m_typeRef);
65  }
66 
67  CFReleaser&
68  operator=(const T& typeRef)
69  {
70  if (typeRef != m_typeRef) {
71  release();
72  m_typeRef = typeRef;
73  }
74  return *this;
75  }
76 
77  CFReleaser&
78  operator=(const CFReleaser& inReleaser)
79  {
80  retain(inReleaser.m_typeRef);
81  return *this;
82  }
83 
85  {
86  release();
87  }
88 
89 public: // Access
90  const T&
91  get() const
92  {
93  return m_typeRef;
94  }
95 
96  T&
97  get()
98  {
99  return m_typeRef;
100  }
101 
102  bool
103  operator==(const std::nullptr_t&)
104  {
105  return m_typeRef == nullptr;
106  }
107 
108  bool
109  operator!=(const std::nullptr_t&)
110  {
111  return m_typeRef != nullptr;
112  }
113 
115  // Miscellaneous //
116 
117  void
118  retain(const T& typeRef)
119  {
120  if (typeRef != nullptr) {
121  CFRetain(typeRef);
122  }
123  release();
124  m_typeRef = typeRef;
125  }
126 
127  void
129  {
130  T typeRef = m_typeRef;
131  m_typeRef = nullptr;
132  retain(typeRef);
133  }
134 
135  void
137  {
138  if (m_typeRef != nullptr) {
139  CFRelease(m_typeRef);
140  m_typeRef = nullptr;
141  }
142  };
143 
144 private:
145  T m_typeRef;
146 };
147 
149 
150 } // namespace tpm
151 } // namespace security
152 } // namespace ndn
153 
154 #endif // NDN_SECURITY_TPM_HELPER_OSX_HPP
bool operator==(const std::nullptr_t &)
Definition: helper-osx.hpp:103
Copyright (c) 2013-2016 Regents of the University of California.
Definition: common.hpp:74
CFReleaser & operator=(const CFReleaser &inReleaser)
Definition: helper-osx.hpp:78
bool operator!=(const std::nullptr_t &)
Definition: helper-osx.hpp:109
void retain(const T &typeRef)
Definition: helper-osx.hpp:118
Helper class to wrap CoreFoundation object pointers.
Definition: helper-osx.hpp:48
CFReleaser & operator=(const T &typeRef)
Definition: helper-osx.hpp:68
CFReleaser< SecKeyRef > KeyRefOsx
Definition: helper-osx.hpp:148
CFReleaser(const CFReleaser &inReleaser)
Definition: helper-osx.hpp:61
CFReleaser(const T &typeRef)
Definition: helper-osx.hpp:56