wrappers?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sanctus
    New Member
    • Mar 2007
    • 84

    wrappers?

    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:

    Code:
    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
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    Originally posted by sanctus
    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:

    Code:
    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?

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #3
      Originally posted by sanctus
      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.

      Comment

      • Roonie
        New Member
        • Mar 2007
        • 99

        #4
        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?

        Comment

        • Banfa
          Recognized Expert Expert
          • Feb 2006
          • 9067

          #5
          Originally posted by Roonie
          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.

          Comment

          • sanctus
            New Member
            • Mar 2007
            • 84

            #6
            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

            Comment

            • sanctus
              New Member
              • Mar 2007
              • 84

              #7
              Further in the program there are some lines which are good example how the programmer uses wrappers, that explained it completely to me.
              Code:
               
              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); 
                }

              Comment

              • weaknessforcats
                Recognized Expert Expert
                • Mar 2007
                • 9214

                #8
                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.

                Comment

                Working...