]> Creatis software - bbtk.git/blob - packages/std/src/bbstdVectorFilterString.cxx
a08d7215e2eee5e5208ef0114a850121f3adb78f
[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     printf("VectorFilterString::InsertStringPos Start\n" );
82     std::vector<std::string> vOut0;
83     std::vector<std::string> vOut1;
84     std::vector<std::string> vOut2;
85     std::vector<std::string> vOut3;
86     std::vector<std::string> vOut4;
87     std::vector<std::string> vOut5;
88     std::vector<std::string> vOut6;
89     std::vector<std::string> vOut7;
90     std::vector<std::string> vOut8;
91     std::vector<std::string> vOut9;
92
93     int i,size      = bbGetInputIn0().size();
94     std::string sk1 = bbGetInputsk1();
95     printf("VectorFilterString::InsertStringPos sk1=%s  sk2=%s \n", bbGetInputsk1().c_str() , bbGetInputsk2().c_str() );
96     int pos         = atoi( bbGetInputsk2().c_str() );
97     
98     printf("VectorFilterString::InsertStringPos pos=%d  sk1=%s \n", pos, sk1.c_str() );
99     for (i=0; i<size; i++)
100     {
101         vOut0.push_back( bbGetInputIn0()[i].insert(pos,sk1) );
102         printf("VectorFilterString::InsertStringPos i=%s   \n", vOut0[i].c_str() );
103         if ( i < bbGetInputIn1().size() ) { vOut1.push_back( bbGetInputIn1()[i].insert(pos,sk1) ); }
104         if ( i < bbGetInputIn2().size() ) { vOut2.push_back( bbGetInputIn2()[i].insert(pos,sk1) ); }
105         if ( i < bbGetInputIn3().size() ) { vOut3.push_back( bbGetInputIn3()[i].insert(pos,sk1) ); }
106         if ( i < bbGetInputIn4().size() ) { vOut4.push_back( bbGetInputIn4()[i].insert(pos,sk1) ); }
107         if ( i < bbGetInputIn5().size() ) { vOut5.push_back( bbGetInputIn5()[i].insert(pos,sk1) ); }
108         if ( i < bbGetInputIn6().size() ) { vOut6.push_back( bbGetInputIn6()[i].insert(pos,sk1) ); }
109         if ( i < bbGetInputIn7().size() ) { vOut7.push_back( bbGetInputIn7()[i].insert(pos,sk1) ); }
110         if ( i < bbGetInputIn8().size() ) { vOut8.push_back( bbGetInputIn8()[i].insert(pos,sk1) ); }
111         if ( i < bbGetInputIn9().size() ) { vOut9.push_back( bbGetInputIn9()[i].insert(pos,sk1) ); }
112     } // for i
113     
114     bbSetOutputOut0( vOut0 );
115     bbSetOutputOut1( vOut1 );
116     bbSetOutputOut2( vOut2 );
117     bbSetOutputOut3( vOut3 );
118     bbSetOutputOut4( vOut4 );
119     bbSetOutputOut5( vOut5 );
120     bbSetOutputOut6( vOut6 );
121     bbSetOutputOut7( vOut7 );
122     bbSetOutputOut8( vOut8 );
123     bbSetOutputOut9( vOut9 );
124 printf("VectorFilterString::InsertStringPos End\n" );
125 }
126
127
128
129 void VectorFilterString::Process()
130 {
131
132 // THE MAIN PROCESSING METHOD BODY
133 //   Here we simply set the input 'In' value to the output 'Out'
134 //   And print out the output value
135 // INPUT/OUTPUT ACCESSORS ARE OF THE FORM :
136 //    void bbSet{Input|Output}NAME(const TYPE&)
137 //    const TYPE& bbGet{Input|Output}NAME() const 
138 //    Where :
139 //    * NAME is the name of the input/output
140 //      (the one provided in the attribute 'name' of the tag 'input')
141 //    * TYPE is the C++ type of the input/output
142 //      (the one provided in the attribute 'type' of the tag 'input')
143
144 //    bbSetOutputOut( bbGetInputIn() );
145 //    std::cout << "Output value = " <<bbGetOutputOut() << std::endl;
146   
147         if (bbGetInputType()==0) 
148         {
149                 std::vector<std::string> vOut0;
150                 std::vector<std::string> vOut1;
151                 std::vector<std::string> vOut2;
152                 std::vector<std::string> vOut3;
153                 std::vector<std::string> vOut4;
154                 std::vector<std::string> vOut5;
155                 std::vector<std::string> vOut6;
156                 std::vector<std::string> vOut7;
157                 std::vector<std::string> vOut8;
158                 std::vector<std::string> vOut9;
159                 ConnectionRepetitions( bbGetInputIn0() , &vOut0 );
160                 ConnectionRepetitions( bbGetInputIn1() , &vOut1 );
161                 ConnectionRepetitions( bbGetInputIn2() , &vOut2 );
162                 ConnectionRepetitions( bbGetInputIn3() , &vOut3 );
163                 ConnectionRepetitions( bbGetInputIn4() , &vOut4 );
164                 ConnectionRepetitions( bbGetInputIn5() , &vOut5 );
165                 ConnectionRepetitions( bbGetInputIn6() , &vOut6 );
166                 ConnectionRepetitions( bbGetInputIn7() , &vOut7 );
167                 ConnectionRepetitions( bbGetInputIn8() , &vOut8 );
168                 ConnectionRepetitions( bbGetInputIn9() , &vOut9 );
169                 bbSetOutputOut0( vOut0 );
170                 bbSetOutputOut1( vOut1 );
171                 bbSetOutputOut2( vOut2 );
172                 bbSetOutputOut3( vOut3 );
173                 bbSetOutputOut4( vOut4 );
174                 bbSetOutputOut5( vOut5 );
175                 bbSetOutputOut6( vOut6 );
176                 bbSetOutputOut7( vOut7 );
177                 bbSetOutputOut8( vOut8 );
178                 bbSetOutputOut9( vOut9 );
179         }
180
181     if (bbGetInputType()==2)
182     {
183         FilterByFindinIn0();
184     }
185
186     if (bbGetInputType()==3)
187     {
188         InsertStringPos();
189     }
190 }
191 //===== 
192 // 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)
193 //===== 
194 void VectorFilterString::bbUserSetDefaultValues()
195 {
196
197 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
198 //    Here we initialize the input 'In' to 0
199    bbSetInputType(0);
200    bbSetInputsk1("");
201    bbSetInputsk2("");
202 }
203 //===== 
204 // 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)
205 //===== 
206 void VectorFilterString::bbUserInitializeProcessing()
207 {
208
209 //  THE INITIALIZATION METHOD BODY :
210 //    Here does nothing 
211 //    but this is where you should allocate the internal/output pointers 
212 //    if any 
213
214   
215 }
216 //===== 
217 // 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)
218 //===== 
219 void VectorFilterString::bbUserFinalizeProcessing()
220 {
221
222 //  THE FINALIZATION METHOD BODY :
223 //    Here does nothing 
224 //    but this is where you should desallocate the internal/output pointers 
225 //    if any
226   
227 }
228
229 } // EO namespace bbstd
230
231