TuttleOFX  1
ofxsProperty.cpp
Go to the documentation of this file.
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 
00037 #include "./ofxsSupportPrivate.h"
00038 
00039 
00040 namespace OFX {
00041 
00042 using namespace OFX::Private;
00043 
00044 void throwPropertyException( OfxStatus          stat,
00045                              const std::string& propName )
00046 {
00047         switch( stat )
00048         {
00049                 case kOfxStatOK:
00050                 case kOfxStatReplyYes:
00051                 case kOfxStatReplyNo:
00052                 case kOfxStatReplyDefault:
00053                         // Throw nothing!
00054                         return;
00055 
00056                 case kOfxStatErrUnknown:
00057                 case kOfxStatErrUnsupported: // unsupported implies unknow here
00058                         if( OFX::PropertySet::getThrowOnUnsupportedProperties() ) // are we suppressing this?
00059                                 BOOST_THROW_EXCEPTION( OFX::Exception::PropertyUnknownToHost( propName ) );
00060                         return;
00061 
00062                 case kOfxStatErrMemory:
00063                         BOOST_THROW_EXCEPTION( std::bad_alloc() );
00064                         return;
00065 
00066                 case kOfxStatErrValue:
00067                         BOOST_THROW_EXCEPTION( OFX::Exception::PropertyValueIllegalToHost( propName.c_str() ) );
00068                         return;
00069 
00070                 // in these cases and default throwSuiteStatusException
00071                 case kOfxStatErrBadHandle:
00072                 case kOfxStatErrBadIndex:
00073                         break;
00074         }
00075         // default case
00076         throwSuiteStatusException( stat );
00077 }
00078 
00079 /** @brief are we logging property get/set */
00080 int PropertySet::_gPropLogging = 1;
00081 
00082 /** @brief Do we throw an exception if a host returns 'unsupported' when setting a property */
00083 bool PropertySet::_gThrowOnUnsupported = true;
00084 
00085 /** @brief Virtual destructor */
00086 PropertySet::~PropertySet() {}
00087 
00088 /** @brief, returns the dimension of the given property from this property set */
00089 int PropertySet::propGetDimension( const char* property, bool throwOnFailure ) const
00090 {
00091         assert( _propHandle != 0 );
00092         int dimension;
00093         OfxStatus stat = gPropSuite->propGetDimension( _propHandle, property, &dimension );
00094         Log::error( stat != kOfxStatOK, "Failed on fetching dimension for property %s, host returned status %s.", property, mapStatusToString( stat ).c_str() );
00095         if( throwOnFailure )
00096                 throwPropertyException( stat, property );
00097 
00098         if( _gPropLogging > 0 )
00099                 Log::print( "Fetched dimension of property %s, returned %d.",  property, dimension );
00100 
00101         return dimension;
00102 }
00103 
00104 /** @brief, resets the property to it's default value */
00105 void PropertySet::propReset( const char* property )
00106 {
00107         assert( _propHandle != 0 );
00108         OfxStatus stat = gPropSuite->propReset( _propHandle, property );
00109         Log::error( stat != kOfxStatOK, "Failed on reseting property %s to its defaults, host returned status %s.", property, mapStatusToString( stat ).c_str() );
00110         throwPropertyException( stat, property );
00111 
00112         if( _gPropLogging > 0 )
00113                 Log::print( "Reset property %s.",  property );
00114 }
00115 
00116 /** @brief, Set a single dimension pointer property */
00117 void PropertySet::propSetPointer( const char* property, void* value, int idx, bool throwOnFailure )
00118 {
00119         assert( _propHandle != 0 );
00120         OfxStatus stat = gPropSuite->propSetPointer( _propHandle, property, idx, value );
00121         OFX::Log::error( stat != kOfxStatOK, "Failed on setting pointer property %s[%d] to %p, host returned status %s;",
00122                          property, idx, value, mapStatusToString( stat ).c_str() );
00123         if( throwOnFailure )
00124                 throwPropertyException( stat, property );
00125 
00126         if( _gPropLogging > 0 )
00127                 Log::print( "Set pointer property %s[%d] to be %p.",  property, idx, value );
00128 }
00129 
00130 /** @brief, Set a single dimension string property */
00131 void PropertySet::propSetString( const char* property, const std::string& value, int idx, bool throwOnFailure )
00132 {
00133         assert( _propHandle != 0 );
00134         OfxStatus stat = gPropSuite->propSetString( _propHandle, property, idx, value.c_str() );
00135         OFX::Log::error( stat != kOfxStatOK, "Failed on setting string property %s[%d] to %s, host returned status %s;",
00136                          property, idx, value.c_str(), mapStatusToString( stat ).c_str() );
00137         if( throwOnFailure )
00138                 throwPropertyException( stat, property );
00139 
00140         if( _gPropLogging > 0 )
00141                 Log::print( "Set string property %s[%d] to be %s.",  property, idx, value.c_str() );
00142 }
00143 
00144 /** @brief, Set a single dimension double property */
00145 void PropertySet::propSetDouble( const char* property, double value, int idx, bool throwOnFailure )
00146 {
00147         assert( _propHandle != 0 );
00148         OfxStatus stat = gPropSuite->propSetDouble( _propHandle, property, idx, value );
00149         OFX::Log::error( stat != kOfxStatOK, "Failed on setting double property %s[%d] to %lf, host returned status %s;",
00150                          property, idx, value, mapStatusToString( stat ).c_str() );
00151         if( throwOnFailure )
00152                 throwPropertyException( stat, property );
00153 
00154         if( _gPropLogging > 0 )
00155                 Log::print( "Set double property %s[%d] to be %lf.",  property, idx, value );
00156 }
00157 
00158 /** @brief, Set a single dimension int property */
00159 void PropertySet::propSetInt( const char* property, int value, int idx, bool throwOnFailure )
00160 {
00161         assert( _propHandle != 0 );
00162         OfxStatus stat = gPropSuite->propSetInt( _propHandle, property, idx, value );
00163         OFX::Log::error( stat != kOfxStatOK, "Failed on setting int property %s[%d] to %d, host returned status %s (%d);",
00164                          property, idx, value, mapStatusToString( stat ).c_str(), stat );
00165         if( throwOnFailure )
00166                 throwPropertyException( stat, property );
00167 
00168         if( _gPropLogging > 0 )
00169                 Log::print( "Set int property %s[%d] to be %d.",  property, idx, value );
00170 }
00171 
00172 /** @brief Get single pointer property */
00173 void*  PropertySet::propGetPointer( const char* property, int idx, bool throwOnFailure ) const
00174 {
00175         assert( _propHandle != 0 );
00176         void* value    = 0;
00177         OfxStatus stat = gPropSuite->propGetPointer( _propHandle, property, idx, &value );
00178         OFX::Log::error( stat != kOfxStatOK, "Failed on getting pointer property %s[%d], host returned status %s;",
00179                          property, idx, mapStatusToString( stat ).c_str() );
00180         if( throwOnFailure )
00181                 throwPropertyException( stat, property );
00182 
00183         if( _gPropLogging > 0 )
00184                 Log::print( "Retrieved pointer property %s[%d], was given %p.",  property, idx, value );
00185 
00186         return value;
00187 }
00188 
00189 /** @brief Get single string property */
00190 std::string PropertySet::propGetString( const char* property, int idx, bool throwOnFailure ) const
00191 {
00192         assert( _propHandle != 0 );
00193         char* value    = NULL;
00194         OfxStatus stat = gPropSuite->propGetString( _propHandle, property, idx, &value );
00195         OFX::Log::error( stat != kOfxStatOK, "Failed on getting string property %s[%d], host returned status %s;",
00196                          property, idx, mapStatusToString( stat ).c_str() );
00197         if( throwOnFailure )
00198                 throwPropertyException( stat, property );
00199 
00200         if( _gPropLogging > 0 )
00201                 Log::print( "Retrieved string property %s[%d], was given %s.", property, idx, value );
00202 
00203     if( value == NULL )
00204         return std::string();
00205 
00206         return std::string( value );
00207 }
00208 
00209 /** @brief Get single double property */
00210 double PropertySet::propGetDouble( const char* property, int idx, bool throwOnFailure ) const
00211 {
00212         assert( _propHandle != 0 );
00213         double value   = 0;
00214         OfxStatus stat = gPropSuite->propGetDouble( _propHandle, property, idx, &value );
00215         OFX::Log::error( stat != kOfxStatOK, "Failed on getting double property %s[%d], host returned status %s;",
00216                          property, idx, mapStatusToString( stat ).c_str() );
00217         if( throwOnFailure )
00218                 throwPropertyException( stat, property );
00219 
00220         if( _gPropLogging > 0 )
00221                 Log::print( "Retrieved double property %s[%d], was given %lf.",  property, idx, value );
00222         return value;
00223 }
00224 
00225 /** @brief Get single int property */
00226 int PropertySet::propGetInt( const char* property, int idx, bool throwOnFailure ) const
00227 {
00228         assert( _propHandle != 0 );
00229         int value      = 0;
00230         OfxStatus stat = gPropSuite->propGetInt( _propHandle, property, idx, &value );
00231         OFX::Log::error( stat != kOfxStatOK, "Failed on getting int property %s[%d], host returned status %s;",
00232                          property, idx, mapStatusToString( stat ).c_str() );
00233         if( throwOnFailure )
00234                 throwPropertyException( stat, property );
00235 
00236         if( _gPropLogging > 0 )
00237                 Log::print( "Retrieved int property %s[%d], was given %d.",  property, idx, value );
00238         return value;
00239 }
00240 
00241 }