PuzzleD

D Interface to libpuzzle
git clone git://xatko.vsos.ethz.ch/PuzzleD.git
Log | Files | Refs

commit 9819f537d9685cc30da219c9ea202d9fb5ab5d8c
parent 0ec7a47e62a39511ce8710fbf920224344bd3098
Author: Dominik Schmidt <das1993@hotmail.com>
Date:   Thu, 27 Aug 2015 00:18:14 +0200

Change class Puzzle to struct.

I _really_ don't feel like heapallocating this structure.
As a consequence, new Puzzles have to be instanciated with Puzzle.get();

Diffstat:
puzzle.d | 19++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/puzzle.d b/puzzle.d @@ -86,13 +86,26 @@ extern(C){ } import std.string; -class Puzzle{ +static bool valid(in PuzzleContext ctx){ + return (ctx.magic==0xdeadbeef); +} +static bool valid(in PuzzleContext *ctx){ + return (ctx!=null && valid(*ctx)); +} + +struct Puzzle{ PuzzleContext ctx; - this(){ + void initialize() + out{ + assert(ctx.valid()); + } + body{ puzzle_init_context(&ctx); } ~this(){ - puzzle_free_context(&ctx); + if(ctx.valid){ + puzzle_free_context(&ctx); + } } DVec dvec(){ return DVec(&ctx);