blob: 0790ec74a75555d75283e798777691cabe68725e [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 */
Alexander Afanasyeve00ffbe2012-03-05 00:01:36 -080022
23#include "sync-diff-leaf.h"
Alexander Afanasyev87c9b5d2012-03-07 17:23:21 -080024#include <boost/throw_exception.hpp>
25typedef boost::error_info<struct tag_errmsg, std::string> errmsg_info;
Alexander Afanasyeve00ffbe2012-03-05 00:01:36 -080026
27namespace Sync {
28
29DiffLeaf::DiffLeaf (NameInfoConstPtr info, const SeqNo &seq)
30 : Leaf (info, seq)
31 , m_op (UPDATE)
32{
33}
34
35DiffLeaf::DiffLeaf (NameInfoConstPtr info)
36 : Leaf (info, SeqNo (0,0))
37 , m_op (REMOVE)
38{
39}
40
Alexander Afanasyev87c9b5d2012-03-07 17:23:21 -080041std::ostream &
42operator << (std::ostream &os, Operation op)
43{
44 switch (op)
45 {
46 case UPDATE:
47 os << "update";
48 break;
49 case REMOVE:
50 os << "remove";
51 break;
52 }
53 return os;
54}
55
56std::istream &
57operator >> (std::istream &is, Operation &op)
58{
59 std::string operation;
60 is >> operation;
61 if (operation == "update")
62 op = UPDATE;
63 else if (operation == "remove")
64 op = REMOVE;
65 else
66 BOOST_THROW_EXCEPTION (SyncDiffLeafOperationParseError () << errmsg_info (operation));
67
68 return is;
69}
70
71
Alexander Afanasyeve00ffbe2012-03-05 00:01:36 -080072}