]> git.tdb.fi Git - libs/core.git/blob - examples/transcode.cpp
Derive Slice from sigc::trackable as it connects to external signals
[libs/core.git] / examples / transcode.cpp
1 #include <iostream>
2 #include <string>
3 #include <msp/stringcodec/codec.h>
4
5 using namespace std;
6 using namespace Msp;
7
8 int main(int argc, char **argv)
9 {
10         if(argc<3)
11         {
12                 cerr<<"Usage: "<<argv[0]<<" <from-enc> <to-enc>\n";
13                 return 1;
14         }
15
16         StringCodec::Codec *from = StringCodec::create_codec(argv[1]);
17         StringCodec::Codec *to = StringCodec::create_codec(argv[2]);
18
19         StringCodec::Decoder *from_dec = from->create_decoder();
20         StringCodec::Encoder *to_enc = to->create_encoder();
21
22         string line;
23         while(getline(cin, line))
24         {
25                 line += '\n';
26                 StringCodec::ustring ustr;
27                 from_dec->decode(line, ustr);
28                 string result;
29                 to_enc->encode(ustr, result);
30                 cout<<result;
31         }
32
33         string result;
34         to_enc->sync(result);
35         cout<<result;
36
37         delete from_dec;
38         delete to_enc;
39         delete from;
40         delete to;
41
42         return 0;
43 }