blob: d0b6f6cce625762735b30551b9e6c3c5baa7822c [file] [log] [blame]
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -08001/* -*- 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 Afanasyevb5547e32012-03-01 21:59:38 -080024#include "sync-diff-leaf.h"
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080025
26#include <boost/make_shared.hpp>
27
28using namespace boost;
29
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080030namespace Sync {
31
32DiffState::DiffState ()
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080033{
34}
35
36DiffState::~DiffState ()
37{
38}
39
40DiffStatePtr
41DiffState::diff () const
42{
43 DiffStatePtr ret = make_shared<DiffState> ();
44
Alexander Afanasyevb5547e32012-03-01 21:59:38 -080045 DiffStatePtr state = m_next;
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080046 while (state != 0)
47 {
48 *ret += *state;
49 state = state->m_next;
50 }
51
52 return ret;
53}
54
55DiffState &
56DiffState::operator += (const DiffState &state)
57{
58 return *this;
59}
60
61// from State
Alexander Afanasyevb5547e32012-03-01 21:59:38 -080062void
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080063DiffState::update (NameInfoConstPtr info, const SeqNo &seq)
64{
Alexander Afanasyevb5547e32012-03-01 21:59:38 -080065 m_leaves.erase (*info);
66
67 DiffLeafPtr leaf = make_shared<DiffLeaf> (info, cref (seq));
68 m_leaves.insert (leaf);
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080069}
70
Alexander Afanasyevb5547e32012-03-01 21:59:38 -080071void
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080072DiffState::remove (NameInfoConstPtr info)
73{
Alexander Afanasyevb5547e32012-03-01 21:59:38 -080074 m_leaves.erase (*info);
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080075
Alexander Afanasyevb5547e32012-03-01 21:59:38 -080076 DiffLeafPtr leaf = make_shared<DiffLeaf> (info);
77 m_leaves.insert (leaf);
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080078}
79
80
81} // ns3