1 /* Copyright (C) 2008 Bradley Smith <brad@brad-smith.co.uk> 2 * 3 * This file is part of GNU Robots. 4 * 5 * GNU Robots is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * GNU Robots 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 General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with GNU Robots. If not, see <http://www.gnu.org/licenses/>. 17 */ 18 19 #ifndef __MAP_H__ 20 #define __MAP_H__ 21 22 #include <glib-object.h> 23 #include <glib.h> 24 25 G_BEGIN_DECLS 26 27 #define G_TYPE_MAP map_get_type() 28 #define G_IS_MAP(obj) G_TYPE_CHECK_INSTANCE_TYPE((obj), \ 29 G_TYPE_MAP) 30 #define G_IS_MAP_CLASS(klass) G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_MAP) 31 #define MAP_GET_CLASS(obj) G_TYPE_INSTANCE_GET_CLASS((obj), \ 32 G_TYPE_MAP, MapClass) 33 #define MAP(obj) G_TYPE_CHECK_INSTANCE_CAST((obj), \ 34 G_TYPE_MAP, Map) 35 #define MAP_CLASS(klass) G_TYPE_CHECK_CLASS_CAST((klass), \ 36 G_TYPE_MAP, MapClass) 37 38 typedef struct 39 { 40 gint num_rows; 41 gint num_cols; 42 } MapSize; 43 44 typedef struct _Map Map; 45 typedef struct _MapClass MapClass; 46 47 struct _Map { 48 GObject object; 49 50 /* The actual Map */ 51 gint **_map; 52 MapSize size; 53 54 gint errors; 55 }; 56 57 struct _MapClass { 58 GObjectClass parent_class; 59 }; 60 61 /* some convenient macros */ 62 #define MAP_GET_OBJECT(map, x, y) ((map)->_map[(y)][(x)]) 63 #define MAP_SET_OBJECT(map, x, y, thing) ((map)->_map[(y)][(x)] = thing) 64 65 /* normal GObject stuff */ 66 GType map_get_type(void); 67 68 /* Our object functions */ 69 Map* map_new_from_file(const gchar *map, gint num_rows, gint num_cols); 70 71 G_END_DECLS 72 73 #endif /* __MAP_H__ */ 74