#ifndef _MStatus #define _MStatus // //- // ========================================================================== // Copyright (C) 1995 - 2006 Autodesk, Inc., and/or its licensors. All // rights reserved. // // The coded instructions, statements, computer programs, and/or related // material (collectively the "Data") in these files contain unpublished // information proprietary to Autodesk, Inc. ("Autodesk") and/or its // licensors, which is protected by U.S. and Canadian federal copyright law // and by international treaties. // // The Data may not be disclosed or distributed to third parties or be // copied or duplicated, in whole or in part, without the prior written // consent of Autodesk. // // The copyright notices in the Software and this entire statement, // including the above license grant, this restriction and the following // disclaimer, must be included in all copies of the Software, in whole // or in part, and all derivative works of the Software, unless such copies // or derivative works are solely in the form of machine-executable object // code generated by a source language processor. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND. // AUTODESK DOES NOT MAKE AND HEREBY DISCLAIMS ANY EXPRESS OR IMPLIED // WARRANTIES INCLUDING, BUT NOT LIMITED TO, THE WARRANTIES OF // NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, // OR ARISING FROM A COURSE OF DEALING, USAGE, OR TRADE PRACTICE. IN NO // EVENT WILL AUTODESK AND/OR ITS LICENSORS BE LIABLE FOR ANY LOST // REVENUES, DATA, OR PROFITS, OR SPECIAL, DIRECT, INDIRECT, OR // CONSEQUENTIAL DAMAGES, EVEN IF AUTODESK AND/OR ITS LICENSORS HAS // BEEN ADVISED OF THE POSSIBILITY OR PROBABILITY OF SUCH DAMAGES. // ========================================================================== //+ // // CLASS: MStatus // // ***************************************************************************** // // CLASS DESCRIPTION (MStatus) // // This class facilitates API level error handling. It encapsulates the status // code and the internal MAYA error code as return by API functions. The // user can query, set, print the error code along with the description. // // ***************************************************************************** #if defined __cplusplus // ***************************************************************************** // INCLUDED HEADER FILES #include #if defined(REQUIRE_IOSTREAM) // External usage #include #else // Internal usage #include #endif // ***************************************************************************** // DECLARATIONS class MString; // ***************************************************************************** // CLASS DECLARATION (MStatus) /// Manipulate Maya Status codes. (OpenMaya) /** Methods for passing status codes between user code and Maya */ #ifdef _WIN32 #pragma warning(disable: 4522) #endif // _WIN32 class OPENMAYA_EXPORT MStatus { public: /// Available Status Codes enum MStatusCode { /// The operation was successful kSuccess = 0, /// The operation failed kFailure, /// The operation failed due to insufficient memory kInsufficientMemory, /// An invalid parameter was provided kInvalidParameter, /// Application is not licensed for the attempted operation kLicenseFailure, /// Returned by MPxNode::compute for unrecognised plugs kUnknownParameter, /// Not currently used kNotImplemented, /// Not currently used kNotFound, /// Not currently used kEndOfFile }; /// MStatus(); /// MStatus( MStatusCode ); /// MStatus( const MStatus& ); /// MStatus& operator=( const MStatus& rhs); /// bool operator==( const MStatus& rhs ) const; /// bool operator==( const MStatusCode rhs ) const; /// bool operator!=( const MStatus& rhs ) const; /// bool operator!=( const MStatusCode rhs ) const; /// bool error() const; /// void clear(); /// MStatusCode statusCode() const; /// MString errorString() const; BEGIN_NO_SCRIPT_SUPPORT: /// void perror( const char * ) const; END_NO_SCRIPT_SUPPORT: /// void perror( const MString& ) const; /// Internal use only void set( bool status, unsigned char statusCode, unsigned char internalStatusCode); void setSuccess(); BEGIN_NO_SCRIPT_SUPPORT: /// NO SCRIPT SUPPORT operator bool() const { return fStatus; } /// NO SCRIPT SUPPORT friend OPENMAYA_EXPORT std::ostream& operator<<( std::ostream&, MStatus&); /// NO SCRIPT SUPPORT friend OPENMAYA_EXPORT inline bool operator==( const MStatus::MStatusCode code, const MStatus& status ) { return ( status.fStatusCode == code ); } /// NO SCRIPT SUPPORT friend OPENMAYA_EXPORT inline bool operator!=( const MStatus::MStatusCode code, const MStatus& status ) { return ( status.fStatusCode != code ); } END_NO_SCRIPT_SUPPORT: protected: // No protected members private: unsigned char fStatusCode; unsigned char fInternalStatusCode; bool fStatus; }; #ifdef _WIN32 #pragma warning(default: 4522) #endif // _WIN32 // The MS typedef can cause errors when linking with // .NET libraries on Windows. Use the MNoMSTypedef // define to force all status codes to be prefixed by // MStatus:: instead of MS::. #if !defined(MNoMSTypedef) typedef MStatus MS; #endif // Convenience macros for checking the return status from API methods. // // Output an error message and returns the value 'retVal' if status // is not kSuccess. // #define CHECK_MSTATUS_AND_RETURN(x, retVal) \ { \ MStatus _maya_status = (x); \ if ( MStatus::kSuccess != _maya_status ) \ { \ cerr << "\nAPI error detected in " << __FILE__ \ << " at line " << __LINE__ << endl; \ _maya_status.perror ( "" ); \ return (retVal); \ } \ } // Same as above, execpt that the return value is the status itself. // #define CHECK_MSTATUS_AND_RETURN_IT(x) \ CHECK_MSTATUS_AND_RETURN((x), (x)) // Output an error message if status is not kSuccess. // #define CHECK_MSTATUS(x) \ { \ MStatus _maya_status = (x); \ if ( MStatus::kSuccess != _maya_status ) \ { \ cerr << "\nAPI error detected in " << __FILE__ \ << " at line " << __LINE__ << endl; \ _maya_status.perror ( "" ); \ } \ } // #define MFAIL(x) ( MStatus::kSuccess != (x) ) inline bool MStatus::operator==( const MStatus& rhs ) const { return ( fStatusCode == rhs.fStatusCode ); } inline bool MStatus::operator==( const MStatus::MStatusCode rhs ) const { return ( fStatusCode == rhs ); } inline bool MStatus::operator!=( const MStatus& rhs ) const { return ( fStatusCode != rhs.fStatusCode ); } inline bool MStatus::operator!=( const MStatus::MStatusCode rhs ) const { return ( fStatusCode != rhs ); } inline bool MStatus::error() const { return !fStatus; } inline MStatus::MStatusCode MStatus::statusCode() const { return ( MStatus::MStatusCode ) fStatusCode; } inline void MStatus::set( bool status, unsigned char theStatusCode, unsigned char internalStatusCode) { fStatus = status; fStatusCode = theStatusCode; fInternalStatusCode = internalStatusCode; } inline void MStatus::setSuccess() { fStatus = true; fStatusCode = MStatus::kSuccess; fInternalStatusCode = 0xff; } #endif /* __cplusplus */ #endif /* _MStatus */