]> Pileus Git - grits/blob - src/objects/gis-object.h
4055d877cbd97a966aa86820d0114257766049c4
[grits] / src / objects / gis-object.h
1 /*
2  * Copyright (C) 2009-2010 Andy Spencer <andy753421@gmail.com>
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 #ifndef __GIS_OBJECT_H__
19 #define __GIS_OBJECT_H__
20
21 #include <glib.h>
22 #include <glib-object.h>
23
24 /* Take that GLib boilerplate! */
25 #define GOBJECT_HEAD( \
26                 MAM, BAR, \
27                 Mam, Bar, \
28                 mam, bar) \
29 GType mam##_##bar##_get_type(void); \
30 typedef struct _##Mam##Bar Mam##Bar; \
31 typedef struct _##Mam##Bar##Class Mam##Bar##Class; \
32 static inline Mam##Bar *MAM##_##BAR(gpointer obj) { \
33         return G_TYPE_CHECK_INSTANCE_CAST(obj, MAM##_TYPE_##BAR, Mam##Bar); \
34 } \
35 static inline gboolean MAM##_IS_##BAR(gpointer obj) { \
36         return G_TYPE_CHECK_INSTANCE_TYPE(obj, MAM##_TYPE_##BAR); \
37 } \
38 static inline Mam##Bar##Class *MAM##_##BAR##_CLASS(gpointer klass) { \
39         return G_TYPE_CHECK_CLASS_CAST(klass, MAM##_TYPE_##BAR, Mam##Bar##Class); \
40 } \
41 static inline gboolean MAM##_IS_##BAR##_CLASS(gpointer klass) { \
42         return G_TYPE_CHECK_CLASS_TYPE(klass, MAM##_TYPE_##BAR); \
43 } \
44 static inline Mam##Bar##Class *MAM##_##BAR##_GET_CLASS(gpointer obj) { \
45         return G_TYPE_INSTANCE_GET_CLASS(obj, MAM##_TYPE_##BAR, Mam##Bar##Class); \
46 }
47
48 #define GOBJECT_BODY( \
49                 parent_type, \
50                 MAM, BAR, \
51                 Mam, Bar, \
52                 mam, bar) \
53 G_DEFINE_TYPE(Mam##Bar, mam##_##bar, parent_type); \
54 static void mam##_##bar##_init(Mam##Bar *mambar) { \
55 } \
56 static void mam##_##bar##_class_init(Mam##Bar##Class *klass) { \
57 } \
58 static Mam##Bar *mam##_##bar##_new() { \
59         return g_object_new(MAM##_TYPE_##BAR, NULL); \
60 }
61
62
63 /* GisPoint */
64 typedef struct _GisPoint GisPoint;
65
66 struct _GisPoint {
67         gdouble lat, lon, elev;
68 };
69
70 GisPoint *gis_point_new();
71 void gis_point_set_lle(GisPoint *point, gdouble lat, gdouble lon, gdouble elev);
72 void gis_point_free(GisPoint *point);
73
74
75 /* GisObject */
76 #define GIS_TYPE_OBJECT (gis_object_get_type())
77
78 GOBJECT_HEAD(
79         GIS, OBJECT,
80         Gis, Object,
81         gis, object);
82
83 struct _GisObject {
84         GObject parent_instance;
85         GisPoint center;
86         gdouble  lod;
87 };
88
89 struct _GisObjectClass {
90         GObjectClass parent_class;
91 };
92
93 static inline GisPoint *gis_object_center(GisObject *object)
94 {
95         return &GIS_OBJECT(object)->center;
96 }
97
98 #endif