blob: 75e0be5ce9c2d5541b1a1901ee32ac012c6af9bc [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>
Alexander Afanasyev64d50692012-03-07 20:48:35 -080027#include <boost/foreach.hpp>
28#include <boost/assert.hpp>
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080029
30using namespace boost;
31
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080032namespace Sync {
33
34DiffState::DiffState ()
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080035{
36}
37
38DiffState::~DiffState ()
39{
40}
41
42DiffStatePtr
43DiffState::diff () const
44{
45 DiffStatePtr ret = make_shared<DiffState> ();
46
Alexander Afanasyevb5547e32012-03-01 21:59:38 -080047 DiffStatePtr state = m_next;
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080048 while (state != 0)
49 {
50 *ret += *state;
51 state = state->m_next;
52 }
53
54 return ret;
55}
56
57DiffState &
58DiffState::operator += (const DiffState &state)
59{
60 return *this;
61}
62
63// from State
Alexander Afanasyevb5547e32012-03-01 21:59:38 -080064void
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080065DiffState::update (NameInfoConstPtr info, const SeqNo &seq)
66{
Alexander Afanasyevb5547e32012-03-01 21:59:38 -080067 m_leaves.erase (*info);
68
69 DiffLeafPtr leaf = make_shared<DiffLeaf> (info, cref (seq));
70 m_leaves.insert (leaf);
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080071}
72
Alexander Afanasyevb5547e32012-03-01 21:59:38 -080073void
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080074DiffState::remove (NameInfoConstPtr info)
75{
Alexander Afanasyevb5547e32012-03-01 21:59:38 -080076 m_leaves.erase (*info);
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080077
Alexander Afanasyevb5547e32012-03-01 21:59:38 -080078 DiffLeafPtr leaf = make_shared<DiffLeaf> (info);
79 m_leaves.insert (leaf);
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080080}
81
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080082} // ns3