#ifndef _cmdUtils_h_
#define _cmdUtils_h_
#include <cassert>
#include <maya/MStatus.h>
#include <maya/MArgDatabase.h>
#define MStatError(status,msg) \
if ( MS::kSuccess != (status) ) { \
MPxCommand::displayError( \
(msg) + MString(":") + (status).errorString()); \
return (status); \
}
#define MStatErrorNullObj(status,msg) \
if ( MS::kSuccess != (status) ) { \
MPxCommand::displayError( \
(msg) + MString(":") + (status).errorString()); \
return MObject::kNullObj; \
}
#define MCheckReturn(expression) \
{ \
MStatus status = (expression); \
if ( MS::kSuccess != (status) ) { \
return (status); \
} \
}
enum CommandMode
{
kCreate = 0x01,
kEdit = 0x02,
kQuery = 0x04
};
template <class T, CommandMode ValidModes>
class OptFlag
{
public:
OptFlag() : fIsSet(false), fArg() {}
{
assert(status == MS::kSuccess);
fIsArgValid = status == MS::kSuccess;
}
bool isModeValid(const CommandMode currentMode)
{
return !fIsSet || ((currentMode & ValidModes) != 0);
}
bool isSet () const { return fIsSet; }
bool isArgValid () const { return fIsArgValid; }
const T& arg () const { return fArg; }
const T& arg(const T& defValue) const
{
if (isSet())
{
assert(isArgValid());
return fArg;
}
else
{
return defValue;
}
}
private:
bool fIsSet;
bool fIsArgValid;
T fArg;
};
template <CommandMode ValidModes>
class OptFlag<void, ValidModes>
{
public:
OptFlag() : fIsSet(false) {}
{
assert(status == MS::kSuccess);
}
bool isModeValid(const CommandMode currentMode)
{
return !fIsSet || ((currentMode & ValidModes) != 0);
}
bool isSet() const { return fIsSet; }
private:
bool fIsSet;
};
#endif // _cmdUtils_h_