blob: e476ee2464a5d2214546e9f05932e64b64f99111 [file] [log] [blame]
Eric Caruso5a9aa6e2020-07-01 11:45:11 -07001// 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
14namespace glib_bridge {
15
16template <typename T>
17struct GObjectUnref {
18 void operator()(T* obj) {
19 if (obj)
20 g_object_unref(obj);
21 }
22};
23
24template <typename T>
25using ScopedGObject = std::unique_ptr<T, GObjectUnref<T>>;
26
27} // namespace glib_bridge
28
29#endif // GLIB_BRIDGE_GLIB_SCOPERS_H_