ã¯ããã«
base64 ãä½ãããã¨æã£ã¦èª¿ã¹ãã boost::serialization ã® Dataflow Iterators ã便å©ããã
Serialization - Dataflow Iterators
å®éã«æ¸ãã¦ã¿ã
#include <iostream> #include <boost/pfto.hpp> #include <boost/archive/iterators/base64_from_binary.hpp> #include <boost/archive/iterators/transform_width.hpp> int main() { using namespace std; using namespace boost::archive::iterators; typedef base64_from_binary<transform_width<istream_iterator<char>, 6, 8 > > base64_iterator; copy( base64_iterator(BOOST_MAKE_PFTO_WRAPPER(istream_iterator<char>(cin))), base64_iterator(BOOST_MAKE_PFTO_WRAPPER(istream_iterator<char>())), ostream_iterator<char>(cout) ); }
ãã®ããã«ãæ¨æºå ¥åã base64 ã«å¤æãã¦æ¨æºåºåã«åºããããã ã£ããã 1 ã¹ãã¼ãã¡ã³ãã§æ¸ãã
ã¡ãã£ã¨è§£èª¬
transform_width
transform_width
以ä¸ã®ãããªæã
#include <iostream> #include <boost/pfto.hpp> #include <boost/archive/iterators/transform_width.hpp> int main() { using namespace std; using namespace boost::archive::iterators; unsigned char buf[] = { 0xff, 0xff, 0x00 }; transform_width<unsigned char *, 6, 8 > it(BOOST_PFTO_WRAPPER(buf)); // input 11111111 11111111 00000000 // output 111111 111111 111100 000000 cout << static_cast<int>(*it) << endl; // => 63 (00111111) ++it; cout << static_cast<int>(*it) << endl; // => 63 (00111111) ++it; cout << static_cast<int>(*it) << endl; // => 60 (00111100) ++it; cout << static_cast<int>(*it) << endl; // => 0 (00000000) }
base64_iterator
6bit ã®æ°å¤ãã base64 ã® 1 æåãã¤ãã¬ã¼ã·ã§ã³ããã
BOOST_PFTO_WRAPPER
ããã¯ã
template<class T> void f(T a) { ... } //ï¼ã©ããªåã§ã OKï¼ template<class T> void f(T* a) { ... } //ï¼ãã¤ã³ã¿ã ã ï¼
ã®ãããªé¢æ°ãã³ãã¬ã¼ãããã£ã¦ f(&obj) ã¨ãã£ãã¨ãã«ã©ã£ã¡ã®ãã³ãã¬ã¼ãã使ã£ã¦ãããåãããªãã³ã³ãã¤ã©ã®ããã«ãããã¯ãã
å®ç¾©å´ã
template<class T> void f(BOOST_PFTO_WRAPPER(T) a) { ... } //ï¼PFTO_WRAPPER ãªãã¤ã ã OKï¼ template<class T> void f(T* a) { ... } //ï¼ãã¤ã³ã¿ã ã ï¼
ã¨ãã¦ãã㨠f(&obj) ã¨ããã°ãã¤ã³ã¿ã®ã»ãã ã¨ãããããä¸ã®ã»ããå¼ã³ãããã° f(BOOST_MAKE_PFTO_WRAPPER(obj)) ã¨æ示çã«ãã£ã¦ããã°ããã