2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ */
28 /*=========================================================================
30 Module: $RCSfile: bbstdStringToVector.h,v $
32 Date: $Date: 2012/11/16 08:51:32 $
33 Version: $Revision: 1.11 $
34 =========================================================================*/
38 #ifndef __bbstdStringToVector_INCLUDED_h__
39 #define __bbstdStringToVector_INCLUDED_h__
41 #include "bbtkAtomicBlackBox.h"
42 #include "bbstd_EXPORT.h"
46 //=================================================================
47 // BlackBox declaration
49 class bbstd_EXPORT StringToVector : public bbtk::AtomicBlackBox
51 BBTK_TEMPLATE_BLACK_BOX_INTERFACE(StringToVector,bbtk::AtomicBlackBox,T);
52 BBTK_DECLARE_INPUT(In,std::string);
53 BBTK_DECLARE_OUTPUT(Out,std::vector<T>);
56 T decode_item(const std::string&);
58 //=================================================================
60 //=================================================================
61 // BlackBox description
62 BBTK_BEGIN_DESCRIBE_TEMPLATE_BLACK_BOX(StringToVector,bbtk::AtomicBlackBox);
63 BBTK_NAME("StringTo"+bbtk::HumanTypeName<std::vector<T> >());
64 BBTK_AUTHOR("laurent.guigues@creatis.insa-lyon.fr");
65 BBTK_DEFAULT_ADAPTOR();
66 BBTK_DESCRIPTION("Converts the content of the input string to a "
67 +bbtk::HumanTypeName<std::vector<T> >()
68 +" ("+bbtk::TypeName<std::vector<T> >()+")");
69 BBTK_TEMPLATE_INPUT(StringToVector, In,"Input",std::string);
70 typedef std::vector<T> Tvector;
71 BBTK_TEMPLATE_OUTPUT(StringToVector, Out,"Output",Tvector);
72 BBTK_END_DESCRIBE_TEMPLATE_BLACK_BOX(StringToVector);
73 //=================================================================
76 template <class T> void StringToVector<T>::bbUserSetDefaultValues() {}
77 template <class T> void StringToVector<T>::bbUserInitializeProcessing() {}
78 template <class T> void StringToVector<T>::bbUserFinalizeProcessing() {}
79 //=================================================================
81 void StringToVector<T>::DoIt()
83 // std::cout << "StringToVector<"<<bbtk::TypeName<T>()<<">::DoIt()"<<std::endl;
86 std::string delimiters(" ,;");
87 std::string str(bbGetInputIn());
88 // std::cout << "'"<< str << "'"<<std::endl;
89 // Skip delimiters at beginning.
90 std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
91 // Find first "non-delimiter".
92 std::string::size_type pos = str.find_first_of(delimiters, lastPos);
93 // bbmOutputOut.clear();
95 while (std::string::npos != pos || std::string::npos != lastPos)
97 // Found a token, add it to the vector.
98 // bbmOutputOut.push_back( this->decode_item( str.substr(lastPos, pos - lastPos) ) );
99 out.push_back( this->decode_item( str.substr(lastPos, pos - lastPos) ) );
100 // std::cout << this->bbGetOutputOut().back() << std::endl;
101 // Skip delimiters. Note the "not_of"
102 lastPos = str.find_first_not_of(delimiters, pos);
103 // Find next "non-delimiter"
104 pos = str.find_first_of(delimiters, lastPos);
106 bbSetOutputOut (out);
107 //bbSignalOutputModification();
108 // std::cout << "s=" << this->bbGetOutputOut().size() << std::endl;
110 //=================================================================
115 #endif //__bbstdStringToVector_INCLUDED_h__