00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef __bbstdVectorToString_INCLUDED_h__
00034 #define __bbstdVectorToString_INCLUDED_h__
00035
00036 #include "bbtkAtomicBlackBox.h"
00037
00038 namespace bbstd
00039 {
00040
00041
00042 template <class T>
00043 class VectorToString : public bbtk::AtomicBlackBox
00044 {
00045 BBTK_TEMPLATE_BLACK_BOX_INTERFACE(VectorToString,bbtk::AtomicBlackBox,T);
00046 BBTK_DECLARE_INPUT(In,std::vector<T>);
00047 BBTK_DECLARE_INPUT(Separator,std::string);
00048 BBTK_DECLARE_OUTPUT(Out,std::string);
00049 BBTK_PROCESS(DoIt);
00050 void DoIt();
00051 virtual void bbUserConstructor();
00052 };
00053
00054
00055
00056
00057 BBTK_BEGIN_DESCRIBE_TEMPLATE_BLACK_BOX(VectorToString,bbtk::AtomicBlackBox);
00058 BBTK_NAME(bbtk::HumanTypeName<std::vector<T> >()+"ToString");
00059 BBTK_AUTHOR("laurent.guigues@creatis.insa-lyon.fr");
00060 BBTK_DEFAULT_ADAPTOR();
00061 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'");
00062 typedef std::vector<T> Tvector;
00063 BBTK_TEMPLATE_INPUT(VectorToString, In,"Input",Tvector);
00064 BBTK_TEMPLATE_INPUT(VectorToString, Separator,"Separator of item in the output string. Default is whitespace.",std::string);
00065 BBTK_TEMPLATE_OUTPUT(VectorToString, Out,"Output",std::string);
00066 BBTK_END_DESCRIBE_TEMPLATE_BLACK_BOX(VectorToString);
00067
00068
00069
00070 template <class T>
00071 void VectorToString<T>::DoIt()
00072 {
00073 std::string out;
00074 typename std::vector<T>::const_iterator i;
00075 for (i=bbmInputIn.begin();i!=bbmInputIn.end();++i)
00076 {
00077 if (i!=bbmInputIn.begin())
00078 out += bbGetInputSeparator();
00079 std::ostringstream s;
00080 s << *i;
00081 out += s.str();
00082 }
00083 bbSetOutputOut(out);
00084 }
00085
00086
00087
00088 template <class T>
00089 void VectorToString<T>::bbUserConstructor()
00090 {
00091 bbSetInputSeparator(" ");
00092 }
00093
00094
00095 }
00096
00097 #endif //__bbstdVectorToString_INCLUDED_h__
00098