]> Creatis software - bbtk.git/blob - packages/std/src/bbstdWriteColumnsString.cxx
#3423 BBTK Feature New Normal - box std MapToLst
[bbtk.git] / packages / std / src / bbstdWriteColumnsString.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 "bbstdWriteColumnsString.h"
5 #include "bbstdPackage.h"
6 namespace bbstd
7 {
8
9 BBTK_ADD_BLACK_BOX_TO_PACKAGE(std,WriteColumnsString)
10 BBTK_BLACK_BOX_IMPLEMENTATION(WriteColumnsString,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 void WriteColumnsString::Process()
15 {
16         std::ofstream write_fi;
17         write_fi.open(bbGetInputFileName().c_str());    
18         std::vector<std::string> headers = bbGetInputHeaders(); //Headers Input
19         bool onHeaders = bbGetInputOnHeaders();
20         std::vector<std::vector<std::string> > values;
21         values.push_back( bbGetInputlstData1() );
22         values.push_back( bbGetInputlstData2() );
23         values.push_back( bbGetInputlstData3() );
24         values.push_back( bbGetInputlstData4() );
25         values.push_back( bbGetInputlstData5() );
26         values.push_back( bbGetInputlstData6() );
27         values.push_back( bbGetInputlstData7() );
28         values.push_back( bbGetInputlstData8() );
29         values.push_back( bbGetInputlstData9() );
30         std::vector<std::vector<std::string> >::iterator it;
31
32         
33
34         for(it = values.begin() ; it != values.end() ; )
35         {
36                 if((*it).empty())
37                 {
38                         it = values.erase(it);
39                 }else
40                 {
41                         it++;
42                 } // if 
43         } // for it
44
45
46         bool ok         = true;
47         int i,size      = values.size();
48         for ( i=0 ; i<size-1 ; i++ )
49         {
50                 if ( values[i].size() != values[i+1].size() )
51                 {
52                         ok=false;
53                 } // if
54         } // for
55
56
57         if (ok==true)
58         {
59                 if(write_fi.is_open())
60                 {       
61                         if(onHeaders == true) // If onHeaders is true, the file is write with Headers.
62                         {
63                                 //Add each header input write to file
64                                 for(unsigned int i=0 ;i< headers.size(); i++ )
65                                 {
66                                         if(i==(headers.size()-1))
67                                         {
68                                                 write_fi << headers[i] << "\n";
69                                         }else{
70                                                 write_fi << headers[i] << "\t";
71                                         } // if
72                                 }//for headersSize
73                         }
74                         unsigned int colSize = values[0].size();
75                         for(unsigned int j=0 ; j<colSize ; j++)
76                         {
77                                 for(unsigned int i=0;i<values.size();i++)
78                                 {
79                                         if(i==(values.size()-1))
80                                         {
81                                                 write_fi << values[i][j] << "\n";
82                                         }else{
83                                                 write_fi << values[i][j] << "\t";
84                                         } // if
85                                 } // for
86                         } // for
87                 } else { // if write_fi.is_open()
88                         std::cout<<"EED WriteColumnsString::Process   Imposible to open file."<<std::endl;
89                 }//if open
90
91         } else {
92                 printf("EED WriteColumnsString::Process   Warning!   The size of the vectors are not equal. \n");
93         }// if ok
94
95         write_fi.close();
96         bbSetOutputOutFileName(bbGetInputFileName().c_str());  
97
98
99 }
100 //===== 
101 // 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)
102 //===== 
103 void WriteColumnsString::bbUserSetDefaultValues()
104 {
105
106 //  SET HERE THE DEFAULT INPUT/OUTPUT VALUES OF YOUR BOX 
107 //    Here we initialize the input 'In' to 0
108    bbSetInputFileName("");      
109    bbSetInputFileName("true");
110 }
111 //===== 
112 // 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)
113 //===== 
114 void WriteColumnsString::bbUserInitializeProcessing()
115 {
116
117 //  THE INITIALIZATION METHOD BODY :
118 //    Here does nothing 
119 //    but this is where you should allocate the internal/output pointers 
120 //    if any 
121 }
122 //===== 
123 // 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)
124 //===== 
125 void WriteColumnsString::bbUserFinalizeProcessing()
126 {
127
128 //  THE FINALIZATION METHOD BODY :
129 //    Here does nothing 
130 //    but this is where you should desallocate the internal/output pointers 
131 //    if any
132   
133 }
134 }
135 // EO namespace bbstd
136
137