]> Creatis software - bbtk.git/blob - packages/std/src/bbstdStringToVector.h
#3152 BBTK Bug New Normal - ShareMemory, ComboBox->list
[bbtk.git] / packages / std / src / bbstdStringToVector.h
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
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
9  #
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.
16  #
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
21  #  liability.
22  #
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  # ------------------------------------------------------------------------ */
26
27
28 /*=========================================================================
29   Program:   bbtk
30   Module:    $RCSfile: bbstdStringToVector.h,v $
31   Language:  C++
32   Date:      $Date: 2012/11/16 08:51:32 $
33   Version:   $Revision: 1.11 $
34 =========================================================================*/
35
36
37
38 #ifndef __bbstdStringToVector_INCLUDED_h__
39 #define __bbstdStringToVector_INCLUDED_h__
40
41 #include "bbtkAtomicBlackBox.h"
42 #include "bbstd_EXPORT.h"
43
44 namespace bbstd
45 {
46   //=================================================================
47   // BlackBox declaration
48   template <class T>
49   class bbstd_EXPORT StringToVector : public bbtk::AtomicBlackBox
50   {  
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>);
54     BBTK_PROCESS(DoIt);
55     void DoIt(); 
56     T decode_item(const std::string&);
57   };
58   //=================================================================  
59
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   //=================================================================
74   
75
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   //=================================================================
80   template <class T>
81   void StringToVector<T>::DoIt()
82   {
83     //  std::cout << "StringToVector<"<<bbtk::TypeName<T>()<<">::DoIt()"<<std::endl;
84     
85     typedef T type;
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();
94 std::vector<T> out;
95     while (std::string::npos != pos || std::string::npos != lastPos)
96       {
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);
105       }
106 bbSetOutputOut (out);
107 //bbSignalOutputModification();
108     //  std::cout << "s=" << this->bbGetOutputOut().size() << std::endl;
109   }
110   //=================================================================
111   
112   
113 } // namespace bbstd
114
115 #endif //__bbstdStringToVector_INCLUDED_h__