]> Creatis software - bbtk.git/blobdiff - kernel/src/bbtkComplexBlackBoxDescriptor.cxx
*** empty log message ***
[bbtk.git] / kernel / src / bbtkComplexBlackBoxDescriptor.cxx
index 2631a337def4b8099797a2ae926c023f9efb22b1..0e1114d52383c1480eb50ca410ba084ff1aa0746 100644 (file)
@@ -3,8 +3,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkComplexBlackBoxDescriptor.cxx,v $
   Language:  C++
-  Date:      $Date: 2008/01/30 12:14:43 $
-  Version:   $Revision: 1.2 $
+  Date:      $Date: 2008/05/14 10:26:29 $
+  Version:   $Revision: 1.16 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
 
 namespace bbtk
 {
-  
+   //=======================================================================
+  /// 
+  ComplexBlackBoxDescriptor::Pointer 
+  ComplexBlackBoxDescriptor::New(const std::string& name)
+  {
+    bbtkDebugMessage("object",1,"##> ComplexBlackBoxDescriptor::New(\""<<name<<"\")"<<std::endl);
+    ComplexBlackBoxDescriptor::Pointer p = 
+      MakePointer(new ComplexBlackBoxDescriptor(name));
+    bbtkDebugMessage("object",1,"<## ComplexBlackBoxDescriptor::New(\""<<name<<"\")"<<std::endl);
+    return p;
+  }
+  //=======================================================================
 
   //=======================================================================
   /// Default ctor
   ComplexBlackBoxDescriptor::ComplexBlackBoxDescriptor(const std::string& name)
-    : BlackBoxDescriptor()
   {
-    bbtkDebugMessageInc("Core",9,"ComplexBlackBoxDescriptor::ComplexBlackBoxDescriptor(\""<<name<<"\")"<<std::endl);
+    bbtkDebugMessage("object",2,"==> ComplexBlackBoxDescriptor::ComplexBlackBoxDescriptor(\""<<name<<"\")"<<std::endl);
     SetTypeName(name);
-    mPrototype = new ComplexBlackBox(name+std::string("Prototype"),this);
-    bbtkDebugDecTab("Core",9);
+    AddToCategory("complex box");
+    mPrototype = ComplexBlackBox::New(name+std::string("Prototype"),
+                                     MakePointer(this,true));
+    mPrototype->SetAsPrototype();
+    bbtkDebugMessage("object",2,"<== ComplexBlackBoxDescriptor::ComplexBlackBoxDescriptor(\""<<name<<"\")"<<std::endl);
   }
   //=======================================================================
 
@@ -48,32 +61,45 @@ namespace bbtk
   /// Default dtor
   ComplexBlackBoxDescriptor::~ComplexBlackBoxDescriptor()
   {
-    bbtkDebugMessageInc("Core",9,"ComplexBlackBoxDescriptor::~ComplexBlackBoxDescriptor(\""<<GetTypeName()<<"\")"<<std::endl);
-
-    delete mPrototype;
-
-    bbtkDebugDecTab("Core",9);
+    bbtkDebugMessage("object",2,"==> ComplexBlackBoxDescriptor::~ComplexBlackBoxDescriptor(\""<<GetTypeName()<<"\")"<<std::endl);
+    //    mPrototype->Delete();
+    mPrototype.reset();
+    bbtkDebugMessage("object",2,"<== ComplexBlackBoxDescriptor::~ComplexBlackBoxDescriptor(\""<<GetTypeName()<<"\")"<<std::endl);
   }
   //=======================================================================
 
+  //=========================================================================
+  /// Check
+  void ComplexBlackBoxDescriptor::Check(bool recursive) const
+  {
+    mPrototype->Check(recursive);
+  }
+  //=========================================================================
 
   //=======================================================================
   /// Creates an instance of name <name> of the ComplexBlackBox of which this is the descriptor 
-  BlackBox* ComplexBlackBoxDescriptor::CreateInstance(const std::string& name)
+  BlackBox::Pointer 
+  ComplexBlackBoxDescriptor::NewBlackBox(const std::string& name)
   {
-    //bbtkError("ComplexBlackBoxDescriptor::CreateInstance not implemented");
-    bbtkDebugMessageInc("Core",5,
-                       "ComplexBlackBoxDescriptor::CreateInstance(\""
+    bbtkDebugMessageInc("Kernel",5,
+                       "ComplexBlackBoxDescriptor::NewBlackBox(\""
                        <<name<<"\") ["
                        <<GetTypeName()<<"]"<<std::endl);
     
     return mPrototype->bbClone(name);
 
-    bbtkDebugDecTab("Core",5);
+    bbtkDebugDecTab("Kernel",5);
   }
   //=======================================================================
 
-
+  /*
+  //=======================================================================
+  /// Release
+  void ComplexBlackBoxDescriptor::Release(bool release_package)
+  {
+  }
+  //=======================================================================
+  */
 
   //=======================================================================
   /// Adds a black box to the complex box
@@ -81,11 +107,16 @@ namespace bbtk
                                        const std::string& name
                                        )
   {
-    bbtkDebugMessageInc("Core",5,
+    bbtkDebugMessageInc("Kernel",5,
                        "ComplexBlackBoxDescriptor::Add(\""
                        <<type<<"\",\""<<name<<"\") ["
                        <<GetTypeName()<<"]"<<std::endl);
     
+    // 
+    if (!GetFactory()) 
+      { 
+       bbtkError("ComplexBlackBoxDescriptor::Add : no factory set");
+      }
     
     // Verify that a box with the same name does not exist already
     if ( mPrototype->bbUnsafeGetBlackBox( name ) ) 
@@ -93,22 +124,32 @@ namespace bbtk
        bbtkError("a black box \""<<name<<"\" already exists");
       }
     // ok : create new one
-    mPrototype->bbAddBlackBox ( /*mFactory->Create*/ NewBlackBox(type,name) );
+    mPrototype->bbAddBlackBox ( GetFactory()->NewBlackBox(type,name) );
 
-    bbtkDebugDecTab("Core",5);
+    bbtkDebugDecTab("Kernel",5);
+  }
+  //=======================================================================
+  
+  //=======================================================================
+  /// Removes a black box from the complex box
+  void ComplexBlackBoxDescriptor::Remove( const std::string& name, 
+                                         bool remove_connections)
+  {    
+    mPrototype->bbRemoveBlackBox(name,remove_connections);
   }
   //=======================================================================
 
- //=======================================================================
+
+  //=======================================================================
   /// Adds a black box to the execution list 
   void ComplexBlackBoxDescriptor::AddToExecutionList ( const std::string& box)
   {
-    bbtkDebugMessageInc("Core",5,
+    bbtkDebugMessageInc("Kernel",5,
                        "ComplexBlackBoxDescriptor::AddToExecutionList(\""
                        <<box<<"\" ["
                        <<GetTypeName()<<"]"<<std::endl);
     // Verify that the box exists
-    BlackBox* b = mPrototype->bbUnsafeGetBlackBox( box ); 
+    BlackBox::Pointer b = mPrototype->bbUnsafeGetBlackBox( box ); 
     if ( !b ) 
       {
        bbtkError("the black box \""<<box<<"\" does not exist");
@@ -116,7 +157,7 @@ namespace bbtk
     // ok 
     mPrototype->bbAddToExecutionList ( box  );
 
-    bbtkDebugDecTab("Core",5);
+    bbtkDebugDecTab("Kernel",5);
     }
 
 
@@ -128,29 +169,37 @@ namespace bbtk
                                            const std::string& input
                                            )
   {
-    bbtkDebugMessageInc("Core",5,
+    bbtkDebugMessageInc("Kernel",5,
                        "ComplexBlackBoxDescriptor::Connect(\""
                        <<from<<"\",\""<<output<<"\",\""
                        <<to<<"\",\""<<input
                        <<"\") ["
                        <<GetTypeName()<<"]"<<std::endl);
+  // 
+    if (!GetFactory()) 
+      { 
+       bbtkError("ComplexBlackBoxDescriptor::Connect : no factory set");
+      }
+    
+
   // Verify that a box with the same name does not exist already
-    BlackBox* bbfrom = mPrototype->bbGetBlackBox( from );
+    BlackBox::Pointer bbfrom = mPrototype->bbGetBlackBox( from );
     if ( !bbfrom ) 
       {
        bbtkError("the black box \""<<from<<"\" does not exist");
       }
-    BlackBox* bbto = mPrototype->bbGetBlackBox( to );
+    BlackBox::Pointer bbto = mPrototype->bbGetBlackBox( to );
     if ( !bbto ) 
       {
        bbtkError("the black box \""<<to<<"\" does not exist");
       }
     
-    Connection* c = /*mFactory->*/ NewConnection( bbfrom, output, bbto, input );
+    Connection::Pointer c 
+      = GetFactory()->NewConnection( bbfrom, output, bbto, input );
 
     mPrototype->bbAddConnection(c);
 
-    bbtkDebugDecTab("Core",5);
+    bbtkDebugDecTab("Kernel",5);
   }
   //=======================================================================
 
@@ -162,14 +211,14 @@ namespace bbtk
                                                const std::string& input,
                                                const std::string& help)
   {
-    bbtkDebugMessageInc("Core",5,
+    bbtkDebugMessageInc("Kernel",5,
                        "ComplexBlackBoxDescriptor::DefineInput(\""
                        <<name<<"\",\""<<box<<"\",\""
                        <<input<<"\",\""<<help
                        <<"\") ["
                        <<GetTypeName()<<"]"<<std::endl);
 
-    BlackBox* bb = mPrototype->bbGetBlackBox( box );
+    BlackBox::Pointer bb = mPrototype->bbGetBlackBox( box );
     if ( !bb ) 
       {
        bbtkError("the black box \""<<box<<"\" does not exist");
@@ -181,14 +230,19 @@ namespace bbtk
                  <<input<<"\"");
       }
     
-    AddInputDescriptor ( new ComplexBlackBoxInputDescriptor ( name,
-                                                             help,
-                                                             box,
-                                                             input,
-                                                             bb->bbGetInputType(input)));
-                                                            
+    const BlackBoxInputDescriptor* d = 
+      bb->bbGetDescriptor()->GetInputDescriptor(input);
+    AddInputDescriptor ( new ComplexBlackBoxInputDescriptor 
+                        ( typeid(ComplexBlackBoxDescriptor),
+                          name,
+                          help,
+                          d->GetNature(),
+                          box,
+                          input,
+                          d->GetTypeInfo()));
     
-    bbtkDebugDecTab("Core",5);
+    
+    bbtkDebugDecTab("Kernel",5);
   }
   //=======================================================================
 
@@ -199,14 +253,14 @@ namespace bbtk
                                                 const std::string& output,
                                                 const std::string& help)
   {
-    bbtkDebugMessageInc("Core",5,
+    bbtkDebugMessageInc("Kernel",5,
                        "ComplexBlackBoxDescriptor::DefineOutput(\""
                        <<name<<"\",\""<<box<<"\",\""
                        <<output<<"\",\""<<help
                        <<"\") ["
                        <<GetTypeName()<<"]"<<std::endl);
 
-    BlackBox* bb = mPrototype->bbGetBlackBox( box );
+    BlackBox::Pointer bb = mPrototype->bbGetBlackBox( box );
     if ( !bb ) 
       {
        bbtkError("the black box \""<<box<<"\" does not exist");
@@ -218,15 +272,19 @@ namespace bbtk
                  <<output<<"\"");
       }
     
+    const BlackBoxOutputDescriptor* d = 
+      bb->bbGetDescriptor()->GetOutputDescriptor(output);
     AddOutputDescriptor ( new ComplexBlackBoxOutputDescriptor 
-                         ( name,
+                         ( typeid(ComplexBlackBoxDescriptor),
+                           name,
                            help,
+                           d->GetNature(),
                            box,
                            output,
-                           bb->bbGetOutputType(output)));
+                           d->GetTypeInfo()));
     
     
-    bbtkDebugDecTab("Core",5);
+    bbtkDebugDecTab("Kernel",5);
   }
   //=======================================================================
 
@@ -256,7 +314,7 @@ namespace bbtk
                                                   int detail, int level,
                                                   const std::string& output_dir, bool relative_link)
   {
-    bbtkDebugMessageInc("Core",9,
+    bbtkDebugMessageInc("Kernel",9,
                        "ComplexBlackBoxDescriptor::InsertHtmlHelp() ["
                        <<GetTypeName()<<"]"<<std::endl);
     
@@ -282,8 +340,12 @@ namespace bbtk
     std::string author = GetAuthor();
     Utilities::html_format(author);
     
-    std::string keyword = GetKeyword();
-    Utilities::html_format(keyword);
+    std::vector<std::string> categories;
+    // Split the category string 
+    std::string delimiters = ";,";
+    Utilities::SplitString(GetCategory(),
+                          delimiters,categories);
+
         
     (s) << "<p><TABLE cellspacing=0  cellpadding=3>\n";
     (s) << "<TR><TD style='vertical-align: top;'><b> Description </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'> " 
@@ -292,14 +354,20 @@ namespace bbtk
     (s) << "<TR><TD style='vertical-align: top;'><b> Author(s) </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'>  " 
         << author << "</TD></TR>\n";
 
-    (s) << "<TR><TD style='vertical-align: top;'><b> Keyword(s) </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'>  " 
-        << keyword << "</TD></TR>\n";      
-
+    (s) << "<TR><TD style='vertical-align: top;'><b> Category(s) </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'>  ";
+    std::vector<std::string>::iterator ci;
+    for (ci=categories.begin(); ci!=categories.end(); ++ci)
+      {
+        s << "<a href=\"../index-category.html#"<< *ci <<"\">" << *ci 
+         << "</a>&nbsp;\n";
+      }
+    s << "</TD></TR>\n";      
     std::string inc = GetScriptFileName();
     if (inc.size()>0) 
       {
-    (s) << "<TR><TD style='vertical-align: top;'><b> Include </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'>  " 
-      << inc << "</TD></TR>\n";
+       s << "<TR><TD style='vertical-align: top;'><b> To use it </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'> include ";
+       s << inc << "&nbsp;&nbsp;<a href=\"../../../bbs/"<<inc<<"\">[source]</a>";
+       s << "</TD></TR>\n";
        
       }
     
@@ -307,18 +375,18 @@ namespace bbtk
        
     if (B.size()) 
     {
-          (s) << "<TR><TD style='vertical-align: top;'><b> Dependencies </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'>  ";
+          (s) << "<TR><TD style='vertical-align: top;'><b> Uses </b></TD><TD style='vertical-align: top;'> : </TD><TD style='vertical-align: top;'>  ";
 
-          std::set<BlackBoxDescriptor*> pdeps;
+          std::set<BlackBoxDescriptor::Pointer> pdeps;
           ComplexBlackBox::BlackBoxMapType::const_iterator b;
           for ( b = B.begin(); b != B.end(); ++b ) 
           {
-             BlackBoxDescriptor* d = b->second->bbGetDescriptor();
+            BlackBoxDescriptor::Pointer d = b->second->bbGetDescriptor();
              if (pdeps.find(d) != pdeps.end()) 
             continue;
              pdeps.insert(d);
 
-             Package* p = d->GetPackage();
+             Package::Pointer p = d->GetPackage();
            
              std::string name = b->second->bbGetTypeName();
 
@@ -412,7 +480,7 @@ namespace bbtk
     //------------
     // End
 
-    bbtkDebugDecTab("Core",9);
+    bbtkDebugDecTab("Kernel",9);
    }
   //=========================================================================
  
@@ -423,9 +491,9 @@ namespace bbtk
     if (full) bbtkMessage("Help",1,"Complex Black Box <"<<
                          GetPackage()->GetName()<<"::"
                          <<GetTypeName()<<">"<<std::endl);
-    bbtkMessage("Help",1," "              << GetDescription() <<std::endl);
-    bbtkMessage("Help",1," By : "         << GetAuthor()      <<std::endl);
-    bbtkMessage("Help",1," Keyword(s) : " << GetKeyword()     <<std::endl);    
+    bbtkMessage("Help",1," "                << GetDescription() <<std::endl);
+    bbtkMessage("Help",1," By : "           << GetAuthor()      <<std::endl);
+    bbtkMessage("Help",1," Category(s) : "  << GetCategory()     <<std::endl);    
     if (mInput.size()) 
       bbtkMessage("Help",1," * Inputs : "<<std::endl);
     else 
@@ -433,12 +501,15 @@ namespace bbtk
     InputDescriptorMapType::const_iterator i;
     unsigned int namelmax = 0;
     unsigned int typelmax = 0;
+    unsigned int natlmax = 0;
     for ( i = mInput.begin();  i != mInput.end(); ++i ) 
     {
           if (i->second->GetName().size()>namelmax) 
             namelmax = i->second->GetName().size();
           if (i->second->GetTypeName().size()>typelmax) 
             typelmax = i->second->GetTypeName().size();
+          if (i->second->GetNature().size()>natlmax) 
+            natlmax = i->second->GetNature().size();
     }
     OutputDescriptorMapType::const_iterator o;
     if (full) 
@@ -449,6 +520,8 @@ namespace bbtk
               namelmax = o->second->GetName().size();
            if (o->second->GetTypeName().size()>typelmax) 
               typelmax = o->second->GetTypeName().size();
+          if (o->second->GetNature().size()>natlmax) 
+            natlmax = o->second->GetNature().size();
           }
     }
     //
@@ -461,10 +534,14 @@ namespace bbtk
           std::string type(i->second->GetTypeName());
           type += ">";
           type.append(1+typelmax-type.size(),' ');
+          std::string nature(i->second->GetNature());
+          nature += "]";
+          nature.append(1+natlmax-nature.size(),' ');
           bbtkMessage("Help",1,
-                   "    '"<<name
-                   <<" <"<<type
-                   <<" : "<<i->second->GetDescription()<<std::endl);
+                      "    '"<<name
+                      <<" <"<<type
+                      <<" ["<<nature
+                      <<" : "<<i->second->GetDescription()<<std::endl);
     }
     if (full) 
     {
@@ -480,9 +557,13 @@ namespace bbtk
             std::string type(o->second->GetTypeName());
             type += ">";
             type.append(1+typelmax-type.size(),' ');
+            std::string nature(o->second->GetNature());
+            nature += "]";
+            nature.append(1+natlmax-nature.size(),' ');
             bbtkMessage("Help",1,
-                        "    '"<<name
+                      "    '"<<name
                         <<" <"<<type
+                        <<" ["<<nature
                         <<" : "<<o->second->GetDescription()<<std::endl);
           }
     }
@@ -509,6 +590,43 @@ namespace bbtk
   }   
   //=======================================================================
 
-
+  //==========================================================================
+  std::string ComplexBlackBoxDescriptor::GetObjectName() const
+  {
+    return std::string("ComplexBlackBoxDescriptor '")+GetFullTypeName()
+      +std::string("'");
+  }
+  //==========================================================================
+  //=======================================================================
+  std::string ComplexBlackBoxDescriptor::GetObjectInfo() const
+  {
+    std::string i;
+    return i;     
+  }
+  //=======================================================================
+ //==========================================================================
+size_t  ComplexBlackBoxDescriptor::GetObjectSize() const 
+{
+  size_t s = Superclass::GetObjectSize();
+  s += ComplexBlackBoxDescriptor::GetObjectInternalSize();
+  return s;
+  }
+  //==========================================================================
+  //==========================================================================
+size_t  ComplexBlackBoxDescriptor::GetObjectInternalSize() const 
+{
+  size_t s = sizeof(ComplexBlackBoxDescriptor);
+  return s;
+  }
+  //==========================================================================
+  //==========================================================================
+  size_t  ComplexBlackBoxDescriptor::GetObjectRecursiveSize() const 
+  {
+    size_t s = Superclass::GetObjectRecursiveSize();
+    s += ComplexBlackBoxDescriptor::GetObjectInternalSize();
+    s += mPrototype->GetObjectRecursiveSize();
+    return s;
+  }
+  //==========================================================================
 
 }