Eric Caruso | 5a9aa6e | 2020-07-01 11:45:11 -0700 | [diff] [blame] | 1 | // Copyright 2020 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | // RAII wrappers for GLib types. |
| 6 | |
| 7 | #ifndef GLIB_BRIDGE_GLIB_SCOPERS_H_ |
| 8 | #define GLIB_BRIDGE_GLIB_SCOPERS_H_ |
| 9 | |
| 10 | #include <glib.h> |
| 11 | |
| 12 | #include <memory> |
| 13 | |
| 14 | namespace glib_bridge { |
| 15 | |
| 16 | template <typename T> |
| 17 | struct GObjectUnref { |
| 18 | void operator()(T* obj) { |
| 19 | if (obj) |
| 20 | g_object_unref(obj); |
| 21 | } |
| 22 | }; |
| 23 | |
| 24 | template <typename T> |
| 25 | using ScopedGObject = std::unique_ptr<T, GObjectUnref<T>>; |
| 26 | |
| 27 | } // namespace glib_bridge |
| 28 | |
| 29 | #endif // GLIB_BRIDGE_GLIB_SCOPERS_H_ |