blob: 80527d696631e2bd388a66e56d638f0291409b29 [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 */
Alexander Afanasyeve00ffbe2012-03-05 00:01:36 -080023
24#include "sync-diff-leaf.h"
Alexander Afanasyev87c9b5d2012-03-07 17:23:21 -080025#include <boost/throw_exception.hpp>
Yingdi Yu7c64e5c2014-04-30 14:06:37 -070026typedef boost::error_info<struct tag_errmsg, std::string> errmsg_info;
Alexander Afanasyeve00ffbe2012-03-05 00:01:36 -080027
Alexander Afanasyevc1030192012-03-08 22:21:28 -080028using namespace Sync::Error;
29
Alexander Afanasyeve00ffbe2012-03-05 00:01:36 -080030namespace Sync {
31
32DiffLeaf::DiffLeaf (NameInfoConstPtr info, const SeqNo &seq)
33 : Leaf (info, seq)
34 , m_op (UPDATE)
35{
36}
37
38DiffLeaf::DiffLeaf (NameInfoConstPtr info)
39 : Leaf (info, SeqNo (0,0))
40 , m_op (REMOVE)
41{
42}
43
Alexander Afanasyev87c9b5d2012-03-07 17:23:21 -080044std::ostream &
45operator << (std::ostream &os, Operation op)
46{
47 switch (op)
48 {
49 case UPDATE:
50 os << "update";
51 break;
52 case REMOVE:
53 os << "remove";
54 break;
55 }
56 return os;
57}
58
59std::istream &
60operator >> (std::istream &is, Operation &op)
61{
62 std::string operation;
63 is >> operation;
64 if (operation == "update")
65 op = UPDATE;
66 else if (operation == "remove")
67 op = REMOVE;
68 else
69 BOOST_THROW_EXCEPTION (SyncDiffLeafOperationParseError () << errmsg_info (operation));
70
71 return is;
72}
73
74
Alexander Afanasyeve00ffbe2012-03-05 00:01:36 -080075}