Line data Source code
1 : /*! 2 : * \file esys/repo/libgit2/guards.h 3 : * \brief 4 : * 5 : * \cond 6 : * __legal_b__ 7 : * 8 : * Copyright (c) 2021 Michel Gillet 9 : * Distributed under the MIT License. 10 : * (See accompanying file LICENSE.txt or 11 : * copy at https://opensource.org/licenses/MIT) 12 : * 13 : * __legal_e__ 14 : * \endcond 15 : * 16 : */ 17 : 18 : #pragma once 19 : 20 : #include "esys/repo/esysrepo_defs.h" 21 : #include "esys/repo/libgit2/guardsrelease.h" 22 : 23 : namespace esys 24 : { 25 : 26 : namespace repo 27 : { 28 : 29 : namespace libgit2 30 : { 31 : 32 : template<typename T> 33 : class GuardS 34 : { 35 : public: 36 : GuardS(); 37 : ~GuardS(); 38 : 39 : const T *get() const; 40 : T *get(); 41 : 42 : protected: 43 : T m_data = {0}; 44 : }; 45 : 46 : template<typename T> 47 64 : GuardS<T>::GuardS() 48 : { 49 : } 50 : 51 : template<typename T> 52 64 : GuardS<T>::~GuardS() 53 : { 54 64 : guards_release<T>(&m_data); 55 64 : } 56 : 57 : template<typename T> 58 : const T *GuardS<T>::get() const 59 : { 60 : return &m_data; 61 : } 62 : 63 : template<typename T> 64 64 : T *GuardS<T>::get() 65 : { 66 : return &m_data; 67 : } 68 : 69 : } // namespace libgit2 70 : 71 : } // namespace repo 72 : 73 : } // namespace esys