X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=kernel%2Fsrc%2FbbtkBlackBox.h;h=a8299e4ea918d5b232b9ec766da5b2d1574d954e;hb=f31300e2cc245436a25e7074a26158ac0eed1518;hp=b70ab75f747a07ad0171f1c07025ebaa9ace7853;hpb=3928b4ad06b5b5fd142f696f58a7828d064e2883;p=bbtk.git diff --git a/kernel/src/bbtkBlackBox.h b/kernel/src/bbtkBlackBox.h index b70ab75..a8299e4 100644 --- a/kernel/src/bbtkBlackBox.h +++ b/kernel/src/bbtkBlackBox.h @@ -2,8 +2,8 @@ Program: bbtk Module: $RCSfile: bbtkBlackBox.h,v $ Language: C++ - Date: $Date: 2008/12/08 12:53:47 $ - Version: $Revision: 1.17 $ + Date: $Date: 2008/12/11 09:50:35 $ + Version: $Revision: 1.21 $ =========================================================================*/ /* --------------------------------------------------------------------- @@ -62,6 +62,8 @@ namespace bbtk class Factory; class Connection; class BlackBoxOutputConnector; + + class BBTK_EXPORT BlackBox : public Object { @@ -115,58 +117,8 @@ namespace bbtk virtual void bbExecute(bool force = false); - /// The type of callback function when an output changes - // typedef BlackBoxOutputConnector::ChangeCallbackType OutputChangeCallbackType; - - /// Adds the function f to the list of functions to call when - /// the output changes. - /// f is of type ChangeCallbackType which is basically: - /// void (*ChangeCallbackType)(BlackBoxOutputConnector*) - /// To pass a member function 'f' of an instance 'c' of a class 'C' - /// as callback you have to 'bind' it, i.e. call: - /// AddChangeObserver ( "Out", boost::bind( &C::f , c, _1 ) ); - void AddChangeObserver(const std::string& output_name, - OutputChangeCallbackType f); - - /// Removes the function f from the list of functions to call when - /// the output changes (TO WRITE) - void RemoveChangeObserver(const std::string& output_name, - OutputChangeCallbackType f); - - - /// Signals that the BlackBox outputs have been modified - /// (without marking the box as MODIFIED because its output state is ok : don't care if you understand : use it !). - /// This method should be used by widgets in response - /// to user interaction when **ALL** outputs have been modified - /// (after the outputs has been updated !). - /// DO NOT PASS reaction = false OR WILL NOT WORK PROPERLY - /// ** USER INTENDED ** - virtual void bbSignalOutputModification(bool reaction = true); - /// Signals that the BlackBox output "output_name" has been modified - /// (without marking the box as MODIFIED because its output state is ok : don't care if you understand : use it !). - /// This method should be used by widgets in response to user interaction - /// only when **ONE** output has been modified - /// (after the output has been updated !) - /// DO NOT PASS reaction = false OR WILL NOT WORK PROPERLY - /// ** USER INTENDED ** - virtual void bbSignalOutputModification( const std::string& output_name, - bool reaction = true); - /// Signals that the BlackBox vector of outputs "output_name" - /// have been modified. - /// Should be used when more than ONE output is modified but not ALL - /// (optimization issue). - /// (without marking the box as MODIFIED because its output state is ok). - /// This method should be used by widgets in response to user interaction - /// When more than one output has been changed but not all - /// (after the outputs have been updated of course!) - /// DO NOT PASS reaction = false OR WILL NOT WORK PROPERLY - /// ** USER INTENDED ** - virtual void bbSignalOutputModification( const std::vector& - output_name, - bool reaction = true); - - /// Gets the status of the box - // virtual const IOStatus& bbGetStatus() const { return bbmStatus; } + + /// Returns true iff the BlackBox has an input of name label @@ -195,6 +147,10 @@ namespace bbtk virtual void bbSetOutput( const std::string &name, Data data) = 0; + /// Gets the status of the input called + IOStatus bbGetInputStatus( const std::string &name ) const + { return mInputConnectorMap.find(name)->second->GetStatus(); } + /// Returns the input connectors map InputConnectorMapType& bbGetInputConnectorMap() { return mInputConnectorMap; } @@ -227,16 +183,61 @@ namespace bbtk /// Prints the Help on the BlackBox type virtual void bbGetHelp(bool full=true) const; + //================================================================== + /// Adds the function f to the list of functions to call when + /// the output changes. + /// f is of type ChangeCallbackType which is basically: + /// void (*ChangeCallbackType)(bbtk::BlackBox::Pointer, + /// const std::string&, + /// bbtk::IOStatus) + /// To pass a member function 'f' of an instance 'c' of a class 'C' + /// as callback you have to 'bind' it, i.e. call: + /// bbAddOutputObserver ( "Out", boost::bind( &C::f , c, _1, _2, _3 ) ); + /// The convenience macro BBTK_BIND_OUTPUT_OBSERVER ( c, C::f ) does it for you + void bbAddOutputObserver(const std::string& output_name, + OutputChangeCallbackType f); + + /// Removes the function f from the list of functions to call when + /// the output changes (TO WRITE) + void bbRemoveOutputObserver(const std::string& output_name, + OutputChangeCallbackType f); + //================================================================== + + + //================================================================== + /// Signals that the BlackBox outputs have been modified + /// (without marking the box as MODIFIED because its output state is ok : don't care if you understand : use it !). + /// This method should be used by widgets in response + /// to user interaction when **ALL** outputs have been modified + /// (after the outputs has been updated !). + /// DO NOT PASS reaction = false OR WILL NOT WORK PROPERLY + /// ** USER INTENDED ** + virtual void bbSignalOutputModification(bool reaction = true); + /// Signals that the BlackBox output "output_name" has been modified + /// (without marking the box as MODIFIED because its output state is ok : don't care if you understand : use it !). + /// This method should be used by widgets in response to user interaction + /// only when **ONE** output has been modified + /// (after the output has been updated !) + /// DO NOT PASS reaction = false OR WILL NOT WORK PROPERLY + /// ** USER INTENDED ** + virtual void bbSignalOutputModification( const std::string& output_name, + bool reaction = true); + /// Signals that the BlackBox vector of outputs "output_name" + /// have been modified. + /// Should be used when more than ONE output is modified but not ALL + /// (optimization issue). + /// (without marking the box as MODIFIED because its output state is ok). + /// This method should be used by widgets in response to user interaction + /// When more than one output has been changed but not all + /// (after the outputs have been updated of course!) + /// DO NOT PASS reaction = false OR WILL NOT WORK PROPERLY + /// ** USER INTENDED ** + virtual void bbSignalOutputModification( const std::vector& + output_name, + bool reaction = true); + //================================================================== + - // Returns true iff the box is up-to-date - // (ChangeTime of inputs are all lower strictly to ChangeTime of outputs - - // i.e. max(inputs)<=min(outputs) ) - // bool bbIsUpToDate() { return mMaxInputChangeTime < mMinOutputChangeTime; } - // Returns true iff the box is out-of-date - // (At least one ChangeTime of an input is greater than one ChangeTime - // of an output - i.e. max(inputs)>min(outputs)) - // == !IsUpToDate() - // bool bbIsOutOfDate() { return mMaxInputChangeTime >= mMinOutputChangeTime; } //================================================================== // Common inputs / outputs to all boxes @@ -332,11 +333,6 @@ namespace bbtk /// ** NOT USER INTENDED ** virtual void bbSetStatusAndPropagate(BlackBoxInputConnector* c, IOStatus s); - /// Signals that the output whose connector is c has changed - /// and propagates the info downward - /// ** NOT USER INTENDED ** - virtual void bbSetStatusAndPropagate(BlackBoxOutputConnector* c, - IOStatus s); //================================================================== private: @@ -365,29 +361,33 @@ namespace bbtk protected: /// @name Pipeline processing methods /// Methods which participate to pipeline processing. - /// Some are pure virtual and prepare particular update mechanism which are implemented by descendents - /// The main method is bbBackwardUpdate which is called by bbExecute and implemented in UserBlackBox and ComplexBlackBox. - /// //@{ //================================================================== - /// Recursive pipeline processing in backward direction - /// (recursion is in backward direction however execution always - /// goes forward). - /// Pure virtual; defined in AtomicBlackBox and ComplexBlackBox + /// Recursive execution method /// /// \param caller : The connection which invoked the method; null if called by bbExecute - virtual void bbBackwardUpdate(Connection::Pointer caller) = 0; + virtual void bbRecursiveExecute(Connection::Pointer caller); //================================================================== //================================================================== /// Updates the BlackBox inputs - /// Calls BackwardUpdate on all BlackBoxInputConnector + /// Calls RecursiveExecute on all BlackBoxInputConnector /// \returns The maximum of final IOStatus after each input update IOStatus bbUpdateInputs(); //================================================================== + //================================================================== + /// Actual processing method (vitual) + /// Overloaded in AtomicBlacBox and descendants + virtual void bbProcess() + { + bbtkError("BlackBox::bbProcess called : how can this happen ?"); +// this->bbUserProcess(); + } + //================================================================== + //================================================================== /// Computes the final IOStatus of inputs and outputs after processing void bbComputePostProcessStatus(); @@ -402,11 +402,10 @@ namespace bbtk /// Shows the window associated to the box /// (called after bbProcess during bbExecute) /// Does nothing here but overloaded in WxBlackBox and WxContainerBlackBox - virtual void bbShowWindow(Connection::Pointer caller) { } - - virtual void bbHideWindow() {} - virtual void bbCloseWindow() { } - //================================================================== + // virtual void bbShowWindow(Connection::Pointer caller) { } + // virtual void bbHideWindow() {} + // virtual void bbCloseWindow() { } + //================================================================== //@} public: @@ -475,8 +474,6 @@ namespace bbtk //================================================================== // ATTRIBUTES - /// The status of the box - // IOStatus bbmStatus; /// Is the box executing ? bool bbmExecuting; /// The name of the black-box @@ -501,37 +498,15 @@ namespace bbtk InputConnectorMapType mInputConnectorMap; //================================================================== - /// The maximum ChangeTime of the inputs - // ChangeTime mMaxInputChangeTime; - /// The minimum ChangeTime of the outputs - // ChangeTime mMinOutputChangeTime; - - - protected: - //========================================================================= - /// Sets the ChangeTime of input - /* - void bbSetInputChangeTime(BlackBoxInputConnector* c, - const ChangeTime& t); - /// Sets the ChangeTime of output - void bbSetOutputChangeTime(BlackBoxOutputConnector* c, - const ChangeTime& t); - */ - // void bbUpdateMaxInputChangeTime(const ChangeTime& t); - // void bbUpdateMinOutputChangeTime(const ChangeTime& t); - - /// Set the change time of the input - // void bbSetInputChangeTime(const std::string& n, ChangeTime); - /// Set the change time of the output - // void bbSetOutputChangeTime(const std::string& n, ChangeTime); - - }; // Class BlackBox + /// Convenient macro to create output observer callbacks (freehand functions) from object and method pointer (see samples/SampleOutputObserver) +#define BBTK_MAKE_OUTPUT_OBSERVER(OBJECT,METHOD) \ + boost::bind( METHOD, OBJECT, _1, _2, _3)