TuttleOFX
1
|
00001 #include "OfxhClipImageSet.hpp" 00002 00003 #include <tuttle/host/ofx/OfxhImageEffectNodeDescriptor.hpp> 00004 00005 #include <boost/algorithm/string/join.hpp> 00006 #include <boost/algorithm/string/predicate.hpp> 00007 00008 namespace tuttle { 00009 namespace host { 00010 namespace ofx { 00011 namespace attribute { 00012 00013 OfxhClipImageSet::OfxhClipImageSet() 00014 : _clipPrefsDirty( true ) 00015 {} 00016 00017 OfxhClipImageSet::OfxhClipImageSet( const OfxhClipImageSet& other ) 00018 : _clipsByOrder( other._clipsByOrder.clone() ) 00019 , _clipPrefsDirty( true ) 00020 { 00021 initMapFromList(); 00022 } 00023 00024 void OfxhClipImageSet::initMapFromList() 00025 { 00026 for( ClipImageVector::iterator it = _clipsByOrder.begin(), itEnd = _clipsByOrder.end(); 00027 it != itEnd; 00028 ++it ) 00029 { 00030 _clipImages[it->getName()] = &( *it ); 00031 } 00032 } 00033 00034 OfxhClipImageSet::~OfxhClipImageSet() 00035 {} 00036 00037 bool OfxhClipImageSet::operator==( const This& other ) const 00038 { 00039 return _clipsByOrder == other._clipsByOrder; 00040 } 00041 00042 void OfxhClipImageSet::copyClipsValues( const OfxhClipImageSet& other ) 00043 { 00044 if( _clipsByOrder.size() != other._clipsByOrder.size() ) 00045 { 00046 BOOST_THROW_EXCEPTION( exception::Bug() 00047 << exception::dev( "You try to copy clips values, but the two lists are not identical." ) ); 00048 } 00049 00050 ClipImageVector::const_iterator oit = other._clipsByOrder.begin(), oitEnd = other._clipsByOrder.end(); 00051 for( ClipImageVector::iterator it = _clipsByOrder.begin(), itEnd = _clipsByOrder.end(); 00052 it != itEnd && oit != oitEnd; 00053 ++it, ++oit ) 00054 { 00055 OfxhClipImage& c = *it; 00056 const OfxhClipImage& oc = *oit; 00057 if( c.getName() != oc.getName() ) 00058 { 00059 BOOST_THROW_EXCEPTION( exception::Bug() 00060 << exception::dev( "You try to copy clips values, but it is not the same clips in the two lists." ) ); 00061 } 00062 c.copyValues( oc ); 00063 } 00064 } 00065 00066 void OfxhClipImageSet::populateClips( const imageEffect::OfxhImageEffectNodeDescriptor& descriptor ) OFX_EXCEPTION_SPEC 00067 { 00068 const imageEffect::OfxhImageEffectNodeDescriptor::ClipImageDescriptorVector& clips = descriptor.getClipsByOrder(); 00069 00070 _clipsByOrder.reserve( clips.size() ); 00071 /// @todo tuttle don't manipulate clip here, delegate to ClipInstanceSet 00072 for( imageEffect::OfxhImageEffectNodeDescriptor::ClipImageDescriptorVector::const_iterator it = clips.begin(), itEnd = clips.end(); 00073 it != itEnd; 00074 ++it ) 00075 { 00076 const std::string& name = it->getName(); 00077 // foreach clip descriptor make a ClipImageInstance 00078 OfxhClipImage* instance = newClipImage( *it ); //( this, *it, counter ); 00079 if( !instance ) 00080 BOOST_THROW_EXCEPTION( exception::Bug() 00081 << exception::dev( "Error on ClipImage creation." ) ); 00082 00083 _clipsByOrder.push_back( instance ); 00084 _clipImages[name] = instance; 00085 } 00086 } 00087 00088 OfxhClipImage& OfxhClipImageSet::getClip( const std::string& name, const bool acceptPartialName ) 00089 { 00090 ClipImageMap::const_iterator it = _clipImages.find( name ); 00091 00092 if( it != _clipImages.end() ) 00093 return *it->second; 00094 00095 std::vector<std::string> matches; 00096 OfxhClipImage* res = NULL; 00097 if( acceptPartialName ) 00098 { 00099 BOOST_FOREACH( ClipImageMap::value_type& p, _clipImages ) 00100 { 00101 if( boost::algorithm::starts_with( p.first, name ) ) 00102 { 00103 matches.push_back( p.first ); 00104 res = p.second; 00105 } 00106 } 00107 if( matches.size() > 1 ) 00108 { 00109 BOOST_THROW_EXCEPTION( exception::Value() 00110 << exception::user() + "Ambiguous partial clip name \"" + name + "\". Possible values are: " + boost::algorithm::join( matches, ", " ) + "." 00111 ); 00112 } 00113 } 00114 00115 if( matches.size() == 0 ) 00116 { 00117 std::ostringstream ss; 00118 ss << "Clip not found (" << name << ").\n"; 00119 ss << "List of existing clips ["; 00120 BOOST_FOREACH( const ClipImageMap::value_type& c, _clipImages ) 00121 { 00122 ss << "(\"" << c.first << "\":\"" << c.second->getClipIdentifier() << "\"), "; 00123 } 00124 ss << "].\n"; 00125 BOOST_THROW_EXCEPTION( OfxhException( ss.str() ) ); 00126 } 00127 return *res; 00128 } 00129 00130 OfxhClipImage* OfxhClipImageSet::getClipPtr( const std::string& name, const bool acceptPartialName ) 00131 { 00132 try 00133 { 00134 return &this->getClip( name, acceptPartialName ); 00135 } 00136 catch(...) 00137 { 00138 return NULL; 00139 } 00140 } 00141 00142 const OfxhClipImage* OfxhClipImageSet::getClipPtr( const std::string& name, const bool acceptPartialName ) const 00143 { 00144 try 00145 { 00146 return &this->getClip( name, acceptPartialName ); 00147 } 00148 catch(...) 00149 { 00150 return NULL; 00151 } 00152 } 00153 00154 00155 } 00156 } 00157 } 00158 } 00159