bbtkBlackBox.h

Go to the documentation of this file.
00001 /*=========================================================================                                                                               
00002   Program:   bbtk
00003   Module:    $RCSfile: bbtkBlackBox.h,v $
00004   Language:  C++
00005   Date:      $Date: 2008/10/17 08:18:12 $
00006   Version:   $Revision: 1.13 $
00007 =========================================================================*/
00008 
00009 /* ---------------------------------------------------------------------
00010 
00011 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
00012 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
00013 *
00014 *  This software is governed by the CeCILL-B license under French law and 
00015 *  abiding by the rules of distribution of free software. You can  use, 
00016 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
00017 *  license as circulated by CEA, CNRS and INRIA at the following URL 
00018 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
00019 *  or in the file LICENSE.txt.
00020 *
00021 *  As a counterpart to the access to the source code and  rights to copy,
00022 *  modify and redistribute granted by the license, users are provided only
00023 *  with a limited warranty  and the software's author,  the holder of the
00024 *  economic rights,  and the successive licensors  have only  limited
00025 *  liability. 
00026 *
00027 *  The fact that you are presently reading this means that you have had
00028 *  knowledge of the CeCILL-B license and that you accept its terms.
00029 * ------------------------------------------------------------------------ */                                                                         
00030 
00031 
00032 
00043 #ifndef __bbtkBlackBox_h__
00044 #define __bbtkBlackBox_h__
00045 
00046 #include "bbtkSystem.h"
00047 #include "bbtkBlackBoxDescriptor.h"
00048 #include "bbtkBlackBoxInputConnector.h"
00049 #include "bbtkBlackBoxOutputConnector.h"
00050 #include <set>
00051 
00052 namespace bbtk
00053 {
00054 
00055   
00056   struct Void { Void(int = 0) {} };
00057   
00058   class Factory;
00059   class Connection;
00060 
00061   class BBTK_EXPORT BlackBox : public Object
00062   {
00063     BBTK_ABSTRACT_OBJECT_INTERFACE(BlackBox);
00064   public: 
00065     //==================================================================
00066     // INTERFACE
00067     //==================================================================
00068  
00070     typedef std::map<std::string, BlackBoxOutputConnector*> 
00071     OutputConnectorMapType;
00073     typedef std::map<std::string, BlackBoxInputConnector*> 
00074     InputConnectorMapType;
00075 
00077     virtual BlackBoxDescriptor::Pointer bbGetDescriptor() const = 0;
00078 
00080     virtual BlackBox::Pointer bbClone(const std::string& name) = 0;
00081 
00083     virtual void bbUserDelete();
00084 
00086     const std::string& bbGetTypeName() const 
00087       { return bbGetDescriptor()->GetTypeName(); }
00088  
00089     
00091     const std::string& bbGetName() const { return bbmName; }
00092 
00094     virtual std::string bbGetFullName() const;
00095 
00097     virtual std::string bbGetNameWithParent() const;
00098     
00100     BlackBox::Pointer bbGetParent() const { return bbmParent.lock(); }
00101 
00102 
00104     virtual void bbExecute(bool force = false);
00105 
00108     virtual void bbSetModifiedStatus(BlackBoxInputConnector* c = 0);
00114     virtual void bbSignalOutputModification(bool reaction = true);
00120     virtual void bbSignalOutputModification( const std::string& output_name,
00121 bool reaction = true);
00128     virtual void bbSignalOutputModification( const std::vector<std::string>& output_name,
00129 bool reaction = true);
00130 
00132     virtual const IOStatus& bbGetStatus() const { return bbmStatus; }
00133 
00134 
00136     virtual bool bbHasInput(const std::string& label) const;
00138     virtual bool bbHasOutput(const std::string& label) const;
00139 
00141     virtual TypeInfo bbGetInputType( const std::string &label ) const;
00143     virtual TypeInfo bbGetOutputType( const std::string &label ) const;
00144 
00146     virtual Data bbGetInput( const std::string &name )  = 0;
00148     virtual Data bbGetOutput( const std::string &name ) = 0;
00149 
00152     virtual void bbSetInput( const std::string &name, Data data,
00153                              bool setModified = true ) = 0;
00154     virtual void bbBruteForceSetInputPointer( const std::string &name, 
00155                                               void* data, 
00156                                               bool setModified = true) =0;
00158     virtual void bbSetOutput( const std::string &name, Data data) = 0;
00159 
00160 
00162     InputConnectorMapType&  bbGetInputConnectorMap() 
00163     { return mInputConnectorMap; }
00165     OutputConnectorMapType& bbGetOutputConnectorMap() 
00166     { return mOutputConnectorMap; }
00168     const InputConnectorMapType&  bbGetInputConnectorMap() const 
00169     { return mInputConnectorMap; } 
00171     const OutputConnectorMapType& bbGetOutputConnectorMap() const 
00172     { return mOutputConnectorMap; }      
00173  
00174 
00176     virtual void bbGetHelp(bool full=true) const;
00177 
00178 
00179     //==================================================================
00180     // Common inputs / outputs to all boxes
00182     std::string bbGetInputBoxProcessMode() { return bbmBoxProcessMode; }
00184     void bbSetInputBoxProcessMode(std::string a) { bbmBoxProcessMode = a; }
00185     typedef enum
00186       {
00187         Pipeline,
00188         Always,
00189         Reactive
00190       }
00191       BoxProcessModeValue;
00193     BoxProcessModeValue bbGetBoxProcessModeValue() const;
00194   
00195     virtual bool bbBoxProcessModeIsReactive() const;
00196 
00197     virtual bool bbBoxProcessModeIsAlways() const;
00198 
00200     Void bbGetInputBoxExecute() { return Void(); }
00202     void bbSetInputBoxExecute(Void = 0) {}
00203 
00205     Void bbGetOutputBoxChange() { return Void(); }
00207     void bbSetOutputBoxChange(Void = 0) { bbSetModifiedStatus(); }
00208 
00209     //==================================================================    
00210 
00211 
00212     //==================================================================    
00213 
00215     void bbInsertHTMLGraph(  std::ofstream& s, 
00216                              int detail, 
00217                              int level,
00218                              bool instanceOrtype,
00219                              const std::string& output_dir,
00220                              bool relative_link ) 
00221     {}
00222 
00231     virtual void bbWriteDotFileBlackBox(FILE *ff,
00232                                         BlackBox::Pointer parentblackbox, 
00233                                         int detail, int level, 
00234                                         bool instanceOrtype,
00235                                         bool relative_link );
00237     virtual void bbWriteDotInputOutputName(FILE *ff,
00238                                            bool inputoutput, 
00239                                            int detail, int level);
00240     
00241      
00242     virtual void bbShowRelations(BlackBox::Pointer parentblackbox, 
00243                                  int detail, int level
00244                                  );
00245     
00246     std::string bbGetOutputAsString( const std::string &output ); //,Factory *factory);
00247     std::string bbGetInputAsString( const std::string &input); //,Factory *factory);
00248     virtual BlackBox::Pointer bbFindBlackBox(const std::string &blackboxname) 
00249     { return BlackBox::Pointer();}
00250 
00251     virtual void Check(bool recursive = true);
00252 
00253         virtual void bbUserOnShow() { }
00254         void bbUserOnShowWidget(std::string nameInput);
00255 
00256 
00257   protected:
00258     //==================================================================
00259     // PROTECTED PART : ACCESSIBLE TO THE BlackBox DEVELOPER 
00260     // (IN INHERITED CLASSES)
00262     BlackBox(const std::string &name);
00264     BlackBox(BlackBox& from, const std::string &name);
00265     //==================================================================
00266 
00267 
00268     //==================================================================
00270     void bbSetStatus( IOStatus t) { bbmStatus = t; } 
00271     //==================================================================
00272     
00273   private:
00274     friend class Connection;
00275     friend class ComplexBlackBox;
00276 
00278     void bbSetParent(BlackBox::Pointer p) { bbmParent = p; }
00279     
00280 
00282     virtual void bbConnectInput( const std::string& name, 
00283                                  Connection* c);
00285     virtual void bbConnectOutput( const std::string& name, 
00286                                   Connection* c);
00288     virtual void bbDisconnectInput( const std::string& name, 
00289                                     Connection* c);
00291     virtual void bbDisconnectOutput( const std::string& name, 
00292                                      Connection* c);
00293 
00294 
00295  
00301 
00302 
00303     //==================================================================   
00318   protected:
00319     virtual IOStatus bbBackwardUpdate(Connection::Pointer caller) = 0;
00320     //==================================================================
00321 
00322     //==================================================================
00333     // virtual void bbForwardUpdate(Connection::Pointer caller) = 0;
00334     //==================================================================
00335   protected:
00336     //==================================================================
00339     // If excludeParent == true then excludes the upstream box connected to input 'Parent' from recursive update
00340     IOStatus bbUpdateInputs(bool excludeParent=false);
00341     //==================================================================
00342 
00343     //==================================================================
00346     //virtual void bbUpdateChildren( Connection::Pointer caller ) { }
00347     //==================================================================
00348 
00349     //==================================================================
00353     // virtual void bbCreateWindow() { }
00357     virtual void bbShowWindow(Connection::Pointer caller) { }
00358 
00359     virtual void bbHideWindow() {}
00360     virtual void bbCloseWindow() { }
00361    //==================================================================
00362 
00364   public: 
00365 
00366     static bool bbGlobalGetSomeBoxExecuting();
00367     static void bbGlobalSetSomeBoxExecuting(bool b);
00368 
00369     static void bbGlobalSetFreezeExecution(bool b);
00370     static bool bbGlobalGetFreezeExecution();
00371 
00374     virtual bool bbCanReact() const;
00375     
00376   protected:  
00377     static void bbGlobalAddToExecutionList( BlackBox::Pointer b );
00378     static void bbGlobalProcessExecutionList();
00379 
00380     //==================================================================
00381   protected:
00382     //==================================================================
00384     virtual void bbAllocateConnectors();
00386     virtual void bbDesallocateConnectors();
00388     virtual void bbCopyIOValues(BlackBox& from);
00389     //==================================================================
00390 
00391     // Black box objects have a special deleter 
00392     // which must take care of releasing the descriptor 
00393     // **AFTER** the box is deleted 
00394     // (Releasing it in the destructor may cause dl close and crash)
00398     struct BBTK_EXPORT Deleter : public Object::Deleter
00399     { 
00400       Deleter();
00401       void Delete(Object* p);
00402     };
00403 
00404     template <class U>
00405     static boost::shared_ptr<U> MakeBlackBoxPointer(U* s, bool lock = false)
00406     {
00407       return MakePointer(s,BlackBox::Deleter(),lock);
00408     }
00409 
00410     virtual void bbDelete() { delete this; }
00411   private:
00412     
00413  
00414     //==================================================================
00415     // PRIVATE PART 
00417     IOStatus bbmStatus;
00419     std::string bbmName;
00421     std::string bbmPackageName;
00422         
00426     std::string bbmBoxProcessMode;
00427 
00429     BlackBox::WeakPointer bbmParent;
00430     //==================================================================
00431 
00432 
00433    //==================================================================
00434     // ATTRIBUTES
00436     OutputConnectorMapType mOutputConnectorMap; 
00438     InputConnectorMapType mInputConnectorMap;
00439     //==================================================================
00440 
00441 
00442  };
00443   // Class BlackBox
00444 
00445 
00446 
00447 
00448 
00449 
00450 
00451  
00452 }
00453 // namespace bbtk
00454 #endif
00455 

Generated on Wed Nov 12 11:37:08 2008 for BBTK by  doxygen 1.5.6