Ejemplo n.º 1
0
void item::remove() {
    //Remove the entry in map that points to current tuple
    item_map_t::iterator item_map_iter;
    item_map_iter=item_map.find(make_tuple(i_id));
    item_map.erase(item_map_iter);
    //Move last tuple in vector in the place of the deleted tuple
    //If current tuple is not the last tuple,
    if(tuple_id != count - 1) {

        //Move content of last tuple to fields in this tuple
        item item_vect_last_iter;
        item_vect_last_iter=item_vect.at(count - 1);

        i_id = item_vect_last_iter.i_id;
        i_im_id = item_vect_last_iter.i_im_id;
        strcpy(i_name, item_vect_last_iter.i_name);
        i_price = item_vect_last_iter.i_price;
        strcpy(i_data, item_vect_last_iter.i_data);

        //Remove the entry for the last tuple in map, and insert a new one with new tuple_id
        item_map_t::iterator item_map_iter;
        item_map_iter=item_map.find(make_tuple(i_id));
        if(item_map_iter != item_map.end())
            item_map.erase(item_map_iter);
        item_map.insert(make_pair(make_tuple(i_id), tuple_id));;

        //Call remove on the last entry of the vector
        item_vect_last_iter.remove();
    }
    else {		//if the tuple is the last tuple in the vector
        count--;
        item_vect.pop_back();
    }
    //item_vect.erase(tuple_id);
}
Ejemplo n.º 2
0
void item::insert() {
    tuple_id = count;
    item_vect.push_back(*this);
    item_map.insert(make_pair(make_tuple(i_id), count));
    count++;
}