diff --git a/data/combination.lisp b/data/combination.lisp index b259d9fcba400d32278dbc4eab50ccd90b89723e..26e6c644a861266ca4621f0d7d410e5c744b1da4 100644 --- a/data/combination.lisp +++ b/data/combination.lisp @@ -3,7 +3,7 @@ ; description: Combinations ; date: Sun Mar 26 2006 - 11:51 ; author: Liam M. Healy -; modified: Thu Apr 6 2006 - 23:17 +; modified: Fri Apr 7 2006 - 18:04 ;******************************************************** ;;; $Id: $ @@ -61,7 +61,7 @@ :c-return-value :return :documentation "The ith element of the combination.") -(defunx combination-list (combination) +(defmethod data-export ((combination gsl-combination)) "The combination as a list." (loop for j below (combination-size combination) collect (gsl-aref combination j))) @@ -91,8 +91,9 @@ :documentation "A pointer to the array of elements in the combination @var{p}.") -(defun-gsl combination-valid ((c gsl-combination-c)) +(defun-gsl data-valid (((pointer combination) :pointer)) "gsl_combination_valid" + :method ((combination gsl-combination)) :c-return-value :return :return (:boolean) :documentation diff --git a/data/data.lisp b/data/data.lisp index 65516ef1450ea16be48926f0137f5bd76c98fee5..8ca442ab85a3d1c6573f8d1eea4eceb98263ac20 100644 --- a/data/data.lisp +++ b/data/data.lisp @@ -3,7 +3,7 @@ ; description: Using GSL storage. ; date: Sun Mar 26 2006 - 16:32 ; author: Liam M. Healy -; modified: Thu Apr 6 2006 - 22:45 +; modified: Fri Apr 7 2006 - 18:00 ;******************************************************** ;;; $Id: $ @@ -87,17 +87,28 @@ (defgeneric set-identity (object) (:documentation "Set elements to represent the identity.")) +(export 'data-import) +(defgeneric data-import (object from) + (:documentation "Import the values from the CL object.")) + +(export 'data-export) +(defgeneric data-export (object) + (:documentation "Create a CL object with the values.")) + +(export 'data-validate) +(defgeneric data-valid (object) + (:documentation "Validate the values in the object.")) (export 'with-data) -(defmacro with-data ((symbol type size &optional zero) &body body) +(defmacro with-data ((symbol type size &optional init validate) &body body) "Allocate GSL data, bind to pointer, - and then deallocated it when done. If zero is T, zero the + and then deallocated it when done. If init is T, init the contents when allocating." (flet ((cl-name (action) (intern (format nil "GSL-~a-~a" type action)))) (let ((ptr (gensym "PTR"))) `(let* ((,ptr - (,(if zero (cl-name 'calloc) (cl-name 'alloc)) + (,(if (eq init t) (cl-name 'calloc) (cl-name 'alloc)) ,@(if (listp size) size (list size)))) (,symbol (make-instance ',(intern (format nil "GSL-~a" type)) @@ -105,13 +116,18 @@ (check-null-pointer ,ptr :ENOMEM (format nil "For '~a of GSL type ~a." ',symbol ',type)) - #+old - (when (cffi:null-pointer-p ,ptr) - (error 'gsl-error - :gsl-errno (cffi:foreign-enum-value 'gsl-errorno :ENOMEM) - :gsl-reason - (format nil "For '~a of GSL type ~a." ',symbol ',type))) (unwind-protect - (progn ,@body) + (progn + ,@(case init + (:identity `((set-identity ,symbol))) + ((t) nil) + (t `((data-import ,symbol ,init)))) + ,@(when + validate + `((unless (data-valid ,symbol) + (error "Invalid ~a, ~a" type init)))) + ,@body) (,(cl-name 'free) ,ptr)))))) +;;;(with-data (p permutation 5 #(2 3 4 0) t) foo) + diff --git a/data/permutation.lisp b/data/permutation.lisp index d2f536a57617a1e0da1fe16b920a49bdf30f0f82..b2b26a477dbb938855a3df8bfa89206cb17689c2 100644 --- a/data/permutation.lisp +++ b/data/permutation.lisp @@ -3,7 +3,7 @@ ; description: Permutations ; date: Sun Mar 26 2006 - 11:51 ; author: Liam M. Healy -; modified: Wed Apr 5 2006 - 23:39 +; modified: Fri Apr 7 2006 - 18:00 ;******************************************************** ;;; $Id: $ @@ -78,8 +78,9 @@ permutation @var{dest}. The two permutations must have the same size.") "A pointer to the array of elements in the permutation @var{p}.") -(defun-gsl permutation-valid ((p gsl-permutation-c)) +(defun-gsl data-valid (((pointer permutation) :pointer)) "gsl_permutation_valid" + :method ((permutation gsl-permutation)) :c-return-value :return :return (:boolean) :documentation