00001 // Last edit: 5/20/07 00002 // 00003 // Name: BB_packer.cpp 00004 // Author: Francois Margot 00005 // Tepper School of Business 00006 // Carnegie Mellon University, Pittsburgh, PA 15213 00007 // email: fmargot@andrew.cmu.edu 00008 // Date: 5/18/07 00009 //----------------------------------------------------------------------------- 00010 // Copyright (C) 2007, Francois Margot, IBM and others. All Rights Reserved. 00011 00012 #include "BCP_buffer.hpp" 00013 #include "BB_cut.hpp" 00014 #include "BB_user_data.hpp" 00015 #include "BB_packer.hpp" 00016 00017 using namespace std; 00018 00019 /****************************************************************************/ 00020 00021 void 00022 BB_packer::pack_cut_algo(const BCP_cut_algo* cut, BCP_buffer& buf) 00023 { 00024 int typ; 00025 const BB_indexed_cut* bb_icut = dynamic_cast<const BB_indexed_cut*>(cut); 00026 if (bb_icut) { 00027 typ = 0; 00028 buf.pack(typ); 00029 bb_icut->pack(buf); 00030 return; 00031 } 00032 const BB_cut* bb_cut = dynamic_cast<const BB_cut*>(cut); 00033 if (bb_cut) { 00034 typ = 1; 00035 buf.pack(typ); 00036 bb_cut->pack(buf); 00037 return; 00038 } 00039 throw BCP_fatal_error("BB_pack_cut(): unknown cut type."); 00040 } 00041 00042 /****************************************************************************/ 00043 00044 BCP_cut_algo* 00045 BB_packer::unpack_cut_algo(BCP_buffer& buf) 00046 { 00047 int typ; 00048 buf.unpack(typ); 00049 switch (typ) { 00050 case 0: 00051 return new BB_indexed_cut(buf); 00052 case 1: 00053 return new BB_cut(buf); 00054 default: 00055 throw BCP_fatal_error("BB_unpack_cut(): unknown cut type."); 00056 break; 00057 } 00058 return NULL; // fake return 00059 } 00060 00061 /****************************************************************************/ 00062 00063 void 00064 BB_packer::pack_user_data(const BCP_user_data* ud, BCP_buffer& buf) 00065 // Normally, no modifications required. 00066 { 00067 const MY_user_data *mud = dynamic_cast<const MY_user_data*> (ud); 00068 if(!mud) 00069 throw BCP_fatal_error("BB_lp::pack_user_data() : unknown data type!\n"); 00070 00071 printf("BB_lp::pack_user_data:\n"); 00072 mud->print(); 00073 mud->pack(buf); 00074 } 00075 00076 /****************************************************************************/ 00077 00078 BCP_user_data* 00079 BB_packer::unpack_user_data(BCP_buffer& buf) 00080 // Normally, no modifications required. 00081 { 00082 MY_user_data *p_ud = new MY_user_data(buf); 00083 printf("BB_lp::unpack_user_data:\n"); 00084 p_ud->print(); 00085 00086 if (p_ud->is_processed) { 00087 p_ud->p_rud = NULL; 00088 delete(p_ud); 00089 p_ud = NULL; 00090 printf("user_data deleted\n"); 00091 } 00092 00093 return(p_ud); 00094 }