• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

/tmp/buildd/coinor-ipopt-3.8.3/Ipopt/contrib/MatlabInterface/src/matlabfunctionhandle.hpp

Go to the documentation of this file.
00001 // Copyright (C) 2008 Peter Carbonetto. All Rights Reserved.
00002 // This code is published under the Common Public License.
00003 //
00004 // Author: Peter Carbonetto
00005 //         Dept. of Computer Science
00006 //         University of British Columbia
00007 //         August 25, 2008
00008 
00009 #ifndef INCLUDE_MATLABFUNCTIONHANDLE
00010 #define INCLUDE_MATLABFUNCTIONHANDLE
00011 
00012 #include "mex.h"
00013 
00014 // Function declarations.
00015 // -----------------------------------------------------------------
00016 // This function returns true if and only if the MATLAB array is a
00017 // valid function handle.
00018 bool isFunctionHandle (const mxArray* ptr);
00019 
00020 // Class MatlabFunctionHandle.
00021 // -----------------------------------------------------------------
00022 // The purpose of this class is twofold. The first aim is to store
00023 // information about a MATLAB function handle. (For more information
00024 // on function handles in MATLAB, type HELP FUNCTION_HANDLE in the
00025 // MATLAB console). The second purpose is to provide a routine for
00026 // evaluating the response of the function, provided inputs to the
00027 // function.
00028 class MatlabFunctionHandle {
00029 public:
00030 
00031   // The default constructor creates a null function handle.
00032   MatlabFunctionHandle() : f(0) { };
00033 
00034   // This constructor accepts as input a pointer to a MATLAB array. It
00035   // is up to the user to ensure that the MATLAB array is a valid
00036   // function handle.
00037   explicit MatlabFunctionHandle (const mxArray* ptr);
00038   
00039   // The destructor.
00040   ~MatlabFunctionHandle();
00041 
00042   // This method is used to call the MATLAB function, provided inputs
00043   // to the function. It is up to the user to make sure that the
00044   // outputs array is of the appropriate size. The function returns
00045   // "true" on success, or "false" on failure. It is up to the user to
00046   // properly deallocate the outputs.
00047   bool evaluate (int nin, int nout, const mxArray** inputs, mxArray** outputs);
00048 
00049   // Returns true if and only if the function handle is not null.
00050   operator bool() const { return f != 0; };
00051 
00052 protected:
00053   mxArray* f;  // The MATLAB function handle.
00054 };
00055 
00056 #endif

Generated on Thu Jul 29 2010 19:56:08 by  doxygen 1.7.1