00001
00002
00003 #if 0
00004 #include <algorithm>
00005
00006 #include "BCP_buffer.hpp"
00007 #include "BCP_error.hpp"
00008 #include "BCP_indexed_pricing.hpp"
00009
00010
00011
00012 void
00013 BCP_indexed_pricing_list::swap(BCP_indexed_pricing_list& x) {
00014 std::swap(_pr_status, x._pr_status);
00015 std::swap(_storage, x._storage);
00016 _del_pos.swap(x._del_pos);
00017 _indices.swap(x._indices);
00018 }
00019
00020 void
00021 BCP_indexed_pricing_list::update(const BCP_indexed_pricing_list& change) {
00022 switch (change.get_storage()){
00023 case BCP_Storage_Explicit:
00024 case BCP_Storage_NoData:
00025 operator=(change);
00026 break;
00027 case BCP_Storage_WrtParent:
00028
00029
00030 if (_storage != BCP_Storage_Explicit) {
00031 throw BCP_fatal_error("\
00032 BCP_indexed_pricing_list::update() : Bad storage.\n");
00033 }
00034 _indices.erase_by_index(change._del_pos);
00035 _indices.append(change._indices);
00036 break;
00037 default:
00038 throw BCP_fatal_error("\
00039 BCP_indexed_pricing_list::update() : unrecognized change list storage.\n");
00040 }
00041 }
00042
00043 BCP_indexed_pricing_list*
00044 BCP_indexed_pricing_list::
00045 as_change(const BCP_indexed_pricing_list& old_list) const
00046 {
00047
00048 if (old_list.get_storage() != BCP_Storage_Explicit ||
00049 _storage != BCP_Storage_Explicit)
00050 throw BCP_fatal_error("\
00051 BCP_indexed_pricing_list::as_change() : Bad storage.\n");
00052 BCP_indexed_pricing_list* change = new BCP_indexed_pricing_list;
00053 BCP_vec<int>::const_iterator oldi = old_list._indices.begin();
00054 BCP_vec<int>::const_iterator lastoldi = old_list._indices.end();
00055 BCP_vec<int>::const_iterator newi = _indices.begin();
00056 BCP_vec<int>::const_iterator lastnewi = _indices.end();
00057 BCP_vec<int>& ch_del = change->_del_pos;
00058 ch_del.reserve(old_list._indices.size());
00059 int pos;
00060 for (pos = 0; oldi != lastoldi && newi != lastnewi; ++oldi, ++pos) {
00061 if (*oldi < *newi){
00062 ch_del.unchecked_push_back(pos);
00063 }else{
00064 ++newi;
00065 }
00066 }
00067
00068 for ( ; oldi != lastoldi; ++oldi, ++pos)
00069 ch_del.unchecked_push_back(pos);
00070
00071 change->_indices.insert(change->_indices.end(), newi, lastnewi);
00072 return change;
00073 }
00074
00075
00076
00077 int
00078 BCP_indexed_pricing_list::pack_size() const {
00079 return sizeof(_pr_status) + sizeof(_storage) + 2 * sizeof(int) +
00080 sizeof(int) * (_del_pos.size() + _indices.size());
00081 }
00082
00083 void
00084 BCP_indexed_pricing_list::pack(BCP_buffer& buf) const {
00085 buf.pack(_pr_status);
00086 if (_pr_status & BCP_PriceIndexedVars){
00087 buf.pack(_storage);
00088 if (_storage != BCP_Storage_NoData)
00089 buf.pack(_del_pos).pack(_indices);
00090 }
00091 }
00092
00093 void
00094 BCP_indexed_pricing_list::unpack(BCP_buffer& buf) {
00095 buf.unpack(_pr_status);
00096 if (_pr_status & BCP_PriceIndexedVars){
00097 buf.unpack(_storage);
00098 if (_storage != BCP_Storage_NoData)
00099 buf.unpack(_del_pos).unpack(_indices);
00100 }
00101 }
00102 #endif