/*
* Copyright © 2018 Christian Persch
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#pragma once
#include
#include
#include "cxx-utils.hh"
namespace vte {
namespace glib {
template
using RefPtr = vte::FreeablePtr;
template
RefPtr
make_ref(T* obj)
{
if (obj)
g_object_ref(obj);
return RefPtr{obj};
}
template
RefPtr
make_ref_sink(T* obj)
{
if (obj)
g_object_ref_sink(obj);
return RefPtr{obj};
}
template
RefPtr
take_ref(T* obj)
{
return RefPtr{obj};
}
template
RefPtr
acquire_ref(GWeakRef* wr)
{
return take_ref(reinterpret_cast(g_weak_ref_get(wr)));
}
} // namespace glib
namespace base {
template
class Unreffer {
public:
void operator()(T* obj) const
{
if (obj)
obj->unref();
}
};
template
using RefPtr = std::unique_ptr>;
template
RefPtr
make_ref(T* obj)
{
if (obj)
obj->ref();
return RefPtr{obj};
}
template
RefPtr
take_ref(T* obj)
{
return RefPtr{obj};
}
} // namespace base
} // namespace vte