.homeworks/hw6/Post.cpp
/* add the update with a old post, get a new post
 * this function is NOT used by any program currently,
 * but is tested CORRECT */
add the update with a old post, get a new post
this function is NOT used by any program currently,
but is tested CORRECT
add the update with a old post get a new post this function is NOT used by any program currently but is tested CORRECT
Post* Post::operator+(const Post& update)
{
    if (update.profile_id != this->profile_id &&
        update.post_id != this->post_id)
        throw "Error: Invalid Update (ID Not Match)";
    Post* newPost = this->clone();
    for (auto var : *update.comments)
    {
        CommentKeyPair thisKey = var.second->getKeyPair();
        if (newPost->comments->count(thisKey))
            *(*newPost->comments)[thisKey] += *var.second;
        else
            (*newPost->comments)[thisKey] = var.second->clone();
    }
    newPost->is_published = update.is_published;
    for (auto var: *update.links)
    {
        string key = var->getKey();
        if (!newPost->links_hash.count(key))
        {
            newPost->links_hash[key] = 1;
            newPost->links->push_back(var->clone());
        }
    }
    for (auto var: *update.reactions)
        (*newPost->reactions)[var.second->getKey()] = var.second->clone();
    for (auto var: *update.receivers)
    {
        if (!newPost->receivers_hash.count(var->getKey()))
        {
            this->receivers_hash[var->getKey()] = 1;
            newPost->receivers->push_back(var->clone());
        }
    }
    if (update.updated_time)
    {
        delete this->updated_time;
        this->updated_time = update.updated_time->clone();
    }
    for (auto var: *update.keywordTable)
        (*newPost->keywordTable)[var.first] = 1;
    if (update.location)
    {
        delete newPost->location;
        newPost->location = update.location->clone();
    }
    return newPost;
}
Post * Post :: operator + ( const Post & update ) { if ( update . profile_id != this -> profile_id && update . post_id != this -> post_id ) throw " " ; Post * newPost = this -> clone ( ) ; for ( auto var : * update . comments ) { CommentKeyPair thisKey = var . second -> getKeyPair ( ) ; if ( newPost -> comments -> count ( thisKey ) ) * ( * newPost -> comments ) [ thisKey ] += * var . second ; else ( * newPost -> comments ) [ thisKey ] = var . second -> clone ( ) ; } newPost -> is_published = update . is_published ; for ( auto var : * update . links ) { string key = var -> getKey ( ) ; if ( ! newPost -> links_hash . count ( key ) ) { newPost -> links_hash [ key ] = 1 ; newPost -> links -> push_back ( var -> clone ( ) ) ; } } for ( auto var : * update . reactions ) ( * newPost -> reactions ) [ var . second -> getKey ( ) ] = var . second -> clone ( ) ; for ( auto var : * update . receivers ) { if ( ! newPost -> receivers_hash . count ( var -> getKey ( ) ) ) { this -> receivers_hash [ var -> getKey ( ) ] = 1 ; newPost -> receivers -> push_back ( var -> clone ( ) ) ; } } if ( update . updated_time ) { delete this -> updated_time ; this -> updated_time = update . updated_time -> clone ( ) ; } for ( auto var : * update . keywordTable ) ( * newPost -> keywordTable ) [ var . first ] = 1 ; if ( update . location ) { delete newPost -> location ; newPost -> location = update . location -> clone ( ) ; } return newPost ; }
add the update with a old post, get a new post
 this function is NOT used by any program currently,
 but is tested CORRECT
add the update with a old post get a new post this function is NOT used by any program currently but is tested CORRECT
// spacial case: id not matching // special case: update time smaller than origional post // to be update // update information // get the new comments // of this comment excists, add to it // get the new links // get the new reactions // get the new receivers // if this receiver is a new receiver, add to vectot // get the new update time // get all the new keywords // update location