/* * moocpp/gobjectutils.h * * Copyright (C) 2004-2015 by Yevgen Muntyan * * This file is part of medit. medit 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 2.1 of the License, * or (at your option) any later version. * * You should have received a copy of the GNU Lesser General Public * License along with medit. If not, see . */ #pragma once #include #include namespace moo { template inline void init_private(TPriv*& p, T* owner, GType owner_type, Args&& ...args) { p = G_TYPE_INSTANCE_GET_PRIVATE(owner, owner_type, TPriv); new(p) TPriv(std::forward(args)...); } template inline void finalize_private(TPriv*& p) { if (p != nullptr) { p->~TPriv(); p = nullptr; } } template inline T* object_ref(T *obj) { return static_cast(g_object_ref(obj)); } struct class_helper { template static size_t address(X* x) { return reinterpret_cast(reinterpret_cast(x)); } template static void verify_g_object_subclass_alignment() { Sup* x = nullptr; Sub* y = static_cast(x); moo_release_assert(class_helper::address(x) == class_helper::address(y)); } }; } // namespace moo