blob: 567ab7e2ca9c2fb2398fba69ea7a5ffb97869ac3 [file] [log] [blame]
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -08001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2/*
Alexander Afanasyev8722d872014-07-02 13:00:29 -07003 * Copyright (c) 2012-2014 University of California, Los Angeles
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -08004 *
Alexander Afanasyev8722d872014-07-02 13:00:29 -07005 * This file is part of ChronoSync, synchronization library for distributed realtime
6 * applications for NDN.
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -08007 *
Alexander Afanasyev8722d872014-07-02 13:00:29 -07008 * ChronoSync is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation, either
10 * version 3 of the License, or (at your option) any later version.
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080011 *
Alexander Afanasyev8722d872014-07-02 13:00:29 -070012 * ChronoSync is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080015 *
Alexander Afanasyev8722d872014-07-02 13:00:29 -070016 * You should have received a copy of the GNU General Public License along with
17 * ChronoSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * @author Zhenkai Zhu <http://irl.cs.ucla.edu/~zhenkai/>
20 * @author Chaoyi Bian <bcy@pku.edu.cn>
21 * @author Alexander Afanasyev <http://lasr.cs.ucla.edu/afanasyev/index.html>
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080022 */
23
24#ifndef SYNC_LEAF_H
25#define SYNC_LEAF_H
26
27#include "sync-seq-no.h"
Alexander Afanasyevb5547e32012-03-01 21:59:38 -080028#include "sync-name-info.h"
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080029
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080030namespace Sync {
31
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080032/**
33 * \ingroup sync
34 * @brief Sync tree leaf
35 */
36class Leaf
37{
38public:
39 /**
40 * @brief Constructor
41 * @param info Smart pointer to leaf's name
42 * @param seq Initial sequence number of the pointer
43 */
Alexander Afanasyeve00ffbe2012-03-05 00:01:36 -080044 Leaf (NameInfoConstPtr info, const SeqNo &seq);
Alexander Afanasyev1fbdcdd2012-03-05 23:14:33 -080045 virtual ~Leaf ();
Yingdi Yu7c64e5c2014-04-30 14:06:37 -070046
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080047 /**
48 * @brief Get name of the leaf
49 */
Alexander Afanasyeve4e2bf72012-03-12 12:44:54 -070050 NameInfoConstPtr
51 getInfo () const { return m_info; }
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080052
53 /**
54 * @brief Get sequence number of the leaf
55 */
56 const SeqNo&
Alexander Afanasyeve00ffbe2012-03-05 00:01:36 -080057 getSeq () const { return m_seq; }
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080058
59 /**
60 * @brief Update sequence number of the leaf
61 * @param seq Sequence number
62 *
63 * Sequence number is updated to the largest value among this->m_seq and seq
64 */
Alexander Afanasyeve00ffbe2012-03-05 00:01:36 -080065 virtual void
66 setSeq (const SeqNo &seq);
Yingdi Yu7c64e5c2014-04-30 14:06:37 -070067
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080068private:
69 NameInfoConstPtr m_info;
70 SeqNo m_seq;
71};
72
73typedef boost::shared_ptr<Leaf> LeafPtr;
Alexander Afanasyevd94542d2012-03-05 08:41:46 -080074typedef boost::shared_ptr<const Leaf> LeafConstPtr;
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080075
Alexander Afanasyeva4ce9cf2012-03-06 14:29:58 -080076inline std::ostream &
77operator << (std::ostream &os, const Leaf &leaf)
78{
Alexander Afanasyev5548c042012-10-04 19:10:09 -070079 os << *leaf.getInfo () << "(" << leaf.getSeq () << ")";
Alexander Afanasyeva4ce9cf2012-03-06 14:29:58 -080080 return os;
81}
82
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080083} // Sync
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080084
85#endif // SYNC_LEAF_H