simpler-tiles 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. data/.gitignore +17 -0
  2. data/Gemfile +2 -0
  3. data/LICENSE +19 -0
  4. data/README +22 -0
  5. data/Rakefile +71 -0
  6. data/doc/SimplerTiles/Bounds.html +506 -0
  7. data/doc/SimplerTiles/Layer.html +593 -0
  8. data/doc/SimplerTiles/Map.html +2081 -0
  9. data/doc/SimplerTiles/PP.html +204 -0
  10. data/doc/SimplerTiles/Query.html +521 -0
  11. data/doc/SimplerTiles/Style.html +577 -0
  12. data/doc/SimplerTiles.html +167 -0
  13. data/doc/_index.html +188 -0
  14. data/doc/class_list.html +47 -0
  15. data/doc/css/common.css +1 -0
  16. data/doc/css/full_list.css +55 -0
  17. data/doc/css/style.css +322 -0
  18. data/doc/file.README.html +89 -0
  19. data/doc/file_list.html +49 -0
  20. data/doc/frames.html +13 -0
  21. data/doc/index.html +89 -0
  22. data/doc/js/app.js +205 -0
  23. data/doc/js/full_list.js +173 -0
  24. data/doc/js/jquery.js +16 -0
  25. data/doc/method_list.html +390 -0
  26. data/doc/top-level-namespace.html +105 -0
  27. data/ext/simpler_tiles/bounds.c +90 -0
  28. data/ext/simpler_tiles/bounds.h +17 -0
  29. data/ext/simpler_tiles/depend +7 -0
  30. data/ext/simpler_tiles/extconf.rb +42 -0
  31. data/ext/simpler_tiles/layer.c +93 -0
  32. data/ext/simpler_tiles/layer.h +16 -0
  33. data/ext/simpler_tiles/map.c +338 -0
  34. data/ext/simpler_tiles/map.h +17 -0
  35. data/ext/simpler_tiles/query.c +87 -0
  36. data/ext/simpler_tiles/query.h +17 -0
  37. data/ext/simpler_tiles/simpler_tiles.c +16 -0
  38. data/ext/simpler_tiles/simpler_tiles.h +25 -0
  39. data/ext/simpler_tiles/style.c +106 -0
  40. data/ext/simpler_tiles/style.h +17 -0
  41. data/index.erb +459 -0
  42. data/index.html +439 -0
  43. data/lib/simpler_tiles/bounds.rb +19 -0
  44. data/lib/simpler_tiles/layer.rb +25 -0
  45. data/lib/simpler_tiles/map.rb +55 -0
  46. data/lib/simpler_tiles/mixins/pp.rb +13 -0
  47. data/lib/simpler_tiles/query.rb +28 -0
  48. data/lib/simpler_tiles/style.rb +19 -0
  49. data/lib/simpler_tiles/version.rb +4 -0
  50. data/lib/simpler_tiles.rb +13 -0
  51. data/simpler-tiles-logo.png +0 -0
  52. data/simpler-tiles.gemspec +30 -0
  53. data/test/helper.rb +8 -0
  54. data/test/test_map.rb +67 -0
  55. data/test/test_simpler_tiles.rb +26 -0
  56. metadata +199 -0
@@ -0,0 +1,93 @@
1
+ #include "layer.h"
2
+ #include <simple-tiles/layer.h>
3
+ #include <simple-tiles/query.h>
4
+ #include <simple-tiles/list.h>
5
+
6
+ VALUE cSimplerTilesLayer;
7
+
8
+ static simplet_layer_t *
9
+ get_layer(VALUE self){
10
+ simplet_layer_t *layer;
11
+ Data_Get_Struct(self, simplet_layer_t, layer);
12
+ return layer;
13
+ }
14
+
15
+ static void
16
+ mark_layer(void *layer){
17
+ simplet_layer_t *lyr = layer;
18
+ VALUE ref = (VALUE)simplet_layer_get_user_data(lyr);
19
+ if(ref) rb_gc_mark(ref);
20
+ }
21
+
22
+ static void
23
+ layer_free(void *layer){
24
+ simplet_layer_t *lyr = layer;
25
+ // test if we have been linked in ruby land
26
+ VALUE refs = (VALUE)simplet_layer_get_user_data(lyr);
27
+ // if not it is safe to free this layer.
28
+ if(!refs) simplet_layer_free(lyr);
29
+ }
30
+
31
+
32
+ /*
33
+ Set the source attribute for the Layer.
34
+
35
+ @return (String)
36
+ @param (String)
37
+ */
38
+ static VALUE
39
+ set_source(VALUE self, VALUE source){
40
+ Check_Type(source, T_STRING);
41
+ simplet_layer_t *layer = get_layer(self);
42
+ simplet_layer_set_source(layer, RSTRING_PTR(source));
43
+ return source;
44
+ }
45
+
46
+ /*
47
+ Get a copy of the Layer's source.
48
+
49
+ @return (String)
50
+ */
51
+ static VALUE
52
+ get_source(VALUE self) {
53
+ simplet_layer_t *layer = get_layer(self);
54
+ char *source;
55
+ simplet_layer_get_source(layer, &source);
56
+ return rb_str_new2(source);
57
+ }
58
+
59
+ /*
60
+ Add a query object to this Layer's list of queries.
61
+
62
+ @param (String)
63
+ @return (Query)
64
+ */
65
+ static VALUE
66
+ add_query(VALUE self, VALUE query){
67
+ simplet_layer_t *layer = get_layer(self);
68
+ simplet_query_t *qry;
69
+ Data_Get_Struct(query, simplet_query_t, qry);
70
+ simplet_layer_add_query_directly(layer, qry);
71
+ VALUE circ_ref = rb_ary_new3(2, self, query);
72
+ simplet_query_set_user_data(qry, (void *)circ_ref);
73
+ return query;
74
+ }
75
+
76
+ VALUE
77
+ layer_alloc(VALUE klass){
78
+ simplet_layer_t *layer;
79
+ if(!(layer = simplet_layer_new("")))
80
+ rb_fatal("Could not allocate space for a new SimplerTiles::Layer in memory.");
81
+
82
+ return Data_Wrap_Struct(klass, mark_layer, layer_free, layer);
83
+ }
84
+
85
+ void init_layer(){
86
+ VALUE rlayer = rb_define_class_under(mSimplerTiles, "Layer", rb_cObject);
87
+ rb_define_alloc_func(rlayer, layer_alloc);
88
+ rb_define_method(rlayer, "source=", set_source, 1);
89
+ rb_define_method(rlayer, "source", get_source, 0);
90
+ rb_define_private_method(rlayer, "add_query", add_query, 1);
91
+
92
+ cSimplerTilesLayer = rlayer;
93
+ }
@@ -0,0 +1,16 @@
1
+ #ifndef _SIMPLER_LAYER_H
2
+ #define _SIMPLER_LAYER_H
3
+
4
+ #include "simpler_tiles.h"
5
+
6
+ #ifdef __cplusplus
7
+ extern "C" {
8
+ #endif
9
+
10
+ void init_layer();
11
+ extern VALUE cSimplerTilesLayer;
12
+ #ifdef __cplusplus
13
+ }
14
+ #endif
15
+
16
+ #endif
@@ -0,0 +1,338 @@
1
+ #include "map.h"
2
+ #include "util.h"
3
+ #include <simple-tiles/map.h>
4
+ #include <simple-tiles/layer.h>
5
+ #include <simple-tiles/bounds.h>
6
+ #include <simple-tiles/list.h>
7
+
8
+ VALUE cSimplerTilesMap;
9
+
10
+ static simplet_map_t *
11
+ get_map(VALUE self){
12
+ simplet_map_t *map;
13
+ Data_Get_Struct(self, simplet_map_t, map);
14
+ return map;
15
+ }
16
+
17
+ /*
18
+ Set the background color of the map.
19
+
20
+ @param (String)
21
+ @return (nil)
22
+ */
23
+ static VALUE
24
+ set_bgcolor(VALUE self, VALUE bgcolor){
25
+ Check_Type(bgcolor, T_STRING);
26
+ simplet_map_t *map = get_map(self);
27
+ simplet_map_set_bgcolor(map, RSTRING_PTR(bgcolor));
28
+ return Qnil;
29
+ }
30
+
31
+ /*
32
+ Return a copy of the background color of the map.
33
+
34
+ @return (String)
35
+ */
36
+ static VALUE
37
+ get_bgcolor(VALUE self){
38
+ simplet_map_t *map = get_map(self);
39
+ char *color;
40
+ simplet_map_get_bgcolor(map, &color);
41
+ return rb_str_new2(color);
42
+ }
43
+
44
+ /*
45
+ Set the projection from an Proj.4 readable string.
46
+
47
+ @param (String)
48
+ @return (String)
49
+ */
50
+ static VALUE
51
+ set_srs(VALUE self, VALUE srs){
52
+ Check_Type(srs, T_STRING);
53
+ simplet_map_t *map = get_map(self);
54
+ simplet_map_set_srs(map, RSTRING_PTR(srs));
55
+ return Qnil;
56
+ }
57
+
58
+ /*
59
+ Return the projection for the map in string representation.
60
+
61
+ @return (String)
62
+ */
63
+ static VALUE
64
+ get_srs(VALUE self){
65
+ simplet_map_t *map = get_map(self);
66
+ char *srs;
67
+ simplet_map_get_srs(map, &srs);
68
+ return rb_str_new2(srs);
69
+ }
70
+
71
+ /*
72
+ Set the bounds on the map.
73
+
74
+ @param (Number, Number, Number, Number)
75
+ @return (nil)
76
+ */
77
+ static VALUE
78
+ set_bounds(VALUE self, VALUE maxx, VALUE maxy, VALUE minx, VALUE miny){
79
+ simplet_map_t *map = get_map(self);
80
+ simplet_map_set_bounds(map, NUM2DBL(maxx), NUM2DBL(maxy), NUM2DBL(minx), NUM2DBL(miny));
81
+ return Qnil;
82
+ }
83
+
84
+ static VALUE
85
+ new_bounds(simplet_bounds_t *bounds){
86
+ VALUE args[4];
87
+ args[0] = rb_float_new(bounds->nw.x);
88
+ args[1] = rb_float_new(bounds->nw.y);
89
+ args[2] = rb_float_new(bounds->se.x);
90
+ args[3] = rb_float_new(bounds->se.y);
91
+ return rb_funcall2(cSimplerTilesBounds, rb_intern("new"), 4, args);
92
+ }
93
+
94
+ /*
95
+ Return the bounds of this map.
96
+
97
+ @return (Bounds)
98
+ */
99
+ static VALUE
100
+ bounds(VALUE self){
101
+ simplet_map_t *map = get_map(self);
102
+ return new_bounds(map->bounds);
103
+ }
104
+ /*
105
+ Return the bounds of this map sized according to it's buffer attribute.
106
+
107
+ @return (Bounds)
108
+ */
109
+ static VALUE
110
+ buffered_bounds(VALUE self){
111
+ simplet_map_t *map = get_map(self);
112
+ cairo_matrix_t mat;
113
+ simplet_map_init_matrix(map, &mat);
114
+ cairo_matrix_invert(&mat);
115
+
116
+ double dx, dy;
117
+ dx = dy = simplet_map_get_buffer(map);
118
+ cairo_matrix_transform_distance(&mat, &dx, &dy);
119
+
120
+ simplet_bounds_t *bbounds = simplet_bounds_buffer(map->bounds, dx);
121
+ if(!bbounds)
122
+ rb_raise(rb_eRuntimeError, "Could not allocate space for a new SimplerTiles::Bounds in memory.");
123
+
124
+ return new_bounds(bbounds);
125
+ }
126
+
127
+ /*
128
+ Set the size in pixels of the final map.
129
+
130
+ @param (Number, Number)
131
+ @return (nil)
132
+ */
133
+ static VALUE
134
+ set_size(VALUE self, VALUE width, VALUE height){
135
+ simplet_map_t *map = get_map(self);
136
+ simplet_map_set_size(map, NUM2INT(width), NUM2INT(height));
137
+ return Qnil;
138
+ }
139
+
140
+ /*
141
+ Set the buffer on the Map.
142
+
143
+ @param (Number)
144
+ @return (Number)
145
+ */
146
+ static VALUE
147
+ set_buffer(VALUE self, VALUE buffer){
148
+ simplet_map_t *map = get_map(self);
149
+ simplet_map_set_buffer(map, NUM2DBL(buffer));
150
+ return rb_float_new(map->buffer);
151
+ }
152
+
153
+ /*
154
+ Get the Map's buffer.
155
+
156
+ @return (Number)
157
+ */
158
+ static VALUE
159
+ get_buffer(VALUE self){
160
+ simplet_map_t *map = get_map(self);
161
+ return rb_float_new(simplet_map_get_buffer(map));
162
+ }
163
+
164
+
165
+ /*
166
+ Get the width of the map.
167
+
168
+ @return (Number)
169
+ */
170
+ static VALUE
171
+ get_width(VALUE self){
172
+ simplet_map_t *map = get_map(self);
173
+ return INT2NUM(simplet_map_get_width(map));
174
+ }
175
+
176
+ /*
177
+ Get the height of the map.
178
+
179
+ @return (Number)
180
+ */
181
+ static VALUE
182
+ get_height(VALUE self){
183
+ simplet_map_t *map = get_map(self);
184
+ return INT2NUM(simplet_map_get_height(map));
185
+ }
186
+
187
+ /*
188
+ Set the width of the Map.
189
+
190
+ @return (Number)
191
+ */
192
+ static VALUE
193
+ set_width(VALUE self, VALUE width){
194
+ simplet_map_t *map = get_map(self);
195
+ simplet_map_set_width(map, NUM2INT(width));
196
+ return get_width(self);
197
+ }
198
+
199
+ /*
200
+ Set the height of the Map.
201
+
202
+ @return (Number)
203
+ */
204
+ static VALUE
205
+ set_height(VALUE self, VALUE height){
206
+ simplet_map_t *map = get_map(self);
207
+ simplet_map_set_height(map, NUM2INT(height));
208
+ return get_height(self);
209
+ }
210
+
211
+
212
+
213
+ /*
214
+ Create and return a {Layer} based on the passed in string.
215
+
216
+ @param (String)
217
+ @return (Layer)
218
+ */
219
+ static VALUE
220
+ add_layer(VALUE self, VALUE layer){
221
+ simplet_map_t *map = get_map(self);
222
+ simplet_layer_t *lyr;
223
+ Data_Get_Struct(layer, simplet_layer_t, lyr);
224
+ simplet_map_add_layer_directly(map, lyr);
225
+ VALUE circ_ref = rb_ary_new3(2, self, layer);
226
+ simplet_layer_set_user_data(lyr, (void *)circ_ref);
227
+ return layer;
228
+ }
229
+
230
+ /*
231
+ Test to see if the Map has fulfilled the requirements for rendering
232
+
233
+ @return (Boolean)
234
+ */
235
+ static VALUE
236
+ is_valid(VALUE self){
237
+ simplet_map_t *map = get_map(self);
238
+ if(!simplet_map_is_valid(map))
239
+ return Qfalse;
240
+ return Qtrue;
241
+ }
242
+
243
+ /*
244
+ Render the Map to the filesystem.
245
+
246
+ @param (String)
247
+ @return (Boolean)
248
+ */
249
+ static VALUE
250
+ save(VALUE self, VALUE path){
251
+ Check_Type(path, T_STRING);
252
+ if(!is_valid(self)) return Qfalse;
253
+ simplet_map_t *map = get_map(self);
254
+ simplet_map_render_to_png(map, RSTRING_PTR(path));
255
+ if(simplet_map_get_status(map) == SIMPLET_OK) {
256
+ return Qtrue;
257
+ } else {
258
+ rb_raise(rb_eRuntimeError, simplet_map_status_to_string(map));
259
+ return Qfalse;
260
+ }
261
+ }
262
+
263
+
264
+ static cairo_status_t
265
+ stream(void* block, const unsigned char *data, unsigned int length){
266
+ ID call = rb_intern("call");
267
+ VALUE rdata = rb_str_new((const char *)data, (long)length);
268
+ rb_funcall((VALUE)block, call, 1, rdata);
269
+ return CAIRO_STATUS_SUCCESS;
270
+ }
271
+
272
+ /*
273
+ Render the map to a png stream and yield values to the passed in block.
274
+
275
+ @yield [chunk] Block that takes chunks of data
276
+ @return (nil)
277
+ */
278
+ static VALUE
279
+ to_png_stream(VALUE self, VALUE block){
280
+ simplet_map_t *map = get_map(self);
281
+
282
+ simplet_map_render_to_stream(map, (void *)block, stream);
283
+ if(simplet_map_get_status(map) != SIMPLET_OK)
284
+ rb_raise(rb_eRuntimeError, simplet_map_status_to_string(map));
285
+
286
+ return Qnil;
287
+ }
288
+
289
+ /*
290
+ Set the map to be slippy via passed in parameters.
291
+
292
+ @param (Number, Number, Number)
293
+ @return (nil)
294
+ */
295
+ static VALUE
296
+ slippy(VALUE self, VALUE x, VALUE y, VALUE z){
297
+ simplet_map_t *map = get_map(self);
298
+ if(simplet_map_set_slippy(map, NUM2INT(x), NUM2INT(y), NUM2INT(z)) != SIMPLET_OK)
299
+ rb_raise(rb_eRuntimeError, simplet_map_status_to_string(map));
300
+ return Qnil;
301
+ }
302
+
303
+ static VALUE
304
+ map_alloc(VALUE klass){
305
+ simplet_map_t *map;
306
+
307
+ if(!(map = simplet_map_new()))
308
+ rb_fatal("Could not allocate space for a new SimplerTiles::Map in memory.");
309
+
310
+ return Data_Wrap_Struct(klass, NULL, simplet_map_free, map);
311
+ }
312
+
313
+ void
314
+ init_map(){
315
+ VALUE rmap = rb_define_class_under(mSimplerTiles, "Map", rb_cObject);
316
+ rb_define_alloc_func(rmap, map_alloc);
317
+ rb_define_method(rmap, "bgcolor=", set_bgcolor, 1);
318
+ rb_define_method(rmap, "bgcolor", get_bgcolor, 0);
319
+ rb_define_method(rmap, "srs=", set_srs, 1);
320
+ rb_define_method(rmap, "srs", get_srs, 0);
321
+ rb_define_method(rmap, "set_size", set_size, 2);
322
+ rb_define_method(rmap, "width", get_width, 0);
323
+ rb_define_method(rmap, "height", get_height, 0);
324
+ rb_define_method(rmap, "width=", set_width, 1);
325
+ rb_define_method(rmap, "height=", set_height, 1);
326
+ rb_define_method(rmap, "buffer", get_buffer, 0);
327
+ rb_define_method(rmap, "buffer=", set_buffer, 1);
328
+ rb_define_method(rmap, "set_bounds", set_bounds, 4);
329
+ rb_define_method(rmap, "bounds", bounds, 0);
330
+ rb_define_method(rmap, "buffered_bounds", buffered_bounds, 0);
331
+ rb_define_method(rmap, "save", save, 1);
332
+ rb_define_method(rmap, "slippy", slippy, 3);
333
+ rb_define_method(rmap, "valid?", is_valid, 0);
334
+ rb_define_private_method(rmap, "to_png_stream", to_png_stream, 1);
335
+ rb_define_private_method(rmap, "add_layer", add_layer, 1);
336
+
337
+ cSimplerTilesMap = rmap;
338
+ }
@@ -0,0 +1,17 @@
1
+ #ifndef _SIMPLER_MAP_H
2
+ #define _SIMPLER_MAP_H
3
+
4
+ #include "simpler_tiles.h"
5
+
6
+ #ifdef __cplusplus
7
+ extern "C" {
8
+ #endif
9
+
10
+ void init_map();
11
+ extern VALUE cSimplerTilesMap;
12
+
13
+ #ifdef __cplusplus
14
+ }
15
+ #endif
16
+
17
+ #endif
@@ -0,0 +1,87 @@
1
+ #include "query.h"
2
+ #include <simple-tiles/query.h>
3
+ #include <simple-tiles/style.h>
4
+
5
+ VALUE cSimplerTilesQuery;
6
+
7
+ static simplet_query_t *
8
+ get_query(VALUE self){
9
+ simplet_query_t *query;
10
+ Data_Get_Struct(self, simplet_query_t, query);
11
+ return query;
12
+ }
13
+
14
+ static void
15
+ mark_query(void *query){
16
+ simplet_query_t *fltr = query;
17
+ VALUE ref = (VALUE)simplet_query_get_user_data(fltr);
18
+ if(ref) rb_gc_mark(ref);
19
+ }
20
+
21
+
22
+ static void
23
+ query_free(void *query){
24
+ simplet_query_t *fltr = query;
25
+ // test if we have been linked in ruby land
26
+ VALUE refs = (VALUE)simplet_query_get_user_data(fltr);
27
+ // if not it is safe to free this query.
28
+ if(!refs) simplet_query_free(fltr);
29
+ }
30
+
31
+ /*
32
+ Set the OGR SQL for this Query.
33
+
34
+ @return (String)
35
+ */
36
+ static VALUE
37
+ set_sql(VALUE self, VALUE query){
38
+ Check_Type(query, T_STRING);
39
+ simplet_query_t *qry = get_query(self);
40
+ simplet_query_set(qry, RSTRING_PTR(query));
41
+ return query;
42
+ }
43
+
44
+ /*
45
+ Get the OGR SQL for this Query.
46
+
47
+ @return (String)
48
+ */
49
+ static VALUE
50
+ get_sql(VALUE self){
51
+ simplet_query_t *query = get_query(self);
52
+ char *str;
53
+ simplet_query_get(query, &str);
54
+ return rb_str_new2(str);
55
+ }
56
+
57
+ static VALUE
58
+ add_style(VALUE self, VALUE style){
59
+ simplet_query_t *query = get_query(self);
60
+ simplet_style_t *style_s;
61
+ Data_Get_Struct(style, simplet_style_t, style_s);
62
+ simplet_query_add_style_directly(query, style_s);
63
+ VALUE circ_ref = rb_ary_new3(2, self, style);
64
+ simplet_style_set_user_data(style_s, (void *)circ_ref);
65
+ return style;
66
+ }
67
+
68
+ static VALUE
69
+ query_alloc(VALUE klass){
70
+ simplet_query_t *query;
71
+
72
+ if(!(query = simplet_query_new(NULL)))
73
+ rb_fatal("Could not allocate space for a new SimplerTiles::Query in memory.");
74
+
75
+ return Data_Wrap_Struct(klass, mark_query, query_free, query);
76
+ };
77
+
78
+
79
+ void init_query(){
80
+ VALUE rquery = rb_define_class_under(mSimplerTiles, "Query", rb_cObject);
81
+ rb_define_alloc_func(rquery, query_alloc);
82
+ rb_define_method(rquery, "query=", set_sql, 1);
83
+ rb_define_method(rquery, "query", get_sql, 0);
84
+ rb_define_private_method(rquery, "add_style", add_style, 1);
85
+
86
+ cSimplerTilesQuery = rquery;
87
+ }
@@ -0,0 +1,17 @@
1
+ #ifndef _SIMPLER_QUERY_H
2
+ #define _SIMPLER_QUERY_H
3
+
4
+ #include "simpler_tiles.h"
5
+
6
+ #ifdef __cplusplus
7
+ extern "C" {
8
+ #endif
9
+
10
+ void init_query();
11
+ extern VALUE cSimplerTilesQuery;
12
+
13
+ #ifdef __cplusplus
14
+ }
15
+ #endif
16
+
17
+ #endif
@@ -0,0 +1,16 @@
1
+ #include "simpler_tiles.h"
2
+
3
+ VALUE mSimplerTiles;
4
+
5
+ void
6
+ Init_simpler_tiles(){
7
+ mSimplerTiles = rb_define_module("SimplerTiles");
8
+ rb_const_set(mSimplerTiles,
9
+ rb_intern("SIMPLE_TILES_VERSION"),
10
+ rb_str_new2(SIMPLE_TILES_VERSION));
11
+ init_map();
12
+ init_bounds();
13
+ init_layer();
14
+ init_query();
15
+ init_style();
16
+ }
@@ -0,0 +1,25 @@
1
+ #ifndef _SIMPLER_TILES_H
2
+ #define _SIMPLER_TILES_H
3
+
4
+ #include <simple-tiles/simple_tiles.h>
5
+ #include <ruby.h>
6
+
7
+ #include "map.h"
8
+ #include "bounds.h"
9
+ #include "layer.h"
10
+ #include "query.h"
11
+ #include "style.h"
12
+
13
+
14
+
15
+ #ifdef __cplusplus
16
+ extern "C" {
17
+ #endif
18
+
19
+ extern VALUE mSimplerTiles;
20
+
21
+ #ifdef __cplusplus
22
+ }
23
+ #endif
24
+
25
+ #endif
@@ -0,0 +1,106 @@
1
+ #include "style.h"
2
+ #include "util.h"
3
+ #include <simple-tiles/style.h>
4
+
5
+ VALUE cSimplerTilesStyle;
6
+
7
+ static simplet_style_t *
8
+ get_style(VALUE self){
9
+ simplet_style_t *style;
10
+ Data_Get_Struct(self, simplet_style_t, style);
11
+ return style;
12
+ }
13
+
14
+ static void
15
+ mark_style(void *style){
16
+ simplet_style_t *stl = style;
17
+ VALUE refs = (VALUE)simplet_style_get_user_data(stl);
18
+ if(refs) rb_gc_mark(refs);
19
+ }
20
+
21
+ static void
22
+ style_free(void *style){
23
+ simplet_style_t *stl = style;
24
+ // test if we have been linked in ruby land
25
+ VALUE refs = (VALUE)simplet_style_get_user_data(stl);
26
+ // if not it is safe to free this style.
27
+ if(!refs) simplet_style_free(stl);
28
+ }
29
+
30
+ static VALUE
31
+ alloc_style(VALUE klass){
32
+ simplet_style_t *style;
33
+
34
+ if(!(style = simplet_style_new(NULL, NULL)))
35
+ rb_fatal("Could not allocate space for a new SimplerTiles::Style in memory.");
36
+
37
+ return Data_Wrap_Struct(klass, mark_style, style_free, style);
38
+ }
39
+
40
+ /*
41
+ Set the arg for this Style.
42
+
43
+ @param (String)
44
+ @return (String)
45
+ */
46
+ static VALUE
47
+ set_arg(VALUE self, VALUE arg){
48
+ Check_Type(arg, T_STRING);
49
+ simplet_style_t *style = get_style(self);
50
+ simplet_style_set_arg(style, RSTRING_PTR(arg));
51
+ return arg;
52
+ }
53
+
54
+
55
+ /*
56
+ Get the arg for this Style.
57
+
58
+ @return (String)
59
+ */
60
+ static VALUE
61
+ get_arg(VALUE self){
62
+ simplet_style_t *style = get_style(self);
63
+ char *arg;
64
+ simplet_style_get_arg(style, &arg);
65
+ return rb_str_new2(arg);
66
+ }
67
+
68
+ /*
69
+ Set the key for this Style.
70
+
71
+ @param (String)
72
+ @return (String)
73
+ */
74
+ static VALUE
75
+ set_key(VALUE self, VALUE key){
76
+ Check_Type(key, T_STRING);
77
+ simplet_style_t *style = get_style(self);
78
+ simplet_style_set_key(style, RSTRING_PTR(key));
79
+ return key;
80
+ }
81
+
82
+ /*
83
+ Get the key for this Style.
84
+
85
+ @param (String)
86
+ @return (String)
87
+ */
88
+ static VALUE
89
+ get_key(VALUE self){
90
+ simplet_style_t *style = get_style(self);
91
+ char *key;
92
+ simplet_style_get_key(style, &key);
93
+ return rb_str_new2(key);
94
+ }
95
+
96
+ void
97
+ init_style(){
98
+ VALUE rstyle = rb_define_class_under(mSimplerTiles, "Style", rb_cObject);
99
+ rb_define_alloc_func(rstyle, alloc_style);
100
+ rb_define_method(rstyle, "arg=", set_arg, 1);
101
+ rb_define_method(rstyle, "arg", get_arg, 0);
102
+ rb_define_method(rstyle, "key=", set_key, 1);
103
+ rb_define_method(rstyle, "key", get_key, 0);
104
+
105
+ cSimplerTilesStyle = rstyle;
106
+ }