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

Discussion of Common Lisp

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

Postby joeish80829 » Fri Apr 04, 2014 7:37 am

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 http://docs.opencv.org/modules/core/doc ... 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)
          (point0))
         ((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)))
joeish80829
 
Posts: 153
Joined: Tue Sep 03, 2013 5:32 am

Return to Common Lisp

Who is online

Users browsing this forum: Google [Bot] and 2 guests

cron