Chaoyi Bian | a1b231a | 2012-03-07 14:29:55 -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 | #define TIXML_USE_STL |
| 24 | |
| 25 | #include <string> |
| 26 | #include <tinyxml.h> |
| 27 | #include "sync-state.h" |
| 28 | #include "sync-std-name-info.h" |
| 29 | |
| 30 | using namespace std; |
| 31 | |
| 32 | namespace Sync |
| 33 | { |
| 34 | string & operator >> (string &DataBuffer, State &state) |
| 35 | { |
| 36 | TiXmlDocument doc; |
| 37 | |
| 38 | doc.Parse(DataBuffer.c_str()); |
| 39 | for (TiXmlElement *iterator = doc.RootElement(); iterator != NULL; iterator = iterator->NextSiblingElement()) |
| 40 | { |
| 41 | if (strcmp(iterator->Attribute("action"), "UPDATE") == 0) |
| 42 | { |
| 43 | TiXmlElement *name = iterator->FirstChildElement(); |
| 44 | TiXmlElement *session = name->NextSiblingElement(); |
| 45 | TiXmlElement *sequence = session->NextSiblingElement(); |
| 46 | NameInfoConstPtr info = StdNameInfo::FindOrCreate(name->GetText()); |
| 47 | SeqNo seqNo(atoi(session->GetText()), atoi(sequence->GetText())); |
| 48 | |
| 49 | state.update(info, seqNo); |
| 50 | } |
| 51 | else |
| 52 | { |
| 53 | TiXmlElement *name = iterator->FirstChildElement(); |
| 54 | NameInfoConstPtr info = StdNameInfo::FindOrCreate(name->GetText()); |
| 55 | state.remove(info); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | return DataBuffer; |
| 60 | } |
| 61 | } |