]> Creatis software - bbtk.git/blob - packages/std/src/bbstdASCII.cxx
c24da54f26b8be29ef98e7bf766fd637e50eca74
[bbtk.git] / packages / std / src / bbstdASCII.cxx
1 #include "bbstdASCII.h"
2 #include "bbstdPackage.h"
3 namespace bbstd
4 {
5   
6   BBTK_ADD_BLACK_BOX_TO_PACKAGE(std,ASCII);
7   BBTK_BLACK_BOX_IMPLEMENTATION(ASCII,bbtk::AtomicBlackBox);
8   void ASCII::Process()
9   {
10     int asciiValue;
11     char strTmp[10];
12     std::string result("");
13     if (bbGetInputIn()!=""){
14       
15       if (bbGetInputtype()==0){
16         std::string commandstr(bbGetInputIn());
17         bool ok=true;
18         int pos1=0,pos2;
19         pos2 = commandstr.find(" ",pos1);
20         std::string ccommand;
21         while (ok==true)
22           {
23             if (pos2==-1)       
24               {
25                 ok=false;
26                 ccommand=commandstr.substr(pos1,commandstr.length()-pos1 );
27               }         else  {
28               ccommand=commandstr.substr(pos1,pos2-pos1);
29             }
30             asciiValue = atoi( ccommand.c_str() );
31             sprintf(strTmp,"%c",asciiValue);
32             result += strTmp;
33             
34             pos1=pos2+1;
35             pos2 = commandstr.find(" ",pos2+1);
36           } // while
37       } // if type 0
38       
39       if (bbGetInputtype()==1){
40         int i,size=bbGetInputIn().size();
41         for (i=0;i<size;i++){
42           asciiValue = (int)bbGetInputIn()[i];
43           sprintf(strTmp,"%d",asciiValue);
44           result +=strTmp;
45           if (i!=size-1) {
46             result +=" ";
47           } // i!=size-1
48         } // for
49       } // type 1
50     }
51     bbSetOutputOut( result );  
52   }
53   
54   void ASCII::bbUserConstructor()
55   {
56     bbSetInputIn("");
57     bbSetInputtype(0);
58   }
59   
60   void ASCII::bbUserCopyConstructor()
61   {
62     
63   }
64   
65   void ASCII::bbUserDestructor()
66   {
67   }
68 }
69 // EO namespace bbstd
70
71