1 /* 2 ** Copyright 2012-2013 Centreon 3 ** 4 ** Licensed under the Apache License, Version 2.0 (the "License"); 5 ** you may not use this file except in compliance with the License. 6 ** You may obtain a copy of the License at 7 ** 8 ** http://www.apache.org/licenses/LICENSE-2.0 9 ** 10 ** Unless required by applicable law or agreed to in writing, software 11 ** distributed under the License is distributed on an "AS IS" BASIS, 12 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 ** See the License for the specific language governing permissions and 14 ** limitations under the License. 15 ** 16 ** For more information : contact@centreon.com 17 */ 18 19 #ifndef CC_DELAYED_DELETE_HH 20 #define CC_DELAYED_DELETE_HH 21 22 #include <cstddef> 23 #include "com/centreon/namespace.hh" 24 25 CC_BEGIN() 26 27 /** 28 * @class delayed_delete delayed_delete.hh "com/centreon/delayed_delete.hh" 29 * @brief Perform a delayed delete. 30 * 31 * This template is used to perfom delayed object deletion using a task 32 * manager. The pointer will be deleted when the run() method is 33 * called. If the run() method has not been called when delayed_delete 34 * is destroyed, the pointer won't be deleted. 35 * 36 * @see task_manager 37 */ 38 template <typename T> 39 class delayed_delete : public task { 40 T* _ptr; 41 /** 42 * Copy internal data members. 43 * 44 * @param[in] dd Object to copy. 45 */ _internal_copy(delayed_delete const & dd)46 void _internal_copy(delayed_delete const& dd) { _ptr = dd._ptr; } 47 48 public: 49 /** 50 * Default constructor. 51 * 52 * @param[in] ptr Pointer to delete. 53 */ delayed_delete(T * ptr)54 delayed_delete(T* ptr) : _ptr(ptr) {} 55 56 /** 57 * Destructor. 58 */ ~delayed_delete()59 ~delayed_delete() noexcept {} 60 61 /** 62 * Copy constructor. 63 * 64 * @param[in] dd Object to copy. 65 */ 66 delayed_delete(delayed_delete const& dd) = delete; 67 68 delayed_delete& operator=(delayed_delete const& dd) = delete; 69 70 /** 71 * Delete pointer. 72 */ run()73 void run() { 74 delete _ptr; 75 _ptr = nullptr; 76 } 77 }; 78 79 CC_END() 80 81 #endif // !CC_DELAYED_DELETE_HH 82