Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 1 | /* -*- 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 Afanasyev | 87c9b5d | 2012-03-07 17:23:21 -0800 | [diff] [blame] | 27 | #include <boost/exception/all.hpp> |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 28 | |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 29 | namespace Sync { |
| 30 | |
| 31 | /** |
| 32 | * @ingroup sync |
| 33 | * @brief Annotation for SYNC leaf |
| 34 | */ |
| 35 | enum 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 | */ |
| 45 | class DiffLeaf : public Leaf |
| 46 | { |
| 47 | public: |
| 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 Afanasyev | e00ffbe | 2012-03-05 00:01:36 -0800 | [diff] [blame] | 53 | DiffLeaf (NameInfoConstPtr info, const SeqNo &seq); |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 54 | |
| 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 Afanasyev | e00ffbe | 2012-03-05 00:01:36 -0800 | [diff] [blame] | 62 | DiffLeaf (NameInfoConstPtr info); |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 63 | |
Alexander Afanasyev | e00ffbe | 2012-03-05 00:01:36 -0800 | [diff] [blame] | 64 | virtual ~DiffLeaf () { } |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 65 | |
Alexander Afanasyev | e00ffbe | 2012-03-05 00:01:36 -0800 | [diff] [blame] | 66 | /** |
| 67 | * @brief Get diff leaf type |
| 68 | */ |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 69 | Operation |
Alexander Afanasyev | e00ffbe | 2012-03-05 00:01:36 -0800 | [diff] [blame] | 70 | getOperation () const { return m_op; } |
| 71 | |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 72 | private: |
| 73 | Operation m_op; |
| 74 | }; |
| 75 | |
Alexander Afanasyev | b5547e3 | 2012-03-01 21:59:38 -0800 | [diff] [blame] | 76 | typedef boost::shared_ptr<DiffLeaf> DiffLeafPtr; |
| 77 | |
Alexander Afanasyev | 87c9b5d | 2012-03-07 17:23:21 -0800 | [diff] [blame] | 78 | std::ostream & |
| 79 | operator << (std::ostream &os, Operation op); |
| 80 | |
| 81 | std::istream & |
| 82 | operator >> (std::istream &is, Operation &op); |
| 83 | |
Alexander Afanasyev | c103019 | 2012-03-08 22:21:28 -0800 | [diff] [blame] | 84 | namespace Error { |
Alexander Afanasyev | 87c9b5d | 2012-03-07 17:23:21 -0800 | [diff] [blame] | 85 | struct SyncDiffLeafOperationParseError : virtual boost::exception, virtual std::exception { }; |
Alexander Afanasyev | c103019 | 2012-03-08 22:21:28 -0800 | [diff] [blame] | 86 | } // Error |
Alexander Afanasyev | 87c9b5d | 2012-03-07 17:23:21 -0800 | [diff] [blame] | 87 | |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 88 | } // Sync |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 89 | |
| 90 | #endif // SYNC_DIFF_LEAF_H |