File: f-utils.h

package info (click to toggle)
f-spot 0.6.2-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 21,784 kB
  • ctags: 16,078
  • sloc: cs: 108,718; sh: 17,053; xml: 13,852; ansic: 3,187; makefile: 2,324
file content (123 lines) | stat: -rw-r--r-- 3,538 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* f-utils.h
 *
 * Copyright (C) 2003  Ettore Perazzoli
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program 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
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * Author: Ettore Perazzoli <ettore@ximian.com>
 */

#ifndef F_UTILS_H
#define F_UTILS_H

#include <gdk-pixbuf/gdk-pixbuf.h>
#include <math.h>


#define F_MAKE_TYPE(name, underscore_name)							\
	GType											\
	underscore_name##_get_type (void)							\
	{											\
		static GType type = 0;								\
												\
		if (type == 0) {								\
			static const GTypeInfo info = {						\
				sizeof (name##Class),						\
				(GBaseInitFunc) NULL,						\
				(GBaseFinalizeFunc) NULL,					\
				(GClassInitFunc) class_init,					\
				NULL,           /* class_finalize */				\
				NULL,           /* class_data */				\
				sizeof (name),							\
				0,               /* n_preallocs */				\
				(GInstanceInitFunc) init,					\
			};									\
												\
			type = g_type_register_static (PARENT_TYPE, #name, &info, 0);		\
		}										\
												\
		return type;									\
	}
	
#define F_MAKE_TYPE_WITH_ERROR(name, underscore_name)						\
	F_MAKE_TYPE (name, underscore_name)							\
	GQuark											\
	underscore_name##_error_quark (void)							\
	{											\
		static GQuark q = 0;								\
												\
		if (q == 0)									\
			q = g_quark_from_static_string (#underscore_name "_error_quark");	\
												\
		return q;									\
	}


/* Refcounting macros.  Note that some of these evaluates OBJ multiple times,
   which is not ideal...  So you want to pass only variables (not functions) to
   them.  */

#define F_UNREF(obj)				\
	G_STMT_START {				\
		if ((obj) != NULL) {		\
			g_object_unref (obj);	\
			(obj) = NULL;		\
		} 				\
	} G_STMT_END

#define F_REF(obj)					\
	((obj) != NULL ? (g_object_ref (obj), (obj))	\
		       : NULL)

#define F_ASSIGN(dest, src)			\
	G_STMT_START {				\
		F_UNREF(dest);			\
		(dest) = F_REF(src);		\
	} G_STMT_END

#define F_WEAK_NULL(dest)									\
	G_STMT_START {										\
		if ((dest) != NULL) {								\
			g_object_remove_weak_pointer (G_OBJECT (dest), (void **) & (dest));	\
			(dest) = NULL;								\
		}										\
	} G_STMT_END

#define F_WEAK_ASSIGN(dest, src)								\
	G_STMT_START {										\
		F_WEAK_NULL(dest);								\
		if ((src) != NULL) {								\
			(dest) = (src);								\
			g_object_add_weak_pointer (G_OBJECT (dest), (void **) & (dest));	\
		}										\
	} G_STMT_END

#define F_BOOLEAN_MEMBER(name)				\
	unsigned int name : 1

#define F_LIST_FOREACH(list, iterator) 		\
	for ((iterator) = (list); (iterator) != NULL; (iterator) = (iterator)->next)

#define F_DOUBLE_EQUAL(a, b)			\
	(fabs (a - b) < 1e-6)


/* Build a relative path from START_PATH to DESTINATION_PATH.  */
char *f_build_relative_path (const char *start_path,
			     const char *destination_path);

#endif /* F_UTILS_H */