blob: b26a7568c67350dcd5adff173b18bfffa95a6ea0 [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"
24
25#include <boost/make_shared.hpp>
26
27using namespace boost;
28
29namespace ns3 {
30namespace Sync {
31
32DiffState::DiffState ()
33 : m_next (0)
34{
35}
36
37DiffState::~DiffState ()
38{
39}
40
41DiffStatePtr
42DiffState::diff () const
43{
44 DiffStatePtr ret = make_shared<DiffState> ();
45
46 DiffState *state = m_next;
47 while (state != 0)
48 {
49 *ret += *state;
50 state = state->m_next;
51 }
52
53 return ret;
54}
55
56DiffState &
57DiffState::operator += (const DiffState &state)
58{
59 return *this;
60}
61
62// from State
63virtual void
64DiffState::update (NameInfoConstPtr info, const SeqNo &seq)
65{
66 LeafContainer::iterator item = m_leafs.find (info);
67 if (item != m_leafs.end ())
68 m_leafs.remove (item);
69
70 m_leafs.insert (make_shared<DiffLeaf> (info, cref (seq)));
71}
72
73virtual void
74DiffState::remove (NameInfoConstPtr info)
75{
76 LeafContainer::iterator item = m_leafs.find (info);
77 if (item != m_leafs.end ())
78 m_leafs.remove (item);
79
80 m_leafs.insert (make_shared<DiffLeaf> (info));
81}
82
83
84} // ns3
85} // Sync