]> Creatis software - bbtk.git/blobdiff - kernel/src/bbtkBlackBox.h
*** empty log message ***
[bbtk.git] / kernel / src / bbtkBlackBox.h
index 21bf67be52e52b9043ce8b299f37c70e74159df8..c4419ff19a1cd2bb099f63a0b734576c12132249 100644 (file)
@@ -2,8 +2,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkBlackBox.h,v $
   Language:  C++
-  Date:      $Date: 2009/05/28 08:12:05 $
-  Version:   $Revision: 1.26 $
+  Date:      $Date: 2009/06/08 14:50:02 $
+  Version:   $Revision: 1.27 $
 =========================================================================*/
 
 /* ---------------------------------------------------------------------
@@ -75,9 +75,12 @@ namespace bbtk
   class BBTK_EXPORT BlackBox : public Object
   {
     BBTK_ABSTRACT_OBJECT_INTERFACE(BlackBox);
+
+
   public: 
+
     //==================================================================
-    // INTERFACE
+    // Types
     //==================================================================
     typedef boost::signals::trackable OutputChangeObserverType;
     typedef boost::signal<void (bbtk::BlackBox::Pointer,
@@ -92,15 +95,35 @@ namespace bbtk
     /// The type of map of input connector pointers
     typedef std::map<std::string, BlackBoxInputConnector*> 
     InputConnectorMapType;
+    //==================================================================
 
-    /// Returns the pointer on the descriptor of the box
-    virtual BlackBoxDescriptor::Pointer bbGetDescriptor() const = 0;
 
+    //==================================================================
+    /// @name Pipeline processing methods
+    ///  Methods which participate to pipeline processing.
+    //@{
+    /// Main processing method of the box.
+    virtual void bbExecute(bool force = false);
+    //@}
+    //==================================================================
+    
+
+
+    //==================================================================
     /// Returns a pointer on a clone of the box with name <name>
     virtual BlackBox::Pointer bbClone(const std::string& name) = 0;
+    //==================================================================
+    
 
-    /// User overloadable destruction method of a black box
-    virtual void bbUserDelete();
+   //==================================================================
+    /// @name General accessors
+    ///  Methods which give access to general informations on the box
+    //@{
+
+    /// Returns the pointer on the descriptor of the box
+    virtual BlackBoxDescriptor::Pointer bbGetDescriptor() const = 0;
 
     /// Returns the Name of the Type of the BlackBox
     const std::string& bbGetTypeName() const 
@@ -118,78 +141,93 @@ namespace bbtk
     
     /// Returns the parent of the BlackBox, i.e the BlackBox that contains it (0 if none)
     BlackBox::Pointer bbGetParent() const { return bbmParent.lock(); }
+    
+    //@}
+    //==================================================================
 
-
-    /// Main processing method of the box.
-    virtual void bbExecute(bool force = false);
-
-
  
 
+    //==================================================================
+    /// @name Inputs/Outputs related methods
+    ///  Methods related to the box inputs and outputs
+    //@{
 
     /// Returns true iff the BlackBox has an input of name label
     virtual bool bbHasInput(const std::string& label) const;
-    /// Returns true iff the BlackBox has an output of name label
-    virtual bool bbHasOutput(const std::string& label) const;
-
     ///  Gets the input type of a given label
     virtual TypeInfo bbGetInputType( const std::string &label ) const;
-    ///  Gets the output type of a given label
-    virtual TypeInfo bbGetOutputType( const std::string &label ) const;
-
+    /// Gets the status of the input called <name>
+    IOStatus bbGetInputStatus( const std::string &name ) const 
+    { return mInputConnectorMap.find(name)->second->GetStatus(); }
     ///  Gets the data of the input called <name>
     virtual Data bbGetInput( const std::string &name )  = 0;
-    ///  Gets the data of the output called <name>
-    virtual Data bbGetOutput( const std::string &name ) = 0;
+    ///  Gets the data of the input called <name> as a string using an Adaptor if possible (else returns empty string)
+    std::string bbGetInputAsString( const std::string &input); 
 
-    /// Sets the data of the input called <name>.
+   /// Sets the data of the input called <name>.
     /// If update_time is false then does not update ChangeTime of input
     virtual void bbSetInput( const std::string &name, Data data,
                             bool update_time = true ) = 0;
+    /// [SYSTEM]: Sets the data of the input called <name> which **MUST* be a pointer
     virtual void bbBruteForceSetInputPointer( const std::string &name, 
                                              void* data, 
                                              bool update_time = true) =0;
+    
+  
+    /// Returns true iff the BlackBox has an output of name label
+    virtual bool bbHasOutput(const std::string& label) const;
+    ///  Gets the output type of a given label
+    virtual TypeInfo bbGetOutputType( const std::string &label ) const;
+    ///  Gets the data of the output called <name>
+    virtual Data bbGetOutput( const std::string &name ) = 0;
+    ///  Gets the data of the output called <name> as a string using an Adaptor if possible (else returns empty string)
+    std::string bbGetOutputAsString( const std::string &output ); //,Factory *factory);
+    
     ///  Sets the data of the output called <name>
     virtual void bbSetOutput( const std::string &name, Data data) = 0;
 
 
-    /// Gets the status of the input called <name>
-    IOStatus bbGetInputStatus( const std::string &name ) const 
-    { return mInputConnectorMap.find(name)->second->GetStatus(); }
-
     ///  Returns the input connectors map
     InputConnectorMapType&  bbGetInputConnectorMap() 
     { return mInputConnectorMap; }
-    ///  Returns the output connectors map
-    OutputConnectorMapType& bbGetOutputConnectorMap() 
-    { return mOutputConnectorMap; }
     ///  Returns the input connectors map (const)
     const InputConnectorMapType&  bbGetInputConnectorMap() const 
     { return mInputConnectorMap; } 
+   ///  Returns the input connector
+    BlackBoxInputConnector&  bbGetInputConnector(const std::string& n) 
+    { return *(mInputConnectorMap.find(n)->second); }
+    ///  Returns the input connector (const)
+    const BlackBoxInputConnector&  bbGetInputConnector(const std::string& n) const
+    { return *(mInputConnectorMap.find(n)->second); }
+
+
+    ///  Returns the output connectors map
+    OutputConnectorMapType& bbGetOutputConnectorMap() 
+    { return mOutputConnectorMap; }
     ///  Returns the output connectors map (const)
     const OutputConnectorMapType& bbGetOutputConnectorMap() const 
     { return mOutputConnectorMap; }      
-
-    ///  Returns the input connector
-    BlackBoxInputConnector&  bbGetInputConnector(const std::string& n) 
-    { return *(mInputConnectorMap.find(n)->second); }
     ///  Returns the output connector
     BlackBoxOutputConnector& bbGetOutputConnector(const std::string& n) 
     { return *(mOutputConnectorMap.find(n)->second); }
-    ///  Returns the input connector (const)
-    const BlackBoxInputConnector&  bbGetInputConnector(const std::string& n) const
-    { return *(mInputConnectorMap.find(n)->second); }
-    ///  Returns the output connector (const)
+     ///  Returns the output connector (const)
     const BlackBoxOutputConnector& bbGetOutputConnector(const std::string& n) const 
     { return *(mOutputConnectorMap.find(n)->second); }
 
-    
+    //@}
+    //==================================================================
 
     /// Prints the Help on the BlackBox type 
     virtual void bbGetHelp(bool full=true) const;
 
+
+
+    //==================================================================
+    /// @name Output signals / observers related methods
+    ///  Methods related to signals emitted by outputs and the 
+    //@{
+
     //==================================================================
     /// Adds the function f to the list of functions to call when 
     /// the output changes.
@@ -243,99 +281,53 @@ namespace bbtk
                                             output_name,
                                             bool reaction = true);
    //==================================================================
+    //@}
 
 
 
-    //==================================================================
-   /// User can redefine this method to set 
-    /// the default values of the box inputs and outputs
-    /// (it is called in the box constructor)
-    virtual void bbUserSetDefaultValues() {}
-
-    /// User can redefine this method to initialize what must be 
-    /// initialized for the box to work, for example allocate dynamic data.
-    /// It is called once and only once before any call to bbUserCreateWidget
-    /// or bbUserProcess.
-    /// What has been allocated here must be desalocated in 
-    /// bbFinalizeProcessing
-    virtual void bbUserInitializeProcessing() {}
-
-    /// User must redefine this method to uninitialize what has been
-    /// initialized in bbUserInitializeProcessing,
-    /// typically desallocate memory that has been allocated dynamically.
-    /// It is called in the box destructor if and only if (iff) 
-    /// bbUserInitializeProcessing has been called previously.
-    virtual void bbUserFinalizeProcessing() {}
-
-
-    /// Initializes processing IF NEEDED. 
-    /// Calls bbRecursiveInitializeProcessing if the box is in 
-    /// "uninitialized" state and put it in "initialized" state.
-    /// On construction, boxes are "uninitialized".
-    /// See also bbFinalizeProcessing
-    void bbInitializeProcessing();
-
-    /// Finalizes processing IF NEEDED.
-    /// Calls bbRecursiveFinalizeProcessing if the box is in 
-    /// "initialized" state and put it in "uninitialized" state.
-    /// On construction, boxes are "uninitialized".
-    /// See also bbInitializeProcessing
-    void bbFinalizeProcessing();
-
-    /// Abstract prototype of the method which 
-    /// Recursively calls itself for the parent black box and then
-    /// calls bbUserInitializeProcessing for its own class. 
-    /// It is redefined in each black box descendant.
-    /// Allows to call bbUserInitializeProcessing for all inherited classes
-    /// (like a constructor does)
-    virtual void bbRecursiveInitializeProcessing() {}
 
 
-    /// Abstract prototype of the method which 
-    /// calls bbUserFinalizeProcessing for its own class and then 
-    /// recursively calls itself for the parent black box.
-    /// It is redefined in each black box descendant.
-    /// Allows to call bbUserFinalizeProcessing for all inherited classes
-    /// (like a destructor does)
-   virtual void bbRecursiveFinalizeProcessing() {}
 
     //==================================================================
-
-
-   //==================================================================
-    // Common inputs / outputs to all boxes
-    /// Returns the value of the input "BoxProcessMode"
+    /// @name Common inputs / outputs to all boxes
+    //@{
+    /// Returns the value of the input 'BoxProcessMode'
     std::string bbGetInputBoxProcessMode() { return bbmBoxProcessMode; }
-    /// Sets the value of the input "BoxProcessMode"
+    /// Sets the value of the input 'BoxProcessMode'
     void bbSetInputBoxProcessMode(std::string a) { bbmBoxProcessMode = a; }
+    /// The possible values of the input 'BoxProcessMode'
     typedef enum
       {
        Pipeline,
        Always,
        Reactive
       }
-      BoxProcessModeValue;
+    BoxProcessModeValue;
     /// Returns the "decoded" value of the input "BoxProcessMode"
     BoxProcessModeValue bbGetBoxProcessModeValue() const;
-  
+    /// Returns true iff the input 'BoxProcessMode' is set to 'Reactive' (or a synonym)
     virtual bool bbBoxProcessModeIsReactive() const;
-
+    /// Returns true iff the input 'BoxProcessMode' is set to 'Always' (or a synonym)
     virtual bool bbBoxProcessModeIsAlways() const;
 
-    /// Returns the value of the input "Execute" 
+    /// Returns the value of the input 'BoxExecute'
     Void bbGetInputBoxExecute() { return Void(); }
-    /// Sets the value of the input "Execute"
+    /// Sets the value of the input 'BoxExecute'
     void bbSetInputBoxExecute(Void = 0) {}
 
-    /// Returns the value of the output "Change"
+    /// Returns the value of the output 'BoxChange'
     Void bbGetOutputBoxChange() { return Void(); }
-    /// Sets the value of the output "Change" : signal a modification
-    void bbSetOutputBoxChange(Void = 0) { } //bbSetModifiedStatus(); }
-
+    /// Sets the value of the output 'BoxChange' 
+    void bbSetOutputBoxChange(Void = 0) { } 
+    //@}
     //==================================================================    
 
 
-    //==================================================================    
+
+    
+    virtual void bbPrintHelp(BlackBox::Pointer parentblackbox, 
+                            int detail, int level
+                            );
 
     /// Does nothing here : overloaded in ComplexBlackBox
     void bbInsertHTMLGraph(  std::ofstream& s, 
@@ -346,6 +338,57 @@ namespace bbtk
                             bool relative_link ) 
     {}
 
+    
+    //==================================================================
+    /// @name Window related methods
+    //@{ 
+    virtual void bbSetShown(bool) {}
+    virtual bool bbIsShown() { return false; }
+    //@}
+    //==================================================================
+
+  protected:
+
+
+
+   //==================================================================
+    /// @name User redefinable methods
+    ///  Virtual methods which can be redefined by inherited classes 
+    //@{
+
+
+    //==================================================================
+    /// User can redefine this method to set 
+    /// the default values of the box inputs and outputs
+    /// (it is called in the box constructor)
+    virtual void bbUserSetDefaultValues() {}
+
+    /// User can redefine this method to initialize what must be 
+    /// initialized for the box to work, for example allocate dynamic data.
+    /// It is called once and only once before any call to bbUserCreateWidget
+    /// or bbUserProcess.
+    /// What has been allocated here must be desalocated in 
+    /// bbFinalizeProcessing
+    virtual void bbUserInitializeProcessing() {}
+
+    /// User must redefine this method to uninitialize what has been
+    /// initialized in bbUserInitializeProcessing,
+    /// typically desallocate memory that has been allocated dynamically.
+    /// It is called in the box destructor if and only if (iff) 
+    /// bbUserInitializeProcessing has been called previously.
+    virtual void bbUserFinalizeProcessing() {}
+    ///
+    virtual void bbUserOnShow() {}
+
+    //==================================================================
+    // @}
+    //==================================================================
+
+
+
+
+    //==================================================================    
+
     /// Write Graphviz-dot description in file. 
     /// Here dumps a single box description (i/o) but overloaded 
     /// in ComplexBlackBox to dump the internal pipeline representation 
@@ -365,22 +408,15 @@ namespace bbtk
                                           int detail, int level);
     
      
-    virtual void bbShowRelations(BlackBox::Pointer parentblackbox, 
-                                int detail, int level
-                                );
     
-    std::string bbGetOutputAsString( const std::string &output ); //,Factory *factory);
-    std::string bbGetInputAsString( const std::string &input); //,Factory *factory);
-    virtual BlackBox::Pointer bbFindBlackBox(const std::string &blackboxname) 
+     virtual BlackBox::Pointer bbFindBlackBox(const std::string &blackboxname) 
     { return BlackBox::Pointer();}
 
     virtual void Check(bool recursive = true);
 
-    virtual void bbSetShown(bool) {}
-    virtual bool bbIsShown() { return false; }
-    virtual void bbUserOnShow() {}
 
-  protected:
+
     //==================================================================
     // PROTECTED PART : ACCESSIBLE TO THE BlackBox DEVELOPER 
     // (IN INHERITED CLASSES)
@@ -391,43 +427,11 @@ namespace bbtk
     //==================================================================
 
 
-    //==================================================================
-    /// Signals that the input whose connector is c has changed 
-    /// and propagates the info downward
-    /// ** NOT USER INTENDED **
-    virtual void bbSetStatusAndPropagate(BlackBoxInputConnector* c,
-                                        IOStatus s);
-    //==================================================================
-    
-  private:
-    //==================================================================
-    friend class Connection;
-    friend class ComplexBlackBox;
-
-    /// Sets the parent of the BlackBox
-    void bbSetParent(BlackBox::Pointer p) { bbmParent = p; }
-    
-
-    /// Connects the input <name> to the connection c
-    virtual void bbConnectInput( const std::string& name, 
-                                Connection* c);
-    /// Connects the output <name> to the connection c
-    virtual void bbConnectOutput( const std::string& name, 
-                                 Connection* c);
-    /// Disconnects the input <name> from the connection c
-    virtual void bbDisconnectInput( const std::string& name, 
-                                   Connection* c);
-    /// Disconnects the output <name> from the connection c
-    virtual void bbDisconnectOutput( const std::string& name, 
-                                    Connection* c);
 
     //==================================================================
-  protected: 
     /// @name Pipeline processing methods
     ///  Methods which participate to pipeline processing.
     //@{
-
-    
     //==================================================================   
     /// Recursive execution method
     /// 
@@ -475,46 +479,139 @@ namespace bbtk
     //==================================================================
     /// Computes the final IOStatus of inputs and outputs after processing
     void bbComputePostProcessStatus();
+    //@}
+    //==================================================================
+
+
+    //==================================================================
+    /// Signals that the input whose connector is c has changed 
+    /// and propagates the info downward
+    /// ** NOT USER INTENDED **
+    virtual void bbSetStatusAndPropagate(BlackBoxInputConnector* c,
+                                        IOStatus s);
+    //==================================================================
+    
+
+
+    //==================================================================
+    /// @name Box con(des)struction / initi(fin)alization methods
+    //@{
+
+    //==================================================================
+    /// Allocates the i/o connectors of the black box
+    virtual void bbAllocateConnectors();
+    /// Desallocates the i/o connectors of the black box
+    virtual void bbDesallocateConnectors();
+    /// Copies the values of the inputs/output from the BlackBox from
+    virtual void bbCopyIOValues(BlackBox& from);
+    //==================================================================
+    
+    //==================================================================  
+    /// Initializes processing IF NEEDED. 
+    /// Calls bbRecursiveInitializeProcessing if the box is in 
+    /// "uninitialized" state and put it in "initialized" state.
+    /// On construction, boxes are "uninitialized".
+    /// See also bbFinalizeProcessing
+    void bbInitializeProcessing();
+
+    /// Finalizes processing IF NEEDED.
+    /// Calls bbRecursiveFinalizeProcessing if the box is in 
+    /// "initialized" state and put it in "uninitialized" state.
+    /// On construction, boxes are "uninitialized".
+    /// See also bbInitializeProcessing
+    void bbFinalizeProcessing();
+
+    /// Abstract prototype of the method which 
+    /// Recursively calls itself for the parent black box and then
+    /// calls bbUserInitializeProcessing for its own class. 
+    /// It is redefined in each black box descendant.
+    /// Allows to call bbUserInitializeProcessing for all inherited classes
+    /// (like a constructor does)
+    virtual void bbRecursiveInitializeProcessing() {}
+
+
+    /// Abstract prototype of the method which 
+    /// calls bbUserFinalizeProcessing for its own class and then 
+    /// recursively calls itself for the parent black box.
+    /// It is redefined in each black box descendant.
+    /// Allows to call bbUserFinalizeProcessing for all inherited classes
+    /// (like a destructor does)
+    virtual void bbRecursiveFinalizeProcessing() {}
     //==================================================================
 
     //@}
-  public: 
+    //==================================================================
+
+
+
+  private:
+    //==================================================================
+    friend class Connection;
+    friend class ComplexBlackBox;
+
+    /// Sets the parent of the BlackBox
+    void bbSetParent(BlackBox::Pointer p) { bbmParent = p; }
+    
+    //==================================================================
+    /// @name Input/output connection/disconnection
+    /// INTERNAL METHODS used by a Connection to connect/disconnect
+    /// itself to the i/o connectors of the box
+    //@{
+
+    /// Connects the input <name> to the connection c
+    virtual void bbConnectInput( const std::string& name, 
+                                Connection* c);
+    /// Connects the output <name> to the connection c
+    virtual void bbConnectOutput( const std::string& name, 
+                                 Connection* c);
+    /// Disconnects the input <name> from the connection c
+    virtual void bbDisconnectInput( const std::string& name, 
+                                   Connection* c);
+    /// Disconnects the output <name> from the connection c
+    virtual void bbDisconnectOutput( const std::string& name, 
+                                    Connection* c);
+    //@}
+    //==================================================================
 
+    /// Returns true if the box can "react",
+    /// which means execute in response to an input change 
+    virtual bool bbCanReact() const;
+
+
+
+    //==================================================================
+    /// @name Manage the execution
+    //@{
     static bool bbGlobalGetSomeBoxExecuting();
     static void bbGlobalSetSomeBoxExecuting(bool b);
 
     static void bbGlobalSetFreezeExecution(bool b);
     static bool bbGlobalGetFreezeExecution();
 
-    /// Returns true if the box can "react",
-    /// which means execute in response to an input change 
-    virtual bool bbCanReact() const;
+    static void bbGlobalAddToExecutionList( BlackBox::Pointer b );
+    static void bbGlobalProcessExecutionList();
+
+    //@}
     
     /// Returns true iff the box is executing
     bool bbGetExecuting() const { return bbmExecuting; }
-
-  protected:  
-    static void bbGlobalAddToExecutionList( BlackBox::Pointer b );
-    static void bbGlobalProcessExecutionList();
     /// Sets the bbmExecuting bool returned by bbGetExecuting
     void bbSetExecuting(bool b) { bbmExecuting = b; }
 
+
+
+  protected:  
+
     //==================================================================
   protected:
-    //==================================================================
-    /// Allocates the i/o connectors of the black box
-    virtual void bbAllocateConnectors();
-    /// Desallocates the i/o connectors of the black box
-    virtual void bbDesallocateConnectors();
-    /// Copies the values of the inputs/output from the BlackBox from
-    virtual void bbCopyIOValues(BlackBox& from);
-    //==================================================================
 
-    //==================================================================
-    // Black box objects have a special deleter 
-    // which must take care of releasing the descriptor 
-    // **AFTER** the box is deleted 
-    // (Releasing it in the destructor may cause dl close and crash)
+
+     //==================================================================
+    /// Black box objects have a special deleter 
+    /// which must take care of releasing the descriptor 
+    /// **AFTER** the box is deleted 
+    /// (Releasing it in the destructor may cause dl close and crash)
     /// Black box deleter 
     /// 1) Calls the user overloadable bbDelete method
     /// 2) Releases the box descriptor
@@ -526,6 +623,7 @@ namespace bbtk
     //==================================================================
 
     //==================================================================
+    /// Like Object::MakePointer but returns a boost::shared_pointer which uses a BlackBox::Deleter to delete the object instead of the default Object::Deleter
     template <class U>
     static boost::shared_ptr<U> MakeBlackBoxPointer(U* s, bool lock = false)
     {
@@ -534,6 +632,10 @@ namespace bbtk
     //==================================================================
 
     //==================================================================
+    /// Effective deletion method called by the Deleter.
+    /// The default implementation is to issue 'delete this'
+    /// but it can be redefined in inherited classes to handle special deletion mechanisms (e.g. ref counting, private destructors, such as vtk objects deletion with method Delete, etc.).
+    /// \return The number of remaining references on the object after the call (if meaningfull...): used by bbtk to warn a user if another smart pointing system is still holding the object...
     virtual int bbDelete() { delete this; return 0; }
     //==================================================================