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 | |
Alexander Afanasyev | de505f2 | 2012-03-02 11:45:45 -0800 | [diff] [blame^] | 23 | #include "sync-ns3-name-info.h" |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 24 | #include "ns3/ccnx-name-components.h" |
| 25 | |
| 26 | #include <boost/lexical_cast.hpp> |
Alexander Afanasyev | b5547e3 | 2012-03-01 21:59:38 -0800 | [diff] [blame] | 27 | #include <utility> |
| 28 | |
| 29 | using namespace std; |
| 30 | using namespace boost; |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 31 | |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 32 | namespace Sync { |
| 33 | |
Alexander Afanasyev | b5547e3 | 2012-03-01 21:59:38 -0800 | [diff] [blame] | 34 | NameInfoConstPtr |
Alexander Afanasyev | de505f2 | 2012-03-02 11:45:45 -0800 | [diff] [blame^] | 35 | Ns3NameInfo::FindOrCreate (ns3::Ptr<const ns3::CcnxNameComponents> name) |
Alexander Afanasyev | b5547e3 | 2012-03-01 21:59:38 -0800 | [diff] [blame] | 36 | { |
| 37 | string key = lexical_cast<string> (*name); |
| 38 | |
Alexander Afanasyev | de505f2 | 2012-03-02 11:45:45 -0800 | [diff] [blame^] | 39 | NameInfoPtr value = NameInfoPtr (new Ns3NameInfo (name)); |
Alexander Afanasyev | b5547e3 | 2012-03-01 21:59:38 -0800 | [diff] [blame] | 40 | pair<NameMap::iterator,bool> item = |
| 41 | m_names.insert (make_pair (key, value)); |
| 42 | |
| 43 | return item.first->second; |
| 44 | } |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 45 | |
Alexander Afanasyev | de505f2 | 2012-03-02 11:45:45 -0800 | [diff] [blame^] | 46 | Ns3NameInfo::Ns3NameInfo (ns3::Ptr<const ns3::CcnxNameComponents> name) |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 47 | : m_name (name) |
| 48 | { |
Alexander Afanasyev | b5547e3 | 2012-03-01 21:59:38 -0800 | [diff] [blame] | 49 | m_id = m_ids ++; // set ID for a newly inserted element |
Alexander Afanasyev | 017784c | 2012-03-02 11:44:13 -0800 | [diff] [blame] | 50 | // m_digest << *name; |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 51 | } |
| 52 | |
Alexander Afanasyev | b5547e3 | 2012-03-01 21:59:38 -0800 | [diff] [blame] | 53 | string |
Alexander Afanasyev | de505f2 | 2012-03-02 11:45:45 -0800 | [diff] [blame^] | 54 | Ns3NameInfo::toString () const |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 55 | { |
Alexander Afanasyev | b5547e3 | 2012-03-01 21:59:38 -0800 | [diff] [blame] | 56 | return lexical_cast<std::string> (*m_name); |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 57 | } |
| 58 | |
Alexander Afanasyev | b5547e3 | 2012-03-01 21:59:38 -0800 | [diff] [blame] | 59 | bool |
Alexander Afanasyev | de505f2 | 2012-03-02 11:45:45 -0800 | [diff] [blame^] | 60 | Ns3NameInfo::operator == (const NameInfo &info) const |
Alexander Afanasyev | b5547e3 | 2012-03-01 21:59:38 -0800 | [diff] [blame] | 61 | { |
| 62 | try |
| 63 | { |
Alexander Afanasyev | de505f2 | 2012-03-02 11:45:45 -0800 | [diff] [blame^] | 64 | return *m_name == *dynamic_cast<const Ns3NameInfo&> (info).m_name; |
Alexander Afanasyev | b5547e3 | 2012-03-01 21:59:38 -0800 | [diff] [blame] | 65 | } |
| 66 | catch (...) |
| 67 | { |
| 68 | return false; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | |
Alexander Afanasyev | 7a696fb | 2012-03-01 17:17:22 -0800 | [diff] [blame] | 73 | } // Sync |