TuttleOFX  1
TuttleOFX/libraries/tuttle/src/tuttle/host/ofx/attribute/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         /// @group Link to child parameters (no ownership)
00039         /// @{
00040         ParamMap _childParams;        ///< child params by name
00041         std::vector<OfxhParam*> _childParamVector; ///< child params list
00042         /// @}
00043 
00044 public:
00045         /// The propery set being passed in belongs to the owning
00046         /// plugin instance.
00047         explicit OfxhParamSet();
00048 
00049         explicit OfxhParamSet( const OfxhParamSet& other );
00050 
00051         virtual ~OfxhParamSet() = 0;
00052 
00053         OfxhParamSet& operator=( const OfxhParamSet& other );
00054 
00055         void copyParamsValues( const OfxhParamSet& other );
00056 
00057         bool operator==( const This& other ) const { return _paramVector == other._paramVector; }
00058 
00059         bool operator!=( const This& other ) const { return !This::operator==( other ); }
00060         
00061         std::size_t getHashAtTime( const OfxTime time ) const;
00062         
00063         /// obtain a handle on this set for passing to the C api
00064         OfxParamSetHandle getParamSetHandle() const { return ( OfxParamSetHandle ) this; }
00065 
00066         const ParamMap& getParamsByName() const { return _params; }
00067         ParamMap&       getParamsByName()       { return _params; }
00068 
00069         const ParamMap& getChildParamsByName() const { return _childParams; }
00070         ParamMap&       getChildParamsByName()       { return _childParams; }
00071 
00072         const ParamMap& getParamsByScriptName() const { return _paramsByScriptName; }
00073         ParamMap&       getParamsByScriptName()       { return _paramsByScriptName; }
00074 
00075         const ParamVector& getParamVector() const { return _paramVector; }
00076         ParamVector&       getParamVector()       { return _paramVector; }
00077 
00078         const std::vector<OfxhParam*>& getChildParamVector() const { return _childParamVector; }
00079         std::vector<OfxhParam*>&       getChildParamVector()       { return _childParamVector; }
00080 
00081         std::size_t getNbParams() const { return _params.size(); }
00082         std::size_t getNbChildParams() const { return _childParams.size(); }
00083         
00084         OfxhParam& getParam( const std::string& name );
00085         const OfxhParam& getParam( const std::string& name ) const { return const_cast<This*>( this )->getParam( name ); }
00086 
00087         OfxhParam& getParamByScriptName( const std::string& scriptName, const bool acceptPartialName = false );
00088         const OfxhParam& getParamByScriptName( const std::string& name, const bool acceptPartialName = false ) const { return const_cast<This*>( this )->getParamByScriptName( name, acceptPartialName ); }
00089         OfxhParam* getParamPtrByScriptName( const std::string& name, const bool acceptPartialName = false );
00090         const OfxhParam* getParamPtrByScriptName( const std::string& name, const bool acceptPartialName = false ) const;
00091 
00092         // get the param
00093         OfxhParam& getParam( const std::size_t index );
00094         const OfxhParam& getParam( const std::size_t index ) const { return const_cast<This*>( this )->getParam( index ); }
00095         OfxhParam& getChildParam( const std::size_t index );
00096         const OfxhParam& getChildParam( const std::size_t index ) const { return const_cast<This*>( this )->getChildParam( index ); }
00097 
00098         #ifndef SWIG
00099         /// The inheriting plugin instance needs to set this up to deal with
00100         /// plug-ins changing their own values.
00101         virtual void paramChanged( const attribute::OfxhParam& param, const EChange change ) = 0;
00102 
00103         /// Triggered when the plug-in calls OfxParameterSuiteV1::paramEditBegin
00104         ///
00105         /// Client host code needs to implement this
00106         virtual void editBegin( const std::string& name ) OFX_EXCEPTION_SPEC = 0;
00107 
00108         /// Triggered when the plug-in calls OfxParameterSuiteV1::paramEditEnd
00109         ///
00110         /// Client host code needs to implement this
00111         virtual void editEnd() OFX_EXCEPTION_SPEC = 0;
00112 
00113         /// reference a param
00114 //      virtual void referenceParam( const std::string& name, OfxhParam* instance ) OFX_EXCEPTION_SPEC;
00115         void declareChildParam( OfxhParam& childParam );
00116 
00117 protected:
00118         /// add a param
00119         virtual void addParam( OfxhParam* instance ) OFX_EXCEPTION_SPEC;
00120 
00121         void reserveParameters( const std::size_t size ) { _paramVector.reserve(size); }
00122 
00123 private:
00124         void initMapFromList();
00125         #endif
00126 };
00127 
00128 }
00129 }
00130 }
00131 }
00132 
00133 #endif
00134