MexParams.cpp

Go to the documentation of this file.
00001 
00005 // This file is part of the SaliencyToolbox - Copyright (C) 2006-2007
00006 // by Dirk B. Walther and the California Institute of Technology.
00007 // See the enclosed LICENSE.TXT document for the license agreement. 
00008 // More information about this project is available at: 
00009 // http://www.saliencytoolbox.net
00010 
00011 #include "MexParams.h"
00012 
00013 // ######################################################################
00014 MexParams::MexParams(const int minOutput, const int maxOutput, 
00015                      const int numOutput, mxArray* plhs[], 
00016                      const int minInput , const int maxInput, 
00017                      const int numInput, const mxArray *prhs[])
00018   : itsNumOutput(numOutput),
00019     itsOutput(plhs),
00020     itsNumInput(numInput),
00021     itsInput(prhs)
00022 {
00023   ASSERT(numOutput >= minOutput);
00024   ASSERT(numOutput <= maxOutput);
00025   ASSERT(numInput >= minInput);
00026   ASSERT(numInput <= maxInput);
00027   ASSERT(K_RightInDd);
00028 }
00029   
00030 // ######################################################################
00031 MexParams::~MexParams()
00032 {
00033   int count = 0;
00034   for (int i = 0; i < itsNumOutput; ++i)
00035     if (itsOutput[i] == NULL)
00036       {
00037         mexError("Output argument %d is unassigned.",i+1);
00038         count++;
00039       }
00040   
00041   if (count > 0)
00042     mexFatal("%d of %d output arguments were unassigned.",count,itsNumOutput);
00043 }
00044   
00045 // ######################################################################
00046 void MexParams::setOutput(const int number, mxArray* out)
00047 {
00048   ASSERT(number >= 0);
00049   if (number < itsNumOutput) itsOutput[number] = out;
00050 }
00051   
00052 // ######################################################################
00053 void MexParams::setScalarOutput(const int number, const double val)
00054 {
00055   setOutput(number, mxCreateScalarDouble(val));
00056 }
00057 
00058 // ######################################################################
00059 mxArray* MexParams::getOutput(const int number)
00060 {
00061   ASSERT(number >= 0);
00062   ASSERT(number < itsNumOutput);
00063   return itsOutput[number];
00064 }
00065    
00066 // ######################################################################
00067 double MexParams::getScalarOutput(const int number)
00068 {
00069   return mxGetScalar(getOutput(number));
00070 }
00071  
00072 // ######################################################################
00073 const mxArray* MexParams::getInput(const int number) const
00074 {
00075   ASSERT(number >= 0);
00076   ASSERT(number < itsNumInput);
00077   return itsInput[number];
00078 }
00079    
00080 // ######################################################################
00081 const double MexParams::getScalarInput(const int number) const
00082 {
00083   return mxGetScalar(getInput(number));
00084 }
00085  
00086 // ######################################################################
00087 int MexParams::getNumberOutput() const
00088 {
00089   return itsNumOutput;
00090 }
00091   
00092 // ######################################################################
00093 int MexParams::getNumberInput() const
00094 {
00095   return itsNumInput;
00096 }

Generated on Fri Sep 7 13:09:49 2007 for SaliencyToolbox by  doxygen 1.5.2