/home/coin/SVN-release/OS-2.2.0/Bcp/src/Member/BCP_indexed_pricing.cpp

Go to the documentation of this file.
00001 // Copyright (C) 2000, International Business Machines
00002 // Corporation and others.  All Rights Reserved.
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       // in this case 'this' must be the parent, and _storage must be
00029       // explicit
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    // note that whatever is new in 'this' list must be at the end of this.
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){ // a deleted one from old
00062          ch_del.unchecked_push_back(pos);
00063       }else{ // they must be equal
00064          ++newi;
00065       }
00066    }
00067    // whatever is left in old is deleted
00068    for ( ; oldi != lastoldi; ++oldi, ++pos)
00069       ch_del.unchecked_push_back(pos);
00070    // whaever is left in new as the added
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

Generated on Thu Aug 5 03:02:52 2010 by  doxygen 1.4.7