X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FProcessObject.h;fp=lib%2FcpPlugins%2FProcessObject.h;h=896346de444f420d78d532c609eb93adcde2b221;hb=2e142df11d6f312a2a2b5097b8da73571ed523e8;hp=0000000000000000000000000000000000000000;hpb=61b3659afe961ed248f30e26f9ca8f28fcfafddc;p=cpPlugins.git diff --git a/lib/cpPlugins/ProcessObject.h b/lib/cpPlugins/ProcessObject.h new file mode 100644 index 0000000..896346d --- /dev/null +++ b/lib/cpPlugins/ProcessObject.h @@ -0,0 +1,141 @@ +// ========================================================================= +// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co) +// ========================================================================= +#ifndef __cpPlugins__ProcessObject__h__ +#define __cpPlugins__ProcessObject__h__ + +#include +#include +#include +#include +#include + +namespace cpPlugins +{ + class Pipeline; + + /*! \brief + */ + class CPPLUGINS_EXPORT ProcessObject + : public Object, + public Parameters + { + cpPluginsTypeMacro( ProcessObject, Object ); + + public: + typedef Parameters TParameters; + typedef InputPort TInputPort; + typedef std::map< std::string, TInputPort > TInputs; + + public: + /*! @defgroup m_Name + * This object's unique identifier. This name will be used as the + * node's, in the graph interpretation of a pipeline, index inside the + * vertices container. + * @{ + */ + const std::string& GetName( ) const; + void SetName( const std::string& name ); + //! @} + + virtual void Print( std::ostream& o ) const override; + void SetPipeline( Pipeline* p ); + + //! IO management + virtual void SetInput( const std::string& name, DataObject* data ); + + virtual DataObject* GetInput( + const std::string& name, const unsigned int id + ); + virtual const DataObject* GetInput( + const std::string& name, const unsigned int id + ) const; + + virtual bool HasInput( const std::string& name ) const; + + std::set< std::string > GetInputsNames( ) const; + unsigned int GetNumberOfInputs( ) const; + unsigned int GetNumberOfInputs( const std::string& name ) const; + virtual std::set< std::string > GetAllInputsNames( ) const; + virtual std::set< std::string > GetAllOutputsNames( ) const; + + //! Pipeline management + virtual bool GetExecutionDebug( ) const; + virtual void SetExecutionDebug( bool d ); + virtual void ExecutionDebugOn( ); + virtual void ExecutionDebugOff( ); + const double& GetLastDuration( ) const; + virtual bool IsUpdated( + const TTimeStamp& d = TTimeRep::now( ) + ) const override; + + // Solve multiple inheritance method name conflict + virtual void Modified( ) override; + virtual void ModifiedInValue( const std::string& name ) override; + virtual void ModifiedInSet( const std::string& name ) override; + virtual void ModifiedInSequence( const std::string& name ) override; + virtual void ModifiedOutValue( const std::string& name ) override; + virtual void ModifiedOutSet( const std::string& name ) override; + virtual void ModifiedOutSequence( const std::string& name ) override; + virtual void ModifiedChoice( const std::string& name ) override; + virtual void Update( ); + + template< class _TXMLNode > + void SaveXML( _TXMLNode* node ) const; + + protected: + ProcessObject( ); + virtual ~ProcessObject( ); + + virtual bool _BeforeUpdate( ); + virtual void _GenerateData( ) = 0; + + template< class _TData > + const _TData* _GetInput( + const std::string& name, const unsigned int& id = 0 + ) const + { + TInputs::const_iterator i = this->m_Inputs.find( name ); + if( i != this->m_Inputs.end( ) ) + return( dynamic_cast< const _TData* >( i->second.Get( id ) ) ); + else + cpPluginsErrorMacro( + this, + << "Input \"" << name << "\" does not belong to this filter." + ); + } + + template< class _TData > + void _ConfigureInput( + const std::string& name, bool required, bool multiple + ) + { + if( this->m_Inputs.find( name ) != this->m_Inputs.end( ) ) + cpPluginsErrorMacro( + this, << "Input \"" << name << "\" already exists." + ); + TInputPort port; + port.Configure< _TData >( required, multiple ); + this->m_Inputs[ name ] = port; + } + + protected: + //! @ingroup m_Name + std::string m_Name; + + //! Input ports (only DataObjects) + TInputs m_Inputs; + + //! Last duration in microseconds + std::ostream* m_OutStream; + bool m_ExecutionDebug; + double m_LastDuration; + + //! Does this object belongs to a Pipeline? + std::weak_ptr< Pipeline > m_Pipeline; + }; // end class +} // end namespace + +#endif // __cpPlugins__ProcessObject__h__ + +// eof - $RCSfile$