blob: 65323d3bb8adc538d420a1128b685be2929b3aef [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 Afanasyeve4e2bf72012-03-12 12:44:54 -070064bool
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080065DiffState::update (NameInfoConstPtr info, const SeqNo &seq)
66{
Alexander Afanasyeve4e2bf72012-03-12 12:44:54 -070067 m_leaves.erase (info);
Alexander Afanasyevb5547e32012-03-01 21:59:38 -080068
69 DiffLeafPtr leaf = make_shared<DiffLeaf> (info, cref (seq));
70 m_leaves.insert (leaf);
Alexander Afanasyeve4e2bf72012-03-12 12:44:54 -070071
72 return true;
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080073}
74
Alexander Afanasyeve4e2bf72012-03-12 12:44:54 -070075bool
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080076DiffState::remove (NameInfoConstPtr info)
77{
Alexander Afanasyeve4e2bf72012-03-12 12:44:54 -070078 m_leaves.erase (info);
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080079
Alexander Afanasyevb5547e32012-03-01 21:59:38 -080080 DiffLeafPtr leaf = make_shared<DiffLeaf> (info);
81 m_leaves.insert (leaf);
Alexander Afanasyeve4e2bf72012-03-12 12:44:54 -070082
83 return true;
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080084}
85
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080086} // ns3