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
......@@ -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
......
......@@ -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)
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment