TuttleOFX  1
OfxhParamSet.hpp
Go to the documentation of this file.
00001 #ifndef _TUTTLE_HOST_OFX_PARAM_PARAMSET_HPP_
00002 #define _TUTTLE_HOST_OFX_PARAM_PARAMSET_HPP_
00003 
00004 #include "OfxhParamSetAccessor.hpp"
00005 #include "OfxhParam.hpp"
00006 
00007 #include <tuttle/host/ofx/OfxhIObject.hpp>
00008 
00009 #include <boost/ptr_container/ptr_vector.hpp>
00010 #include <boost/foreach.hpp>
00011 
00012 #include <map>
00013 
00014 namespace tuttle {
00015 namespace host {
00016 namespace ofx {
00017 namespace attribute {
00018 
00019 /// A set of parameters
00020 ///
00021 /// As we are the owning object we delete the params inside ourselves. It was tempting
00022 /// to make params autoref objects and have shared ownership with the client code
00023 /// but that adds complexity for no strong gain.
00024 class OfxhParamSet
00025         : public OfxhParamSetAccessor
00026         , virtual public OfxhIObject
00027 {
00028 public:
00029         typedef OfxhParamSet This;
00030         typedef std::map<std::string, OfxhParam*> ParamMap;
00031         typedef boost::ptr_vector<OfxhParam> ParamVector;
00032 
00033 protected:
00034         ParamMap _params;             ///< params by name
00035         ParamMap _paramsByScriptName; ///< params by script name
00036         ParamVector _paramVector;     ///< params list
00037 
00038 public:
00039         /// The propery set being passed in belongs to the owning
00040         /// plugin instance.
00041         explicit OfxhParamSet();
00042 
00043         explicit OfxhParamSet( const OfxhParamSet& other );
00044 
00045         virtual ~OfxhParamSet() = 0;
00046 
00047         void operator=( const OfxhParamSet& other );
00048 
00049         void copyParamsValues( const OfxhParamSet& other );
00050 
00051         bool operator==( const This& other ) const { return _paramVector == other._paramVector; }
00052 
00053         bool operator!=( const This& other ) const { return !This::operator==( other ); }
00054         
00055         std::size_t getHashAtTime( const OfxTime time ) const;
00056         
00057         /// obtain a handle on this set for passing to the C api
00058         OfxParamSetHandle getParamSetHandle() const { return ( OfxParamSetHandle ) this; }
00059 
00060         const ParamMap& getParamsByName() const { return _params; }
00061         ParamMap&       getParamsByName()       { return _params; }
00062 
00063         const ParamMap& getParamsByScriptName() const { return _paramsByScriptName; }
00064         ParamMap&       getParamsByScriptName()       { return _paramsByScriptName; }
00065 
00066         const ParamVector& getParamVector() const { return _paramVector; }
00067         ParamVector&       getParamVector()       { return _paramVector; }
00068 
00069         std::size_t getNbParams() const { return _params.size(); }
00070         
00071         OfxhParam& getParam( const std::string& name );
00072         const OfxhParam& getParam( const std::string& name ) const { return const_cast<This*>( this )->getParam( name ); }
00073 
00074         OfxhParam& getParamByScriptName( const std::string& scriptName, const bool acceptPartialName = false );
00075         const OfxhParam& getParamByScriptName( const std::string& name, const bool acceptPartialName = false ) const { return const_cast<This*>( this )->getParamByScriptName( name, acceptPartialName ); }
00076         OfxhParam* getParamPtrByScriptName( const std::string& name, const bool acceptPartialName = false );
00077         const OfxhParam* getParamPtrByScriptName( const std::string& name, const bool acceptPartialName = false ) const;
00078 
00079         // get the param
00080         OfxhParam& getParam( const std::size_t index );
00081         const OfxhParam& getParam( const std::size_t index ) const { return const_cast<This*>( this )->getParam( index ); }
00082 
00083         #ifndef SWIG
00084         /// The inheriting plugin instance needs to set this up to deal with
00085         /// plug-ins changing their own values.
00086         virtual void paramChanged( const attribute::OfxhParam& param, const EChange change ) = 0;
00087 
00088         /// Triggered when the plug-in calls OfxParameterSuiteV1::paramEditBegin
00089         ///
00090         /// Client host code needs to implement this
00091         virtual void editBegin( const std::string& name ) OFX_EXCEPTION_SPEC = 0;
00092 
00093         /// Triggered when the plug-in calls OfxParameterSuiteV1::paramEditEnd
00094         ///
00095         /// Client host code needs to implement this
00096         virtual void editEnd() OFX_EXCEPTION_SPEC = 0;
00097 
00098 protected:
00099         /// reference a param
00100 //      virtual void referenceParam( const std::string& name, OfxhParam* instance ) OFX_EXCEPTION_SPEC;
00101 
00102         /// add a param
00103         virtual void addParam( OfxhParam* instance ) OFX_EXCEPTION_SPEC;
00104 
00105         /// make a parameter instance
00106         ///
00107         /// Client host code needs to implement this
00108         virtual OfxhParam* newParam( const OfxhParamDescriptor& Descriptor ) OFX_EXCEPTION_SPEC = 0;
00109 
00110         void reserveParameters( const std::size_t size ) { _paramVector.reserve(size); }
00111 
00112 private:
00113         void initMapFromList();
00114         #endif
00115 };
00116 
00117 }
00118 }
00119 }
00120 }
00121 
00122 #endif
00123