.homeworks/hw5/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)
    {
        cerr << "Error: Invalid Update (ID Not Match)" << endl;
        return Post();
    }
    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.reactions)
        newPost->reactions->push_back(var->clone());
    for (auto var: *update.receivers)
        newPost->receivers->push_back(var->clone());
    if (update.updated_time)
    {
        delete this->updated_time;
        this->updated_time = update.updated_time->clone();
    }
    if (update.updated_time)
        newPost->updated_time = update.updated_time->clone();
    return *newPost;
}
Post Post :: operator + ( const Post & update ) { if ( update . profile_id != this -> profile_id && update . post_id != this -> post_id ) { cerr << " " << endl ; return Post ( ) ; } 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 . reactions ) newPost -> reactions -> push_back ( var -> clone ( ) ) ; for ( auto var : * update . receivers ) newPost -> receivers -> push_back ( var -> clone ( ) ) ; if ( update . updated_time ) { delete this -> updated_time ; this -> updated_time = update . updated_time -> clone ( ) ; } if ( update . updated_time ) newPost -> updated_time = update . updated_time -> 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:  // update information // get the new comments // of this comment excists, add to it // get the new reactions // get the new receivers // get the new update time // get the new update time