]> Creatis software - bbtk.git/commitdiff
*** empty log message ***
authorEduardo Davila <Eduardo.Davila@creatis.insa-lyon.fr>
Tue, 5 Feb 2008 11:08:54 +0000 (11:08 +0000)
committerEduardo Davila <Eduardo.Davila@creatis.insa-lyon.fr>
Tue, 5 Feb 2008 11:08:54 +0000 (11:08 +0000)
20 files changed:
packages/std/bbs/boxes/bbPrependDataPath.bbs [new file with mode: 0755]
packages/std/src/bbstdConcatStrings.cxx [new file with mode: 0644]
packages/std/src/bbstdConcatStrings.h [new file with mode: 0644]
packages/std/src/bbstdConfiguration.cxx [new file with mode: 0644]
packages/std/src/bbstdConfiguration.h [new file with mode: 0644]
packages/std/src/bbstdMagicBox.cxx [new file with mode: 0644]
packages/std/src/bbstdMagicBox.h [new file with mode: 0644]
packages/std/src/bbstdMakeFileName.cxx [new file with mode: 0644]
packages/std/src/bbstdMakeFileName.h [new file with mode: 0644]
packages/std/src/bbstdMultipleInputs.xml [new file with mode: 0644]
packages/std/src/bbstdStringSelect.cxx [new file with mode: 0644]
packages/std/src/bbstdStringSelect.h [new file with mode: 0644]
packages/std/src/bbstdStringTo.cxx [new file with mode: 0644]
packages/std/src/bbstdStringTo.h [new file with mode: 0644]
packages/std/src/bbstdStringToVector.cxx [new file with mode: 0644]
packages/std/src/bbstdStringToVector.h [new file with mode: 0644]
packages/std/src/bbstdToString.cxx [new file with mode: 0644]
packages/std/src/bbstdToString.h [new file with mode: 0644]
packages/std/src/bbstdVectorToString.cxx [new file with mode: 0644]
packages/std/src/bbstdVectorToString.h [new file with mode: 0644]

diff --git a/packages/std/bbs/boxes/bbPrependDataPath.bbs b/packages/std/bbs/boxes/bbPrependDataPath.bbs
new file mode 100755 (executable)
index 0000000..ee5d57a
--- /dev/null
@@ -0,0 +1,18 @@
+load std
+define PrependDataPath
+  author "jpr@creatis.insa-lyon.fr"
+  description "Prepends the input string file 'last name' with the default DataPath found in bbtk_config_xml"
+
+  # For getting default Data Path
+  new Configuration c
+  
+  # For making a full path name, avoiding troubles with / or \
+  new MakeFileName mfn
+  
+  connect c.DataPath mfn.Directory
+  
+  # used in GUI mode (-g option)
+  input  In   mfn.File "Last Filename"
+  output Out mfn.Out   "Full path Filename"
+endefine
+
diff --git a/packages/std/src/bbstdConcatStrings.cxx b/packages/std/src/bbstdConcatStrings.cxx
new file mode 100644 (file)
index 0000000..5ca9c5f
--- /dev/null
@@ -0,0 +1,41 @@
+#include "bbstdConcatStrings.h"
+#include "bbstdPackage.h"
+
+namespace bbstd
+{
+
+       BBTK_ADD_BLACK_BOX_TO_PACKAGE(std,ConcatStrings)
+       BBTK_USER_BLACK_BOX_IMPLEMENTATION(ConcatStrings,bbtk::UserBlackBox);
+
+       void ConcatStrings::bbUserConstructor() 
+   { 
+      bbSetInputIn1("");
+      bbSetInputIn2("");
+      bbSetInputIn3("");
+      bbSetInputIn4("");
+      bbSetInputIn5("");
+      bbSetInputIn6("");
+      bbSetInputIn7("");
+      bbSetInputIn8("");
+      bbSetInputIn9("");
+      bbSetInputIn10("");
+   }
+
+
+       void ConcatStrings::DoProcess()
+       {
+      bbSetOutputOut(  bbGetInputIn1() + 
+                                               bbGetInputIn2() +
+                                               bbGetInputIn3() +
+                                               bbGetInputIn4() +
+                                               bbGetInputIn5() +
+                                               bbGetInputIn6() +
+                                               bbGetInputIn7() +
+                                               bbGetInputIn8() +
+                                               bbGetInputIn9() +
+                                               bbGetInputIn10()  );      
+       }
+}
+// EO namespace bbstd
+
+
diff --git a/packages/std/src/bbstdConcatStrings.h b/packages/std/src/bbstdConcatStrings.h
new file mode 100644 (file)
index 0000000..9c2ea9b
--- /dev/null
@@ -0,0 +1,55 @@
+#ifndef __bbstdConcatStrings_h_INCLUDED__
+#define __bbstdConcatStrings_h_INCLUDED__
+
+#include "bbtkUserBlackBox.h"
+
+namespace bbstd
+{
+
+  class ConcatStrings
+    : 
+    public bbtk::UserBlackBox
+  {
+    BBTK_USER_BLACK_BOX_INTERFACE(ConcatStrings,bbtk::UserBlackBox);
+    BBTK_DECLARE_INPUT(In1, std::string);
+    BBTK_DECLARE_INPUT(In2, std::string);
+    BBTK_DECLARE_INPUT(In3, std::string);
+    BBTK_DECLARE_INPUT(In4, std::string);
+    BBTK_DECLARE_INPUT(In5, std::string);
+    BBTK_DECLARE_INPUT(In6, std::string);
+    BBTK_DECLARE_INPUT(In7, std::string);
+    BBTK_DECLARE_INPUT(In8, std::string);
+    BBTK_DECLARE_INPUT(In9, std::string);
+    BBTK_DECLARE_INPUT(In10,std::string);
+    BBTK_DECLARE_OUTPUT(Out,std::string);
+    BBTK_PROCESS(DoProcess);
+    void DoProcess();
+
+  protected:
+    virtual void bbUserConstructor();
+
+  };
+
+  BBTK_BEGIN_DESCRIBE_BLACK_BOX(ConcatStrings,bbtk::UserBlackBox);
+  BBTK_NAME("ConcatStrings");
+  BBTK_AUTHOR("jpr@creatis.insa-lyon.fr");
+  BBTK_DESCRIPTION("String concatenation");
+    BBTK_INPUT(ConcatStrings,In1, "String 1", std::string);
+    BBTK_INPUT(ConcatStrings,In2, "String 2", std::string);  
+    BBTK_INPUT(ConcatStrings,In3, "String 3", std::string);  
+    BBTK_INPUT(ConcatStrings,In4, "String 4", std::string);  
+    BBTK_INPUT(ConcatStrings,In5, "String 5", std::string);  
+    BBTK_INPUT(ConcatStrings,In6, "String 6", std::string);  
+    BBTK_INPUT(ConcatStrings,In7, "String 7", std::string);  
+    BBTK_INPUT(ConcatStrings,In8, "String 8", std::string);  
+    BBTK_INPUT(ConcatStrings,In9, "String 9", std::string);  
+    BBTK_INPUT(ConcatStrings,In10,"String 10",std::string);  
+    BBTK_OUTPUT(ConcatStrings,Out,"Concatenated string",std::string);
+  BBTK_END_DESCRIBE_BLACK_BOX(ConcatStrings);
+
+}
+// EO namespace bbstd
+
+#endif //  __bbstdConcatStrings_h_INCLUDED__
+
+
diff --git a/packages/std/src/bbstdConfiguration.cxx b/packages/std/src/bbstdConfiguration.cxx
new file mode 100644 (file)
index 0000000..8fab8fe
--- /dev/null
@@ -0,0 +1,34 @@
+#include "bbstdConfiguration.h"
+#include "bbstdPackage.h"
+
+#include "bbtkConfigurationFile.h"
+namespace bbstd
+{
+
+       BBTK_ADD_BLACK_BOX_TO_PACKAGE(std,Configuration)
+       BBTK_USER_BLACK_BOX_IMPLEMENTATION(Configuration,bbtk::UserBlackBox);
+
+       void Configuration::bbUserConstructor() 
+   { 
+
+   }
+
+
+       void Configuration::DoProcess()
+       {
+      bbSetOutputDataPath( bbtk::ConfigurationFile::GetInstance().Get_data_path() );
+      bbSetOutputFileSeparator( bbtk::ConfigurationFile::GetInstance().Get_file_separator() );
+
+#if defined(__GNUC__)
+      bbSetOutputSystemType( 0 );
+#elif defined(_WIN32)
+      bbSetOutputSystemType( 1 );
+#else
+      bbSetOutputSystemType( -1 );
+#endif
+
+       }
+}
+// EO namespace bbstd
+
+
diff --git a/packages/std/src/bbstdConfiguration.h b/packages/std/src/bbstdConfiguration.h
new file mode 100644 (file)
index 0000000..6d88344
--- /dev/null
@@ -0,0 +1,39 @@
+#ifndef __bbstdConfiguration_h_INCLUDED__
+#define __bbstdConfiguration_h_INCLUDED__
+
+#include "bbtkUserBlackBox.h"
+
+namespace bbstd
+{
+
+  class Configuration
+    : 
+    public bbtk::UserBlackBox
+  {
+    BBTK_USER_BLACK_BOX_INTERFACE(Configuration,bbtk::UserBlackBox);
+      BBTK_DECLARE_OUTPUT(DataPath,std::string);
+      BBTK_DECLARE_OUTPUT(FileSeparator,std::string);
+      BBTK_DECLARE_OUTPUT(SystemType,int);
+    BBTK_PROCESS(DoProcess);
+    void DoProcess();
+
+  protected:
+    virtual void bbUserConstructor();
+
+  };
+
+  BBTK_BEGIN_DESCRIBE_BLACK_BOX(Configuration,bbtk::UserBlackBox);
+  BBTK_NAME("Configuration");
+  BBTK_AUTHOR("jpr@creatis.insa-lyon.fr");
+  BBTK_DESCRIPTION("Gets configuration informations");
+    BBTK_OUTPUT(Configuration,DataPath,"Sample Data Path",std::string);
+    BBTK_OUTPUT(Configuration,FileSeparator,"/ or \\",std::string);  
+    BBTK_OUTPUT(Configuration,SystemType,"0=Linux 1=Windows",int);  
+  BBTK_END_DESCRIBE_BLACK_BOX(Configuration);
+
+}
+// EO namespace bbstd
+
+#endif //  __bbstdConfiguration_h_INCLUDED__
+
+
diff --git a/packages/std/src/bbstdMagicBox.cxx b/packages/std/src/bbstdMagicBox.cxx
new file mode 100644 (file)
index 0000000..bf111dd
--- /dev/null
@@ -0,0 +1,12 @@
+#include "bbstdMagicBox.h"
+#include "bbstdPackage.h"
+namespace bbstd
+{
+
+BBTK_ADD_BLACK_BOX_TO_PACKAGE(std,MagicBox)
+BBTK_USER_BLACK_BOX_IMPLEMENTATION(MagicBox,bbtk::UserBlackBox);
+
+}
+// EO namespace bbstd
+
+
diff --git a/packages/std/src/bbstdMagicBox.h b/packages/std/src/bbstdMagicBox.h
new file mode 100644 (file)
index 0000000..5c70c64
--- /dev/null
@@ -0,0 +1,85 @@
+#ifndef __bbstdMagicBox_h_INCLUDED_H__
+#define __bbstdMagicBox_h_INCLUDED_H__
+
+#include "bbtkUserBlackBox.h"
+
+namespace bbstd
+{
+  
+  //==================================================================
+  class /*BBTK_EXPORT*/ MagicBox
+    : 
+    public bbtk::UserBlackBox
+  {
+    BBTK_USER_BLACK_BOX_INTERFACE(MagicBox,bbtk::UserBlackBox);
+    BBTK_DECLARE_INPUT(In,bbtk::Data);
+    BBTK_DECLARE_OUTPUT(Out,bbtk::Data);
+    BBTK_PROCESS(DoProcess);
+    void DoProcess() { bbSetOutputOut( bbGetInputIn() ); }
+    
+  protected:
+    //    virtual void bbUserConstructor();
+    
+  };
+  //==================================================================
+  
+  
+  //==================================================================
+  // We have to create a particular SetFunctor for MagicBox because
+  // its input is of type bbtk::Data (i.e. any) and :
+  // 1) an any cannot store an any (construction with an any invokes the copy constr.)
+  // 2) we cannot invoke the Set method with the content of the any because 
+  //   it expects an any 
+  // hence the method Set **MUST NOT** extract the content of the Data 
+  // prior to invoking the set method
+  class MagicBoxSetFunctor : public bbtk::UserBlackBoxSetFunctor
+  {
+  public:
+    /// Type of pointer on a UBB::Set method  
+    typedef void (MagicBox::*SetMethodPointerType)(bbtk::Data);
+    
+    /// Construction with the pointer on the Set method
+    MagicBoxSetFunctor(SetMethodPointerType s) :
+      mSetMethodPointer(s) 
+    {}
+    
+    /// Concrete application of the Set method of object o
+    void Set(bbtk::UserBlackBox* o, const bbtk::Data& d)
+    { 
+      bbtkDebugMessage("Data",9,"MagicBoxSetfunctor::Set()"<<std::endl);
+      (((MagicBox*)o)->*mSetMethodPointer)(d);
+    }
+    
+    /// 
+    bbtk::TypeInfo GetTypeInfo() const { return typeid(bbtk::Data); }
+    std::string GetTypeName() const { return bbtk::TypeName<bbtk::Data>(); }
+    std::string GetHumanTypeName() const { return bbtk::HumanTypeName<bbtk::Data>(); }
+    bool IsPointerType() const { return false; }
+    void BruteForceSetPointer(bbtk::UserBlackBox*, void*) {}
+  private:
+    ///  Pointer on the Set method  
+    SetMethodPointerType mSetMethodPointer;
+  };
+  //===========================================================================
+
+
+
+  BBTK_BEGIN_DESCRIBE_BLACK_BOX(MagicBox,bbtk::UserBlackBox);
+  BBTK_NAME("MagicBox");
+  BBTK_AUTHOR("laurent.guigues@creatis.insa-lyon.fr");
+  BBTK_DESCRIPTION("MagicBox");
+  AddInputDescriptor(new bbtk::UserBlackBoxInputDescriptor             
+                    ("In","Input data",
+                     new bbtk::UserBlackBoxTGetFunctor<MagicBox,bbtk::Data,bbtk::Data>
+                     (&MagicBox::bbGetInputIn),
+                     new MagicBoxSetFunctor (&MagicBox::bbSetInputIn) ) );
+  AddOutputDescriptor(new bbtk::UserBlackBoxOutputDescriptor           
+                     ("Out","Output data",
+                      new bbtk::UserBlackBoxTGetFunctor<MagicBox,bbtk::Data,bbtk::Data>
+                      (&MagicBox::bbGetOutputOut),
+                      new MagicBoxSetFunctor (&MagicBox::bbSetOutputOut) ) );
+  BBTK_END_DESCRIBE_BLACK_BOX(MagicBox);
+}
+// namespace bbstd
+
+#endif // __bbstdMagicBox_h_INCLUDED_H__
diff --git a/packages/std/src/bbstdMakeFileName.cxx b/packages/std/src/bbstdMakeFileName.cxx
new file mode 100644 (file)
index 0000000..73a6ece
--- /dev/null
@@ -0,0 +1,32 @@
+#include "bbstdMakeFileName.h"
+#include "bbstdPackage.h"
+#include "bbtkConfigurationFile.h"
+
+namespace bbstd
+{
+
+       BBTK_ADD_BLACK_BOX_TO_PACKAGE(std,MakeFileName)
+       BBTK_USER_BLACK_BOX_IMPLEMENTATION(MakeFileName,bbtk::UserBlackBox);
+
+       void MakeFileName::bbUserConstructor()
+   {
+      bbSetInputDirectory("");
+      bbSetInputFile("");
+      bbSetInputExtent("");
+   }
+
+       void MakeFileName::DoProcess()
+       {
+      std::string fileSep = bbtk::ConfigurationFile::GetInstance().Get_file_separator();
+      std::string fullFileName = bbGetInputDirectory();
+      if ( fullFileName.c_str()[fullFileName.size()-1] != '/' && fullFileName.c_str()[fullFileName.size()-1] != '\\' )
+         fullFileName += fileSep;
+      fullFileName += bbGetInputFile();
+      if ( bbGetInputExtent() != "")
+         if ( bbGetInputExtent()[0] != '.' )
+            fullFileName += ".";
+      fullFileName +=  bbGetInputExtent();
+      bbSetOutputOut( fullFileName );    
+       }
+}
+// EO namespace bbstd
diff --git a/packages/std/src/bbstdMakeFileName.h b/packages/std/src/bbstdMakeFileName.h
new file mode 100644 (file)
index 0000000..780ff1c
--- /dev/null
@@ -0,0 +1,39 @@
+#ifndef __bbstdMakeFileName_h_INCLUDED__
+#define __bbstdMakeFileName_h_INCLUDED__
+
+#include "bbtkUserBlackBox.h"
+
+namespace bbstd
+{
+  class MakeFileName
+    :
+  public bbtk::UserBlackBox
+  {
+    BBTK_USER_BLACK_BOX_INTERFACE(MakeFileName,bbtk::UserBlackBox);
+    BBTK_DECLARE_INPUT(Directory,std::string);
+    BBTK_DECLARE_INPUT(File,std::string);
+    BBTK_DECLARE_INPUT(Extent,std::string);
+    BBTK_DECLARE_OUTPUT(Out,std::string);
+    BBTK_PROCESS(DoProcess);
+    void DoProcess();
+
+  protected:
+    virtual void bbUserConstructor();
+
+  };
+
+  BBTK_BEGIN_DESCRIBE_BLACK_BOX(MakeFileName,bbtk::UserBlackBox);
+  BBTK_NAME("MakeFileName");
+  BBTK_AUTHOR("jpr@creatis.insa-lyon.fr");
+  BBTK_DESCRIPTION("Makes a kosher file name");
+  BBTK_INPUT(MakeFileName,Directory,"Directory Name",std::string);
+  BBTK_INPUT(MakeFileName,File,"File Name",std::string);
+  BBTK_INPUT(MakeFileName,Extent,"Extention",std::string);
+
+  BBTK_OUTPUT(MakeFileName,Out,"Full File Name",std::string);
+  BBTK_END_DESCRIBE_BLACK_BOX(MakeFileName);
+
+}
+// EO namespace bbstd
+
+#endif //  __bbstdMakeFileName_h_INCLUDED__
diff --git a/packages/std/src/bbstdMultipleInputs.xml b/packages/std/src/bbstdMultipleInputs.xml
new file mode 100644 (file)
index 0000000..f2cc3c9
--- /dev/null
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="iso-8859-1"?>
+
+<blackbox name="MultipleInputs">
+
+  <author>laurent.guigues@creatis.insa-lyon.fr</author>
+  <description>This box has multiple Void inputs and one Void output. Hence it relays any input modification to its output. It is usefull to plug different BoxChange outputs into the same BoxExecute.</description>
+
+  <parentblackbox>bbtk::UserBlackBox</parentblackbox>
+  <package>std</package>
+
+  <namespace>bbstd</namespace>
+
+  <input name="In1" type="bbtk::Void">Input 1</input>
+  <input name="In2" type="bbtk::Void">Input 2</input>
+  <input name="In3" type="bbtk::Void">Input 3</input>
+  <input name="In4" type="bbtk::Void">Input 4</input>
+  <input name="In5" type="bbtk::Void">Input 5</input>
+
+  <output name="Out" type="bbtk::Void">Output</output>
+
+</blackbox>
+
diff --git a/packages/std/src/bbstdStringSelect.cxx b/packages/std/src/bbstdStringSelect.cxx
new file mode 100644 (file)
index 0000000..ff20216
--- /dev/null
@@ -0,0 +1,44 @@
+#include "bbstdStringSelect.h"
+#include "bbstdPackage.h"
+
+namespace bbstd
+{
+
+       BBTK_ADD_BLACK_BOX_TO_PACKAGE(std,StringSelect)
+       BBTK_USER_BLACK_BOX_IMPLEMENTATION(StringSelect,bbtk::UserBlackBox);
+
+       void StringSelect::bbUserConstructor() 
+               { 
+                       bbSetInputIn(0);
+                       bbSetInputIn0("");
+                       bbSetInputIn1("");
+                       bbSetInputIn2("");
+                       bbSetInputIn3("");
+                       bbSetInputIn4("");
+                       bbSetInputIn5("");
+                       bbSetInputIn6("");
+                       bbSetInputIn7("");
+                       bbSetInputIn8("");
+                       bbSetInputIn9("");
+               }
+
+
+
+       void StringSelect::DoProcess()
+       {
+               if (bbGetInputIn()==0) bbSetOutputOut( bbGetInputIn0() );
+               else if (bbGetInputIn()==1) bbSetOutputOut( bbGetInputIn1() );
+               else if (bbGetInputIn()==2) bbSetOutputOut( bbGetInputIn2() );
+               else if (bbGetInputIn()==3) bbSetOutputOut( bbGetInputIn3() );
+               else if (bbGetInputIn()==4) bbSetOutputOut( bbGetInputIn4() );
+               else if (bbGetInputIn()==5) bbSetOutputOut( bbGetInputIn5() );
+               else if (bbGetInputIn()==6) bbSetOutputOut( bbGetInputIn6() );
+               else if (bbGetInputIn()==7) bbSetOutputOut( bbGetInputIn7() );
+               else if (bbGetInputIn()==8) bbSetOutputOut( bbGetInputIn8() );
+               else if (bbGetInputIn()==9) bbSetOutputOut( bbGetInputIn9() );
+         
+       }
+}
+// EO namespace bbstd
+
+
diff --git a/packages/std/src/bbstdStringSelect.h b/packages/std/src/bbstdStringSelect.h
new file mode 100644 (file)
index 0000000..18c5d21
--- /dev/null
@@ -0,0 +1,57 @@
+#ifndef __bbstdStringSelect_h_INCLUDED__
+#define __bbstdStringSelect_h_INCLUDED__
+
+#include "bbtkUserBlackBox.h"
+
+namespace bbstd
+{
+
+  class /*BBTK_EXPORT*/ StringSelect
+    : 
+    public bbtk::UserBlackBox
+  {
+    BBTK_USER_BLACK_BOX_INTERFACE(StringSelect,bbtk::UserBlackBox);
+    BBTK_DECLARE_INPUT(In,int);
+    BBTK_DECLARE_INPUT(In0,std::string);
+    BBTK_DECLARE_INPUT(In1,std::string);
+    BBTK_DECLARE_INPUT(In2,std::string);
+    BBTK_DECLARE_INPUT(In3,std::string);
+    BBTK_DECLARE_INPUT(In4,std::string);
+    BBTK_DECLARE_INPUT(In5,std::string);
+    BBTK_DECLARE_INPUT(In6,std::string);
+    BBTK_DECLARE_INPUT(In7,std::string);
+    BBTK_DECLARE_INPUT(In8,std::string);
+    BBTK_DECLARE_INPUT(In9,std::string);
+    BBTK_DECLARE_OUTPUT(Out,std::string);
+    BBTK_PROCESS(DoProcess);
+    void DoProcess();
+
+  protected:
+    virtual void bbUserConstructor();
+
+  };
+
+  BBTK_BEGIN_DESCRIBE_BLACK_BOX(StringSelect,bbtk::UserBlackBox);
+  BBTK_NAME("StringSelect");
+  BBTK_AUTHOR("eduardo.davila@creatis.insa-lyon.fr");
+  BBTK_DESCRIPTION("String selection with 0-9 entries");
+  BBTK_INPUT(StringSelect,In,"Index of the string to select",int);
+  BBTK_INPUT(StringSelect,In0,"String of index 0",std::string);
+  BBTK_INPUT(StringSelect,In1,"String of index 1",std::string);
+  BBTK_INPUT(StringSelect,In2,"String of index 2",std::string);
+  BBTK_INPUT(StringSelect,In3,"String of index 3",std::string);
+  BBTK_INPUT(StringSelect,In4,"String of index 4",std::string);
+  BBTK_INPUT(StringSelect,In5,"String of index 4",std::string);
+  BBTK_INPUT(StringSelect,In6,"String of index 6",std::string);
+  BBTK_INPUT(StringSelect,In7,"String of index 7",std::string);
+  BBTK_INPUT(StringSelect,In8,"String of index 8",std::string);
+  BBTK_INPUT(StringSelect,In9,"String of index 9",std::string);
+  BBTK_OUTPUT(StringSelect,Out,"Selected string",std::string);
+  BBTK_END_DESCRIBE_BLACK_BOX(StringSelect);
+
+}
+// EO namespace bbstd
+
+#endif //  __bbstdStringSelect_h_INCLUDED__
+
+
diff --git a/packages/std/src/bbstdStringTo.cxx b/packages/std/src/bbstdStringTo.cxx
new file mode 100644 (file)
index 0000000..6bd3cdc
--- /dev/null
@@ -0,0 +1,99 @@
+#include "bbstdStringTo.h"
+#include "bbstdPackage.h"
+
+
+namespace bbstd 
+{
+
+  //====================================================================
+  BBTK_USER_BLACK_BOX_TEMPLATE_IMPLEMENTATION(StringTo,
+                                              bbtk::UserBlackBox);
+  //====================================================================
+
+  //====================================================================
+  // Template specialization of DoIt
+  template <> void StringTo<bool> ::DoIt()
+  {
+    if ( (bbGetInputIn()=="true") || 
+         (bbGetInputIn()=="TRUE") || 
+         (bbGetInputIn()=="True") || 
+         (bbGetInputIn()=="1")     )  
+    {
+       bbSetOutputOut(true);
+    }
+    else if ( (bbGetInputIn()=="false") || 
+              (bbGetInputIn()=="FALSE") ||
+              (bbGetInputIn()=="False") ||
+              (bbGetInputIn()=="0") )  
+    {   
+       bbSetOutputOut(false); 
+    }
+    else 
+    {
+       bbtkError("cannot convert '"<<bbGetInputIn()<<"' to a bool");
+    }
+  }
+  
+  // Template specialization of DoIt
+  template <> void StringTo<bbtk::Void> ::DoIt()
+  {
+  }
+  
+  template <> void StringTo<int8_t> ::DoIt()
+  {
+    bbSetOutputOut( (int8_t)atoi ( bbGetInputIn().c_str() ) );
+  }
+  
+  template <> void StringTo<uint8_t> ::DoIt()
+  {
+    bbSetOutputOut( (uint8_t)atoi ( bbGetInputIn().c_str() ) );
+  }
+  
+  template <> void StringTo<int16_t> ::DoIt()
+  {
+    bbSetOutputOut( (int16_t)atoi ( bbGetInputIn().c_str() ) );
+  }
+  
+  template <> void StringTo<uint16_t> ::DoIt()
+  {
+    bbSetOutputOut( (uint16_t)atoi ( bbGetInputIn().c_str() ) );
+  }
+  
+  template <> void StringTo<int32_t> ::DoIt()
+  {
+    bbSetOutputOut( (int32_t)atoi ( bbGetInputIn().c_str() ) );
+  }
+  
+  template <> void StringTo<uint32_t> ::DoIt()
+  {
+    bbSetOutputOut( (uint32_t)atoi ( bbGetInputIn().c_str() ) );
+  }
+  
+  template <> void StringTo<float> ::DoIt()
+  {
+    bbSetOutputOut( (float)atof ( bbGetInputIn().c_str() ) );
+  }
+  
+  template <> void StringTo<double> ::DoIt()
+  {
+    bbSetOutputOut( atof ( bbGetInputIn().c_str() ) );
+  }
+  
+  //====================================================================
+  
+  //====================================================================
+  // Add the specialized adaptors to the package
+  typedef bbtk::Void Void;
+  BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringTo,bool);
+  BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringTo,int8_t);
+  BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringTo,uint8_t);
+  BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringTo,int16_t);
+  BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringTo,uint16_t);
+  BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringTo,int32_t);
+  BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringTo,uint32_t);
+  BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringTo,float);
+  BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringTo,double);
+  BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringTo,Void);
+  //====================================================================
+  
+} // namespace bbstd
diff --git a/packages/std/src/bbstdStringTo.h b/packages/std/src/bbstdStringTo.h
new file mode 100644 (file)
index 0000000..13ec026
--- /dev/null
@@ -0,0 +1,45 @@
+#ifndef __bbstdStringTo_h_INCLUDED__
+#define __bbstdStringTo_h_INCLUDED__
+
+#include "bbtkUserBlackBox.h"
+
+
+namespace bbstd 
+{
+
+  //=================================================================
+  // UserBlackBox declaration
+  template <class T>
+  class StringTo : public bbtk::UserBlackBox
+  {  
+    BBTK_USER_BLACK_BOX_INTERFACE(StringTo,bbtk::UserBlackBox);
+    BBTK_DECLARE_INPUT(In,std::string);
+    BBTK_DECLARE_OUTPUT(Out,T);
+    BBTK_PROCESS(DoIt);
+    void DoIt(); 
+  };
+  //=================================================================
+  
+  
+  
+  
+  //=================================================================
+  // UserBlackBox description
+  BBTK_BEGIN_DESCRIBE_TEMPLATE_BLACK_BOX(StringTo);
+  BBTK_NAME("StringTo"+bbtk::HumanTypeName<T>());
+  BBTK_AUTHOR("laurent.guigues@creatis.insa-lyon.fr");
+  BBTK_DEFAULT_ADAPTOR();
+  BBTK_DESCRIPTION("Converts the content of the input string to a "+bbtk::TypeName<T>());
+  BBTK_TEMPLATE_INPUT(StringTo, In,"Input",std::string);
+  BBTK_TEMPLATE_OUTPUT(StringTo, Out,"Output",T);
+  BBTK_END_DESCRIBE_TEMPLATE_BLACK_BOX(StringTo);
+  //=================================================================
+  
+} // namespace bbstd
+
+#endif // __bbstdStringTo_h_INCLUDED__
+
+
+
+
diff --git a/packages/std/src/bbstdStringToVector.cxx b/packages/std/src/bbstdStringToVector.cxx
new file mode 100644 (file)
index 0000000..69e2a46
--- /dev/null
@@ -0,0 +1,86 @@
+#include "bbstdStringToVector.h"
+#include "bbstdPackage.h"
+
+
+namespace bbstd
+{
+  //====================================================================
+  BBTK_USER_BLACK_BOX_TEMPLATE_IMPLEMENTATION(StringToVector,
+                                             bbtk::UserBlackBox);
+  //====================================================================
+  
+  
+  
+  
+  //====================================================================
+  // Template specialization of decode_item
+  template <> int8_t StringToVector<int8_t> ::decode_item(const std::string& s)
+  {
+    return (int8_t)atoi ( s.c_str() );
+  }
+  
+  template <> uint8_t StringToVector<uint8_t> ::decode_item(const std::string& s)
+  {
+    return (uint8_t)atoi ( s.c_str() );
+}
+
+template <> int16_t StringToVector<int16_t> ::decode_item(const std::string& s)
+{
+  return (int16_t)atoi ( s.c_str() );
+}
+
+template <> uint16_t StringToVector<uint16_t> ::decode_item(const std::string& s)
+{
+  return (uint16_t)atoi ( s.c_str() );
+}
+
+template <> int32_t StringToVector<int32_t> ::decode_item(const std::string& s)
+{
+  return (int32_t)atoi ( s.c_str() );
+}
+
+template <> uint32_t StringToVector<uint32_t> ::decode_item(const std::string& s) 
+{
+  return (uint32_t)atoi ( s.c_str() );
+}
+
+template <> long StringToVector<long> ::decode_item(const std::string& s)
+{
+  // std::cout << bbGetFullName() << " v="<<s<<std::endl;
+  return (long)atoi ( s.c_str() );
+}
+
+template <> float StringToVector<float> ::decode_item(const std::string& s)
+{
+  return (float)atof ( s.c_str() );
+}
+
+template <> double StringToVector<double> ::decode_item(const std::string& s)
+{
+  return atof ( s.c_str() );
+}
+
+template <> std::string StringToVector<std::string> ::decode_item(const std::string& s)
+{
+  return s;
+}
+
+//====================================================================
+
+//====================================================================
+// Add the specialized adaptors to the package
+
+BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringToVector,int8_t);
+BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringToVector,uint8_t);
+BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringToVector,int16_t);
+BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringToVector,uint16_t);
+BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringToVector,int32_t);
+BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringToVector,uint32_t);
+BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringToVector,long);
+BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringToVector,float);
+BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringToVector,double);
+typedef std::string string;
+BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,StringToVector,string);
+//====================================================================
+
+} // namespace bbstd
diff --git a/packages/std/src/bbstdStringToVector.h b/packages/std/src/bbstdStringToVector.h
new file mode 100644 (file)
index 0000000..cd39769
--- /dev/null
@@ -0,0 +1,74 @@
+#ifndef __bbstdStringToVector_INCLUDED_h__
+#define __bbstdStringToVector_INCLUDED_h__
+
+#include "bbtkUserBlackBox.h"
+
+namespace bbstd
+{
+
+//=================================================================
+// UserBlackBox declaration
+template <class T>
+class StringToVector : public bbtk::UserBlackBox
+{  
+  BBTK_USER_BLACK_BOX_INTERFACE(StringToVector,bbtk::UserBlackBox);
+  BBTK_DECLARE_INPUT(In,std::string);
+  BBTK_DECLARE_OUTPUT(Out,std::vector<T>);
+  BBTK_PROCESS(DoIt);
+  void DoIt(); 
+  T decode_item(const std::string&);
+};
+//=================================================================
+
+
+//=================================================================
+// UserBlackBox description
+BBTK_BEGIN_DESCRIBE_TEMPLATE_BLACK_BOX(StringToVector);
+BBTK_NAME("StringTo"+bbtk::TypeName<std::vector<T> >());
+BBTK_AUTHOR("laurent.guigues@creatis.insa-lyon.fr");
+BBTK_DEFAULT_ADAPTOR();
+BBTK_DESCRIPTION("Converts the content of the input string to a "+bbtk::TypeName<std::vector<T> >());
+BBTK_TEMPLATE_INPUT(StringToVector, In,"Input",std::string);
+typedef std::vector<T> Tvector;
+BBTK_TEMPLATE_OUTPUT(StringToVector, Out,"Output",Tvector);
+BBTK_END_DESCRIBE_TEMPLATE_BLACK_BOX(StringToVector);
+//=================================================================
+
+
+
+//=================================================================
+template <class T>
+void StringToVector<T>::DoIt()
+{
+  //  std::cout << "StringToVector<"<<bbtk::TypeName<T>()<<">::DoIt()"<<std::endl;
+
+  typedef T type;
+  std::string delimiters(" ,;");
+  std::string str(bbGetInputIn()); 
+  //  std::cout << "'"<< str << "'"<<std::endl;
+  // Skip delimiters at beginning.
+  std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
+  // Find first "non-delimiter".
+  std::string::size_type pos     = str.find_first_of(delimiters, lastPos);
+  bbmOutputOut.clear();
+  while (std::string::npos != pos || std::string::npos != lastPos)
+    {
+      // Found a token, add it to the vector.
+      bbmOutputOut.push_back( 
+                            this->decode_item( str.substr(lastPos, pos - lastPos) ) );
+      //      std::cout << this->bbGetOutputOut().back() << std::endl;
+      // Skip delimiters.  Note the "not_of"
+      lastPos = str.find_first_not_of(delimiters, pos);
+      // Find next "non-delimiter"
+      pos = str.find_first_of(delimiters, lastPos);
+    }
+  //  std::cout << "s=" << this->bbGetOutputOut().size() << std::endl;
+}
+//=================================================================
+
+
+} // namespace bbstd
+
+#endif //__bbstdStringToVector_INCLUDED_h__
+
diff --git a/packages/std/src/bbstdToString.cxx b/packages/std/src/bbstdToString.cxx
new file mode 100644 (file)
index 0000000..691a821
--- /dev/null
@@ -0,0 +1,38 @@
+#include "bbstdToString.h"
+#include "bbstdPackage.h"
+#include <sstream>
+
+namespace bbstd 
+{
+
+  //====================================================================
+  BBTK_USER_BLACK_BOX_TEMPLATE_IMPLEMENTATION(ToString,
+                                              bbtk::UserBlackBox);
+  //====================================================================
+  
+  //====================================================================
+  template <class T> void ToString<T> ::DoIt()
+  {
+    std::ostringstream s;
+    s <<  bbGetInputIn(); 
+    bbSetOutputOut( s.str() );
+  }
+  //====================================================================
+  
+  //====================================================================
+  // Add the specialized adaptors to the package
+  BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,ToString,bool);
+  BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,ToString,int8_t);
+  BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,ToString,uint8_t);
+  BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,ToString,int16_t);
+  BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,ToString,uint16_t);
+  BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,ToString,int32_t);
+  BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,ToString,uint32_t);
+  BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,ToString,float);
+  BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,ToString,double);
+  //====================================================================
+  
+
+} // namespace bbstd
+
diff --git a/packages/std/src/bbstdToString.h b/packages/std/src/bbstdToString.h
new file mode 100644 (file)
index 0000000..31c330d
--- /dev/null
@@ -0,0 +1,40 @@
+#ifndef __bbstdToString_h_INCLUDED__
+#define __bbstdToString_h_INCLUDED__
+
+#include "bbtkUserBlackBox.h"
+
+namespace bbstd 
+{
+  
+  //=================================================================
+  // UserBlackBox declaration
+  template <class T>
+  class ToString : public bbtk::UserBlackBox
+  {  
+    BBTK_USER_BLACK_BOX_INTERFACE(ToString,bbtk::UserBlackBox);
+    BBTK_DECLARE_INPUT(In,T);
+    BBTK_DECLARE_OUTPUT(Out,std::string);
+    BBTK_PROCESS(DoIt);
+    void DoIt(); 
+  };
+  //=================================================================
+  
+  
+  
+  
+  //=================================================================
+  // UserBlackBox description
+  BBTK_BEGIN_DESCRIBE_TEMPLATE_BLACK_BOX(ToString);
+  BBTK_NAME(bbtk::TypeName<T>()+"ToString");
+  BBTK_AUTHOR("laurent.guigues@creatis.insa-lyon.fr");
+  BBTK_DEFAULT_ADAPTOR();
+  BBTK_DESCRIPTION("Converts a "+bbtk::TypeName<T>()+" into a string");
+  BBTK_TEMPLATE_INPUT(ToString, In,"Input",T);
+  BBTK_TEMPLATE_OUTPUT(ToString, Out,"Output",std::string);
+  BBTK_END_DESCRIBE_TEMPLATE_BLACK_BOX(ToString);
+  //=================================================================
+  
+} // namespace bbstd 
+
+#endif // __bbstdToString_h_INCLUDED__
diff --git a/packages/std/src/bbstdVectorToString.cxx b/packages/std/src/bbstdVectorToString.cxx
new file mode 100644 (file)
index 0000000..68cc28a
--- /dev/null
@@ -0,0 +1,86 @@
+#include "bbstdVectorToString.h"
+#include "bbstdPackage.h"
+
+
+namespace bbstd
+{
+  //====================================================================
+  BBTK_USER_BLACK_BOX_TEMPLATE_IMPLEMENTATION(VectorToString,
+                                             bbtk::UserBlackBox);
+  //====================================================================
+  
+  
+  
+  /*
+  //====================================================================
+  // Template specialization of encode_item
+  template <> int8_t VectorToString<int8_t> ::encode_item(const std::string& s)
+  {
+    return (int8_t)atoi ( s.c_str() );
+  }
+  
+  template <> uint8_t VectorToString<uint8_t> ::encode_item(const std::string& s)
+  {
+    return (uint8_t)atoi ( s.c_str() );
+}
+
+template <> int16_t VectorToString<int16_t> ::encode_item(const std::string& s)
+{
+  return (int16_t)atoi ( s.c_str() );
+}
+
+template <> uint16_t VectorToString<uint16_t> ::encode_item(const std::string& s)
+{
+  return (uint16_t)atoi ( s.c_str() );
+}
+
+template <> int32_t VectorToString<int32_t> ::encode_item(const std::string& s)
+{
+  return (int32_t)atoi ( s.c_str() );
+}
+
+template <> uint32_t VectorToString<uint32_t> ::encode_item(const std::string& s) 
+{
+  return (uint32_t)atoi ( s.c_str() );
+}
+
+template <> long VectorToString<long> ::encode_item(const std::string& s)
+{
+  return (long)atoi ( s.c_str() );
+}
+
+template <> float VectorToString<float> ::encode_item(const std::string& s)
+{
+  return (float)atof ( s.c_str() );
+}
+
+template <> double VectorToString<double> ::encode_item(const std::string& s)
+{
+  return atof ( s.c_str() );
+}
+
+template <> std::string VectorToString<std::string> ::encode_item(const std::string& s)
+{
+  return s;
+}
+  */
+
+//====================================================================
+
+//====================================================================
+// Add the specialized adaptors to the package
+
+BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,VectorToString,int8_t);
+BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,VectorToString,uint8_t);
+BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,VectorToString,int16_t);
+BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,VectorToString,uint16_t);
+BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,VectorToString,int32_t);
+BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,VectorToString,uint32_t);
+BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,VectorToString,long);
+BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,VectorToString,float);
+BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,VectorToString,double);
+typedef std::string string;
+BBTK_ADD_TEMPLATE_BLACK_BOX_TO_PACKAGE(std,VectorToString,string);
+//====================================================================
+
+} // namespace bbstd
diff --git a/packages/std/src/bbstdVectorToString.h b/packages/std/src/bbstdVectorToString.h
new file mode 100644 (file)
index 0000000..3c28ff1
--- /dev/null
@@ -0,0 +1,70 @@
+#ifndef __bbstdVectorToString_INCLUDED_h__
+#define __bbstdVectorToString_INCLUDED_h__
+
+#include "bbtkUserBlackBox.h"
+
+namespace bbstd
+{
+
+  //=================================================================
+  // UserBlackBox declaration
+  template <class T>
+  class VectorToString : public bbtk::UserBlackBox
+  {  
+    BBTK_USER_BLACK_BOX_INTERFACE(VectorToString,bbtk::UserBlackBox);
+    BBTK_DECLARE_INPUT(In,std::vector<T>);
+    BBTK_DECLARE_INPUT(Separator,std::string);
+    BBTK_DECLARE_OUTPUT(Out,std::string);
+    BBTK_PROCESS(DoIt);
+    void DoIt(); 
+    virtual void bbUserConstructor();
+  };
+  //=================================================================
+  
+  
+  
+  //=================================================================
+  // UserBlackBox description
+  BBTK_BEGIN_DESCRIBE_TEMPLATE_BLACK_BOX(VectorToString);
+  BBTK_NAME(bbtk::TypeName<std::vector<T> >()+"ToString");
+  BBTK_AUTHOR("laurent.guigues@creatis.insa-lyon.fr");
+  BBTK_DEFAULT_ADAPTOR();
+  BBTK_DESCRIPTION("Converts the content of the input vector ("+bbtk::TypeName<std::vector<T> >()+") to a string in which each item is separated by the value of the input 'Separator'");
+  typedef std::vector<T> Tvector;
+  BBTK_TEMPLATE_INPUT(VectorToString, In,"Input",Tvector);
+  BBTK_TEMPLATE_INPUT(VectorToString, Separator,"Separator of item in the output string. Default is whitespace.",std::string);
+  BBTK_TEMPLATE_OUTPUT(VectorToString, Out,"Output",std::string);
+  BBTK_END_DESCRIBE_TEMPLATE_BLACK_BOX(VectorToString);
+  //=================================================================
+  
+
+  
+  //=================================================================
+  template <class T>
+  void VectorToString<T>::DoIt()
+  {
+    std::string out;
+    typename std::vector<T>::const_iterator i;
+    for (i=bbmInputIn.begin();i!=bbmInputIn.end();++i)
+      {
+       if (i!=bbmInputIn.begin()) out += bbGetInputSeparator();
+       std::ostringstream s;                           
+       s <<  *i;
+       out += s.str();
+      }
+    bbSetOutputOut(out);
+  }
+  //=================================================================
+  
+  //=================================================================
+  template <class T>
+  void VectorToString<T>::bbUserConstructor()
+  {
+    bbSetInputSeparator(" ");
+  }
+  //=================================================================
+
+} // namespace bbstd
+
+#endif //__bbstdVectorToString_INCLUDED_h__
+