TuttleOFX  1
TuttleOFX/libraries/tuttle/src/tuttle/host/attribute/ParamChoice.cpp
Go to the documentation of this file.
00001 #include "ParamChoice.hpp"
00002 #include "expression.hpp"
00003 
00004 #include <tuttle/host/INode.hpp>
00005 
00006 namespace tuttle {
00007 namespace host {
00008 namespace attribute {
00009 
00010 ParamChoice::ParamChoice( INode&                           effect,
00011                           const std::string&                         name,
00012                           const ofx::attribute::OfxhParamDescriptor& descriptor )
00013         : Param( effect )
00014         , ofx::attribute::OfxhParamChoice( descriptor, name, effect.getParamSet() )
00015 {
00016         _value = getDefault();
00017 }
00018 
00019 int ParamChoice::getDefault() const
00020 {
00021         return getProperties().getIntProperty( kOfxParamPropDefault );
00022 }
00023 
00024 void ParamChoice::getValue( int& v ) const OFX_EXCEPTION_SPEC
00025 {
00026         v = _value;
00027 }
00028 
00029 void ParamChoice::getValueAtTime( const OfxTime time, int& v ) const OFX_EXCEPTION_SPEC
00030 {
00031         v = _value; ///< @todo: in time !
00032 }
00033 
00034 void ParamChoice::setValue( const int& v, const ofx::attribute::EChange change ) OFX_EXCEPTION_SPEC
00035 {
00036         const std::size_t nbKeys = this->getChoiceKeys().size();
00037         if( v < 0 ||
00038             static_cast<std::size_t>(v) > nbKeys )
00039         {
00040                 BOOST_THROW_EXCEPTION( exception::Value()
00041                                 << exception::user() + "Choice index is out of range. Index is "+v+" for " + nbKeys + " values."
00042                         );
00043         }
00044         _value = v;
00045         paramChanged( change );
00046 }
00047 
00048 void ParamChoice::setValueAtTime( const OfxTime time, const int& v, const ofx::attribute::EChange change ) OFX_EXCEPTION_SPEC
00049 {
00050         const std::size_t nbKeys = this->getChoiceKeys().size();
00051         if( v < 0 ||
00052             static_cast<std::size_t>(v) > nbKeys )
00053         {
00054                 BOOST_THROW_EXCEPTION( exception::Value()
00055                                 << exception::user() + "Choice index is out of range. Index is "+v+" for " + nbKeys + " values."
00056                         );
00057         }
00058         _value = v; ///< @todo: in time !
00059         paramChanged( change );
00060 }
00061 
00062 void ParamChoice::setValueFromExpression( const std::string& value, const ofx::attribute::EChange change ) OFX_EXCEPTION_SPEC
00063 {
00064         try
00065         {
00066                 const std::string key = extractValueFromExpression<std::string>( value );
00067                 OfxhParamChoice::setValue( key, change );
00068                 return;
00069         }
00070         catch(...)
00071         {
00072                 try
00073                 {
00074                         const int id = extractValueFromExpression<int>( value );
00075                         this->setValue( id, change );
00076                         return;
00077                 }
00078                 catch(...)
00079                 {}
00080                 throw;
00081         }
00082 }
00083 
00084 void ParamChoice::copy( const ParamChoice& p ) OFX_EXCEPTION_SPEC
00085 {
00086         _value = p._value;
00087         //      paramChanged( ofx::attribute::eChangeUserEdited );
00088 }
00089 
00090 void ParamChoice::copy( const OfxhParam& p ) OFX_EXCEPTION_SPEC
00091 {
00092         const ParamChoice& param = dynamic_cast<const ParamChoice&>( p );
00093 
00094         copy( param );
00095 }
00096 
00097 }
00098 }
00099 }
00100