]> Creatis software - bbtk.git/blobdiff - kernel/src/bbtkComplexBlackBoxDescriptor.cxx
=== MAJOR RELEASE ====
[bbtk.git] / kernel / src / bbtkComplexBlackBoxDescriptor.cxx
index 679557533a763c58d095c50de67622675c931cf8..efe06f170e8444cc9ee7105576d1b5a4d5a66887 100644 (file)
@@ -3,8 +3,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkComplexBlackBoxDescriptor.cxx,v $
   Language:  C++
-  Date:      $Date: 2008/04/09 11:16:57 $
-  Version:   $Revision: 1.14 $
+  Date:      $Date: 2008/04/18 12:59:15 $
+  Version:   $Revision: 1.15 $
                                                                                 
   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(),
-      mFactory(0)
   {
-    bbtkDebugMessageInc("Kernel",9,"ComplexBlackBoxDescriptor::ComplexBlackBoxDescriptor(\""<<name<<"\")"<<std::endl);
+    bbtkDebugMessage("object",2,"==> ComplexBlackBoxDescriptor::ComplexBlackBoxDescriptor(\""<<name<<"\")"<<std::endl);
     SetTypeName(name);
     AddToCategory("complex box");
-    mPrototype = new ComplexBlackBox(name+std::string("Prototype"),this);
-    // this->Reference();
-    bbtkDebugDecTab("Kernel",9);
+    mPrototype = ComplexBlackBox::New(name+std::string("Prototype"),
+                                     MakePointer(this,true));
+    mPrototype->SetAsPrototype();
+    bbtkDebugMessage("object",2,"<== ComplexBlackBoxDescriptor::ComplexBlackBoxDescriptor(\""<<name<<"\")"<<std::endl);
   }
   //=======================================================================
 
@@ -51,12 +61,10 @@ namespace bbtk
   /// Default dtor
   ComplexBlackBoxDescriptor::~ComplexBlackBoxDescriptor()
   {
-    bbtkDebugMessageInc("Kernel",1,"ComplexBlackBoxDescriptor::~ComplexBlackBoxDescriptor(\""<<GetTypeName()<<"\")"<<std::endl);
-
-    delete mPrototype;
-
-    bbtkDebugMessage("Kernel",1,"EO ComplexBlackBoxDescriptor::~ComplexBlackBoxDescriptor(\""<<GetTypeName()<<"\")"<<std::endl);
-   bbtkDebugDecTab("Kernel",1);
+    bbtkDebugMessage("object",2,"==> ComplexBlackBoxDescriptor::~ComplexBlackBoxDescriptor(\""<<GetTypeName()<<"\")"<<std::endl);
+    //    mPrototype->Delete();
+    mPrototype.reset();
+    bbtkDebugMessage("object",2,"<== ComplexBlackBoxDescriptor::~ComplexBlackBoxDescriptor(\""<<GetTypeName()<<"\")"<<std::endl);
   }
   //=======================================================================
 
@@ -70,11 +78,11 @@ namespace bbtk
 
   //=======================================================================
   /// 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("Kernel",5,
-                       "ComplexBlackBoxDescriptor::CreateInstance(\""
+                       "ComplexBlackBoxDescriptor::NewBlackBox(\""
                        <<name<<"\") ["
                        <<GetTypeName()<<"]"<<std::endl);
     
@@ -84,7 +92,14 @@ namespace bbtk
   }
   //=======================================================================
 
-
+  /*
+  //=======================================================================
+  /// Release
+  void ComplexBlackBoxDescriptor::Release(bool release_package)
+  {
+  }
+  //=======================================================================
+  */
 
   //=======================================================================
   /// Adds a black box to the complex box
@@ -98,7 +113,7 @@ namespace bbtk
                        <<GetTypeName()<<"]"<<std::endl);
     
     // 
-    if (mFactory == 0
+    if (!GetFactory()
       { 
        bbtkError("ComplexBlackBoxDescriptor::Add : no factory set");
       }
@@ -109,13 +124,23 @@ namespace bbtk
        bbtkError("a black box \""<<name<<"\" already exists");
       }
     // ok : create new one
-    mPrototype->bbAddBlackBox ( mFactory->NewBlackBox(type,name) );
+    mPrototype->bbAddBlackBox ( GetFactory()->NewBlackBox(type,name) );
 
     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)
   {
@@ -124,7 +149,7 @@ namespace bbtk
                        <<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");
@@ -151,25 +176,26 @@ namespace bbtk
                        <<"\") ["
                        <<GetTypeName()<<"]"<<std::endl);
   // 
-    if (mFactory == 0
+    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);
 
@@ -192,7 +218,7 @@ namespace bbtk
                        <<"\") ["
                        <<GetTypeName()<<"]"<<std::endl);
 
-    BlackBox* bb = mPrototype->bbGetBlackBox( box );
+    BlackBox::Pointer bb = mPrototype->bbGetBlackBox( box );
     if ( !bb ) 
       {
        bbtkError("the black box \""<<box<<"\" does not exist");
@@ -234,7 +260,7 @@ namespace bbtk
                        <<"\") ["
                        <<GetTypeName()<<"]"<<std::endl);
 
-    BlackBox* bb = mPrototype->bbGetBlackBox( box );
+    BlackBox::Pointer bb = mPrototype->bbGetBlackBox( box );
     if ( !bb ) 
       {
        bbtkError("the black box \""<<box<<"\" does not exist");
@@ -351,16 +377,16 @@ namespace bbtk
     {
           (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();
 
@@ -564,7 +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;
+  }
+  //==========================================================================
 
 }