// g++ -I . -I .. -I /home/brian/boost_1_48_0/ rbtree_marshalling.cc #include #include #include #include #include #include #include using namespace boost::intrusive; int main() try { int fd = open("nout", O_WRONLY | O_CREAT, S_IRWXU); if (fd < 0) { std::cout << "open failed." << "\n"; return 0; } SendBufferFile sendbuf; sendbuf.hndl = fd; Base aBase(43); Derived aDerived(31); rbtree tree; tree.insert_unique(aBase); tree.insert_unique(aDerived); rbtree::iterator rbit = tree.begin(); rbtree::iterator rbend = tree.end(); for (; rbit != rbend; ++rbit) { (*rbit).PrintName(); } message_manager messageManager(200000); messageManager.Marshal(sendbuf, tree); sendbuf.Flush(); close(fd); fd = open("nout", O_RDONLY); if (fd < 0) { std::cout << "open failed." << "\n"; return 0; } ReceiveBufferFile buf(4096); buf.hndl = fd; buf.GotPacket(); rbtree tree2; messageManager.Receive(buf, tree2); std::cout << "size of tree2 is " << tree2.size() << std::endl; rbit = tree2.begin(); rbend = tree2.end(); for (; rbit != rbend; ++rbit) { (*rbit).PrintName(); } return 1; } catch (failure const & ex) { std::cout << "failure exception " << ex.what(); } /************** The output should be as follows: Derived Base size of tree2 is 2 Derived Base ***************/