| 1 | % (c) 2009-2018 Lehrstuhl fuer Softwaretechnik und Programmiersprachen, | |
| 2 | % Heinrich Heine Universitaet Duesseldorf | |
| 3 | % This software is licenced under EPL 1.0 (http://www.eclipse.org/org/documents/epl-v10.html) | |
| 4 | ||
| 5 | :- module(counter, [ | |
| 6 | counter_init/0, | |
| 7 | new_counter/1, | |
| 8 | get_counter/2, | |
| 9 | set_counter/2, | |
| 10 | inc_counter/1, inc_counter/2, | |
| 11 | reset_counter/1 | |
| 12 | ]). | |
| 13 | ||
| 14 | foreign_resource('counter', [new_counter,get_counter,inc_counter,set_counter,reset_counter]). | |
| 15 | foreign(new_counter, c, new_counter(+atom)). | |
| 16 | foreign(get_counter, c, get_counter(+atom, [-integer])). | |
| 17 | foreign(inc_counter, c, inc_counter(+atom, [-integer])). | |
| 18 | foreign(set_counter, c, set_counter(+atom, +integer)). | |
| 19 | foreign(reset_counter, c, reset_counter(+atom)). | |
| 20 | ||
| 21 | % with this line below we need to adapt the Makefile to include the counter resource in the binary: | |
| 22 | % (maybe this is a good idea) | |
| 23 | % :- load_foreign_resource(counter). | |
| 24 | ||
| 25 | :- dynamic loaded/0. | |
| 26 | ||
| 27 | counter_init :- | |
| 28 | (loaded -> true | |
| 29 | ; (assert(loaded), | |
| 30 | %assert_dir, | |
| 31 | assert(user:library_directory('.')), | |
| 32 | %print('loading counter foreign resource'),nl, | |
| 33 | load_foreign_resource(library(counter))) | |
| 34 | ). | |
| 35 | ||
| 36 | inc_counter(Counter) :- | |
| 37 | inc_counter(Counter, _NewVal). |