1 // Copyright 2020 The PDFium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CORE_FXCRT_AUTONULLER_H_ 6 #define CORE_FXCRT_AUTONULLER_H_ 7 8 #include "core/fxcrt/fx_memory.h" 9 #include "core/fxcrt/unowned_ptr.h" 10 11 namespace fxcrt { 12 13 template <typename T> 14 class AutoNuller { 15 public: 16 FX_STACK_ALLOCATED(); 17 AutoNuller(T * location)18 explicit AutoNuller(T* location) : m_Location(location) {} ~AutoNuller()19 ~AutoNuller() { 20 if (m_Location) 21 *m_Location = nullptr; 22 } AbandonNullification()23 void AbandonNullification() { m_Location = nullptr; } 24 25 private: 26 UnownedPtr<T> m_Location; 27 }; 28 29 } // namespace fxcrt 30 31 using fxcrt::AutoNuller; 32 33 #endif // CORE_FXCRT_AUTONULLER_H_ 34