]> Creatis software - bbtk.git/blob - packages/std/src/bbstdVectorToString.h
Renamed UserBlackBox into AtomicBlackBox which is a better name (versus ComplexBlackB...
[bbtk.git] / packages / std / src / bbstdVectorToString.h
1 #ifndef __bbstdVectorToString_INCLUDED_h__
2 #define __bbstdVectorToString_INCLUDED_h__
3
4 #include "bbtkAtomicBlackBox.h"
5
6 namespace bbstd
7 {
8   //=================================================================
9   // BlackBox declaration
10   template <class T>
11   class VectorToString : public bbtk::AtomicBlackBox
12   {  
13     BBTK_USER_BLACK_BOX_INTERFACE(VectorToString,bbtk::AtomicBlackBox);
14       BBTK_DECLARE_INPUT(In,std::vector<T>);
15       BBTK_DECLARE_INPUT(Separator,std::string);
16       BBTK_DECLARE_OUTPUT(Out,std::string);
17     BBTK_PROCESS(DoIt);
18     void DoIt(); 
19     virtual void bbUserConstructor();
20   };
21   //=================================================================
22
23   //=================================================================
24   // BlackBox description
25   BBTK_BEGIN_DESCRIBE_TEMPLATE_BLACK_BOX(VectorToString);
26   BBTK_NAME(bbtk::TypeName<std::vector<T> >()+"ToString");
27   BBTK_AUTHOR("laurent.guigues@creatis.insa-lyon.fr");
28   BBTK_CATEGORY("adaptor");
29   BBTK_DEFAULT_ADAPTOR();
30   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'");
31     typedef std::vector<T> Tvector;
32     BBTK_TEMPLATE_INPUT(VectorToString, In,"Input",Tvector);
33     BBTK_TEMPLATE_INPUT(VectorToString, Separator,"Separator of item in the output string. Default is whitespace.",std::string);
34     BBTK_TEMPLATE_OUTPUT(VectorToString, Out,"Output",std::string);
35   BBTK_END_DESCRIBE_TEMPLATE_BLACK_BOX(VectorToString);
36   //=================================================================
37
38   //=================================================================
39   template <class T>
40   void VectorToString<T>::DoIt()
41   {
42     std::string out;
43     typename std::vector<T>::const_iterator i;
44     for (i=bbmInputIn.begin();i!=bbmInputIn.end();++i)
45     {
46       if (i!=bbmInputIn.begin())
47          out += bbGetInputSeparator();
48       std::ostringstream s;
49       s <<  *i;
50       out += s.str();
51     }
52     bbSetOutputOut(out);
53   }
54   //=================================================================
55
56   //=================================================================  
57   template <class T>
58   void VectorToString<T>::bbUserConstructor()
59   {
60     bbSetInputSeparator(" ");
61   }
62   //=================================================================
63
64 } // namespace bbstd
65
66 #endif //__bbstdVectorToString_INCLUDED_h__
67