Program: bbtk
Module: $RCSfile: bbtkBlackBox.h,v $
Language: C++
- Date: $Date: 2008/12/10 09:33:18 $
- Version: $Revision: 1.20 $
+ Date: $Date: 2008/12/11 09:50:35 $
+ Version: $Revision: 1.21 $
=========================================================================*/
/* ---------------------------------------------------------------------
class BlackBoxOutputConnector;
-#define BBTK_MAKE_OUTPUT_OBSERVER(OBJECT,METHOD) \
- boost::bind( METHOD, OBJECT, _1, _2, _3)
class BBTK_EXPORT BlackBox : public Object
{
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)(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<std::string>&
- 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
/// 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<std::string>&
+ 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
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();
/// 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:
//==================================================================
// ATTRIBUTES
- /// The status of the box
- // IOStatus bbmStatus;
/// Is the box executing ?
bool bbmExecuting;
/// The name of the black-box
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)