blob: 1e3143a43379341e571eb86dcfcd9be4ac70a253 [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#ifndef SYNC_DIFF_LEAF_H
24#define SYNC_DIFF_LEAF_H
25
26#include "sync-leaf.h"
Alexander Afanasyev87c9b5d2012-03-07 17:23:21 -080027#include <boost/exception/all.hpp>
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080028
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080029namespace Sync {
30
31/**
32 * @ingroup sync
33 * @brief Annotation for SYNC leaf
34 */
35enum Operation
36 {
37 UPDATE, ///< @brief Leaf was added or updated
38 REMOVE ///< @brief Leaf was removed
39 };
40
41/**
42 * @ingroup sync
43 * @brief Annotated SYNC leaf
44 */
45class DiffLeaf : public Leaf
46{
47public:
48 /**
49 * @brief Constructor to create an UPDATE diff leaf
50 * @param info Smart pointer to leaf's name
51 * @param seq Initial sequence number of the pointer
52 */
Alexander Afanasyeve00ffbe2012-03-05 00:01:36 -080053 DiffLeaf (NameInfoConstPtr info, const SeqNo &seq);
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080054
55 /**
56 * @brief Constructor to create an REMOVE diff leaf
57 * @param info Smart pointer to leaf's name
58 *
59 * This constructor creates a leaf with phony sequence number
60 * with 0 session ID and 0 sequence number
61 */
Alexander Afanasyeve00ffbe2012-03-05 00:01:36 -080062 DiffLeaf (NameInfoConstPtr info);
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080063
Alexander Afanasyeve00ffbe2012-03-05 00:01:36 -080064 virtual ~DiffLeaf () { }
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080065
Alexander Afanasyeve00ffbe2012-03-05 00:01:36 -080066 /**
67 * @brief Get diff leaf type
68 */
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080069 Operation
Alexander Afanasyeve00ffbe2012-03-05 00:01:36 -080070 getOperation () const { return m_op; }
71
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080072private:
73 Operation m_op;
74};
75
Alexander Afanasyevb5547e32012-03-01 21:59:38 -080076typedef boost::shared_ptr<DiffLeaf> DiffLeafPtr;
77
Alexander Afanasyev87c9b5d2012-03-07 17:23:21 -080078std::ostream &
79operator << (std::ostream &os, Operation op);
80
81std::istream &
82operator >> (std::istream &is, Operation &op);
83
Alexander Afanasyevc1030192012-03-08 22:21:28 -080084namespace Error {
Alexander Afanasyev87c9b5d2012-03-07 17:23:21 -080085struct SyncDiffLeafOperationParseError : virtual boost::exception, virtual std::exception { };
Alexander Afanasyevc1030192012-03-08 22:21:28 -080086} // Error
Alexander Afanasyev87c9b5d2012-03-07 17:23:21 -080087
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080088} // Sync
Alexander Afanasyev7a696fb2012-03-01 17:17:22 -080089
90#endif // SYNC_DIFF_LEAF_H