BB_packer.cpp
Go to the documentation of this file.
1 // Last edit: 5/20/07
2 //
3 // Name: BB_packer.cpp
4 // Author: Francois Margot
5 // Tepper School of Business
6 // Carnegie Mellon University, Pittsburgh, PA 15213
7 // email: fmargot@andrew.cmu.edu
8 // Date: 5/18/07
9 //-----------------------------------------------------------------------------
10 // Copyright (C) 2007, Francois Margot, IBM and others. All Rights Reserved.
11 
12 #include "BCP_buffer.hpp"
13 #include "BB_cut.hpp"
14 #include "BB_user_data.hpp"
15 #include "BB_packer.hpp"
16 
17 using namespace std;
18 
19 /****************************************************************************/
20 
21 void
23 {
24  int typ;
25  const BB_indexed_cut* bb_icut = dynamic_cast<const BB_indexed_cut*>(cut);
26  if (bb_icut) {
27  typ = 0;
28  buf.pack(typ);
29  bb_icut->pack(buf);
30  return;
31  }
32  const BB_cut* bb_cut = dynamic_cast<const BB_cut*>(cut);
33  if (bb_cut) {
34  typ = 1;
35  buf.pack(typ);
36  bb_cut->pack(buf);
37  return;
38  }
39  throw BCP_fatal_error("BB_pack_cut(): unknown cut type.");
40 }
41 
42 /****************************************************************************/
43 
46 {
47  int typ;
48  buf.unpack(typ);
49  switch (typ) {
50  case 0:
51  return new BB_indexed_cut(buf);
52  case 1:
53  return new BB_cut(buf);
54  default:
55  throw BCP_fatal_error("BB_unpack_cut(): unknown cut type.");
56  break;
57  }
58  return NULL; // fake return
59 }
60 
61 /****************************************************************************/
62 
63 void
65 // Normally, no modifications required.
66 {
67  const MY_user_data *mud = dynamic_cast<const MY_user_data*> (ud);
68  if(!mud)
69  throw BCP_fatal_error("BB_lp::pack_user_data() : unknown data type!\n");
70 
71  printf("BB_lp::pack_user_data:\n");
72  mud->print();
73  mud->pack(buf);
74 }
75 
76 /****************************************************************************/
77 
80  // Normally, no modifications required.
81 {
82  MY_user_data *p_ud = new MY_user_data(buf);
83  printf("BB_lp::unpack_user_data:\n");
84  p_ud->print();
85 
86  if (p_ud->is_processed) {
87  p_ud->p_rud = NULL;
88  delete(p_ud);
89  p_ud = NULL;
90  printf("user_data deleted\n");
91  }
92 
93  return(p_ud);
94 }
void pack(BCP_buffer &buf) const
Packing cut to a buffer.
Definition: BB_cut.cpp:10
BCP_buffer & pack(const T &value)
Pack a single object of type T.
Definition: BCP_buffer.hpp:177
BCP_buffer & unpack(T &value)
Unpack a single object of type T.
Definition: BCP_buffer.hpp:186
This is the class from which the user should derive her own algorithmic cuts.
Definition: BCP_cut.hpp:242
When doing a sprint sort of algorithm on the cuts (i.e., leave out a number of cuts at the beginning ...
Definition: BB_cut.hpp:19
void print() const
Dump the fields of the class.
virtual BCP_cut_algo * unpack_cut_algo(BCP_buffer &buf)
Unpack an algorithmic cut.
Definition: BB_packer.cpp:45
real_user_data * p_rud
Pointer on an object holding the user data itself.
void pack(BCP_buffer &buf) const
Packing cut to a buffer.
Definition: BB_cut.cpp:33
void pack(BCP_buffer &buf) const
Packing to buffer.
Simple representation of a cut by storing non zero coefficients only.
Definition: BB_cut.hpp:64
Class taking care of interaction between user data and Bcp.
Currently there isn&#39;t any error handling in BCP.
Definition: BCP_error.hpp:20
int is_processed
Indicator for mmory management: If is_processed = 1, the associated user data may be erased...
virtual void pack_cut_algo(const BCP_cut_algo *cut, BCP_buffer &buf)
Pack an algorithmic cut.
Definition: BB_packer.cpp:22
This class describes the message buffer used for all processes of BCP.
Definition: BCP_buffer.hpp:39
virtual BCP_user_data * unpack_user_data(BCP_buffer &buf)
Unpack an user data.
Definition: BB_packer.cpp:79
virtual void pack_user_data(const BCP_user_data *ud, BCP_buffer &buf)
Pack an user data.
Definition: BB_packer.cpp:64