Page 1 of 1

How do I wrap a C++ class in CFFi or Common Lisp

PostPosted: Fri Apr 04, 2014 7:37 am
by joeish80829
I have a bunch or C wrappers for C++ OpenCV code I'm writing and I was hoping someone could show me how the best way would be in CFFI to write theses functions. They're from a C++ class
the OpenCV Point_ class defined here ... nto#Point_

Here are the functions below. So far I'm making the top 2 functions point0 and point2 use the same name "point" with this function:

Code: Select all
(defun point (&optional (x nil) (y nil))
       (cond ((eq (or x y) nil)
         ((and x y)
          (point2 x y))
         (t nil)))

but I also have functions to retrieve the x and y coordinates of a point that belong to the same class. I call those point-x and point-y..I was hoping someone could write me up the best way on how to use these Point_ class wrappers . Is it with defclass or define-foreign-type or am I already doing a good job? I could use this info in making all my other class wrappers correctly. I'd rather a proffessional tell me the best way before I start wrapping all my functions.

Code: Select all
;; Point* cv_create_Point(int x, int y)
(defcfun ("cv_create_Point" point0) (:pointer point)
  "Point constructor")
;; Point* cv_create_Point(int x, int y)
(defcfun ("cv_create_Point2" point2) (:pointer point)
  "Point constructor"
  (x :int)
  (y :int))
;; _Tp x, y
;; int cv_Point_getX(Point* self)
(defcfun ("cv_Point_getX" point-x) :int
  "Retrieves X coordinate of a point"
  (self (:pointer point)))
;; _Tp x, y
;; int cv_Point_getY(Point* self)
(defcfun ("cv_Point_getY" point-y) :int
  "Retrieves y coordinate of a point"
  (self (:pointer point)))