// g++ -I . -I .. -I /home/brian/boost_1_39_0/ -std=c++0x rbtree_marshalling.cc #include #include #include #include #include #define EE_FILEIO #include uint32_t msg_length_max = 200000; int main() try { int fd = open("nout", O_WRONLY | O_CREAT, S_IRWXU); if (fd < 0) { std::cout << "open failed." << "\n"; return 0; } std::auto_ptr sendbuf(new SendBuffer(2048)); std::auto_ptr > buf(new ReceiveBuffer(2048)); sendbuf->sock_ = 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::Send(sendbuf.get(), tree); close(fd); fd = open("nout", O_RDONLY); if (fd < 0) { std::cout << "open failed." << "\n"; return 0; } buf->sock_ = fd; rbtree tree2; uint32_t message_length; buf->SetMsgLength(sizeof(message_length)); buf->Give(message_length); buf->SetMsgLength(message_length); message_manager::Receive(buf.get(), 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 ***************/