Skip to content
Snippets Groups Projects
Commit 0f53cd96 authored by Mark Winter's avatar Mark Winter
Browse files

Mex command info now depends only on static-defined name

- Removed need for module-load information (Windows-loader specific).
- File containing mexFunction, must now also define MexCommand::mexName static variable.
parent 8e87cc5d
No related branches found
No related tags found
No related merge requests found
#include "MexCommand.h"
std::string MexCommand::mexName = "Mex";
void mexFunction(int nlhs,mxArray* plhs[],int nrhs,const mxArray* prhs[])
{
MexCommand::run(nlhs,plhs,nrhs,prhs);
......
......@@ -10,18 +10,6 @@
#include "../WrapCmds/CommandList.h"
#undef BUILD_COMMANDS
// Module name info
HMODULE ModuleInfo::hModule;
std::string ModuleInfo::name;
BOOL WINAPI DllMain(HINSTANCE hInstDLL,DWORD fdwReason,LPVOID lpReserved)
{
if(fdwReason == DLL_PROCESS_ATTACH)
ModuleInfo::setModuleHandle(hInstDLL);
return TRUE;
}
// MexCommandInfo - This command can be used to provide an easy to parse matlab command info structure for all MEX commands.
std::string MexInfo::check(int nlhs,mxArray* plhs[],int nrhs,const mxArray* prhs[]) const
......
......@@ -4,61 +4,12 @@
#include "../Cuda/ImageDimensions.cuh"
#include <mex.h>
#include <windows.h>
#undef min
#undef max
#include <vector>
#include <string>
#include <algorithm>
#include <exception>
// Static class for holding some module information
class ModuleInfo
{
public:
static void setModuleHandle(HMODULE handle)
{
hModule = handle;
}
static void initModuleInfo()
{
if(name.length() == 0)
name = initName();
}
static const std::string& getName()
{
return name;
}
private:
static std::string initName()
{
if(hModule == NULL)
return "";
char pathBuffer[1024];
DWORD result = GetModuleFileName((HMODULE)hModule,pathBuffer,1024);
if(FAILED(result))
return "";
std::string path(pathBuffer);
std::size_t startOffset = path.find_last_of('\\') + 1;
path = path.substr(startOffset);
std::size_t endOffset = path.find_last_of('.');
return path.substr(0,endOffset);
}
private:
static std::string name;
static HMODULE hModule;
};
// Abstract base class for mex commands
class MexCommand
{
......@@ -77,8 +28,6 @@ public:
// Runs through any registered commands.
static void run(int nlhs,mxArray* plhs[],int nrhs,const mxArray* prhs[])
{
ModuleInfo::initModuleInfo();
// Require a string as command input.
if(nrhs < 1 || !mxIsChar(prhs[0]))
mexErrMsgTxt(MexCommand::printUsageList().c_str());
......@@ -118,9 +67,7 @@ public:
std::string offset(" ");
std::string usageStr;
ModuleInfo::initModuleInfo();
usageStr += offset + ModuleInfo::getName() + "(command, ...)\n\n";
usageStr += offset + mexName + "(command, ...)\n\n";
usageStr += offset + "Command List:\n";
for(int i=0; i < m_numCommands; ++i)
......@@ -146,7 +93,7 @@ protected:
for(int i=0; i < m_numCommands; ++i)
usageStr += " " + buildUsageString(m_commands[i]) + "\n";
usageStr += "\nUse " + ModuleInfo::getName() + "('help',command) for detailed command info.\n";
usageStr += "\nUse " + mexName + "('help',command) for detailed command info.\n";
return usageStr;
}
......@@ -199,7 +146,7 @@ protected:
usageString += outputs[outputs.size()-1] + "] = ";
}
usageString += ModuleInfo::getName();
usageString += mexName;
usageString += "(";
usageString += "'" + mexCmd->m_cmdString + "'";
......@@ -279,6 +226,8 @@ protected:
static Vec<std::size_t> MexCommand::FillKernel(const mxArray* matKernelIn, float** kernel);
private:
static std::string mexName;
static const std::size_t m_numCommands;
static MexCommand* const m_commands[];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment