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 10 namespace fxcrt { 11 12 template <typename T> 13 class AutoNuller { 14 public: 15 FX_STACK_ALLOCATED(); 16 AutoNuller(T * location)17 explicit AutoNuller(T* location) : m_Location(location) {} ~AutoNuller()18 ~AutoNuller() { 19 if (m_Location) 20 *m_Location = nullptr; 21 } AbandonNullification()22 void AbandonNullification() { m_Location = nullptr; } 23 24 private: 25 T* m_Location; 26 }; 27 28 } // namespace fxcrt 29 30 using fxcrt::AutoNuller; 31 32 #endif // CORE_FXCRT_AUTONULLER_H_ 33