Skip to content
Snippets Groups Projects
Commit 3976c84e authored by liam's avatar liam
Browse files

Generic functions and some methods data-import, data-export,

data-validate.  Option to import and validate using theses in
with-data.


git-svn-id: svn+ssh://pop/opt/space/mathematics/gsl/trunk@3026 a3d8a0fb-c1db-0310-ace7-a616afeb9e30
parent 2f2c875b
No related branches found
No related tags found
No related merge requests found
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
; description: Combinations ; description: Combinations
; date: Sun Mar 26 2006 - 11:51 ; date: Sun Mar 26 2006 - 11:51
; author: Liam M. Healy ; author: Liam M. Healy
; modified: Thu Apr 6 2006 - 23:17 ; modified: Fri Apr 7 2006 - 18:04
;******************************************************** ;********************************************************
;;; $Id: $ ;;; $Id: $
...@@ -61,7 +61,7 @@ ...@@ -61,7 +61,7 @@
:c-return-value :return :c-return-value :return
:documentation "The ith element of the combination.") :documentation "The ith element of the combination.")
(defunx combination-list (combination) (defmethod data-export ((combination gsl-combination))
"The combination as a list." "The combination as a list."
(loop for j below (combination-size combination) (loop for j below (combination-size combination)
collect (gsl-aref combination j))) collect (gsl-aref combination j)))
...@@ -91,8 +91,9 @@ ...@@ -91,8 +91,9 @@
:documentation :documentation
"A pointer to the array of elements in the combination @var{p}.") "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" "gsl_combination_valid"
:method ((combination gsl-combination))
:c-return-value :return :c-return-value :return
:return (:boolean) :return (:boolean)
:documentation :documentation
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
; description: Using GSL storage. ; description: Using GSL storage.
; date: Sun Mar 26 2006 - 16:32 ; date: Sun Mar 26 2006 - 16:32
; author: Liam M. Healy ; author: Liam M. Healy
; modified: Thu Apr 6 2006 - 22:45 ; modified: Fri Apr 7 2006 - 18:00
;******************************************************** ;********************************************************
;;; $Id: $ ;;; $Id: $
...@@ -87,17 +87,28 @@ ...@@ -87,17 +87,28 @@
(defgeneric set-identity (object) (defgeneric set-identity (object)
(:documentation "Set elements to represent the identity.")) (: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) (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, "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." contents when allocating."
(flet ((cl-name (action) (flet ((cl-name (action)
(intern (format nil "GSL-~a-~a" type action)))) (intern (format nil "GSL-~a-~a" type action))))
(let ((ptr (gensym "PTR"))) (let ((ptr (gensym "PTR")))
`(let* ((,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)))) ,@(if (listp size) size (list size))))
(,symbol (,symbol
(make-instance ',(intern (format nil "GSL-~a" type)) (make-instance ',(intern (format nil "GSL-~a" type))
...@@ -105,13 +116,18 @@ ...@@ -105,13 +116,18 @@
(check-null-pointer ,ptr (check-null-pointer ,ptr
:ENOMEM :ENOMEM
(format nil "For '~a of GSL type ~a." ',symbol ',type)) (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 (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)))))) (,(cl-name 'free) ,ptr))))))
;;;(with-data (p permutation 5 #(2 3 4 0) t) foo)
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
; description: Permutations ; description: Permutations
; date: Sun Mar 26 2006 - 11:51 ; date: Sun Mar 26 2006 - 11:51
; author: Liam M. Healy ; author: Liam M. Healy
; modified: Wed Apr 5 2006 - 23:39 ; modified: Fri Apr 7 2006 - 18:00
;******************************************************** ;********************************************************
;;; $Id: $ ;;; $Id: $
...@@ -78,8 +78,9 @@ permutation @var{dest}. The two permutations must have the same size.") ...@@ -78,8 +78,9 @@ permutation @var{dest}. The two permutations must have the same size.")
"A pointer to the array of elements in the "A pointer to the array of elements in the
permutation @var{p}.") permutation @var{p}.")
(defun-gsl permutation-valid ((p gsl-permutation-c)) (defun-gsl data-valid (((pointer permutation) :pointer))
"gsl_permutation_valid" "gsl_permutation_valid"
:method ((permutation gsl-permutation))
:c-return-value :return :c-return-value :return
:return (:boolean) :return (:boolean)
:documentation :documentation
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment