From e27f49d94042bf18dc5067807594325eea8b6d56 Mon Sep 17 00:00:00 2001 From: Eduardo Davila Date: Tue, 5 Feb 2008 11:08:54 +0000 Subject: [PATCH] *** empty log message *** --- packages/std/bbs/boxes/bbPrependDataPath.bbs | 18 ++++ packages/std/src/bbstdConcatStrings.cxx | 41 ++++++++ packages/std/src/bbstdConcatStrings.h | 55 +++++++++++ packages/std/src/bbstdConfiguration.cxx | 34 +++++++ packages/std/src/bbstdConfiguration.h | 39 ++++++++ packages/std/src/bbstdMagicBox.cxx | 12 +++ packages/std/src/bbstdMagicBox.h | 85 +++++++++++++++++ packages/std/src/bbstdMakeFileName.cxx | 32 +++++++ packages/std/src/bbstdMakeFileName.h | 39 ++++++++ packages/std/src/bbstdMultipleInputs.xml | 22 +++++ packages/std/src/bbstdStringSelect.cxx | 44 +++++++++ packages/std/src/bbstdStringSelect.h | 57 +++++++++++ packages/std/src/bbstdStringTo.cxx | 99 ++++++++++++++++++++ packages/std/src/bbstdStringTo.h | 45 +++++++++ packages/std/src/bbstdStringToVector.cxx | 86 +++++++++++++++++ packages/std/src/bbstdStringToVector.h | 74 +++++++++++++++ packages/std/src/bbstdToString.cxx | 38 ++++++++ packages/std/src/bbstdToString.h | 40 ++++++++ packages/std/src/bbstdVectorToString.cxx | 86 +++++++++++++++++ packages/std/src/bbstdVectorToString.h | 70 ++++++++++++++ 20 files changed, 1016 insertions(+) create mode 100755 packages/std/bbs/boxes/bbPrependDataPath.bbs create mode 100644 packages/std/src/bbstdConcatStrings.cxx create mode 100644 packages/std/src/bbstdConcatStrings.h create mode 100644 packages/std/src/bbstdConfiguration.cxx create mode 100644 packages/std/src/bbstdConfiguration.h create mode 100644 packages/std/src/bbstdMagicBox.cxx create mode 100644 packages/std/src/bbstdMagicBox.h create mode 100644 packages/std/src/bbstdMakeFileName.cxx create mode 100644 packages/std/src/bbstdMakeFileName.h create mode 100644 packages/std/src/bbstdMultipleInputs.xml create mode 100644 packages/std/src/bbstdStringSelect.cxx create mode 100644 packages/std/src/bbstdStringSelect.h create mode 100644 packages/std/src/bbstdStringTo.cxx create mode 100644 packages/std/src/bbstdStringTo.h create mode 100644 packages/std/src/bbstdStringToVector.cxx create mode 100644 packages/std/src/bbstdStringToVector.h create mode 100644 packages/std/src/bbstdToString.cxx create mode 100644 packages/std/src/bbstdToString.h create mode 100644 packages/std/src/bbstdVectorToString.cxx create mode 100644 packages/std/src/bbstdVectorToString.h diff --git a/packages/std/bbs/boxes/bbPrependDataPath.bbs b/packages/std/bbs/boxes/bbPrependDataPath.bbs new file mode 100755 index 0000000..ee5d57a --- /dev/null +++ b/packages/std/bbs/boxes/bbPrependDataPath.bbs @@ -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 index 0000000..5ca9c5f --- /dev/null +++ b/packages/std/src/bbstdConcatStrings.cxx @@ -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 index 0000000..9c2ea9b --- /dev/null +++ b/packages/std/src/bbstdConcatStrings.h @@ -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 index 0000000..8fab8fe --- /dev/null +++ b/packages/std/src/bbstdConfiguration.cxx @@ -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 index 0000000..6d88344 --- /dev/null +++ b/packages/std/src/bbstdConfiguration.h @@ -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 index 0000000..bf111dd --- /dev/null +++ b/packages/std/src/bbstdMagicBox.cxx @@ -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 index 0000000..5c70c64 --- /dev/null +++ b/packages/std/src/bbstdMagicBox.h @@ -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()"<*mSetMethodPointer)(d); + } + + /// + bbtk::TypeInfo GetTypeInfo() const { return typeid(bbtk::Data); } + std::string GetTypeName() const { return bbtk::TypeName(); } + std::string GetHumanTypeName() const { return bbtk::HumanTypeName(); } + 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::bbGetInputIn), + new MagicBoxSetFunctor (&MagicBox::bbSetInputIn) ) ); + AddOutputDescriptor(new bbtk::UserBlackBoxOutputDescriptor + ("Out","Output data", + new bbtk::UserBlackBoxTGetFunctor + (&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 index 0000000..73a6ece --- /dev/null +++ b/packages/std/src/bbstdMakeFileName.cxx @@ -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 index 0000000..780ff1c --- /dev/null +++ b/packages/std/src/bbstdMakeFileName.h @@ -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 index 0000000..f2cc3c9 --- /dev/null +++ b/packages/std/src/bbstdMultipleInputs.xml @@ -0,0 +1,22 @@ + + + + + laurent.guigues@creatis.insa-lyon.fr + 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. + + bbtk::UserBlackBox + std + + bbstd + + Input 1 + Input 2 + Input 3 + Input 4 + Input 5 + + Output + + + diff --git a/packages/std/src/bbstdStringSelect.cxx b/packages/std/src/bbstdStringSelect.cxx new file mode 100644 index 0000000..ff20216 --- /dev/null +++ b/packages/std/src/bbstdStringSelect.cxx @@ -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 index 0000000..18c5d21 --- /dev/null +++ b/packages/std/src/bbstdStringSelect.h @@ -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 index 0000000..6bd3cdc --- /dev/null +++ b/packages/std/src/bbstdStringTo.cxx @@ -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 ::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 '"< void StringTo ::DoIt() + { + } + + template <> void StringTo ::DoIt() + { + bbSetOutputOut( (int8_t)atoi ( bbGetInputIn().c_str() ) ); + } + + template <> void StringTo ::DoIt() + { + bbSetOutputOut( (uint8_t)atoi ( bbGetInputIn().c_str() ) ); + } + + template <> void StringTo ::DoIt() + { + bbSetOutputOut( (int16_t)atoi ( bbGetInputIn().c_str() ) ); + } + + template <> void StringTo ::DoIt() + { + bbSetOutputOut( (uint16_t)atoi ( bbGetInputIn().c_str() ) ); + } + + template <> void StringTo ::DoIt() + { + bbSetOutputOut( (int32_t)atoi ( bbGetInputIn().c_str() ) ); + } + + template <> void StringTo ::DoIt() + { + bbSetOutputOut( (uint32_t)atoi ( bbGetInputIn().c_str() ) ); + } + + template <> void StringTo ::DoIt() + { + bbSetOutputOut( (float)atof ( bbGetInputIn().c_str() ) ); + } + + template <> void StringTo ::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 index 0000000..13ec026 --- /dev/null +++ b/packages/std/src/bbstdStringTo.h @@ -0,0 +1,45 @@ +#ifndef __bbstdStringTo_h_INCLUDED__ +#define __bbstdStringTo_h_INCLUDED__ + +#include "bbtkUserBlackBox.h" + + +namespace bbstd +{ + + + //================================================================= + // UserBlackBox declaration + template + 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()); + BBTK_AUTHOR("laurent.guigues@creatis.insa-lyon.fr"); + BBTK_DEFAULT_ADAPTOR(); + BBTK_DESCRIPTION("Converts the content of the input string to a "+bbtk::TypeName()); + 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 index 0000000..69e2a46 --- /dev/null +++ b/packages/std/src/bbstdStringToVector.cxx @@ -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 ::decode_item(const std::string& s) + { + return (int8_t)atoi ( s.c_str() ); + } + + template <> uint8_t StringToVector ::decode_item(const std::string& s) + { + return (uint8_t)atoi ( s.c_str() ); +} + +template <> int16_t StringToVector ::decode_item(const std::string& s) +{ + return (int16_t)atoi ( s.c_str() ); +} + +template <> uint16_t StringToVector ::decode_item(const std::string& s) +{ + return (uint16_t)atoi ( s.c_str() ); +} + +template <> int32_t StringToVector ::decode_item(const std::string& s) +{ + return (int32_t)atoi ( s.c_str() ); +} + +template <> uint32_t StringToVector ::decode_item(const std::string& s) +{ + return (uint32_t)atoi ( s.c_str() ); +} + +template <> long StringToVector ::decode_item(const std::string& s) +{ + // std::cout << bbGetFullName() << " v="< float StringToVector ::decode_item(const std::string& s) +{ + return (float)atof ( s.c_str() ); +} + +template <> double StringToVector ::decode_item(const std::string& s) +{ + return atof ( s.c_str() ); +} + +template <> std::string StringToVector ::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 index 0000000..cd39769 --- /dev/null +++ b/packages/std/src/bbstdStringToVector.h @@ -0,0 +1,74 @@ +#ifndef __bbstdStringToVector_INCLUDED_h__ +#define __bbstdStringToVector_INCLUDED_h__ + +#include "bbtkUserBlackBox.h" + +namespace bbstd +{ + +//================================================================= +// UserBlackBox declaration +template +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); + 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 >()); +BBTK_AUTHOR("laurent.guigues@creatis.insa-lyon.fr"); +BBTK_DEFAULT_ADAPTOR(); +BBTK_DESCRIPTION("Converts the content of the input string to a "+bbtk::TypeName >()); +BBTK_TEMPLATE_INPUT(StringToVector, In,"Input",std::string); +typedef std::vector Tvector; +BBTK_TEMPLATE_OUTPUT(StringToVector, Out,"Output",Tvector); +BBTK_END_DESCRIBE_TEMPLATE_BLACK_BOX(StringToVector); +//================================================================= + + + +//================================================================= +template +void StringToVector::DoIt() +{ + // std::cout << "StringToVector<"<()<<">::DoIt()"<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 index 0000000..691a821 --- /dev/null +++ b/packages/std/src/bbstdToString.cxx @@ -0,0 +1,38 @@ +#include "bbstdToString.h" +#include "bbstdPackage.h" +#include + + +namespace bbstd +{ + + //==================================================================== + BBTK_USER_BLACK_BOX_TEMPLATE_IMPLEMENTATION(ToString, + bbtk::UserBlackBox); + //==================================================================== + + //==================================================================== + template void ToString ::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 index 0000000..31c330d --- /dev/null +++ b/packages/std/src/bbstdToString.h @@ -0,0 +1,40 @@ +#ifndef __bbstdToString_h_INCLUDED__ +#define __bbstdToString_h_INCLUDED__ + +#include "bbtkUserBlackBox.h" + +namespace bbstd +{ + + //================================================================= + // UserBlackBox declaration + template + 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()+"ToString"); + BBTK_AUTHOR("laurent.guigues@creatis.insa-lyon.fr"); + BBTK_DEFAULT_ADAPTOR(); + BBTK_DESCRIPTION("Converts a "+bbtk::TypeName()+" 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 index 0000000..68cc28a --- /dev/null +++ b/packages/std/src/bbstdVectorToString.cxx @@ -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 ::encode_item(const std::string& s) + { + return (int8_t)atoi ( s.c_str() ); + } + + template <> uint8_t VectorToString ::encode_item(const std::string& s) + { + return (uint8_t)atoi ( s.c_str() ); +} + +template <> int16_t VectorToString ::encode_item(const std::string& s) +{ + return (int16_t)atoi ( s.c_str() ); +} + +template <> uint16_t VectorToString ::encode_item(const std::string& s) +{ + return (uint16_t)atoi ( s.c_str() ); +} + +template <> int32_t VectorToString ::encode_item(const std::string& s) +{ + return (int32_t)atoi ( s.c_str() ); +} + +template <> uint32_t VectorToString ::encode_item(const std::string& s) +{ + return (uint32_t)atoi ( s.c_str() ); +} + +template <> long VectorToString ::encode_item(const std::string& s) +{ + return (long)atoi ( s.c_str() ); +} + +template <> float VectorToString ::encode_item(const std::string& s) +{ + return (float)atof ( s.c_str() ); +} + +template <> double VectorToString ::encode_item(const std::string& s) +{ + return atof ( s.c_str() ); +} + +template <> std::string VectorToString ::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 index 0000000..3c28ff1 --- /dev/null +++ b/packages/std/src/bbstdVectorToString.h @@ -0,0 +1,70 @@ +#ifndef __bbstdVectorToString_INCLUDED_h__ +#define __bbstdVectorToString_INCLUDED_h__ + +#include "bbtkUserBlackBox.h" + +namespace bbstd +{ + + //================================================================= + // UserBlackBox declaration + template + class VectorToString : public bbtk::UserBlackBox + { + BBTK_USER_BLACK_BOX_INTERFACE(VectorToString,bbtk::UserBlackBox); + BBTK_DECLARE_INPUT(In,std::vector); + 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 >()+"ToString"); + BBTK_AUTHOR("laurent.guigues@creatis.insa-lyon.fr"); + BBTK_DEFAULT_ADAPTOR(); + BBTK_DESCRIPTION("Converts the content of the input vector ("+bbtk::TypeName >()+") to a string in which each item is separated by the value of the input 'Separator'"); + typedef std::vector 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 + void VectorToString::DoIt() + { + std::string out; + typename std::vector::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 + void VectorToString::bbUserConstructor() + { + bbSetInputSeparator(" "); + } + //================================================================= + +} // namespace bbstd + +#endif //__bbstdVectorToString_INCLUDED_h__ + -- 2.45.1