]> Creatis software - bbtk.git/blob - packages/std/src/bbstdVectorFilterString.cxx
#3492 SaveLstPoints
[bbtk.git] / packages / std / src / bbstdVectorFilterString.cxx
1 //===== 
2 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
3 //===== 
4 #include "bbstdVectorFilterString.h"
5 #include "bbstdPackage.h"
6 namespace bbstd
7 {
8
9 BBTK_ADD_BLACK_BOX_TO_PACKAGE(std,VectorFilterString)
10 BBTK_BLACK_BOX_IMPLEMENTATION(VectorFilterString,bbtk::AtomicBlackBox);
11 //===== 
12 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
13 //===== 
14
15 void VectorFilterString::ConnectionRepetitions( std::vector<std::string> vIn,std::vector<std::string> *vOut  )
16 {
17         int i,size=vIn.size();
18         int itmp=0, acum=0;
19         std::string stmp;
20         for( i=0;i<size;i++)
21         {
22                 if (vIn[i].compare( vIn[itmp])==0) 
23                 {
24                         acum++;
25                 } else {
26                         itmp=i;
27                         vOut->push_back(std::to_string(acum));
28                         acum=1;
29                 }
30         } // for
31         vOut->push_back(std::to_string(acum));
32 }
33
34 void VectorFilterString::FilterByFindinIn0()
35 {
36         std::vector<std::string> vOut0;
37         std::vector<std::string> vOut1;
38         std::vector<std::string> vOut2;
39         std::vector<std::string> vOut3;
40         std::vector<std::string> vOut4;
41         std::vector<std::string> vOut5;
42         std::vector<std::string> vOut6;
43         std::vector<std::string> vOut7;
44         std::vector<std::string> vOut8;
45         std::vector<std::string> vOut9;
46
47         int i,size = bbGetInputIn0().size();
48         int pos;
49         for (i=0; i<size; i++)
50         {
51                 pos=bbGetInputIn0()[i].find( bbGetInputsk1());
52                 if (  pos  >= 0)
53                 {
54                         vOut0.push_back( bbGetInputIn0()[i] );
55                         if ( i < bbGetInputIn1().size() ) { vOut1.push_back( bbGetInputIn1()[i] ); }
56                         if ( i < bbGetInputIn2().size() ) { vOut2.push_back( bbGetInputIn2()[i] ); }
57                         if ( i < bbGetInputIn3().size() ) { vOut3.push_back( bbGetInputIn3()[i] ); }
58                         if ( i < bbGetInputIn4().size() ) { vOut4.push_back( bbGetInputIn4()[i] ); }
59                         if ( i < bbGetInputIn5().size() ) { vOut5.push_back( bbGetInputIn5()[i] ); }
60                         if ( i < bbGetInputIn6().size() ) { vOut6.push_back( bbGetInputIn6()[i] ); }
61                         if ( i < bbGetInputIn7().size() ) { vOut7.push_back( bbGetInputIn7()[i] ); }
62                         if ( i < bbGetInputIn8().size() ) { vOut8.push_back( bbGetInputIn8()[i] ); }
63                         if ( i < bbGetInputIn9().size() ) { vOut9.push_back( bbGetInputIn9()[i] ); }
64                 } // if pos
65         } // for i
66         
67         bbSetOutputOut0( vOut0 );
68         bbSetOutputOut1( vOut1 );
69         bbSetOutputOut2( vOut2 );
70         bbSetOutputOut3( vOut3 );
71         bbSetOutputOut4( vOut4 );
72         bbSetOutputOut5( vOut5 );
73         bbSetOutputOut6( vOut6 );
74         bbSetOutputOut7( vOut7 );
75         bbSetOutputOut8( vOut8 );
76         bbSetOutputOut9( vOut9 );
77 }
78
79 void VectorFilterString::InsertStringPos()
80 {
81     std::vector<std::string> vOut0;
82     std::vector<std::string> vOut1;
83     std::vector<std::string> vOut2;
84     std::vector<std::string> vOut3;
85     std::vector<std::string> vOut4;
86     std::vector<std::string> vOut5;
87     std::vector<std::string> vOut6;
88     std::vector<std::string> vOut7;
89     std::vector<std::string> vOut8;
90     std::vector<std::string> vOut9;
91     int i,size      = bbGetInputIn0().size();
92     std::string sk1 = bbGetInputsk1();
93     int pos         = atoi( bbGetInputsk2().c_str() );
94     for (i=0; i<size; i++)
95     {
96         vOut0.push_back( bbGetInputIn0()[i].insert(pos,sk1) );
97         if ( i < bbGetInputIn1().size() ) { vOut1.push_back( bbGetInputIn1()[i].insert(pos,sk1) ); }
98         if ( i < bbGetInputIn2().size() ) { vOut2.push_back( bbGetInputIn2()[i].insert(pos,sk1) ); }
99         if ( i < bbGetInputIn3().size() ) { vOut3.push_back( bbGetInputIn3()[i].insert(pos,sk1) ); }
100         if ( i < bbGetInputIn4().size() ) { vOut4.push_back( bbGetInputIn4()[i].insert(pos,sk1) ); }
101         if ( i < bbGetInputIn5().size() ) { vOut5.push_back( bbGetInputIn5()[i].insert(pos,sk1) ); }
102         if ( i < bbGetInputIn6().size() ) { vOut6.push_back( bbGetInputIn6()[i].insert(pos,sk1) ); }
103         if ( i < bbGetInputIn7().size() ) { vOut7.push_back( bbGetInputIn7()[i].insert(pos,sk1) ); }
104         if ( i < bbGetInputIn8().size() ) { vOut8.push_back( bbGetInputIn8()[i].insert(pos,sk1) ); }
105         if ( i < bbGetInputIn9().size() ) { vOut9.push_back( bbGetInputIn9()[i].insert(pos,sk1) ); }
106     } // for i
107     bbSetOutputOut0( vOut0 );
108     bbSetOutputOut1( vOut1 );
109     bbSetOutputOut2( vOut2 );
110     bbSetOutputOut3( vOut3 );
111     bbSetOutputOut4( vOut4 );
112     bbSetOutputOut5( vOut5 );
113     bbSetOutputOut6( vOut6 );
114     bbSetOutputOut7( vOut7 );
115     bbSetOutputOut8( vOut8 );
116     bbSetOutputOut9( vOut9 );
117 }
118
119 void VectorFilterString::InvertLists()
120 {
121     std::vector<std::string> vOut0;
122     std::vector<std::string> vOut1;
123     std::vector<std::string> vOut2;
124     std::vector<std::string> vOut3;
125     std::vector<std::string> vOut4;
126     std::vector<std::string> vOut5;
127     std::vector<std::string> vOut6;
128     std::vector<std::string> vOut7;
129     std::vector<std::string> vOut8;
130     std::vector<std::string> vOut9;
131     int i,size      = bbGetInputIn0().size();
132 //    std::string sk1 = bbGetInputsk1();
133 //    int pos         = atoi( bbGetInputsk2().c_str() );
134     for (i=size-1; i>=0; i--)
135     {
136             if ( i < bbGetInputIn0().size() ) { vOut0.push_back( bbGetInputIn0()[i] );  }
137             if ( i < bbGetInputIn1().size() ) { vOut1.push_back( bbGetInputIn1()[i] );  }
138             if ( i < bbGetInputIn2().size() ) { vOut2.push_back( bbGetInputIn2()[i] );  }
139             if ( i < bbGetInputIn3().size() ) { vOut3.push_back( bbGetInputIn3()[i] );  }
140             if ( i < bbGetInputIn4().size() ) { vOut4.push_back( bbGetInputIn4()[i] );  }
141             if ( i < bbGetInputIn5().size() ) { vOut5.push_back( bbGetInputIn5()[i] );  }
142             if ( i < bbGetInputIn6().size() ) { vOut6.push_back( bbGetInputIn6()[i] );  }
143             if ( i < bbGetInputIn7().size() ) { vOut7.push_back( bbGetInputIn7()[i] );  }
144             if ( i < bbGetInputIn8().size() ) { vOut8.push_back( bbGetInputIn8()[i] );  }
145             if ( i < bbGetInputIn9().size() ) { vOut9.push_back( bbGetInputIn9()[i] );  }
146     } // for i
147     bbSetOutputOut0( vOut0 );
148     bbSetOutputOut1( vOut1 );
149     bbSetOutputOut2( vOut2 );
150     bbSetOutputOut3( vOut3 );
151     bbSetOutputOut4( vOut4 );
152     bbSetOutputOut5( vOut5 );
153     bbSetOutputOut6( vOut6 );
154     bbSetOutputOut7( vOut7 );
155     bbSetOutputOut8( vOut8 );
156     bbSetOutputOut9( vOut9 );
157 }
158
159
160
161 void VectorFilterString::Process()
162 {
163
164 // THE MAIN PROCESSING METHOD BODY
165 //   Here we simply set the input 'In' value to the output 'Out'
166 //   And print out the output value
167 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
168 //    void bbSet{Input|Output}NAME(const TYPE&)
169 //    const TYPE& bbGet{Input|Output}NAME() const 
170 //    Where :
171 //    * NAME is the name of the input/output
172 //      (the one provided in the attribute 'name' of the tag 'input')
173 //    * TYPE is the C++ type of the input/output
174 //      (the one provided in the attribute 'type' of the tag 'input')
175
176 //    bbSetOutputOut( bbGetInputIn() );
177 //    std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
178   
179         if (bbGetInputType()==0) 
180         {
181                 std::vector<std::string> vOut0;
182                 std::vector<std::string> vOut1;
183                 std::vector<std::string> vOut2;
184                 std::vector<std::string> vOut3;
185                 std::vector<std::string> vOut4;
186                 std::vector<std::string> vOut5;
187                 std::vector<std::string> vOut6;
188                 std::vector<std::string> vOut7;
189                 std::vector<std::string> vOut8;
190                 std::vector<std::string> vOut9;
191                 ConnectionRepetitions( bbGetInputIn0() , &vOut0 );
192                 ConnectionRepetitions( bbGetInputIn1() , &vOut1 );
193                 ConnectionRepetitions( bbGetInputIn2() , &vOut2 );
194                 ConnectionRepetitions( bbGetInputIn3() , &vOut3 );
195                 ConnectionRepetitions( bbGetInputIn4() , &vOut4 );
196                 ConnectionRepetitions( bbGetInputIn5() , &vOut5 );
197                 ConnectionRepetitions( bbGetInputIn6() , &vOut6 );
198                 ConnectionRepetitions( bbGetInputIn7() , &vOut7 );
199                 ConnectionRepetitions( bbGetInputIn8() , &vOut8 );
200                 ConnectionRepetitions( bbGetInputIn9() , &vOut9 );
201                 bbSetOutputOut0( vOut0 );
202                 bbSetOutputOut1( vOut1 );
203                 bbSetOutputOut2( vOut2 );
204                 bbSetOutputOut3( vOut3 );
205                 bbSetOutputOut4( vOut4 );
206                 bbSetOutputOut5( vOut5 );
207                 bbSetOutputOut6( vOut6 );
208                 bbSetOutputOut7( vOut7 );
209                 bbSetOutputOut8( vOut8 );
210                 bbSetOutputOut9( vOut9 );
211         }
212
213     if (bbGetInputType()==2)
214     {
215         FilterByFindinIn0();
216     }
217
218     if (bbGetInputType()==3)
219     {
220         InsertStringPos();
221     }
222     
223     if (bbGetInputType()==4)
224     {
225         InvertLists();
226     }
227
228     
229 }
230 //===== 
231 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
232 //===== 
233 void VectorFilterString::bbUserSetDefaultValues()
234 {
235
236 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
237 //    Here we initialize the input 'In' to 0
238    bbSetInputType(0);
239    bbSetInputsk1("");
240    bbSetInputsk2("");
241 }
242 //===== 
243 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
244 //===== 
245 void VectorFilterString::bbUserInitializeProcessing()
246 {
247
248 //  THE INITIALIZATION METHOD BODY :
249 //    Here does nothing 
250 //    but this is where you should allocate the internal/output pointers 
251 //    if any 
252
253   
254 }
255 //===== 
256 // Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost)
257 //===== 
258 void VectorFilterString::bbUserFinalizeProcessing()
259 {
260
261 //  THE FINALIZATION METHOD BODY :
262 //    Here does nothing 
263 //    but this is where you should desallocate the internal/output pointers 
264 //    if any
265   
266 }
267
268 } // EO namespace bbstd
269
270