TuttleOFX
1
|
00001 #ifndef _TUTTLE_PLUGIN_ISACTIVEFUNCTOR_HPP_ 00002 #define _TUTTLE_PLUGIN_ISACTIVEFUNCTOR_HPP_ 00003 00004 #include <tuttle/plugin/global.hpp> 00005 00006 #include <ofxsParam.h> 00007 00008 #include <boost/ptr_container/ptr_vector.hpp> 00009 #include <boost/foreach.hpp> 00010 00011 namespace tuttle { 00012 namespace plugin { 00013 namespace interact { 00014 00015 struct IsActiveFunctor 00016 { 00017 typedef IsActiveFunctor This; 00018 virtual ~IsActiveFunctor() = 0; 00019 virtual bool active() const = 0; 00020 virtual This* clone() const = 0; 00021 00022 }; 00023 00024 inline IsActiveFunctor* new_clone( const IsActiveFunctor& a ) 00025 { 00026 return a.clone(); 00027 } 00028 00029 template<bool negate = false> 00030 struct AlwaysActiveFunctor : public IsActiveFunctor 00031 { 00032 typedef AlwaysActiveFunctor<negate> This; 00033 00034 bool active() const { return !negate; } 00035 This* clone() const { return new This(*this); } 00036 }; 00037 00038 template<bool negate = false> 00039 class IsEnableParamFunctor : public IsActiveFunctor 00040 { 00041 typedef IsEnableParamFunctor<negate> This; 00042 OFX::Param* _param; 00043 00044 public: 00045 IsEnableParamFunctor( OFX::Param* param ) 00046 : _param( param ) 00047 {} 00048 bool active() const { return _param->getIsEnable() != negate; } 00049 This* clone() const { return new This(*this); } 00050 }; 00051 00052 template<bool negate = false> 00053 class IsNotSecretParamFunctor : public IsActiveFunctor 00054 { 00055 typedef IsNotSecretParamFunctor<negate> This; 00056 OFX::Param* _param; 00057 00058 public: 00059 IsNotSecretParamFunctor( OFX::Param* param ) 00060 : _param( param ) 00061 {} 00062 bool active() const { return _param->getIsSecret() == negate; } 00063 This* clone() const { return new This(*this); } 00064 }; 00065 00066 template<bool negate = false> 00067 class IsActiveBooleanParamFunctor : public IsActiveFunctor 00068 { 00069 typedef IsActiveBooleanParamFunctor<negate> This; 00070 OFX::BooleanParam* _param; 00071 00072 public: 00073 IsActiveBooleanParamFunctor( OFX::BooleanParam* param ) 00074 : _param( param ) 00075 {} 00076 00077 bool active() const { return _param->getValue() != negate; } 00078 This* clone() const { return new This(*this); } 00079 }; 00080 00081 template<bool negate = false> 00082 class IsActiveChoiceParamFunctor : public IsActiveFunctor 00083 { 00084 typedef IsActiveChoiceParamFunctor<negate> This; 00085 OFX::ChoiceParam* _param; 00086 00087 public: 00088 IsActiveChoiceParamFunctor( OFX::ChoiceParam* param ) 00089 : _param( param ) 00090 {} 00091 00092 bool active() const { return _param->getValue() != negate; } 00093 This* clone() const { return new This(*this); } 00094 }; 00095 00096 template<bool negate = false> 00097 class AndActiveFunctor : public IsActiveFunctor 00098 { 00099 typedef AndActiveFunctor<negate> This; 00100 boost::ptr_vector<IsActiveFunctor> _list; 00101 public: 00102 void push_back( IsActiveFunctor* f ) 00103 { 00104 _list.push_back(f); 00105 } 00106 00107 bool active() const 00108 { 00109 BOOST_FOREACH( const IsActiveFunctor& f, _list ) 00110 { 00111 if( ! f.active() ) 00112 { 00113 return negate; 00114 } 00115 } 00116 return !negate; 00117 } 00118 This* clone() const { return new This(*this); } 00119 }; 00120 00121 template<bool negate = false> 00122 class OrActiveFunctor : public IsActiveFunctor 00123 { 00124 typedef OrActiveFunctor<negate> This; 00125 boost::ptr_vector<IsActiveFunctor> _list; 00126 public: 00127 void push_back( IsActiveFunctor* f ) 00128 { 00129 _list.push_back(f); 00130 } 00131 00132 bool active() const 00133 { 00134 BOOST_FOREACH( const IsActiveFunctor& f, _list ) 00135 { 00136 if( f.active() ) 00137 { 00138 return !negate; 00139 } 00140 } 00141 return negate; 00142 } 00143 This* clone() const { return new This(*this); } 00144 }; 00145 00146 00147 00148 } 00149 } 00150 } 00151 00152 #endif 00153