Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 1 | /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /* |
| 3 | * Copyright (c) 2012 University of California, Los Angeles |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation; |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | * |
| 18 | * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu> |
| 19 | * 卞超轶 Chaoyi Bian <bcy@pku.edu.cn> |
| 20 | * Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 21 | */ |
| 22 | |
| 23 | #include "sync-diff-state.h" |
Alexander Afanasyev | b5547e3 | 2012-03-01 21:59:38 -0800 | [diff] [blame] | 24 | #include "sync-diff-leaf.h" |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 25 | |
| 26 | #include <boost/make_shared.hpp> |
| 27 | |
| 28 | using namespace boost; |
| 29 | |
| 30 | namespace ns3 { |
| 31 | namespace Sync { |
| 32 | |
| 33 | DiffState::DiffState () |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 34 | { |
| 35 | } |
| 36 | |
| 37 | DiffState::~DiffState () |
| 38 | { |
| 39 | } |
| 40 | |
| 41 | DiffStatePtr |
| 42 | DiffState::diff () const |
| 43 | { |
| 44 | DiffStatePtr ret = make_shared<DiffState> (); |
| 45 | |
Alexander Afanasyev | b5547e3 | 2012-03-01 21:59:38 -0800 | [diff] [blame] | 46 | DiffStatePtr state = m_next; |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 47 | while (state != 0) |
| 48 | { |
| 49 | *ret += *state; |
| 50 | state = state->m_next; |
| 51 | } |
| 52 | |
| 53 | return ret; |
| 54 | } |
| 55 | |
| 56 | DiffState & |
| 57 | DiffState::operator += (const DiffState &state) |
| 58 | { |
| 59 | return *this; |
| 60 | } |
| 61 | |
| 62 | // from State |
Alexander Afanasyev | b5547e3 | 2012-03-01 21:59:38 -0800 | [diff] [blame] | 63 | void |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 64 | DiffState::update (NameInfoConstPtr info, const SeqNo &seq) |
| 65 | { |
Alexander Afanasyev | b5547e3 | 2012-03-01 21:59:38 -0800 | [diff] [blame] | 66 | m_leaves.erase (*info); |
| 67 | |
| 68 | DiffLeafPtr leaf = make_shared<DiffLeaf> (info, cref (seq)); |
| 69 | m_leaves.insert (leaf); |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 70 | } |
| 71 | |
Alexander Afanasyev | b5547e3 | 2012-03-01 21:59:38 -0800 | [diff] [blame] | 72 | void |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 73 | DiffState::remove (NameInfoConstPtr info) |
| 74 | { |
Alexander Afanasyev | b5547e3 | 2012-03-01 21:59:38 -0800 | [diff] [blame] | 75 | m_leaves.erase (*info); |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 76 | |
Alexander Afanasyev | b5547e3 | 2012-03-01 21:59:38 -0800 | [diff] [blame] | 77 | DiffLeafPtr leaf = make_shared<DiffLeaf> (info); |
| 78 | m_leaves.insert (leaf); |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | |
| 82 | } // ns3 |
| 83 | } // Sync |