add new sigc++2 directory
[ardour.git] / libs / glibmm2 / glib / glibmm / interface.cc
1 // -*- c++ -*-
2 /* $Id: interface.cc 209 2005-03-07 15:42:20Z murrayc $ */
3
4 /* Copyright (C) 2002 The gtkmm Development Team
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free
18  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  */
20
21 #include <glibmm/interface.h>
22 #include <glibmm/private/interface_p.h>
23
24
25 namespace Glib
26 {
27
28 /**** Glib::Interface_Class ************************************************/
29
30 void Interface_Class::add_interface(GType instance_type) const
31 {
32   //This check is distabled, because it checks whether any of the types's bases implement the interface, not just the specific type.
33   //if( !g_type_is_a(instance_type, gtype_) ) //For convenience, don't complain about calling this twice.
34   //{
35     const GInterfaceInfo interface_info =
36     {
37       class_init_func_,
38       0, // interface_finalize
39       0, // interface_data
40     };
41
42     g_type_add_interface_static(instance_type, gtype_, &interface_info);
43   //}
44 }
45
46
47 /**** Interface Glib::Interface ********************************************/
48
49 Interface::Interface(const Interface_Class& interface_class)
50 {
51   //gobject_ will be set in the Object constructor.
52   //Any instantiable class that derives from Interface should also inherit from Object.
53
54   // If I understand it correctly, gobject_ shouldn't be 0 now.  daniel.
55   // TODO: Make this a g_assert() if the assumption above is correct.
56
57   g_return_if_fail(gobject_ != 0);
58
59   if(custom_type_name_ && !is_anonymous_custom_())
60   {
61     void *const instance_class = G_OBJECT_GET_CLASS(gobject_);
62
63     if(!g_type_interface_peek(instance_class, interface_class.get_type()))
64     {
65       interface_class.add_interface(G_OBJECT_CLASS_TYPE(instance_class));
66     }
67   }
68 }
69
70 Interface::Interface(GObject* castitem)
71 {
72   // Connect GObject and wrapper instances.
73   ObjectBase::initialize(castitem);
74 }
75
76 Interface::~Interface()
77 {}
78
79 GType Interface::get_type()
80 {
81   return G_TYPE_INTERFACE;
82 }
83
84 GType Interface::get_base_type()
85 {
86   return G_TYPE_INTERFACE;
87 }
88
89 RefPtr<ObjectBase> wrap_interface(GObject* object, bool take_copy)
90 {
91   return Glib::RefPtr<ObjectBase>( wrap_auto(object, take_copy) );
92 }
93
94 } // namespace Glib
95