BCP_indexed_pricing.cpp
Go to the documentation of this file.
1 // Copyright (C) 2000, International Business Machines
2 // Corporation and others. All Rights Reserved.
3 #if 0
4 #include <algorithm>
5 
6 #include "BCP_buffer.hpp"
7 #include "BCP_error.hpp"
9 
10 //-----------------------------------------------------------------------------
11 
12 void
13 BCP_indexed_pricing_list::swap(BCP_indexed_pricing_list& x) {
14  std::swap(_pr_status, x._pr_status);
15  std::swap(_storage, x._storage);
16  _del_pos.swap(x._del_pos);
17  _indices.swap(x._indices);
18 }
19 
20 void
21 BCP_indexed_pricing_list::update(const BCP_indexed_pricing_list& change) {
22  switch (change.get_storage()){
24  case BCP_Storage_NoData:
25  operator=(change);
26  break;
28  // in this case 'this' must be the parent, and _storage must be
29  // explicit
30  if (_storage != BCP_Storage_Explicit) {
31  throw BCP_fatal_error("\
32 BCP_indexed_pricing_list::update() : Bad storage.\n");
33  }
34  _indices.erase_by_index(change._del_pos);
35  _indices.append(change._indices);
36  break;
37  default:
38  throw BCP_fatal_error("\
39 BCP_indexed_pricing_list::update() : unrecognized change list storage.\n");
40  }
41 }
42 
43 BCP_indexed_pricing_list*
44 BCP_indexed_pricing_list::
45 as_change(const BCP_indexed_pricing_list& old_list) const
46 {
47  // note that whatever is new in 'this' list must be at the end of this.
48  if (old_list.get_storage() != BCP_Storage_Explicit ||
49  _storage != BCP_Storage_Explicit)
50  throw BCP_fatal_error("\
51 BCP_indexed_pricing_list::as_change() : Bad storage.\n");
52  BCP_indexed_pricing_list* change = new BCP_indexed_pricing_list;
53  BCP_vec<int>::const_iterator oldi = old_list._indices.begin();
54  BCP_vec<int>::const_iterator lastoldi = old_list._indices.end();
55  BCP_vec<int>::const_iterator newi = _indices.begin();
56  BCP_vec<int>::const_iterator lastnewi = _indices.end();
57  BCP_vec<int>& ch_del = change->_del_pos;
58  ch_del.reserve(old_list._indices.size());
59  int pos;
60  for (pos = 0; oldi != lastoldi && newi != lastnewi; ++oldi, ++pos) {
61  if (*oldi < *newi){ // a deleted one from old
62  ch_del.unchecked_push_back(pos);
63  }else{ // they must be equal
64  ++newi;
65  }
66  }
67  // whatever is left in old is deleted
68  for ( ; oldi != lastoldi; ++oldi, ++pos)
69  ch_del.unchecked_push_back(pos);
70  // whaever is left in new as the added
71  change->_indices.insert(change->_indices.end(), newi, lastnewi);
72  return change;
73 }
74 
75 //#############################################################################
76 
77 int
78 BCP_indexed_pricing_list::pack_size() const {
79  return sizeof(_pr_status) + sizeof(_storage) + 2 * sizeof(int) +
80  sizeof(int) * (_del_pos.size() + _indices.size());
81 }
82 
83 void
84 BCP_indexed_pricing_list::pack(BCP_buffer& buf) const {
85  buf.pack(_pr_status);
86  if (_pr_status & BCP_PriceIndexedVars){
87  buf.pack(_storage);
88  if (_storage != BCP_Storage_NoData)
89  buf.pack(_del_pos).pack(_indices);
90  }
91 }
92 
93 void
94 BCP_indexed_pricing_list::unpack(BCP_buffer& buf) {
95  buf.unpack(_pr_status);
96  if (_pr_status & BCP_PriceIndexedVars){
97  buf.unpack(_storage);
98  if (_storage != BCP_Storage_NoData)
99  buf.unpack(_del_pos).unpack(_indices);
100  }
101 }
102 #endif
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
pos
position where the operator should be printed when printing the expression
No data is stored.
Definition: BCP_enum.hpp:86
iterator begin()
Return an iterator to the beginning of the object.
Definition: BCP_vector.hpp:99
void reserve(const size_t n)
Reallocate the object to make space for n entries.
The data stored is an explicit listing of values.
Definition: BCP_enum.hpp:88
The data stored is with respect to the same kind of data in the parent of the search tree node...
Definition: BCP_enum.hpp:91
static int
Definition: OSdtoa.cpp:2173
Currently there isn&#39;t any error handling in BCP.
Definition: BCP_error.hpp:20
iterator end()
Return an iterator to the end of the object.
Definition: BCP_vector.hpp:104
The class BCP_vec serves the same purpose as the vector class in the standard template library...
Definition: BCP_vector.hpp:24
This class describes the message buffer used for all processes of BCP.
Definition: BCP_buffer.hpp:39
void unchecked_push_back(const_reference x)
Append x to the end of the vector.
void fint fint fint real fint real * x