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.PatternSpec;
20 
21 private import dazzle.c.functions;
22 public  import dazzle.c.types;
23 private import glib.ConstructionException;
24 private import glib.Str;
25 private import gobject.ObjectG;
26 private import gtkd.Loader;
27 
28 
29 /** */
30 public class PatternSpec
31 {
32 	/** the main Gtk struct */
33 	protected DzlPatternSpec* dzlPatternSpec;
34 	protected bool ownedRef;
35 
36 	/** Get the main Gtk struct */
37 	public DzlPatternSpec* getPatternSpecStruct(bool transferOwnership = false)
38 	{
39 		if (transferOwnership)
40 			ownedRef = false;
41 		return dzlPatternSpec;
42 	}
43 
44 	/** the main Gtk struct as a void* */
45 	protected void* getStruct()
46 	{
47 		return cast(void*)dzlPatternSpec;
48 	}
49 
50 	/**
51 	 * Sets our main struct and passes it to the parent class.
52 	 */
53 	public this (DzlPatternSpec* dzlPatternSpec, bool ownedRef = false)
54 	{
55 		this.dzlPatternSpec = dzlPatternSpec;
56 		this.ownedRef = ownedRef;
57 	}
58 
59 	~this ()
60 	{
61 		if ( Linker.isLoaded(LIBRARY_DAZZLE) && ownedRef )
62 			dzl_pattern_spec_unref(dzlPatternSpec);
63 	}
64 
65 
66 	/** */
67 	public static GType getType()
68 	{
69 		return dzl_pattern_spec_get_type();
70 	}
71 
72 	/** */
73 	public this(string keywords)
74 	{
75 		auto p = dzl_pattern_spec_new(Str.toStringz(keywords));
76 
77 		if(p is null)
78 		{
79 			throw new ConstructionException("null returned by new");
80 		}
81 
82 		this(cast(DzlPatternSpec*) p);
83 	}
84 
85 	/** */
86 	public string getText()
87 	{
88 		return Str.toString(dzl_pattern_spec_get_text(dzlPatternSpec));
89 	}
90 
91 	/** */
92 	public bool match(string haystack)
93 	{
94 		return dzl_pattern_spec_match(dzlPatternSpec, Str.toStringz(haystack)) != 0;
95 	}
96 
97 	alias doref = ref_;
98 	/** */
99 	public PatternSpec ref_()
100 	{
101 		auto p = dzl_pattern_spec_ref(dzlPatternSpec);
102 
103 		if(p is null)
104 		{
105 			return null;
106 		}
107 
108 		return ObjectG.getDObject!(PatternSpec)(cast(DzlPatternSpec*) p, true);
109 	}
110 
111 	/** */
112 	public void unref()
113 	{
114 		dzl_pattern_spec_unref(dzlPatternSpec);
115 	}
116 }