454,908 Members | 1,364 Online
Need help? Post your question and get tips & solutions from a community of 454,908 IT Pros & Developers. It's quick & easy.

# wrappers?

 P: 84 I looked up the net and some books but I didn't find nowhere something just explaining what wrappers are, can anyone explain this or give a link? The problem arises from this piece of code: Expand|Select|Wrap|Line Numbers static void spline(double*, double*, const int, const double, const double, double*); //! Generates interpolating coefficients for subsequent interpolation with splint Nrecipes  static void spline(double* x, double* y, const int n, double *yp1, double* ypn, double* y2) { spline(x,y,n,*yp1,*ypn,y2); } //!< wrapper   To me it just seems a double (non in C++, but in the usual english sense) declaration of the same function, once giving a name to the variables and once not. By the way what is the difference between declaring a function with names of its variables and only with the type of variables? Thank you very much in advance Mar 22 '07 #1
7 Replies

 Expert Mod 2.5K+ P: 4,677 I looked up the net and some books but I didn't find nowhere something just explaining what wrappers are, can anyone explain this or give a link? The problem arises from this piece of code: Expand|Select|Wrap|Line Numbers static void spline(double*, double*, const int, const double, const double, double*); //! Generates interpolating coefficients for subsequent interpolation with splint Nrecipes  static void spline(double* x, double* y, const int n, double *yp1, double* ypn, double* y2) { spline(x,y,n,*yp1,*ypn,y2); } //!< wrapper   To me it just seems a double (non in C++, but in the usual english sense) declaration of the same function, once giving a name to the variables and once not. By the way what is the difference between declaring a function with names of its variables and only with the type of variables? Thank you very much in advance This was returned with a google search of 'programming wrappers'. Does it help? http://en.wikipedia.org/wiki/Wrapper Mar 22 '07 #2

 Expert Mod 5K+ P: 8,916 To me it just seems a double (non in C++, but in the usual english sense) declaration of the same function, once giving a name to the variables and once not. No look more closely at the parameter types of the declaration and definition. Mar 22 '07 #3

 P: 99 yeah, it looks to me like you have a function prototype, and then the definition of that function . . . (or attempted definition - if you want to be recursively doing nothing forever) . . . right? Mar 22 '07 #4

 Expert Mod 5K+ P: 8,916 yeah, it looks to me like you have a function prototype, and then the definition of that function . . . (or attempted definition - if you want to be recursively doing nothing forever) . . . right? Wrong, it's C++ (I assume) remember. Mar 22 '07 #5

 P: 84 Yes the link helps but I have to ponder it a bit further before being able to say I really understand it. And yes, it is C++. Thanks Mar 23 '07 #6

 P: 84 Further in the program there are some lines which are good example how the programmer uses wrappers, that explained it completely to me. Expand|Select|Wrap|Line Numbers   void set(const double, const double); //!< new data point (x,y) for a spline that  owns its xdata   void set(const double); //!< new data point (y) for a spline that shares the  xdata with mother and sisters   /*! Wrapper for set() that depending on wether     the spline owns the xdata or not, calls the     two possible set() functions */   void setForce(double x, double y ) {       if (own) set(x,y); else set(y);    }   Mar 25 '07 #7

 Expert Mod 5K+ P: 9,197 A wrapper is a term given to a function that makes two incompatible functions compatible. For example, assume there is a requirement to manage an array of x-y data pairs: struct Point { int x-value; int y-value; }; The function used might be: void Change(Point* thePoint, Point* newValue); In order to call this function you need the address of a Point variable with the new value. A wrapper function can be used to avoid having the calling function create the Point variable with the new value: void Change(Point* thePoint, int x, int y) { Point data; data.x-value = x; data.y-value = y; Change(thePoint, &data); } Here you can see how the void Change(Point* thePoint, int x, int y) "wraps-around" the void Change(Point* thePoint, Point* newValue) function. What the user sees is: Point array[5]; Change(&array[0], 4,6); Wrappers often occur when the original function is third-party and cannot be easily revised for your requirements. Check out the Adapter design pattern. Mar 25 '07 #8