1 /*
2  * This file is part of d-dazzle.
3  *
4  * d-dazzle is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * d-dazzle is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with d-dazzle; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 module dazzle.CounterArena;
20 
21 private import dazzle.Counter;
22 private import dazzle.c.functions;
23 public  import dazzle.c.types;
24 private import glib.ConstructionException;
25 private import gobject.ObjectG;
26 private import gtkd.Loader;
27 
28 
29 /** */
30 public class CounterArena
31 {
32 	/** the main Gtk struct */
33 	protected DzlCounterArena* dzlCounterArena;
34 	protected bool ownedRef;
35 
36 	/** Get the main Gtk struct */
37 	public DzlCounterArena* getCounterArenaStruct(bool transferOwnership = false)
38 	{
39 		if (transferOwnership)
40 			ownedRef = false;
41 		return dzlCounterArena;
42 	}
43 
44 	/** the main Gtk struct as a void* */
45 	protected void* getStruct()
46 	{
47 		return cast(void*)dzlCounterArena;
48 	}
49 
50 	/**
51 	 * Sets our main struct and passes it to the parent class.
52 	 */
53 	public this (DzlCounterArena* dzlCounterArena, bool ownedRef = false)
54 	{
55 		this.dzlCounterArena = dzlCounterArena;
56 		this.ownedRef = ownedRef;
57 	}
58 
59 	~this ()
60 	{
61 		if ( Linker.isLoaded(LIBRARY_DAZZLE) && ownedRef )
62 			dzl_counter_arena_unref(dzlCounterArena);
63 	}
64 
65 
66 	/** */
67 	public static GType getType()
68 	{
69 		return dzl_counter_arena_get_type();
70 	}
71 
72 	/** */
73 	public this(GPid pid)
74 	{
75 		auto p = dzl_counter_arena_new_for_pid(pid);
76 
77 		if(p is null)
78 		{
79 			throw new ConstructionException("null returned by new_for_pid");
80 		}
81 
82 		this(cast(DzlCounterArena*) p);
83 	}
84 
85 	alias foreac = foreach_;
86 	/**
87 	 * Calls @func for every counter found in @area.
88 	 *
89 	 * Params:
90 	 *     func = A callback to execute
91 	 *     userData = user data for @func
92 	 */
93 	public void foreach_(DzlCounterForeachFunc func, void* userData)
94 	{
95 		dzl_counter_arena_foreach(dzlCounterArena, func, userData);
96 	}
97 
98 	alias doref = ref_;
99 	/** */
100 	public CounterArena ref_()
101 	{
102 		auto p = dzl_counter_arena_ref(dzlCounterArena);
103 
104 		if(p is null)
105 		{
106 			return null;
107 		}
108 
109 		return ObjectG.getDObject!(CounterArena)(cast(DzlCounterArena*) p, true);
110 	}
111 
112 	/** */
113 	public void register(Counter counter)
114 	{
115 		dzl_counter_arena_register(dzlCounterArena, (counter is null) ? null : counter.getCounterStruct());
116 	}
117 
118 	/** */
119 	public void unref()
120 	{
121 		dzl_counter_arena_unref(dzlCounterArena);
122 	}
123 
124 	/** */
125 	public static CounterArena getDefault()
126 	{
127 		auto p = dzl_counter_arena_get_default();
128 
129 		if(p is null)
130 		{
131 			return null;
132 		}
133 
134 		return ObjectG.getDObject!(CounterArena)(cast(DzlCounterArena*) p, true);
135 	}
136 }