TuttleOFX
1
|
00001 /* 00002 * OFX Support Library, a library that skins the OFX plug-in API with C++ classes. 00003 * Copyright (C) 2004-2005 The Open Effects Association Ltd 00004 * Author Bruno Nicoletti bruno@thefoundry.co.uk 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions are met: 00008 * 00009 * Redistributions of source code must retain the above copyright notice, 00010 * this list of conditions and the following disclaimer. 00011 * Redistributions in binary form must reproduce the above copyright notice, 00012 * this list of conditions and the following disclaimer in the documentation 00013 * and/or other materials provided with the distribution. 00014 * Neither the name The Open Effects Association Ltd, nor the names of its 00015 * contributors may be used to endorse or promote products derived from this 00016 * software without specific prior written permission. 00017 * 00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00019 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00020 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00021 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 00022 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00023 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00024 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 00025 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00026 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00027 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00028 * 00029 * The Open Effects Association Ltd 00030 * 1 Wardour St 00031 * London W1D 6PA 00032 * England 00033 * 00034 * 00035 */ 00036 #include "./ofxsSupportPrivate.h" 00037 00038 #include <boost/throw_exception.hpp> 00039 #include <boost/lexical_cast.hpp> 00040 00041 #include <cstddef> 00042 00043 namespace OFX { 00044 00045 /** @brief Throws an @ref OFX::Exception depending on the status flag passed in */ 00046 void throwSuiteStatusException( const OfxStatus stat ) 00047 { 00048 switch( stat ) 00049 { 00050 case kOfxStatOK: 00051 case kOfxStatReplyYes: 00052 case kOfxStatReplyNo: 00053 case kOfxStatReplyDefault: 00054 // Throw nothing! 00055 return; 00056 00057 case kOfxStatErrMemory: 00058 BOOST_THROW_EXCEPTION( std::bad_alloc() ); 00059 return; 00060 } 00061 // default case 00062 BOOST_THROW_EXCEPTION( OFX::Exception::Suite( stat, "Threw suite exception!" ) ); 00063 } 00064 00065 void throwHostMissingSuiteException( const std::string& name ) 00066 { 00067 BOOST_THROW_EXCEPTION( OFX::Exception::Suite( kOfxStatErrUnsupported, "Threw suite exception! Host missing '" + name + "' suite." ) ); 00068 } 00069 00070 /** @brief maps status to a string */ 00071 std::string mapStatusToString( const OfxStatus stat ) 00072 { 00073 switch( stat ) 00074 { 00075 case kOfxStatOK: return "kOfxStatOK"; 00076 case kOfxStatFailed: return "kOfxStatFailed"; 00077 case kOfxStatErrFatal: return "kOfxStatErrFatal"; 00078 case kOfxStatErrUnknown: return "kOfxStatErrUnknown"; 00079 case kOfxStatErrMissingHostFeature: return "kOfxStatErrMissingHostFeature"; 00080 case kOfxStatErrUnsupported: return "kOfxStatErrUnsupported"; 00081 case kOfxStatErrExists: return "kOfxStatErrExists"; 00082 case kOfxStatErrFormat: return "kOfxStatErrFormat"; 00083 case kOfxStatErrMemory: return "kOfxStatErrMemory"; 00084 case kOfxStatErrBadHandle: return "kOfxStatErrBadHandle"; 00085 case kOfxStatErrBadIndex: return "kOfxStatErrBadIndex"; 00086 case kOfxStatErrValue: return "kOfxStatErrValue"; 00087 case kOfxStatReplyYes: return "kOfxStatReplyYes"; 00088 case kOfxStatReplyNo: return "kOfxStatReplyNo"; 00089 case kOfxStatReplyDefault: return "kOfxStatReplyDefault"; 00090 case kOfxStatErrImageFormat: return "kOfxStatErrImageFormat"; 00091 } 00092 return "UNKNOWN STATUS CODE: " + boost::lexical_cast<std::string>(stat); 00093 } 00094 00095 /** @brief namespace for memory allocation that is done via wrapping the ofx memory suite */ 00096 namespace memory { 00097 00098 /** @brief allocate n bytes, returns a pointer to it */ 00099 void* allocate( const std::size_t nBytes, ImageEffect* effect ) throw( std::bad_alloc ) 00100 { 00101 void* data = 0; 00102 OfxStatus stat = OFX::Private::gMemorySuite->memoryAlloc( ( void* )( effect ? effect->getHandle() : 0 ), nBytes, &data ); 00103 00104 if( stat != kOfxStatOK ) 00105 BOOST_THROW_EXCEPTION( std::bad_alloc() ); 00106 return data; 00107 } 00108 00109 /** @brief free n previously allocated memory */ 00110 void free( void* ptr ) throw( ) 00111 { 00112 // C++ standard ensures it is safe to delete the NULL pointer. 00113 // Please note errors are ignored, this could be a bad thing however 00114 // standard requires a no throw destructor so we do. 00115 OFX::Private::gMemorySuite->memoryFree( ptr ); 00116 } 00117 00118 } 00119 } 00120