akmhoque | 66e6618 | 2014-02-21 17:56:03 -0600 | [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" |
| 27 | #include <boost/exception/all.hpp> |
| 28 | |
| 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 | */ |
| 53 | DiffLeaf (NameInfoConstPtr info, const SeqNo &seq); |
| 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 | */ |
| 62 | DiffLeaf (NameInfoConstPtr info); |
| 63 | |
| 64 | virtual ~DiffLeaf () { } |
| 65 | |
| 66 | /** |
| 67 | * @brief Get diff leaf type |
| 68 | */ |
| 69 | Operation |
| 70 | getOperation () const { return m_op; } |
| 71 | |
| 72 | private: |
| 73 | Operation m_op; |
| 74 | }; |
| 75 | |
| 76 | typedef boost::shared_ptr<DiffLeaf> DiffLeafPtr; |
| 77 | typedef boost::shared_ptr<const DiffLeaf> DiffLeafConstPtr; |
| 78 | |
| 79 | std::ostream & |
| 80 | operator << (std::ostream &os, Operation op); |
| 81 | |
| 82 | std::istream & |
| 83 | operator >> (std::istream &is, Operation &op); |
| 84 | |
| 85 | namespace Error { |
| 86 | struct SyncDiffLeafOperationParseError : virtual boost::exception, virtual std::exception { }; |
| 87 | } // Error |
| 88 | |
| 89 | } // Sync |
| 90 | |
| 91 | #endif // SYNC_DIFF_LEAF_H |